]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commit
Fix a data race related to DB properties (#8206)
authorLevi Tamasi <ltamasi@fb.com>
Mon, 19 Apr 2021 23:37:16 +0000 (16:37 -0700)
committerLevi Tamasi <ltamasi@fb.com>
Tue, 20 Apr 2021 17:17:49 +0000 (10:17 -0700)
commitf2228962c5559b6e6ae9ed2d3e91774416dc5d2d
treefb49efd64ed11e8b6d93003d1f3b93d7481ab0b2
parenteef93446a35b4d5eec04cc8191f9740553cfda01
Fix a data race related to DB properties (#8206)

Summary:
Historically, the DB properties `rocksdb.cur-size-active-mem-table`,
`rocksdb.cur-size-all-mem-tables`, and `rocksdb.size-all-mem-tables` called
the method `MemTable::ApproximateMemoryUsage` for mutable memtables,
which is not safe without synchronization. This resulted in data races with
memtable inserts. The patch changes the code handling these properties
to use `MemTable::ApproximateMemoryUsageFast` instead, which returns a
cached value backed by an atomic variable. Two test cases had to be updated
for this change. `MemoryTest.MemTableAndTableReadersTotal` was fixed by
increasing the value size used so each value ends up in its own memtable,
which was the original intention (note: the test has been broken in the sense
that the test code didn't consider that memtable sizes below 64 KB get
increased to 64 KB by `SanitizeOptions`, and has been passing only by
accident). `DBTest.MemoryUsageWithMaxWriteBufferSizeToMaintain` relies on
completely up-to-date values and thus was changed to use `ApproximateMemoryUsage`
directly instead of going through the DB properties. Note: this should be safe in this case
since there's only a single thread involved.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/8206

Test Plan: `make check`

Reviewed By: riversand963

Differential Revision: D27866811

Pulled By: ltamasi

fbshipit-source-id: 7bd754d0565e0a65f1f7f0e78ffc093beef79394
db/db_test.cc
db/internal_stats.cc
utilities/memory/memory_test.cc