diff --git a/cache/cache_bench_tool.cc b/cache/cache_bench_tool.cc index 2fc5ed34b..56db2fea3 100644 --- a/cache/cache_bench_tool.cc +++ b/cache/cache_bench_tool.cc @@ -114,6 +114,8 @@ DEFINE_uint32( "(-stress_cache_key) Simulated file size in MiB, for accounting purposes"); DEFINE_uint32(sck_reopen_nfiles, 100, "(-stress_cache_key) Simulate DB re-open average every n files"); +DEFINE_uint32(sck_newdb_nreopen, 1000, + "(-stress_cache_key) Simulate new DB average every n re-opens"); DEFINE_uint32(sck_restarts_per_day, 24, "(-stress_cache_key) Average simulated process restarts per day " "(across DBs)"); @@ -780,7 +782,7 @@ class StressCacheKey { void RunOnce() { // Re-initialized simulated state - const size_t db_count = FLAGS_sck_db_count; + const size_t db_count = std::max(size_t{FLAGS_sck_db_count}, size_t{1}); dbs_.reset(new TableProperties[db_count]{}); const size_t table_mask = (size_t{1} << FLAGS_sck_table_bits) - 1; table_.reset(new uint64_t[table_mask + 1]{}); @@ -797,7 +799,8 @@ class StressCacheKey { process_count_ = 0; session_count_ = 0; - ResetProcess(); + newdb_count_ = 0; + ResetProcess(/*newdbs*/ true); Random64 r{std::random_device{}()}; @@ -816,9 +819,9 @@ class StressCacheKey { } // Any other periodic actions before simulating next file if (!FLAGS_sck_footer_unique_id && r.OneIn(FLAGS_sck_reopen_nfiles)) { - ResetSession(db_i); + ResetSession(db_i, /*newdb*/ r.OneIn(FLAGS_sck_newdb_nreopen)); } else if (r.OneIn(restart_nfiles_)) { - ResetProcess(); + ResetProcess(/*newdbs*/ false); } // Simulate next file OffsetableCacheKey ock; @@ -870,7 +873,7 @@ class StressCacheKey { // Our goal is to predict probability of no collisions, not expected // number of collisions. To make the distinction, we have to get rid // of observing correlated collisions, which this takes care of: - ResetProcess(); + ResetProcess(/*newdbs*/ false); } else { // Replace (end of lifetime for file that was in this slot) table_[pos] = reduced_key; @@ -888,10 +891,11 @@ class StressCacheKey { } // Report printf( - "%" PRIu64 " days, %" PRIu64 " proc, %" PRIu64 - " sess, %u coll, occ %g%%, ejected %g%% \r", + "%" PRIu64 " days, %" PRIu64 " proc, %" PRIu64 " sess, %" PRIu64 + " newdb, %u coll, occ %g%%, ejected %g%% \r", file_count / FLAGS_sck_files_per_day, process_count_, - session_count_, collisions_this_run, 100.0 * sampled_count / 1000.0, + session_count_, newdb_count_ - FLAGS_sck_db_count, + collisions_this_run, 100.0 * sampled_count / 1000.0, 100.0 * (1.0 - sampled_count / 1000.0 * table_mask / file_count)); fflush(stdout); } @@ -899,16 +903,27 @@ class StressCacheKey { collisions_ += collisions_this_run; } - void ResetSession(size_t i) { + void ResetSession(size_t i, bool newdb) { dbs_[i].db_session_id = DBImpl::GenerateDbSessionId(nullptr); + if (newdb) { + ++newdb_count_; + if (FLAGS_sck_footer_unique_id) { + // Simulate how footer id would behave + dbs_[i].db_id = "none"; + } else { + // db_id might be ignored, depending on the implementation details + dbs_[i].db_id = std::to_string(newdb_count_); + dbs_[i].orig_file_number = 0; + } + } session_count_++; } - void ResetProcess() { + void ResetProcess(bool newdbs) { process_count_++; DBImpl::TEST_ResetDbSessionIdGen(); for (size_t i = 0; i < FLAGS_sck_db_count; ++i) { - ResetSession(i); + ResetSession(i, newdbs); } if (FLAGS_sck_footer_unique_id) { // For footer unique ID, this tracks process-wide generated SST file @@ -923,6 +938,7 @@ class StressCacheKey { std::unique_ptr table_; uint64_t process_count_ = 0; uint64_t session_count_ = 0; + uint64_t newdb_count_ = 0; uint64_t collisions_ = 0; uint32_t restart_nfiles_ = 0; double multiplier_ = 0.0;