From 20dea55bb781ede1ba7e82484605be4d2beaaaf2 Mon Sep 17 00:00:00 2001 From: Peter Dillinger Date: Tue, 4 Feb 2025 12:53:26 -0800 Subject: [PATCH] [NO COMMIT] Validate usage of allow_refresh=false --- db/arena_wrapped_db_iter.cc | 1 + db/db_impl/db_impl.cc | 3 +++ db/db_impl/db_impl.h | 2 ++ table/sst_file_reader.cc | 2 ++ utilities/transactions/write_prepared_txn_db.cc | 3 +++ utilities/transactions/write_unprepared_txn_db.cc | 2 ++ 6 files changed, 13 insertions(+) diff --git a/db/arena_wrapped_db_iter.cc b/db/arena_wrapped_db_iter.cc index 27cae5eb199..50d203424ea 100644 --- a/db/arena_wrapped_db_iter.cc +++ b/db/arena_wrapped_db_iter.cc @@ -60,6 +60,7 @@ void ArenaWrappedDBIter::Init( cfh, expose_blob_index); sv_number_ = version_number; + assert(allow_refresh || gAllowFalseAllowRefresh); allow_refresh_ = allow_refresh; memtable_range_tombstone_iter_ = nullptr; } diff --git a/db/db_impl/db_impl.cc b/db/db_impl/db_impl.cc index 97fa3ccbcf6..12442fc68cc 100644 --- a/db/db_impl/db_impl.cc +++ b/db/db_impl/db_impl.cc @@ -116,6 +116,9 @@ namespace ROCKSDB_NAMESPACE { +// XXX: debug only +thread_local bool gAllowFalseAllowRefresh = false; + const std::string kDefaultColumnFamilyName("default"); const std::string kPersistentStatsColumnFamilyName( "___rocksdb_stats_history___"); diff --git a/db/db_impl/db_impl.h b/db/db_impl/db_impl.h index bb2ff6eee95..fc5568270af 100644 --- a/db/db_impl/db_impl.h +++ b/db/db_impl/db_impl.h @@ -72,6 +72,8 @@ namespace ROCKSDB_NAMESPACE { +extern thread_local bool gAllowFalseAllowRefresh; + class Arena; class ArenaWrappedDBIter; class InMemoryStatsHistoryIterator; diff --git a/table/sst_file_reader.cc b/table/sst_file_reader.cc index 847497bad55..c3c7d43daea 100644 --- a/table/sst_file_reader.cc +++ b/table/sst_file_reader.cc @@ -16,6 +16,7 @@ #include "table/table_builder.h" #include "table/table_iterator.h" #include "table/table_reader.h" +#include "util/defer.h" namespace ROCKSDB_NAMESPACE { @@ -86,6 +87,7 @@ Iterator* SstFileReader::NewIterator(const ReadOptions& roptions) { auto sequence = roptions.snapshot != nullptr ? roptions.snapshot->GetSequenceNumber() : kMaxSequenceNumber; + SaveAndRestore ovr(&gAllowFalseAllowRefresh, true); ArenaWrappedDBIter* res = new ArenaWrappedDBIter(); res->Init( r->options.env, roptions, r->ioptions, r->moptions, nullptr /* version */, diff --git a/utilities/transactions/write_prepared_txn_db.cc b/utilities/transactions/write_prepared_txn_db.cc index 26b413bf8b2..47116118b56 100644 --- a/utilities/transactions/write_prepared_txn_db.cc +++ b/utilities/transactions/write_prepared_txn_db.cc @@ -19,6 +19,7 @@ #include "rocksdb/utilities/transaction_db.h" #include "test_util/sync_point.h" #include "util/cast_util.h" +#include "util/defer.h" #include "util/mutexlock.h" #include "util/string_util.h" #include "utilities/transactions/pessimistic_transaction.h" @@ -401,6 +402,7 @@ Iterator* WritePreparedTxnDB::NewIterator(const ReadOptions& _read_options, read_options.io_activity = Env::IOActivity::kDBIterator; } constexpr bool expose_blob_index = false; + SaveAndRestore ovr(&gAllowFalseAllowRefresh, true); constexpr bool allow_refresh = false; std::shared_ptr own_snapshot = nullptr; SequenceNumber snapshot_seq = kMaxSequenceNumber; @@ -448,6 +450,7 @@ Status WritePreparedTxnDB::NewIterators( read_options.io_activity = Env::IOActivity::kDBIterator; } constexpr bool expose_blob_index = false; + SaveAndRestore ovr(&gAllowFalseAllowRefresh, true); constexpr bool allow_refresh = false; std::shared_ptr own_snapshot = nullptr; SequenceNumber snapshot_seq = kMaxSequenceNumber; diff --git a/utilities/transactions/write_unprepared_txn_db.cc b/utilities/transactions/write_unprepared_txn_db.cc index 7c3d13ccf5f..3d148c7c861 100644 --- a/utilities/transactions/write_unprepared_txn_db.cc +++ b/utilities/transactions/write_unprepared_txn_db.cc @@ -8,6 +8,7 @@ #include "db/arena_wrapped_db_iter.h" #include "rocksdb/utilities/transaction_db.h" #include "util/cast_util.h" +#include "util/defer.h" namespace ROCKSDB_NAMESPACE { @@ -403,6 +404,7 @@ Iterator* WriteUnpreparedTxnDB::NewIterator(const ReadOptions& _read_options, } // TODO(lth): Refactor so that this logic is shared with WritePrepared. constexpr bool expose_blob_index = false; + SaveAndRestore ovr(&gAllowFalseAllowRefresh, true); constexpr bool allow_refresh = false; std::shared_ptr own_snapshot = nullptr; SequenceNumber snapshot_seq = kMaxSequenceNumber;