Skip to content

Commit

Permalink
Storage: Extract an MultiGet Options for rocksdb::MultiGet (#1582)
Browse files Browse the repository at this point in the history
  • Loading branch information
mapleFU authored Jul 13, 2023
1 parent 7b6cd7a commit 7af5bb5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/storage/storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ rocksdb::ReadOptions Storage::DefaultScanOptions() const {
return read_options;
}

rocksdb::ReadOptions Storage::DefaultMultiGetOptions() const {
rocksdb::ReadOptions read_options;
read_options.async_io = config_->rocks_db.read_options.async_io;

return read_options;
}

rocksdb::BlockBasedTableOptions Storage::InitTableOptions() {
rocksdb::BlockBasedTableOptions table_options;
table_options.format_version = 5;
Expand Down
1 change: 1 addition & 0 deletions src/storage/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,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::ReadOptions DefaultMultiGetOptions() 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);
Expand Down
8 changes: 4 additions & 4 deletions src/types/redis_hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,17 @@ rocksdb::Status Hash::MGet(const Slice &user_key, const std::vector<Slice> &fiel
}

LatestSnapShot ss(storage_);
rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
rocksdb::ReadOptions read_options = storage_->DefaultMultiGetOptions();
read_options.snapshot = ss.GetSnapShot();
std::vector<rocksdb::Slice> keys;

keys.reserve(fields.size());
std::vector<std::string> sub_keys;
sub_keys.resize(fields.size());
int i = 0;
for (const auto &field : fields) {
for (size_t i = 0; i < fields.size(); i++) {
auto &field = fields[i];
InternalKey(ns_key, field, metadata.version, storage_->IsSlotIdEncoded()).Encode(&(sub_keys[i]));
keys.emplace_back(sub_keys[i++]);
keys.emplace_back(sub_keys[i]);
}

std::vector<rocksdb::PinnableSlice> values_vector;
Expand Down
2 changes: 1 addition & 1 deletion src/types/redis_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ std::vector<rocksdb::Status> String::getRawValues(const std::vector<Slice> &keys
std::vector<std::string> *raw_values) {
raw_values->clear();

rocksdb::ReadOptions read_options;
rocksdb::ReadOptions read_options = storage_->DefaultMultiGetOptions();
LatestSnapShot ss(storage_);
read_options.snapshot = ss.GetSnapShot();
raw_values->resize(keys.size());
Expand Down

0 comments on commit 7af5bb5

Please sign in to comment.