This is an automated email from the ASF dual-hosted git repository.

hulk pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new 95be5eae Style: Change Storage::SetReadOptions to DefaultScanOptions 
(#1574)
95be5eae is described below

commit 95be5eae0da2151c8b6e9b0f5ec5f9300f5ab35a
Author: mwish <[email protected]>
AuthorDate: Tue Jul 11 11:56:46 2023 +0800

    Style: Change Storage::SetReadOptions to DefaultScanOptions (#1574)
    
    Now kvrocks has `SetWriteOptions` and `SetReadOptions`.  However, their 
syntax wasn't consistent.
    `SetWriteOptions` would set the `Storage` internal `rocksdb::WriteOptions` 
during initialize,
    and the detail option can be got by `DefaultWriteOptions()`. So it'd be 
better to change the SetReadOptions
    to DefaultScanOptions which is more precise.
---
 src/cluster/slot_migrate.cc   |  9 +++------
 src/storage/redis_db.cc       | 18 ++++++------------
 src/storage/storage.cc        |  5 ++++-
 src/storage/storage.h         |  2 +-
 src/types/redis_bitmap.cc     |  3 +--
 src/types/redis_hash.cc       |  9 +++------
 src/types/redis_list.cc       |  9 +++------
 src/types/redis_set.cc        |  6 ++----
 src/types/redis_sortedint.cc  |  6 ++----
 src/types/redis_stream.cc     | 12 ++++--------
 src/types/redis_zset.cc       | 15 +++++----------
 utils/kvrocks2redis/parser.cc |  3 +--
 12 files changed, 35 insertions(+), 62 deletions(-)

diff --git a/src/cluster/slot_migrate.cc b/src/cluster/slot_migrate.cc
index 786e5eb9..fca6b23a 100644
--- a/src/cluster/slot_migrate.cc
+++ b/src/cluster/slot_migrate.cc
@@ -307,9 +307,8 @@ Status SlotMigrator::sendSnapshot() {
 
   LOG(INFO) << "[migrate] Start migrating snapshot of slot " << slot;
 
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   read_options.snapshot = slot_snapshot_;
-  storage_->SetReadOptions(read_options);
   rocksdb::ColumnFamilyHandle *cf_handle = 
storage_->GetCFHandle(engine::kMetadataColumnFamilyName);
   auto iter = 
util::UniqueIterator(storage_->GetDB()->NewIterator(read_options, cf_handle));
 
@@ -660,9 +659,8 @@ Status SlotMigrator::migrateComplexKey(const rocksdb::Slice 
&key, const Metadata
   cmd = type_to_cmd[metadata.Type()];
 
   std::vector<std::string> user_cmd = {cmd, key.ToString()};
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   read_options.snapshot = slot_snapshot_;
-  storage_->SetReadOptions(read_options);
   // Should use th raw db iterator to avoid reading uncommitted writes in 
transaction mode
   auto iter = 
util::UniqueIterator(storage_->GetDB()->NewIterator(read_options));
 
@@ -762,9 +760,8 @@ Status SlotMigrator::migrateComplexKey(const rocksdb::Slice 
&key, const Metadata
 }
 
 Status SlotMigrator::migrateStream(const Slice &key, const StreamMetadata 
&metadata, std::string *restore_cmds) {
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   read_options.snapshot = slot_snapshot_;
-  storage_->SetReadOptions(read_options);
   // Should use th raw db iterator to avoid reading uncommitted writes in 
transaction mode
   auto iter = util::UniqueIterator(
       storage_->GetDB()->NewIterator(read_options, 
storage_->GetCFHandle(engine::kStreamColumnFamilyName)));
diff --git a/src/storage/redis_db.cc b/src/storage/redis_db.cc
index 1d2bb229..27f9e847 100644
--- a/src/storage/redis_db.cc
+++ b/src/storage/redis_db.cc
@@ -181,9 +181,8 @@ void Database::Keys(const std::string &prefix, 
std::vector<std::string> *keys, K
 
   uint64_t ttl_sum = 0;
   LatestSnapShot ss(storage_);
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   read_options.snapshot = ss.GetSnapShot();
-  storage_->SetReadOptions(read_options);
   auto iter = util::UniqueIterator(storage_, read_options, 
metadata_cf_handle_);
 
   while (true) {
@@ -235,9 +234,8 @@ rocksdb::Status Database::Scan(const std::string &cursor, 
uint64_t limit, const
   std::string ns_prefix, ns_cursor, ns, user_key, value, index_key;
 
   LatestSnapShot ss(storage_);
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   read_options.snapshot = ss.GetSnapShot();
-  storage_->SetReadOptions(read_options);
   auto iter = util::UniqueIterator(storage_, read_options, 
metadata_cf_handle_);
 
   AppendNamespacePrefix(cursor, &ns_cursor);
@@ -358,9 +356,8 @@ rocksdb::Status Database::FlushDB() {
 
 rocksdb::Status Database::FlushAll() {
   LatestSnapShot ss(storage_);
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   read_options.snapshot = ss.GetSnapShot();
-  storage_->SetReadOptions(read_options);
   auto iter = util::UniqueIterator(storage_, read_options, 
metadata_cf_handle_);
   iter->SeekToFirst();
   if (!iter->Valid()) {
@@ -472,9 +469,8 @@ rocksdb::Status Database::FindKeyRangeWithPrefix(const 
std::string &prefix, cons
   end->clear();
 
   LatestSnapShot ss(storage_);
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   read_options.snapshot = ss.GetSnapShot();
-  storage_->SetReadOptions(read_options);
   auto iter = util::UniqueIterator(storage_, read_options, cf_handle);
   iter->Seek(prefix);
   if (!iter->Valid() || !iter->key().starts_with(prefix)) {
@@ -526,9 +522,8 @@ rocksdb::Status Database::ClearKeysOfSlot(const 
rocksdb::Slice &ns, int slot) {
 rocksdb::Status Database::GetSlotKeysInfo(int slot, std::map<int, uint64_t> 
*slotskeys, std::vector<std::string> *keys,
                                           int count) {
   LatestSnapShot ss(storage_);
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   read_options.snapshot = ss.GetSnapShot();
-  storage_->SetReadOptions(read_options);
 
   auto iter = util::UniqueIterator(storage_, read_options, 
metadata_cf_handle_);
   bool end = false;
@@ -574,9 +569,8 @@ rocksdb::Status SubKeyScanner::Scan(RedisType type, const 
Slice &user_key, const
   if (!s.ok()) return s;
 
   LatestSnapShot ss(storage_);
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   read_options.snapshot = ss.GetSnapShot();
-  storage_->SetReadOptions(read_options);
   auto iter = util::UniqueIterator(storage_, read_options);
   std::string match_prefix_key;
   if (!subkey_prefix.empty()) {
diff --git a/src/storage/storage.cc b/src/storage/storage.cc
index b2b6757f..68bbe119 100644
--- a/src/storage/storage.cc
+++ b/src/storage/storage.cc
@@ -86,9 +86,12 @@ void Storage::SetWriteOptions(const 
Config::RocksDB::WriteOptions &config) {
   write_opts_.memtable_insert_hint_per_batch = 
config.memtable_insert_hint_per_batch;
 }
 
-void Storage::SetReadOptions(rocksdb::ReadOptions &read_options) {
+rocksdb::ReadOptions Storage::DefaultScanOptions() const {
+  rocksdb::ReadOptions read_options;
   read_options.fill_cache = false;
   read_options.async_io = config_->rocks_db.read_options.async_io;
+
+  return read_options;
 }
 
 rocksdb::BlockBasedTableOptions Storage::InitTableOptions() {
diff --git a/src/storage/storage.h b/src/storage/storage.h
index ae4dc577..866eefb4 100644
--- a/src/storage/storage.h
+++ b/src/storage/storage.h
@@ -70,7 +70,6 @@ class Storage {
   ~Storage();
 
   void SetWriteOptions(const Config::RocksDB::WriteOptions &config);
-  void SetReadOptions(rocksdb::ReadOptions &read_options);
   Status Open(bool read_only = false);
   void CloseDB();
   void EmptyDB();
@@ -99,6 +98,7 @@ class Storage {
 
   rocksdb::Status Write(const rocksdb::WriteOptions &options, 
rocksdb::WriteBatch *updates);
   const rocksdb::WriteOptions &DefaultWriteOptions() { return write_opts_; }
+  rocksdb::ReadOptions DefaultScanOptions() const;
   rocksdb::Status Delete(const rocksdb::WriteOptions &options, 
rocksdb::ColumnFamilyHandle *cf_handle,
                          const rocksdb::Slice &key);
   rocksdb::Status DeleteRange(const std::string &first_key, const std::string 
&last_key);
diff --git a/src/types/redis_bitmap.cc b/src/types/redis_bitmap.cc
index e18deef0..14ac636f 100644
--- a/src/types/redis_bitmap.cc
+++ b/src/types/redis_bitmap.cc
@@ -109,10 +109,9 @@ rocksdb::Status Bitmap::GetString(const Slice &user_key, 
const uint32_t max_btos
   fragment.reserve(kBitmapSegmentBytes * 2);
   InternalKey(ns_key, "", metadata.version, 
storage_->IsSlotIdEncoded()).Encode(&prefix_key);
 
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   LatestSnapShot ss(storage_);
   read_options.snapshot = ss.GetSnapShot();
-  storage_->SetReadOptions(read_options);
 
   auto iter = util::UniqueIterator(storage_, read_options);
   for (iter->Seek(prefix_key); iter->Valid() && 
iter->key().starts_with(prefix_key); iter->Next()) {
diff --git a/src/types/redis_hash.cc b/src/types/redis_hash.cc
index 73516746..278f6207 100644
--- a/src/types/redis_hash.cc
+++ b/src/types/redis_hash.cc
@@ -171,9 +171,8 @@ rocksdb::Status Hash::MGet(const Slice &user_key, const 
std::vector<Slice> &fiel
   }
 
   LatestSnapShot ss(storage_);
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   read_options.snapshot = ss.GetSnapShot();
-  storage_->SetReadOptions(read_options);
   std::vector<rocksdb::Slice> keys;
 
   keys.reserve(fields.size());
@@ -302,14 +301,13 @@ rocksdb::Status Hash::RangeByLex(const Slice &user_key, 
const RangeLexSpec &spec
   InternalKey(ns_key, start_member, metadata.version, 
storage_->IsSlotIdEncoded()).Encode(&start_key);
   InternalKey(ns_key, "", metadata.version, 
storage_->IsSlotIdEncoded()).Encode(&prefix_key);
   InternalKey(ns_key, "", metadata.version + 1, 
storage_->IsSlotIdEncoded()).Encode(&next_version_prefix_key);
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   LatestSnapShot ss(storage_);
   read_options.snapshot = ss.GetSnapShot();
   rocksdb::Slice upper_bound(next_version_prefix_key);
   read_options.iterate_upper_bound = &upper_bound;
   rocksdb::Slice lower_bound(prefix_key);
   read_options.iterate_lower_bound = &lower_bound;
-  storage_->SetReadOptions(read_options);
 
   auto iter = util::UniqueIterator(storage_, read_options);
   if (!spec.reversed) {
@@ -359,12 +357,11 @@ rocksdb::Status Hash::GetAll(const Slice &user_key, 
std::vector<FieldValue> *fie
   InternalKey(ns_key, "", metadata.version, 
storage_->IsSlotIdEncoded()).Encode(&prefix_key);
   InternalKey(ns_key, "", metadata.version + 1, 
storage_->IsSlotIdEncoded()).Encode(&next_version_prefix_key);
 
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   LatestSnapShot ss(storage_);
   read_options.snapshot = ss.GetSnapShot();
   rocksdb::Slice upper_bound(next_version_prefix_key);
   read_options.iterate_upper_bound = &upper_bound;
-  storage_->SetReadOptions(read_options);
 
   auto iter = util::UniqueIterator(storage_, read_options);
   for (iter->Seek(prefix_key); iter->Valid() && 
iter->key().starts_with(prefix_key); iter->Next()) {
diff --git a/src/types/redis_list.cc b/src/types/redis_list.cc
index af58bf69..fe764c11 100644
--- a/src/types/redis_list.cc
+++ b/src/types/redis_list.cc
@@ -186,14 +186,13 @@ rocksdb::Status List::Rem(const Slice &user_key, int 
count, const Slice &elem, u
 
   bool reversed = count < 0;
   std::vector<uint64_t> to_delete_indexes;
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   LatestSnapShot ss(storage_);
   read_options.snapshot = ss.GetSnapShot();
   rocksdb::Slice upper_bound(next_version_prefix);
   read_options.iterate_upper_bound = &upper_bound;
   rocksdb::Slice lower_bound(prefix);
   read_options.iterate_lower_bound = &lower_bound;
-  storage_->SetReadOptions(read_options);
 
   auto iter = util::UniqueIterator(storage_, read_options);
   for (iter->Seek(start_key); iter->Valid() && iter->key().starts_with(prefix);
@@ -277,12 +276,11 @@ rocksdb::Status List::Insert(const Slice &user_key, const 
Slice &pivot, const Sl
   InternalKey(ns_key, "", metadata.version, 
storage_->IsSlotIdEncoded()).Encode(&prefix);
   InternalKey(ns_key, "", metadata.version + 1, 
storage_->IsSlotIdEncoded()).Encode(&next_version_prefix);
 
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   LatestSnapShot ss(storage_);
   read_options.snapshot = ss.GetSnapShot();
   rocksdb::Slice upper_bound(next_version_prefix);
   read_options.iterate_upper_bound = &upper_bound;
-  storage_->SetReadOptions(read_options);
 
   auto iter = util::UniqueIterator(storage_, read_options);
   for (iter->Seek(start_key); iter->Valid() && 
iter->key().starts_with(prefix); iter->Next()) {
@@ -387,12 +385,11 @@ rocksdb::Status List::Range(const Slice &user_key, int 
start, int stop, std::vec
   InternalKey(ns_key, "", metadata.version, 
storage_->IsSlotIdEncoded()).Encode(&prefix);
   InternalKey(ns_key, "", metadata.version + 1, 
storage_->IsSlotIdEncoded()).Encode(&next_version_prefix);
 
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   LatestSnapShot ss(storage_);
   read_options.snapshot = ss.GetSnapShot();
   rocksdb::Slice upper_bound(next_version_prefix);
   read_options.iterate_upper_bound = &upper_bound;
-  storage_->SetReadOptions(read_options);
 
   auto iter = util::UniqueIterator(storage_, read_options);
   for (iter->Seek(start_key); iter->Valid() && 
iter->key().starts_with(prefix); iter->Next()) {
diff --git a/src/types/redis_set.cc b/src/types/redis_set.cc
index 0a26c9f9..588b0e3a 100644
--- a/src/types/redis_set.cc
+++ b/src/types/redis_set.cc
@@ -146,12 +146,11 @@ rocksdb::Status Set::Members(const Slice &user_key, 
std::vector<std::string> *me
   InternalKey(ns_key, "", metadata.version, 
storage_->IsSlotIdEncoded()).Encode(&prefix);
   InternalKey(ns_key, "", metadata.version + 1, 
storage_->IsSlotIdEncoded()).Encode(&next_version_prefix);
 
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   LatestSnapShot ss(storage_);
   read_options.snapshot = ss.GetSnapShot();
   rocksdb::Slice upper_bound(next_version_prefix);
   read_options.iterate_upper_bound = &upper_bound;
-  storage_->SetReadOptions(read_options);
 
   auto iter = util::UniqueIterator(storage_, read_options);
   for (iter->Seek(prefix); iter->Valid() && iter->key().starts_with(prefix); 
iter->Next()) {
@@ -219,12 +218,11 @@ rocksdb::Status Set::Take(const Slice &user_key, 
std::vector<std::string> *membe
   InternalKey(ns_key, "", metadata.version, 
storage_->IsSlotIdEncoded()).Encode(&prefix);
   InternalKey(ns_key, "", metadata.version + 1, 
storage_->IsSlotIdEncoded()).Encode(&next_version_prefix);
 
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   LatestSnapShot ss(storage_);
   read_options.snapshot = ss.GetSnapShot();
   rocksdb::Slice upper_bound(next_version_prefix);
   read_options.iterate_upper_bound = &upper_bound;
-  storage_->SetReadOptions(read_options);
 
   auto iter = util::UniqueIterator(storage_, read_options);
   for (iter->Seek(prefix); iter->Valid() && iter->key().starts_with(prefix); 
iter->Next()) {
diff --git a/src/types/redis_sortedint.cc b/src/types/redis_sortedint.cc
index 8a634a9d..5c7883a7 100644
--- a/src/types/redis_sortedint.cc
+++ b/src/types/redis_sortedint.cc
@@ -131,14 +131,13 @@ rocksdb::Status Sortedint::Range(const Slice &user_key, 
uint64_t cursor_id, uint
   InternalKey(ns_key, "", metadata.version, 
storage_->IsSlotIdEncoded()).Encode(&prefix);
   InternalKey(ns_key, "", metadata.version + 1, 
storage_->IsSlotIdEncoded()).Encode(&next_version_prefix);
 
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   LatestSnapShot ss(storage_);
   read_options.snapshot = ss.GetSnapShot();
   rocksdb::Slice upper_bound(next_version_prefix);
   read_options.iterate_upper_bound = &upper_bound;
   rocksdb::Slice lower_bound(prefix);
   read_options.iterate_lower_bound = &lower_bound;
-  storage_->SetReadOptions(read_options);
 
   uint64_t id = 0, pos = 0;
   auto iter = util::UniqueIterator(storage_, read_options);
@@ -172,14 +171,13 @@ rocksdb::Status Sortedint::RangeByValue(const Slice 
&user_key, SortedintRangeSpe
   InternalKey(ns_key, "", metadata.version, 
storage_->IsSlotIdEncoded()).Encode(&prefix_key);
   InternalKey(ns_key, "", metadata.version + 1, 
storage_->IsSlotIdEncoded()).Encode(&next_version_prefix_key);
 
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   LatestSnapShot ss(storage_);
   read_options.snapshot = ss.GetSnapShot();
   rocksdb::Slice upper_bound(next_version_prefix_key);
   read_options.iterate_upper_bound = &upper_bound;
   rocksdb::Slice lower_bound(prefix_key);
   read_options.iterate_lower_bound = &lower_bound;
-  storage_->SetReadOptions(read_options);
 
   int pos = 0;
   auto iter = util::UniqueIterator(storage_, read_options);
diff --git a/src/types/redis_stream.cc b/src/types/redis_stream.cc
index 9dd7fd42..fa0320eb 100644
--- a/src/types/redis_stream.cc
+++ b/src/types/redis_stream.cc
@@ -186,14 +186,13 @@ rocksdb::Status Stream::DeleteEntries(const Slice 
&stream_name, const std::vecto
   std::string prefix_key;
   InternalKey(ns_key, "", metadata.version, 
storage_->IsSlotIdEncoded()).Encode(&prefix_key);
 
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   LatestSnapShot ss(storage_);
   read_options.snapshot = ss.GetSnapShot();
   rocksdb::Slice upper_bound(next_version_prefix_key);
   read_options.iterate_upper_bound = &upper_bound;
   rocksdb::Slice lower_bound(prefix_key);
   read_options.iterate_lower_bound = &lower_bound;
-  storage_->SetReadOptions(read_options);
 
   auto iter = util::UniqueIterator(storage_, read_options, stream_cf_handle_);
 
@@ -295,14 +294,13 @@ rocksdb::Status Stream::Len(const Slice &stream_name, 
const StreamLenOptions &op
   std::string next_version_prefix_key;
   InternalKey(ns_key, "", metadata.version + 1, 
storage_->IsSlotIdEncoded()).Encode(&next_version_prefix_key);
 
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   LatestSnapShot ss(storage_);
   read_options.snapshot = ss.GetSnapShot();
   rocksdb::Slice lower_bound(prefix_key);
   read_options.iterate_lower_bound = &lower_bound;
   rocksdb::Slice upper_bound(next_version_prefix_key);
   read_options.iterate_upper_bound = &upper_bound;
-  storage_->SetReadOptions(read_options);
 
   auto iter = util::UniqueIterator(storage_, read_options, stream_cf_handle_);
   std::string start_key = internalKeyFromEntryID(ns_key, metadata, 
options.entry_id);
@@ -360,14 +358,13 @@ rocksdb::Status Stream::range(const std::string &ns_key, 
const StreamMetadata &m
   std::string prefix_key;
   InternalKey(ns_key, "", metadata.version, 
storage_->IsSlotIdEncoded()).Encode(&prefix_key);
 
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   LatestSnapShot ss(storage_);
   read_options.snapshot = ss.GetSnapShot();
   rocksdb::Slice upper_bound(next_version_prefix_key);
   read_options.iterate_upper_bound = &upper_bound;
   rocksdb::Slice lower_bound(prefix_key);
   read_options.iterate_lower_bound = &lower_bound;
-  storage_->SetReadOptions(read_options);
 
   auto iter = util::UniqueIterator(storage_, read_options, stream_cf_handle_);
   iter->Seek(start_key);
@@ -563,14 +560,13 @@ uint64_t Stream::trim(const std::string &ns_key, const 
StreamTrimOptions &option
   std::string prefix_key;
   InternalKey(ns_key, "", metadata->version, 
storage_->IsSlotIdEncoded()).Encode(&prefix_key);
 
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   LatestSnapShot ss(storage_);
   read_options.snapshot = ss.GetSnapShot();
   rocksdb::Slice upper_bound(next_version_prefix_key);
   read_options.iterate_upper_bound = &upper_bound;
   rocksdb::Slice lower_bound(prefix_key);
   read_options.iterate_lower_bound = &lower_bound;
-  storage_->SetReadOptions(read_options);
 
   auto iter = util::UniqueIterator(storage_, read_options, stream_cf_handle_);
   std::string start_key = internalKeyFromEntryID(ns_key, *metadata, 
metadata->first_entry_id);
diff --git a/src/types/redis_zset.cc b/src/types/redis_zset.cc
index e38e734b..9d6ba9b6 100644
--- a/src/types/redis_zset.cc
+++ b/src/types/redis_zset.cc
@@ -183,14 +183,13 @@ rocksdb::Status ZSet::Pop(const Slice &user_key, int 
count, bool min, MemberScor
   WriteBatchLogData log_data(kRedisZSet);
   batch->PutLogData(log_data.Encode());
 
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   LatestSnapShot ss(storage_);
   read_options.snapshot = ss.GetSnapShot();
   rocksdb::Slice upper_bound(next_version_prefix_key);
   read_options.iterate_upper_bound = &upper_bound;
   rocksdb::Slice lower_bound(prefix_key);
   read_options.iterate_lower_bound = &lower_bound;
-  storage_->SetReadOptions(read_options);
 
   auto iter = util::UniqueIterator(storage_, read_options, score_cf_handle_);
   iter->Seek(start_key);
@@ -255,14 +254,13 @@ rocksdb::Status ZSet::RangeByRank(const Slice &user_key, 
const RangeRankSpec &sp
   InternalKey(ns_key, "", metadata.version + 1, 
storage_->IsSlotIdEncoded()).Encode(&next_verison_prefix_key);
 
   int removed_subkey = 0;
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   LatestSnapShot ss(storage_);
   read_options.snapshot = ss.GetSnapShot();
   rocksdb::Slice upper_bound(next_verison_prefix_key);
   read_options.iterate_upper_bound = &upper_bound;
   rocksdb::Slice lower_bound(prefix_key);
   read_options.iterate_lower_bound = &lower_bound;
-  storage_->SetReadOptions(read_options);
 
   auto batch = storage_->GetWriteBatchBase();
   auto iter = util::UniqueIterator(storage_, read_options, score_cf_handle_);
@@ -363,14 +361,13 @@ rocksdb::Status ZSet::RangeByScore(const Slice &user_key, 
const RangeScoreSpec &
   InternalKey(ns_key, "", metadata.version, 
storage_->IsSlotIdEncoded()).Encode(&prefix_key);
   InternalKey(ns_key, "", metadata.version + 1, 
storage_->IsSlotIdEncoded()).Encode(&next_version_prefix_key);
 
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   LatestSnapShot ss(storage_);
   read_options.snapshot = ss.GetSnapShot();
   rocksdb::Slice upper_bound(next_version_prefix_key);
   read_options.iterate_upper_bound = &upper_bound;
   rocksdb::Slice lower_bound(prefix_key);
   read_options.iterate_lower_bound = &lower_bound;
-  storage_->SetReadOptions(read_options);
 
   int pos = 0;
   auto iter = util::UniqueIterator(storage_, read_options, score_cf_handle_);
@@ -450,14 +447,13 @@ rocksdb::Status ZSet::RangeByLex(const Slice &user_key, 
const RangeLexSpec &spec
   InternalKey(ns_key, "", metadata.version, 
storage_->IsSlotIdEncoded()).Encode(&prefix_key);
   InternalKey(ns_key, "", metadata.version + 1, 
storage_->IsSlotIdEncoded()).Encode(&next_version_prefix_key);
 
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   LatestSnapShot ss(storage_);
   read_options.snapshot = ss.GetSnapShot();
   rocksdb::Slice upper_bound(next_version_prefix_key);
   read_options.iterate_upper_bound = &upper_bound;
   rocksdb::Slice lower_bound(prefix_key);
   read_options.iterate_lower_bound = &lower_bound;
-  storage_->SetReadOptions(read_options);
 
   int pos = 0;
   auto iter = util::UniqueIterator(storage_, read_options);
@@ -579,7 +575,7 @@ rocksdb::Status ZSet::Rank(const Slice &user_key, const 
Slice &member, bool reve
   rocksdb::Status s = GetMetadata(ns_key, &metadata);
   if (!s.ok()) return s.IsNotFound() ? rocksdb::Status::OK() : s;
 
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   LatestSnapShot ss(storage_);
   read_options.snapshot = ss.GetSnapShot();
   std::string score_bytes, member_key;
@@ -600,7 +596,6 @@ rocksdb::Status ZSet::Rank(const Slice &user_key, const 
Slice &member, bool reve
   read_options.iterate_upper_bound = &upper_bound;
   rocksdb::Slice lower_bound(prefix_key);
   read_options.iterate_lower_bound = &lower_bound;
-  storage_->SetReadOptions(read_options);
 
   auto iter = util::UniqueIterator(storage_, read_options, score_cf_handle_);
   iter->Seek(start_key);
diff --git a/utils/kvrocks2redis/parser.cc b/utils/kvrocks2redis/parser.cc
index 404b49b9..f477c819 100644
--- a/utils/kvrocks2redis/parser.cc
+++ b/utils/kvrocks2redis/parser.cc
@@ -90,11 +90,10 @@ Status Parser::parseComplexKV(const Slice &ns_key, const 
Metadata &metadata) {
   std::string next_version_prefix_key;
   InternalKey(ns_key, "", metadata.version + 1, 
slot_id_encoded_).Encode(&next_version_prefix_key);
 
-  rocksdb::ReadOptions read_options;
+  rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
   read_options.snapshot = latest_snapshot_->GetSnapShot();
   rocksdb::Slice upper_bound(next_version_prefix_key);
   read_options.iterate_upper_bound = &upper_bound;
-  storage_->SetReadOptions(read_options);
 
   std::string output;
   auto iter = util::UniqueIterator(storage_, read_options);

Reply via email to