Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSET change it to batch write instead of batch per key #1634

Merged
merged 9 commits into from
Aug 7, 2023
10 changes: 4 additions & 6 deletions src/types/redis_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -373,22 +373,20 @@ rocksdb::Status String::MSet(const std::vector<StringPair> &pairs, uint64_t ttl)
// Data race, key string maybe overwrite by other key while didn't lock the key here,
// to improve the set performance
std::string ns_key;
git-hulk marked this conversation as resolved.
Show resolved Hide resolved
auto batch = storage_->GetWriteBatchBase();
WriteBatchLogData log_data(kRedisString);
batch->PutLogData(log_data.Encode());
for (const auto &pair : pairs) {
std::string bytes;
Metadata metadata(kRedisString, false);
metadata.expire = expire;
metadata.Encode(&bytes);
bytes.append(pair.value.data(), pair.value.size());
auto batch = storage_->GetWriteBatchBase();
WriteBatchLogData log_data(kRedisString);
batch->PutLogData(log_data.Encode());
AppendNamespacePrefix(pair.key, &ns_key);
batch->Put(metadata_cf_handle_, ns_key, bytes);
LockGuard guard(storage_->GetLockManager(), ns_key);
enjoy-binbin marked this conversation as resolved.
Show resolved Hide resolved
auto s = storage_->Write(storage_->DefaultWriteOptions(), batch->GetWriteBatch());
if (!s.ok()) return s;
}
return rocksdb::Status::OK();
return storage_->Write(storage_->DefaultWriteOptions(), batch->GetWriteBatch());
}

rocksdb::Status String::MSetNX(const std::vector<StringPair> &pairs, uint64_t ttl, bool *flag) {
Expand Down