diff --git a/include/pika_db.h b/include/pika_db.h index 8280b6bf38..2c4fdaede6 100644 --- a/include/pika_db.h +++ b/include/pika_db.h @@ -129,9 +129,6 @@ class DB : public std::enable_shared_from_this, public pstd::noncopyable { void SetCompactRangeOptions(const bool is_canceled); std::shared_ptr LockMgr(); - void DbRWLockWriter(); - void DbRWLockReader(); - void DbRWUnLock(); /* * Cache used */ @@ -164,7 +161,6 @@ class DB : public std::enable_shared_from_this, public pstd::noncopyable { std::string log_path_; std::string bgsave_sub_path_; pstd::Mutex key_info_protector_; - std::shared_mutex db_rwlock_; std::atomic binlog_io_error_; std::shared_mutex dbs_rw_; // class may be shared, using shared_ptr would be a better choice diff --git a/include/pika_repl_server_conn.h b/include/pika_repl_server_conn.h index 8c473a4258..c96159e0fe 100644 --- a/include/pika_repl_server_conn.h +++ b/include/pika_repl_server_conn.h @@ -32,9 +32,6 @@ class PikaReplServerConn : public net::PbConn { const InnerMessage::InnerRequest::TrySync& try_sync_request, const std::shared_ptr& conn, InnerMessage::InnerResponse::TrySync* try_sync_response); - static void BuildConsensusMeta(const bool& reject, const std::vector& hints, const uint32_t& term, - InnerMessage::InnerResponse* response); - static void HandleDBSyncRequest(void* arg); static void HandleBinlogSyncRequest(void* arg); static void HandleRemoveSlaveNodeRequest(void* arg); diff --git a/src/pika_admin.cc b/src/pika_admin.cc index b0afb5ae98..5ee92c6e11 100644 --- a/src/pika_admin.cc +++ b/src/pika_admin.cc @@ -814,9 +814,9 @@ void ShutdownCmd::DoInitial() { // no return void ShutdownCmd::Do() { DLOG(WARNING) << "handle \'shutdown\'"; - db_->DbRWUnLock(); + db_->DBUnlockShared(); g_pika_server->Exit(); - db_->DbRWLockReader(); + db_->DBLockShared(); res_.SetRes(CmdRes::kNone); } @@ -1338,11 +1338,11 @@ void InfoCmd::InfoData(std::string& info) { } background_errors.clear(); memtable_usage = table_reader_usage = 0; - db_item.second->DbRWLockReader(); + db_item.second->DBLockShared(); db_item.second->storage()->GetUsage(storage::PROPERTY_TYPE_ROCKSDB_CUR_SIZE_ALL_MEM_TABLES, &memtable_usage); db_item.second->storage()->GetUsage(storage::PROPERTY_TYPE_ROCKSDB_ESTIMATE_TABLE_READER_MEM, &table_reader_usage); db_item.second->storage()->GetUsage(storage::PROPERTY_TYPE_ROCKSDB_BACKGROUND_ERRORS, &background_errors); - db_item.second->DbRWUnLock(); + db_item.second->DBUnlockShared(); total_memtable_usage += memtable_usage; total_table_reader_usage += table_reader_usage; for (const auto& item : background_errors) { @@ -1376,9 +1376,9 @@ void InfoCmd::InfoRocksDB(std::string& info) { continue; } std::string rocksdb_info; - db_item.second->DbRWLockReader(); + db_item.second->DBLockShared(); db_item.second->storage()->GetRocksDBInfo(rocksdb_info); - db_item.second->DbRWUnLock(); + db_item.second->DBUnlockShared(); tmp_stream << rocksdb_info; } info.append(tmp_stream.str()); @@ -3101,9 +3101,9 @@ void DiskRecoveryCmd::Do() { } db_item.second->SetBinlogIoErrorrelieve(); background_errors_.clear(); - db_item.second->DbRWLockReader(); + db_item.second->DBLockShared(); db_item.second->storage()->GetUsage(storage::PROPERTY_TYPE_ROCKSDB_BACKGROUND_ERRORS, &background_errors_); - db_item.second->DbRWUnLock(); + db_item.second->DBUnlockShared(); for (const auto &item: background_errors_) { if (item.second != 0) { rocksdb::Status s = db_item.second->storage()->GetDBByIndex(item.first)->Resume(); diff --git a/src/pika_command.cc b/src/pika_command.cc index b76baca28b..6d370735a6 100644 --- a/src/pika_command.cc +++ b/src/pika_command.cc @@ -889,11 +889,11 @@ void Cmd::InternalProcessCommand(const HintKeys& hint_keys) { void Cmd::DoCommand(const HintKeys& hint_keys) { if (!IsSuspend()) { - db_->DbRWLockReader(); + db_->DBLockShared(); } DEFER { if (!IsSuspend()) { - db_->DbRWUnLock(); + db_->DBUnlockShared(); } }; if (IsNeedCacheDo() diff --git a/src/pika_db.cc b/src/pika_db.cc index ce51132499..0cf5a06dcd 100644 --- a/src/pika_db.cc +++ b/src/pika_db.cc @@ -72,8 +72,6 @@ void DB::SetBinlogIoError() { return binlog_io_error_.store(true); } void DB::SetBinlogIoErrorrelieve() { return binlog_io_error_.store(false); } bool DB::IsBinlogIoError() { return binlog_io_error_.load(); } std::shared_ptr DB::LockMgr() { return lock_mgr_; } -void DB::DbRWLockReader() { db_rwlock_.lock_shared(); } -void DB::DbRWUnLock() { db_rwlock_.unlock(); } std::shared_ptr DB::cache() const { return cache_; } std::shared_ptr DB::storage() const { return storage_; } @@ -197,8 +195,6 @@ void DB::SetCompactRangeOptions(const bool is_canceled) { storage_->SetCompactRangeOptions(is_canceled); } -void DB::DbRWLockWriter() { db_rwlock_.lock(); } - DisplayCacheInfo DB::GetCacheInfo() { std::lock_guard l(key_info_protector_); return cache_info_; @@ -360,7 +356,7 @@ bool DB::InitBgsaveEngine() { } { - std::lock_guard lock(db_rwlock_); + std::lock_guard lock(dbs_rw_); LogOffset bgsave_offset; // term, index are 0 db->Logger()->GetProducerStatus(&(bgsave_offset.b_offset.filenum), &(bgsave_offset.b_offset.offset)); @@ -548,7 +544,7 @@ bool DB::ChangeDb(const std::string& new_path) { tmp_path += "_bak"; pstd::DeleteDirIfExist(tmp_path); - std::lock_guard l(db_rwlock_); + std::lock_guard l(dbs_rw_); LOG(INFO) << "DB: " << db_name_ << ", Prepare change db from: " << tmp_path; storage_.reset(); @@ -580,7 +576,7 @@ void DB::ClearBgsave() { } bool DB::FlushSubDB(const std::string& db_name) { - std::lock_guard rwl(db_rwlock_); + std::lock_guard rwl(dbs_rw_); return FlushSubDBWithoutLock(db_name); } @@ -634,7 +630,7 @@ void DB::ResetDisplayCacheInfo(int status) { } bool DB::FlushDB() { - std::lock_guard rwl(db_rwlock_); + std::lock_guard rwl(dbs_rw_); std::lock_guard l(bgsave_protector_); return FlushDBWithoutLock(); } diff --git a/src/pika_repl_bgworker.cc b/src/pika_repl_bgworker.cc index 4f372351f2..06d060324f 100644 --- a/src/pika_repl_bgworker.cc +++ b/src/pika_repl_bgworker.cc @@ -219,7 +219,7 @@ void PikaReplBgWorker::HandleBGWorkerWriteDB(void* arg) { pstd::lock::MultiRecordLock record_lock(c_ptr->GetDB()->LockMgr()); record_lock.Lock(c_ptr->current_key()); if (!c_ptr->IsSuspend()) { - c_ptr->GetDB()->DbRWLockReader(); + c_ptr->GetDB()->DBLockShared(); } if (c_ptr->IsNeedCacheDo() && PIKA_CACHE_NONE != g_pika_conf->cache_model() @@ -236,7 +236,7 @@ void PikaReplBgWorker::HandleBGWorkerWriteDB(void* arg) { c_ptr->Do(); } if (!c_ptr->IsSuspend()) { - c_ptr->GetDB()->DbRWUnLock(); + c_ptr->GetDB()->DBUnlockShared(); } record_lock.Unlock(c_ptr->current_key()); if (g_pika_conf->slowlog_slower_than() >= 0) { diff --git a/src/pika_repl_server_conn.cc b/src/pika_repl_server_conn.cc index 21847db3cd..38cbde7b1c 100644 --- a/src/pika_repl_server_conn.cc +++ b/src/pika_repl_server_conn.cc @@ -216,23 +216,6 @@ bool PikaReplServerConn::TrySyncOffsetCheck(const std::shared_ptr& return true; } -void PikaReplServerConn::BuildConsensusMeta(const bool& reject, const std::vector& hints, - const uint32_t& term, InnerMessage::InnerResponse* response) { - InnerMessage::ConsensusMeta* consensus_meta = response->mutable_consensus_meta(); - consensus_meta->set_term(term); - consensus_meta->set_reject(reject); - if (!reject) { - return; - } - for (const auto& hint : hints) { - InnerMessage::BinlogOffset* offset = consensus_meta->add_hint(); - offset->set_filenum(hint.b_offset.filenum); - offset->set_offset(hint.b_offset.offset); - offset->set_term(hint.l_offset.term); - offset->set_index(hint.l_offset.index); - } -} - void PikaReplServerConn::HandleDBSyncRequest(void* arg) { std::unique_ptr task_arg(static_cast(arg)); const std::shared_ptr req = task_arg->req; diff --git a/src/pika_server.cc b/src/pika_server.cc index 699a9291ce..eaabfc10d8 100644 --- a/src/pika_server.cc +++ b/src/pika_server.cc @@ -347,9 +347,9 @@ bool PikaServer::IsKeyScaning() { bool PikaServer::IsCompacting() { std::shared_lock db_rwl(dbs_rw_); for (const auto& db_item : dbs_) { - db_item.second->DbRWLockReader(); + db_item.second->DBLockShared(); std::string task_type = db_item.second->storage()->GetCurrentTaskType(); - db_item.second->DbRWUnLock(); + db_item.second->DBUnlockShared(); if (strcasecmp(task_type.data(), "no") != 0) { return true; } @@ -446,27 +446,27 @@ void PikaServer::PrepareDBTrySync() { void PikaServer::DBSetMaxCacheStatisticKeys(uint32_t max_cache_statistic_keys) { std::shared_lock rwl(dbs_rw_); for (const auto& db_item : dbs_) { - db_item.second->DbRWLockReader(); + db_item.second->DBLockShared(); db_item.second->storage()->SetMaxCacheStatisticKeys(max_cache_statistic_keys); - db_item.second->DbRWUnLock(); + db_item.second->DBUnlockShared(); } } void PikaServer::DBSetSmallCompactionThreshold(uint32_t small_compaction_threshold) { std::shared_lock rwl(dbs_rw_); for (const auto& db_item : dbs_) { - db_item.second->DbRWLockReader(); + db_item.second->DBLockShared(); db_item.second->storage()->SetSmallCompactionThreshold(small_compaction_threshold); - db_item.second->DbRWUnLock(); + db_item.second->DBUnlockShared(); } } void PikaServer::DBSetSmallCompactionDurationThreshold(uint32_t small_compaction_duration_threshold) { std::shared_lock rwl(dbs_rw_); for (const auto& db_item : dbs_) { - db_item.second->DbRWLockReader(); + db_item.second->DBLockShared(); db_item.second->storage()->SetSmallCompactionDurationThreshold(small_compaction_duration_threshold); - db_item.second->DbRWUnLock(); + db_item.second->DBUnlockShared(); } } @@ -1386,9 +1386,7 @@ storage::Status PikaServer::RewriteStorageOptions(const storage::OptionType& opt storage::Status s; std::shared_lock db_rwl(dbs_rw_); for (const auto& db_item : dbs_) { - db_item.second->DbRWLockWriter(); s = db_item.second->storage()->SetOptions(option_type, storage::ALL_DB, options_map); - db_item.second->DbRWUnLock(); if (!s.ok()) { return s; } @@ -1567,9 +1565,9 @@ void PikaServer::DisableCompact() { /* cancel in-progress manual compactions */ std::shared_lock rwl(dbs_rw_); for (const auto& db_item : dbs_) { - db_item.second->DbRWLockWriter(); + db_item.second->DBLock(); db_item.second->SetCompactRangeOptions(true); - db_item.second->DbRWUnLock(); + db_item.second->DBUnlock(); } } diff --git a/src/pika_transaction.cc b/src/pika_transaction.cc index fa77be3e86..af9ea3ca5b 100644 --- a/src/pika_transaction.cc +++ b/src/pika_transaction.cc @@ -145,22 +145,22 @@ void ExecCmd::Lock() { g_pika_rm->DBLock(); } - std::for_each(r_lock_dbs_.begin(), r_lock_dbs_.end(), [this](auto& need_lock_slot) { - if (lock_db_keys_.count(need_lock_slot) != 0) { - pstd::lock::MultiRecordLock record_lock(need_lock_slot->LockMgr()); - record_lock.Lock(lock_db_keys_[need_lock_slot]); + std::for_each(r_lock_dbs_.begin(), r_lock_dbs_.end(), [this](auto& need_lock_db) { + if (lock_db_keys_.count(need_lock_db) != 0) { + pstd::lock::MultiRecordLock record_lock(need_lock_db->LockMgr()); + record_lock.Lock(lock_db_keys_[need_lock_db]); } - need_lock_slot->DbRWLockReader(); + need_lock_db->DBLockShared(); }); } void ExecCmd::Unlock() { - std::for_each(r_lock_dbs_.begin(), r_lock_dbs_.end(), [this](auto& need_lock_slot) { - if (lock_db_keys_.count(need_lock_slot) != 0) { - pstd::lock::MultiRecordLock record_lock(need_lock_slot->LockMgr()); - record_lock.Unlock(lock_db_keys_[need_lock_slot]); + std::for_each(r_lock_dbs_.begin(), r_lock_dbs_.end(), [this](auto& need_lock_db) { + if (lock_db_keys_.count(need_lock_db) != 0) { + pstd::lock::MultiRecordLock record_lock(need_lock_db->LockMgr()); + record_lock.Unlock(lock_db_keys_[need_lock_db]); } - need_lock_slot->DbRWUnLock(); + need_lock_db->DBUnlockShared(); }); if (is_lock_rm_dbs_) { g_pika_rm->DBUnlock(); diff --git a/src/storage/src/redis_hashes.cc b/src/storage/src/redis_hashes.cc index bf91e568ab..8ff90747aa 100644 --- a/src/storage/src/redis_hashes.cc +++ b/src/storage/src/redis_hashes.cc @@ -122,7 +122,6 @@ Status Redis::HDel(const Slice& key, const std::vector& fields, int std::string meta_value; int32_t del_cnt = 0; uint64_t version = 0; - ScopeRecordLock l(lock_mgr_, key); ScopeSnapshot ss(db_, &snapshot); read_options.snapshot = snapshot; @@ -281,7 +280,6 @@ Status Redis::HGetallWithTTL(const Slice& key, std::vector* fvs, int Status Redis::HIncrby(const Slice& key, const Slice& field, int64_t value, int64_t* ret) { *ret = 0; rocksdb::WriteBatch batch; - ScopeRecordLock l(lock_mgr_, key); uint64_t version = 0; uint32_t statistic = 0; @@ -359,7 +357,6 @@ Status Redis::HIncrby(const Slice& key, const Slice& field, int64_t value, int64 Status Redis::HIncrbyfloat(const Slice& key, const Slice& field, const Slice& by, std::string* new_value) { new_value->clear(); rocksdb::WriteBatch batch; - ScopeRecordLock l(lock_mgr_, key); uint64_t version = 0; uint32_t statistic = 0; @@ -553,7 +550,6 @@ Status Redis::HMSet(const Slice& key, const std::vector& fvs) { } rocksdb::WriteBatch batch; - ScopeRecordLock l(lock_mgr_, key); uint64_t version = 0; std::string meta_value; @@ -617,7 +613,6 @@ Status Redis::HMSet(const Slice& key, const std::vector& fvs) { Status Redis::HSet(const Slice& key, const Slice& field, const Slice& value, int32_t* res) { rocksdb::WriteBatch batch; - ScopeRecordLock l(lock_mgr_, key); uint64_t version = 0; uint32_t statistic = 0; @@ -682,7 +677,6 @@ Status Redis::HSet(const Slice& key, const Slice& field, const Slice& value, int Status Redis::HSetnx(const Slice& key, const Slice& field, const Slice& value, int32_t* ret) { rocksdb::WriteBatch batch; - ScopeRecordLock l(lock_mgr_, key); uint64_t version = 0; std::string meta_value; @@ -1030,8 +1024,6 @@ Status Redis::PKHRScanRange(const Slice& key, const Slice& field_start, const st Status Redis::HashesExpire(const Slice& key, int64_t ttl) { std::string meta_value; - ScopeRecordLock l(lock_mgr_, key); - BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kHashesMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { @@ -1055,8 +1047,6 @@ Status Redis::HashesExpire(const Slice& key, int64_t ttl) { Status Redis::HashesDel(const Slice& key) { std::string meta_value; - ScopeRecordLock l(lock_mgr_, key); - BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kHashesMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { @@ -1077,8 +1067,6 @@ Status Redis::HashesDel(const Slice& key) { Status Redis::HashesExpireat(const Slice& key, int64_t timestamp) { std::string meta_value; - ScopeRecordLock l(lock_mgr_, key); - BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kHashesMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { @@ -1101,8 +1089,6 @@ Status Redis::HashesExpireat(const Slice& key, int64_t timestamp) { Status Redis::HashesPersist(const Slice& key) { std::string meta_value; - ScopeRecordLock l(lock_mgr_, key); - BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kHashesMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { diff --git a/src/storage/src/redis_lists.cc b/src/storage/src/redis_lists.cc index f15a11b113..0d71445e59 100644 --- a/src/storage/src/redis_lists.cc +++ b/src/storage/src/redis_lists.cc @@ -141,7 +141,6 @@ Status Redis::LInsert(const Slice& key, const BeforeOrAfter& before_or_after, co const std::string& value, int64_t* ret) { *ret = 0; rocksdb::WriteBatch batch; - ScopeRecordLock l(lock_mgr_, key); std::string meta_value; BaseMetaKey base_meta_key(key); @@ -266,7 +265,6 @@ Status Redis::LPop(const Slice& key, int64_t count, std::vector* el elements->clear(); rocksdb::WriteBatch batch; - ScopeRecordLock l(lock_mgr_, key); std::string meta_value; @@ -312,7 +310,6 @@ Status Redis::LPop(const Slice& key, int64_t count, std::vector* el Status Redis::LPush(const Slice& key, const std::vector& values, uint64_t* ret) { *ret = 0; rocksdb::WriteBatch batch; - ScopeRecordLock l(lock_mgr_, key); uint64_t index = 0; uint64_t version = 0; @@ -360,7 +357,6 @@ Status Redis::LPush(const Slice& key, const std::vector& values, ui Status Redis::LPushx(const Slice& key, const std::vector& values, uint64_t* len) { *len = 0; rocksdb::WriteBatch batch; - ScopeRecordLock l(lock_mgr_, key); std::string meta_value; @@ -505,7 +501,6 @@ Status Redis::LRangeWithTTL(const Slice& key, int64_t start, int64_t stop, std:: Status Redis::LRem(const Slice& key, int64_t count, const Slice& value, uint64_t* ret) { *ret = 0; rocksdb::WriteBatch batch; - ScopeRecordLock l(lock_mgr_, key); std::string meta_value; BaseMetaKey base_meta_key(key); @@ -627,7 +622,6 @@ Status Redis::LRem(const Slice& key, int64_t count, const Slice& value, uint64_t Status Redis::LSet(const Slice& key, int64_t index, const Slice& value) { uint32_t statistic = 0; - ScopeRecordLock l(lock_mgr_, key); std::string meta_value; BaseMetaKey base_meta_key(key); @@ -659,7 +653,6 @@ Status Redis::LSet(const Slice& key, int64_t index, const Slice& value) { Status Redis::LTrim(const Slice& key, int64_t start, int64_t stop) { rocksdb::WriteBatch batch; - ScopeRecordLock l(lock_mgr_, key); uint32_t statistic = 0; std::string meta_value; @@ -723,7 +716,6 @@ Status Redis::RPop(const Slice& key, int64_t count, std::vector* el elements->clear(); rocksdb::WriteBatch batch; - ScopeRecordLock l(lock_mgr_, key); std::string meta_value; @@ -771,7 +763,6 @@ Status Redis::RPoplpush(const Slice& source, const Slice& destination, std::stri uint32_t statistic = 0; Status s; rocksdb::WriteBatch batch; - MultiScopeRecordLock l(lock_mgr_, {source.ToString(), destination.ToString()}); if (source.compare(destination) == 0) { std::string meta_value; BaseMetaKey base_source(source); @@ -937,7 +928,6 @@ Status Redis::RPushx(const Slice& key, const std::vector& values, u *len = 0; rocksdb::WriteBatch batch; - ScopeRecordLock l(lock_mgr_, key); std::string meta_value; BaseMetaKey base_meta_key(key); @@ -968,8 +958,6 @@ Status Redis::RPushx(const Slice& key, const std::vector& values, u Status Redis::ListsExpire(const Slice& key, int64_t ttl) { std::string meta_value; - ScopeRecordLock l(lock_mgr_, key); - BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kListsMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { @@ -993,8 +981,6 @@ Status Redis::ListsExpire(const Slice& key, int64_t ttl) { Status Redis::ListsDel(const Slice& key) { std::string meta_value; - ScopeRecordLock l(lock_mgr_, key); - BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kListsMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { @@ -1015,8 +1001,6 @@ Status Redis::ListsDel(const Slice& key) { Status Redis::ListsExpireat(const Slice& key, int64_t timestamp) { std::string meta_value; - ScopeRecordLock l(lock_mgr_, key); - BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kListsMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { @@ -1039,7 +1023,6 @@ Status Redis::ListsExpireat(const Slice& key, int64_t timestamp) { Status Redis::ListsPersist(const Slice& key) { std::string meta_value; - ScopeRecordLock l(lock_mgr_, key); BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kListsMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { diff --git a/src/storage/src/redis_sets.cc b/src/storage/src/redis_sets.cc index 38c556bec7..b8d521f982 100644 --- a/src/storage/src/redis_sets.cc +++ b/src/storage/src/redis_sets.cc @@ -117,7 +117,6 @@ rocksdb::Status Redis::SAdd(const Slice& key, const std::vector& me } rocksdb::WriteBatch batch; - ScopeRecordLock l(lock_mgr_, key); uint64_t version = 0; std::string meta_value; @@ -283,7 +282,6 @@ rocksdb::Status Redis::SDiffstore(const Slice& destination, const std::vector vaild_sets; @@ -464,7 +462,6 @@ rocksdb::Status Redis::SInterstore(const Slice& destination, const std::vector vaild_sets; @@ -687,8 +684,6 @@ rocksdb::Status Redis::SMove(const Slice& source, const Slice& destination, cons uint32_t statistic = 0; std::string meta_value; std::vector keys{source.ToString(), destination.ToString()}; - MultiScopeRecordLock ml(lock_mgr_, keys); - if (source == destination) { *ret = 1; return rocksdb::Status::OK(); @@ -780,7 +775,6 @@ rocksdb::Status Redis::SPop(const Slice& key, std::vector* members, std::string meta_value; rocksdb::WriteBatch batch; - ScopeRecordLock l(lock_mgr_, key); uint64_t start_us = pstd::NowMicros(); @@ -886,7 +880,6 @@ rocksdb::Status Redis::SRandmember(const Slice& key, int32_t count, std::vector< std::string meta_value; rocksdb::WriteBatch batch; - ScopeRecordLock l(lock_mgr_, key); std::vector targets; std::unordered_set unique; @@ -949,7 +942,6 @@ rocksdb::Status Redis::SRandmember(const Slice& key, int32_t count, std::vector< rocksdb::Status Redis::SRem(const Slice& key, const std::vector& members, int32_t* ret) { *ret = 0; rocksdb::WriteBatch batch; - ScopeRecordLock l(lock_mgr_, key); uint64_t version = 0; uint32_t statistic = 0; @@ -1200,8 +1192,6 @@ rocksdb::Status Redis::SScan(const Slice& key, int64_t cursor, const std::string rocksdb::Status Redis::SetsExpire(const Slice& key, int64_t ttl) { std::string meta_value; - ScopeRecordLock l(lock_mgr_, key); - BaseMetaKey base_meta_key(key); rocksdb::Status s = db_->Get(default_read_options_, handles_[kSetsMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { @@ -1225,8 +1215,6 @@ rocksdb::Status Redis::SetsExpire(const Slice& key, int64_t ttl) { rocksdb::Status Redis::SetsDel(const Slice& key) { std::string meta_value; - ScopeRecordLock l(lock_mgr_, key); - BaseMetaKey base_meta_key(key); rocksdb::Status s = db_->Get(default_read_options_, handles_[kSetsMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { @@ -1247,8 +1235,6 @@ rocksdb::Status Redis::SetsDel(const Slice& key) { rocksdb::Status Redis::SetsExpireat(const Slice& key, int64_t timestamp) { std::string meta_value; - ScopeRecordLock l(lock_mgr_, key); - BaseMetaKey base_meta_key(key); rocksdb::Status s = db_->Get(default_read_options_, handles_[kSetsMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { @@ -1271,8 +1257,6 @@ rocksdb::Status Redis::SetsExpireat(const Slice& key, int64_t timestamp) { rocksdb::Status Redis::SetsPersist(const Slice& key) { std::string meta_value; - ScopeRecordLock l(lock_mgr_, key); - BaseMetaKey base_meta_key(key); rocksdb::Status s = db_->Get(default_read_options_, handles_[kSetsMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { diff --git a/src/storage/src/redis_strings.cc b/src/storage/src/redis_strings.cc index 9b1d2859d5..c71aec5878 100644 --- a/src/storage/src/redis_strings.cc +++ b/src/storage/src/redis_strings.cc @@ -110,8 +110,6 @@ Status Redis::StringsPKPatternMatchDel(const std::string& pattern, int32_t* ret) Status Redis::Append(const Slice& key, const Slice& value, int32_t* ret) { std::string old_value; *ret = 0; - ScopeRecordLock l(lock_mgr_, key); - BaseKey base_key(key); Status s = db_->Get(default_read_options_, base_key.Encode(), &old_value); if (s.ok()) { @@ -280,7 +278,6 @@ Status Redis::BitOp(BitOpType op, const std::string& dest_key, const std::vector *ret = static_cast(dest_value.size()); StringsValue strings_value(Slice(dest_value.c_str(), max_len)); - ScopeRecordLock l(lock_mgr_, dest_key); BaseKey base_dest_key(dest_key); return db_->Put(default_write_options_, base_dest_key.Encode(), strings_value.Encode()); } @@ -288,8 +285,6 @@ Status Redis::BitOp(BitOpType op, const std::string& dest_key, const std::vector Status Redis::Decrby(const Slice& key, int64_t value, int64_t* ret) { std::string old_value; std::string new_value; - ScopeRecordLock l(lock_mgr_, key); - BaseKey base_key(key); Status s = db_->Get(default_read_options_, base_key.Encode(), &old_value); if (s.ok()) { @@ -488,8 +483,6 @@ Status Redis::GetrangeWithValue(const Slice& key, int64_t start_offset, int64_t } Status Redis::GetSet(const Slice& key, const Slice& value, std::string* old_value) { - ScopeRecordLock l(lock_mgr_, key); - BaseKey base_key(key); Status s = db_->Get(default_read_options_, base_key.Encode(), old_value); if (s.ok()) { @@ -509,8 +502,6 @@ Status Redis::GetSet(const Slice& key, const Slice& value, std::string* old_valu Status Redis::Incrby(const Slice& key, int64_t value, int64_t* ret) { std::string old_value; std::string new_value; - ScopeRecordLock l(lock_mgr_, key); - BaseKey base_key(key); Status s = db_->Get(default_read_options_, base_key.Encode(), &old_value); char buf[32] = {0}; @@ -557,7 +548,6 @@ Status Redis::Incrbyfloat(const Slice& key, const Slice& value, std::string* ret } BaseKey base_key(key); - ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, base_key.Encode(), &old_value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&old_value); @@ -637,8 +627,6 @@ Status Redis::MSetnx(const std::vector& kvs, int32_t* ret) { Status Redis::Set(const Slice& key, const Slice& value) { StringsValue strings_value(value); - ScopeRecordLock l(lock_mgr_, key); - BaseKey base_key(key); return db_->Put(default_write_options_, base_key.Encode(), strings_value.Encode()); } @@ -649,7 +637,6 @@ Status Redis::Setxx(const Slice& key, const Slice& value, int32_t* ret, int64_t StringsValue strings_value(value); BaseKey base_key(key); - ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, base_key.Encode(), &old_value); if (s.ok()) { ParsedStringsValue parsed_strings_value(old_value); @@ -679,7 +666,6 @@ Status Redis::SetBit(const Slice& key, int64_t offset, int32_t on, int32_t* ret) } BaseKey base_key(key); - ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, base_key.Encode(), &meta_value); if (s.ok() || s.IsNotFound()) { std::string data_value; @@ -732,7 +718,6 @@ Status Redis::Setex(const Slice& key, const Slice& value, int64_t ttl) { } BaseKey base_key(key); - ScopeRecordLock l(lock_mgr_, key); return db_->Put(default_write_options_, base_key.Encode(), strings_value.Encode()); } @@ -741,7 +726,6 @@ Status Redis::Setnx(const Slice& key, const Slice& value, int32_t* ret, int64_t std::string old_value; BaseKey base_key(key); - ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, base_key.Encode(), &old_value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&old_value); @@ -774,7 +758,6 @@ Status Redis::Setvx(const Slice& key, const Slice& value, const Slice& new_value std::string old_value; BaseKey base_key(key); - ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, base_key.Encode(), &old_value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&old_value); @@ -808,7 +791,6 @@ Status Redis::Delvx(const Slice& key, const Slice& value, int32_t* ret) { std::string old_value; BaseKey base_key(key); - ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, base_key.Encode(), &old_value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&old_value); @@ -836,8 +818,6 @@ Status Redis::Setrange(const Slice& key, int64_t start_offset, const Slice& valu return Status::InvalidArgument("offset < 0"); } - ScopeRecordLock l(lock_mgr_, key); - BaseKey base_key(key); Status s = db_->Get(default_read_options_, base_key.Encode(), &old_value); if (s.ok()) { @@ -1084,7 +1064,6 @@ Status Redis::PKSetexAt(const Slice& key, const Slice& value, int64_t timestamp) StringsValue strings_value(value); BaseKey base_key(key); - ScopeRecordLock l(lock_mgr_, key); strings_value.SetEtime(uint64_t(timestamp)); return db_->Put(default_write_options_, base_key.Encode(), strings_value.Encode()); } @@ -1112,8 +1091,6 @@ Status Redis::StringsExpire(const Slice& key, int64_t ttl) { Status Redis::StringsDel(const Slice& key) { std::string value; - ScopeRecordLock l(lock_mgr_, key); - BaseKey base_key(key); Status s = db_->Get(default_read_options_, base_key.Encode(), &value); if (s.ok()) { @@ -1128,8 +1105,6 @@ Status Redis::StringsDel(const Slice& key) { Status Redis::StringsExpireat(const Slice& key, int64_t timestamp) { std::string value; - ScopeRecordLock l(lock_mgr_, key); - BaseKey base_key(key); Status s = db_->Get(default_read_options_, base_key.Encode(), &value); if (s.ok()) { @@ -1150,8 +1125,6 @@ Status Redis::StringsExpireat(const Slice& key, int64_t timestamp) { Status Redis::StringsPersist(const Slice& key) { std::string value; - ScopeRecordLock l(lock_mgr_, key); - BaseKey base_key(key); Status s = db_->Get(default_read_options_, base_key.Encode(), &value); if (s.ok()) { @@ -1173,8 +1146,6 @@ Status Redis::StringsPersist(const Slice& key) { Status Redis::StringsTTL(const Slice& key, int64_t* timestamp) { std::string value; - ScopeRecordLock l(lock_mgr_, key); - BaseKey base_key(key); Status s = db_->Get(default_read_options_, base_key.Encode(), &value); if (s.ok()) { diff --git a/src/storage/src/redis_zsets.cc b/src/storage/src/redis_zsets.cc index 9cde3cfaf6..b34da44a38 100644 --- a/src/storage/src/redis_zsets.cc +++ b/src/storage/src/redis_zsets.cc @@ -112,7 +112,6 @@ Status Redis::ZPopMax(const Slice& key, const int64_t count, std::vectorclear(); rocksdb::WriteBatch batch; - ScopeRecordLock l(lock_mgr_, key); std::string meta_value; BaseMetaKey base_meta_key(key); @@ -160,7 +159,6 @@ Status Redis::ZPopMin(const Slice& key, const int64_t count, std::vectorclear(); rocksdb::WriteBatch batch; - ScopeRecordLock l(lock_mgr_, key); std::string meta_value; BaseMetaKey base_meta_key(key); @@ -220,8 +218,6 @@ Status Redis::ZAdd(const Slice& key, const std::vector& score_membe uint64_t version = 0; std::string meta_value; rocksdb::WriteBatch batch; - ScopeRecordLock l(lock_mgr_, key); - BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kZsetsMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { @@ -395,8 +391,6 @@ Status Redis::ZIncrby(const Slice& key, const Slice& member, double increment, d uint64_t version = 0; std::string meta_value; rocksdb::WriteBatch batch; - ScopeRecordLock l(lock_mgr_, key); - BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kZsetsMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { @@ -693,8 +687,6 @@ Status Redis::ZRem(const Slice& key, const std::vector& members, in std::string meta_value; rocksdb::WriteBatch batch; - ScopeRecordLock l(lock_mgr_, key); - BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kZsetsMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { @@ -746,8 +738,6 @@ Status Redis::ZRemrangebyrank(const Slice& key, int32_t start, int32_t stop, int uint32_t statistic = 0; std::string meta_value; rocksdb::WriteBatch batch; - ScopeRecordLock l(lock_mgr_, key); - BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kZsetsMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { @@ -804,8 +794,6 @@ Status Redis::ZRemrangebyscore(const Slice& key, double min, double max, bool le uint32_t statistic = 0; std::string meta_value; rocksdb::WriteBatch batch; - ScopeRecordLock l(lock_mgr_, key); - BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kZsetsMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { @@ -1111,7 +1099,6 @@ Status Redis::ZUnionstore(const Slice& destination, const std::vector member_score_map; Status s; @@ -1212,7 +1199,6 @@ Status Redis::ZInterstore(const Slice& destination, const std::vectorGet(default_read_options_, handles_[kZsetsMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { @@ -1495,8 +1478,6 @@ Status Redis::ZsetsExpire(const Slice& key, int64_t ttl) { Status Redis::ZsetsDel(const Slice& key) { std::string meta_value; - ScopeRecordLock l(lock_mgr_, key); - BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kZsetsMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { @@ -1517,8 +1498,6 @@ Status Redis::ZsetsDel(const Slice& key) { Status Redis::ZsetsExpireat(const Slice& key, int64_t timestamp) { std::string meta_value; - ScopeRecordLock l(lock_mgr_, key); - BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kZsetsMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { @@ -1617,8 +1596,6 @@ Status Redis::ZScan(const Slice& key, int64_t cursor, const std::string& pattern Status Redis::ZsetsPersist(const Slice& key) { std::string meta_value; - ScopeRecordLock l(lock_mgr_, key); - BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kZsetsMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) {