Skip to content

Commit

Permalink
code review from mapleFU. mark and guard life
Browse files Browse the repository at this point in the history
  • Loading branch information
enjoy-binbin committed Aug 3, 2023
1 parent 3860daa commit ecd0f5e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/types/redis_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,12 @@ rocksdb::Status String::GetDel(const std::string &user_key, std::string *value)

rocksdb::Status String::Set(const std::string &user_key, const std::string &value) {
std::vector<StringPair> pairs{StringPair{user_key, value}};
return MSet(pairs, 0, true);
return MSet(pairs, /*ttl=*/0, /*lock=*/true);
}

rocksdb::Status String::SetEX(const std::string &user_key, const std::string &value, uint64_t ttl) {
std::vector<StringPair> pairs{StringPair{user_key, value}};
return MSet(pairs, ttl, true);
return MSet(pairs, /*ttl=*/ttl, /*lock=*/true);
}

rocksdb::Status String::SetNX(const std::string &user_key, const std::string &value, uint64_t ttl, bool *flag) {
Expand Down Expand Up @@ -384,7 +384,10 @@ rocksdb::Status String::MSet(const std::vector<StringPair> &pairs, uint64_t ttl,
batch->PutLogData(log_data.Encode());
AppendNamespacePrefix(pair.key, &ns_key);
batch->Put(metadata_cf_handle_, ns_key, bytes);
if (lock) LockGuard guard(storage_->GetLockManager(), ns_key);
std::optional<LockGuard> guard;
if (lock) {
guard(storage_->GetLockManager(), ns_key);
}
auto s = storage_->Write(storage_->DefaultWriteOptions(), batch->GetWriteBatch());
if (!s.ok()) return s;
}
Expand Down

0 comments on commit ecd0f5e

Please sign in to comment.