From dae49e829e36a0a0afbec91f19e5c9460b29753e Mon Sep 17 00:00:00 2001 From: sdong Date: Wed, 14 Oct 2015 15:13:46 -0700 Subject: [PATCH] Make DBTest.ReadLatencyHistogramByLevel more robust Summary: Two fixes: 1. Wait compaction after generating each L0 file so that we are sure there are one L0 file left. 2. https://reviews.facebook.net/D48423 increased from 500 keys to 700 keys but in verification phase we are still querying the first 500 keys. It is a bug to fix. Test Plan: Run the test in the same environment that fails by chance of one in tens of times. It doesn't fail after 1000 times. Reviewers: yhchiang, IslamAbdelRahman, igor, rven, kradhakrishnan Reviewed By: rven, kradhakrishnan Subscribers: leveldb, dhruba Differential Revision: https://reviews.facebook.net/D48759 --- db/db_test.cc | 9 +++++---- util/histogram.cc | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/db/db_test.cc b/db/db_test.cc index 6503ded82..5ba988b3c 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -657,9 +657,10 @@ TEST_F(DBTest, ReadLatencyHistogramByLevel) { DestroyAndReopen(options); int key_index = 0; Random rnd(301); - for (int num = 0; num < 7; num++) { + for (int num = 0; num < 8; num++) { Put("foo", "bar"); GenerateNewFile(&rnd, &key_index); + dbfull()->TEST_WaitForCompact(); } dbfull()->TEST_WaitForCompact(); @@ -667,7 +668,7 @@ TEST_F(DBTest, ReadLatencyHistogramByLevel) { ASSERT_TRUE(dbfull()->GetProperty("rocksdb.dbstats", &prop)); // Get() after flushes, See latency histogram tracked. - for (int key = 0; key < 500; key++) { + for (int key = 0; key < key_index; key++) { Get(Key(key)); } ASSERT_TRUE(dbfull()->GetProperty("rocksdb.dbstats", &prop)); @@ -678,7 +679,7 @@ TEST_F(DBTest, ReadLatencyHistogramByLevel) { // Reopen and issue Get(). See thee latency tracked Reopen(options); dbfull()->TEST_WaitForCompact(); - for (int key = 0; key < 500; key++) { + for (int key = 0; key < key_index; key++) { Get(Key(key)); } ASSERT_TRUE(dbfull()->GetProperty("rocksdb.dbstats", &prop)); @@ -709,7 +710,7 @@ TEST_F(DBTest, ReadLatencyHistogramByLevel) { ASSERT_NE(std::string::npos, prop.find("** Level 0 read latency histogram")); ASSERT_NE(std::string::npos, prop.find("** Level 1 read latency histogram")); ASSERT_EQ(std::string::npos, prop.find("** Level 2 read latency histogram")); - for (int key = 0; key < 500; key++) { + for (int key = 0; key < key_index; key++) { Get(Key(key)); } ASSERT_TRUE(dbfull()->GetProperty("rocksdb.dbstats", &prop)); diff --git a/util/histogram.cc b/util/histogram.cc index 5a875e54d..4165121f0 100644 --- a/util/histogram.cc +++ b/util/histogram.cc @@ -82,7 +82,7 @@ void HistogramImpl::Clear() { memset(buckets_, 0, sizeof buckets_); } -bool HistogramImpl::Empty() { return sum_squares_ == 0; } +bool HistogramImpl::Empty() { return num_ == 0; } void HistogramImpl::Add(uint64_t value) { const size_t index = bucketMapper.IndexForValue(value);