@@ -2548,7 +2548,7 @@ TEST_P(DBIteratorTest, AutoRefreshIterator) {
25482548 Options options = CurrentOptions ();
25492549 options.disable_auto_compactions = true ;
25502550 for (const bool auto_refresh_enabled : {false , true }) {
2551- for (const bool use_snapshot : {false , true }) {
2551+ for (const bool explicit_snapshot : {false , true }) {
25522552 DestroyAndReopen (options);
25532553 // Multi dimensional iterator:
25542554 //
@@ -2566,9 +2566,14 @@ TEST_P(DBIteratorTest, AutoRefreshIterator) {
25662566 }
25672567
25682568 ReadOptions read_options;
2569- read_options.snapshot = use_snapshot ? db_->GetSnapshot () : nullptr ;
2569+ std::unique_ptr<ManagedSnapshot> snapshot = nullptr ;
2570+ if (explicit_snapshot) {
2571+ snapshot = std::make_unique<ManagedSnapshot>(db_);
2572+ }
2573+ read_options.snapshot =
2574+ explicit_snapshot ? snapshot->snapshot () : nullptr ;
25702575 read_options.auto_refresh_iterator_enabled = auto_refresh_enabled;
2571- Iterator* iter = NewIterator (read_options);
2576+ std::unique_ptr< Iterator> iter ( NewIterator (read_options) );
25722577
25732578 // This update should NOT be visible from the iterator.
25742579 ASSERT_OK (Put (Key (5 ), " new val" ));
@@ -2593,24 +2598,13 @@ TEST_P(DBIteratorTest, AutoRefreshIterator) {
25932598 for (iter->SeekToFirst (); iter->Valid (); iter->Next ()) {
25942599 ASSERT_OK (iter->status ());
25952600 it_num++;
2596-
25972601 if (it_num == trigger_compact_on_it) {
25982602 // Bump the superversion by manually scheduling flush + compaction.
25992603 ASSERT_OK (Flush ());
26002604 ASSERT_OK (
26012605 dbfull ()->CompactRange (CompactRangeOptions (), nullptr , nullptr ));
26022606 ASSERT_OK (dbfull ()->TEST_WaitForBackgroundWork ());
26032607
2604- // Flush and compaction background tasks are completed by now.
2605- std::vector<LiveFileMetaData> new_files;
2606- db_->GetLiveFilesMetaData (&new_files);
2607-
2608- // We expect a single, new SST file.
2609- ASSERT_EQ (new_files.size (), 1 );
2610- for (const auto & old_file : old_files) {
2611- ASSERT_TRUE (old_file.file_number != new_files[0 ].file_number );
2612- }
2613-
26142608 // For accuracy, capture the memtables size right before consecutive
26152609 // iterator call to Next() will update its' stale superversion ref.
26162610 dbfull ()->GetIntProperty (" rocksdb.size-all-mem-tables" ,
@@ -2623,10 +2617,12 @@ TEST_P(DBIteratorTest, AutoRefreshIterator) {
26232617 ASSERT_OK (iter->GetProperty (" rocksdb.iterator.super-version-number" ,
26242618 &prop_value));
26252619 uint64_t new_superversion_number = std::stoi (prop_value);
2620+ Status expected_status_for_preexisting_files;
26262621 if (!auto_refresh_enabled) {
26272622 ASSERT_EQ (superversion_number, new_superversion_number);
26282623 ASSERT_EQ (all_memtables_size_after_refresh,
26292624 all_memtables_size_before_refresh);
2625+ expected_status_for_preexisting_files = Status::OK ();
26302626 } else {
26312627 // Iterator is expected to detect its' superversion staleness.
26322628 ASSERT_LT (superversion_number, new_superversion_number);
@@ -2635,6 +2631,12 @@ TEST_P(DBIteratorTest, AutoRefreshIterator) {
26352631 // upon automatical iterator refresh.
26362632 ASSERT_GT (all_memtables_size_before_refresh,
26372633 all_memtables_size_after_refresh);
2634+ expected_status_for_preexisting_files = Status::NotFound ();
2635+ }
2636+
2637+ for (const auto & file : old_files) {
2638+ ASSERT_EQ (env_->FileExists (file.db_path + " /" + file.name ),
2639+ expected_status_for_preexisting_files);
26382640 }
26392641 }
26402642
@@ -2653,11 +2655,6 @@ TEST_P(DBIteratorTest, AutoRefreshIterator) {
26532655 }
26542656 ASSERT_EQ (kv->second , " val" + std::to_string (val));
26552657 }
2656-
2657- delete iter;
2658- if (use_snapshot) {
2659- db_->ReleaseSnapshot (read_options.snapshot );
2660- }
26612658 }
26622659 }
26632660}
0 commit comments