Fix tsan error

Summary:
The tsan error was because the random implementation we have is not
thread safe, using Random::GetTLSInstance

Test Plan: Run tests in Linux

Reviewers: sdong

Subscribers: andrewkr, dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D59559
main
krad 9 years ago
parent bc8af90e8c
commit 81f6b33d93
  1. 4
      utilities/persistent_cache/hash_table_evictable.h
  2. 2
      utilities/persistent_cache/persistent_cache_test.cc

@ -76,7 +76,8 @@ class EvictableHashTable : private HashTable<T*, Hash, Equal> {
// Evict one of the least recently used object // Evict one of the least recently used object
// //
T* Evict(const std::function<void(T*)>& fn = nullptr) { T* Evict(const std::function<void(T*)>& fn = nullptr) {
const size_t start_idx = rand_.Next() % hash_table::nlocks_; uint32_t random = Random::GetTLSInstance()->Next();
const size_t start_idx = random % hash_table::nlocks_;
T* t = nullptr; T* t = nullptr;
// iterate from start_idx .. 0 .. start_idx // iterate from start_idx .. 0 .. start_idx
@ -157,7 +158,6 @@ class EvictableHashTable : private HashTable<T*, Hash, Equal> {
return hash_table::locks_[lock_idx]; return hash_table::locks_[lock_idx];
} }
Random64 rand_{static_cast<uint64_t>(time(nullptr))};
std::unique_ptr<LRUListType[]> lru_lists_; std::unique_ptr<LRUListType[]> lru_lists_;
}; };

@ -26,7 +26,6 @@ TEST_F(PersistentCacheTierTest, VolatileCacheInsert) {
} }
} }
#ifndef ROCKSDB_TSAN_RUN
TEST_F(PersistentCacheTierTest, VolatileCacheInsertWithEviction) { TEST_F(PersistentCacheTierTest, VolatileCacheInsertWithEviction) {
for (auto nthreads : {1, 5}) { for (auto nthreads : {1, 5}) {
for (auto max_keys : {1 * 1024 * 1024}) { for (auto max_keys : {1 * 1024 * 1024}) {
@ -36,7 +35,6 @@ TEST_F(PersistentCacheTierTest, VolatileCacheInsertWithEviction) {
} }
} }
} }
#endif
// test table with volatile page cache // test table with volatile page cache
TEST_F(PersistentCacheDBTest, VolatileCacheTest) { TEST_F(PersistentCacheDBTest, VolatileCacheTest) {

Loading…
Cancel
Save