From af7872ffd1fb437c663430d29a5d6e674db1ca90 Mon Sep 17 00:00:00 2001 From: Yu Zhang Date: Thu, 23 Feb 2023 17:00:04 -0800 Subject: [PATCH] Fix a TestGet failure when user defined timestamp is enabled (#11249) Summary: Stressing small DB with small number of keys and user-defined timestamp enabled usually fails pretty quickly in TestGet. Example command to reproduce the failure: ` tools/db_crashtest.py blackbox --enable_ts --simple --delrangepercent=0 --delpercent=5 --max_key=100 --interval=3 --write_buffer_size=262144 --target_file_size_base=262144 --max_bytes_for_level_base=262144 --subcompactions=1` Example failure: `error : inconsistent values for key 0000000000000009000000000000000A7878: expected state has the key, Get() returns NotFound.` Fixes this test failure by refreshing the read up to timestamp to the most up to date timestamp, a.k.a now, after a key is locked. Without this, things could happen in this order and cause a test failure:
TestGet thread A writing thread
read_opts.timestamp = GetNow()
Lock key, do write
Lock key, read(read_opts) return NotFound
Pull Request resolved: https://github.com/facebook/rocksdb/pull/11249 Reviewed By: ltamasi Differential Revision: D43551302 Pulled By: jowlyzhang fbshipit-source-id: 26877ab379bdb97acd2682a2632bc29718427f38 --- db_stress_tool/no_batched_ops_stress.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/db_stress_tool/no_batched_ops_stress.cc b/db_stress_tool/no_batched_ops_stress.cc index b88773e8c..ad9971012 100644 --- a/db_stress_tool/no_batched_ops_stress.cc +++ b/db_stress_tool/no_batched_ops_stress.cc @@ -492,6 +492,11 @@ class NonBatchedOpsStressTest : public StressTest { ReadOptions read_opts_copy = read_opts; std::string read_ts_str; Slice read_ts_slice; + if (FLAGS_user_timestamp_size > 0) { + read_ts_str = GetNowNanos(); + read_ts_slice = read_ts_str; + read_opts_copy.timestamp = &read_ts_slice; + } bool read_older_ts = MaybeUseOlderTimestampForPointLookup( thread, read_ts_str, read_ts_slice, read_opts_copy); @@ -514,7 +519,7 @@ class NonBatchedOpsStressTest : public StressTest { // found case thread->stats.AddGets(1, 1); // we only have the latest expected state - if (!FLAGS_skip_verifydb && !read_opts_copy.timestamp && + if (!FLAGS_skip_verifydb && !read_older_ts && thread->shared->Get(rand_column_families[0], rand_keys[0]) == SharedState::DELETION_SENTINEL) { thread->shared->SetVerificationFailure();