fix readampbitmap tests

Summary:
fix test failure of ReadAmpBitmap and ReadAmpBitmapLiveInCacheAfterDBClose.
test ReadAmpBitmapLiveInCacheAfterDBClose individually and make check
Closes https://github.com/facebook/rocksdb/pull/2271

Differential Revision: D5038133

Pulled By: lightmark

fbshipit-source-id: 803cd6f45ccfdd14a9d9473c8af311033e164be8
This commit is contained in:
Aaron Gao 2017-05-10 11:53:28 -07:00
parent 7e62c5d67a
commit 22f277e034

View File

@ -1723,7 +1723,8 @@ TEST_F(DBTest2, ReadAmpBitmapLiveInCacheAfterDBClose) {
// the blocks again regardless of them being already in the cache // the blocks again regardless of them being already in the cache
return; return;
} }
uint32_t bytes_per_bit[2] = {1, 16};
for (size_t k = 0; k < 2; k++) {
std::shared_ptr<Cache> lru_cache = NewLRUCache(1024 * 1024 * 1024); std::shared_ptr<Cache> lru_cache = NewLRUCache(1024 * 1024 * 1024);
std::shared_ptr<Statistics> stats = rocksdb::CreateDBStatistics(); std::shared_ptr<Statistics> stats = rocksdb::CreateDBStatistics();
@ -1733,7 +1734,7 @@ TEST_F(DBTest2, ReadAmpBitmapLiveInCacheAfterDBClose) {
bbto.use_delta_encoding = false; bbto.use_delta_encoding = false;
// Huge block cache to make it easier to calculate read amplification // Huge block cache to make it easier to calculate read amplification
bbto.block_cache = lru_cache; bbto.block_cache = lru_cache;
bbto.read_amp_bytes_per_bit = 16; bbto.read_amp_bytes_per_bit = bytes_per_bit[k];
options.table_factory.reset(NewBlockBasedTableFactory(bbto)); options.table_factory.reset(NewBlockBasedTableFactory(bbto));
options.statistics = stats; options.statistics = stats;
DestroyAndReopen(options); DestroyAndReopen(options);
@ -1755,12 +1756,13 @@ TEST_F(DBTest2, ReadAmpBitmapLiveInCacheAfterDBClose) {
// Iter1: Read half the DB, Read even keys // Iter1: Read half the DB, Read even keys
// Key(0), Key(2), Key(4), Key(6), Key(8), ... // Key(0), Key(2), Key(4), Key(6), Key(8), ...
for (int i = 0; i < kNumEntries; i += 2) { for (int i = 0; i < kNumEntries; i += 2) {
std::string k = Key(i); std::string key = Key(i);
ASSERT_OK(db_->Get(ReadOptions(), k, &value)); ASSERT_OK(db_->Get(ReadOptions(), key, &value));
if (read_keys.find(i) == read_keys.end()) { if (read_keys.find(i) == read_keys.end()) {
auto ik = InternalKey(k, 0, ValueType::kTypeValue); auto internal_key = InternalKey(key, 0, ValueType::kTypeValue);
total_useful_bytes += GetEncodedEntrySize(ik.size(), value.size()); total_useful_bytes +=
GetEncodedEntrySize(internal_key.size(), value.size());
read_keys.insert(i); read_keys.insert(i);
} }
} }
@ -1781,12 +1783,13 @@ TEST_F(DBTest2, ReadAmpBitmapLiveInCacheAfterDBClose) {
// Iter2: Read half the DB, Read odd keys // Iter2: Read half the DB, Read odd keys
// Key(1), Key(3), Key(5), Key(7), Key(9), ... // Key(1), Key(3), Key(5), Key(7), Key(9), ...
for (int i = 1; i < kNumEntries; i += 2) { for (int i = 1; i < kNumEntries; i += 2) {
std::string k = Key(i); std::string key = Key(i);
ASSERT_OK(db_->Get(ReadOptions(), k, &value)); ASSERT_OK(db_->Get(ReadOptions(), key, &value));
if (read_keys.find(i) == read_keys.end()) { if (read_keys.find(i) == read_keys.end()) {
auto ik = InternalKey(k, 0, ValueType::kTypeValue); auto internal_key = InternalKey(key, 0, ValueType::kTypeValue);
total_useful_bytes += GetEncodedEntrySize(ik.size(), value.size()); total_useful_bytes +=
GetEncodedEntrySize(internal_key.size(), value.size());
read_keys.insert(i); read_keys.insert(i);
} }
} }
@ -1796,9 +1799,17 @@ TEST_F(DBTest2, ReadAmpBitmapLiveInCacheAfterDBClose) {
size_t total_loaded_bytes_iter2 = size_t total_loaded_bytes_iter2 =
options.statistics->getTickerCount(READ_AMP_TOTAL_READ_BYTES); options.statistics->getTickerCount(READ_AMP_TOTAL_READ_BYTES);
// We reached read_amp of 100% because we read all the keys in the DB
// Read amp is on average 100% since we read all what we loaded in memory
if (k == 0) {
ASSERT_EQ(total_useful_bytes_iter1 + total_useful_bytes_iter2, ASSERT_EQ(total_useful_bytes_iter1 + total_useful_bytes_iter2,
total_loaded_bytes_iter1 + total_loaded_bytes_iter2); total_loaded_bytes_iter1 + total_loaded_bytes_iter2);
} else {
ASSERT_NEAR((total_useful_bytes_iter1 + total_useful_bytes_iter2) * 1.0f /
(total_loaded_bytes_iter1 + total_loaded_bytes_iter2),
1, .01);
}
}
} }
#ifndef ROCKSDB_LITE #ifndef ROCKSDB_LITE