From 8100546ffc2782d1d20327d1d0a8bbe7cacdfa76 Mon Sep 17 00:00:00 2001 From: git-hulk Date: Mon, 30 Oct 2023 09:50:44 +0800 Subject: [PATCH] Unify server's shorten form, change svr to srv --- src/cluster/cluster.cc | 42 +++--- src/cluster/cluster.h | 4 +- src/cluster/slot_import.cc | 10 +- src/cluster/slot_import.h | 4 +- src/cluster/slot_migrate.cc | 18 +-- src/cluster/slot_migrate.h | 4 +- src/cluster/sync_migrate_context.cc | 4 +- src/cluster/sync_migrate_context.h | 4 +- src/commands/cmd_bit.cc | 20 +-- src/commands/cmd_bloom_filter.cc | 32 ++--- src/commands/cmd_cluster.cc | 32 ++--- src/commands/cmd_geo.cc | 32 ++--- src/commands/cmd_hash.cc | 68 +++++----- src/commands/cmd_json.cc | 16 +-- src/commands/cmd_key.cc | 48 +++---- src/commands/cmd_list.cc | 92 ++++++------- src/commands/cmd_pubsub.cc | 24 ++-- src/commands/cmd_replication.cc | 56 ++++---- src/commands/cmd_script.cc | 14 +- src/commands/cmd_server.cc | 164 ++++++++++++------------ src/commands/cmd_set.cc | 72 +++++------ src/commands/cmd_sortedint.cc | 24 ++-- src/commands/cmd_stream.cc | 60 ++++----- src/commands/cmd_string.cc | 96 +++++++------- src/commands/cmd_txn.cc | 24 ++-- src/commands/cmd_zset.cc | 114 ++++++++-------- src/commands/commander.h | 2 +- src/commands/scan_base.h | 8 +- src/config/config.cc | 4 +- src/config/config.h | 2 +- src/server/redis_connection.cc | 56 ++++---- src/server/redis_connection.h | 4 +- src/server/redis_request.cc | 6 +- src/server/redis_request.h | 4 +- src/server/worker.cc | 40 +++--- src/server/worker.h | 4 +- src/storage/scripting.cc | 4 +- src/storage/scripting.h | 2 +- tests/gocase/unit/expire/expire_test.go | 6 +- 39 files changed, 610 insertions(+), 610 deletions(-) diff --git a/src/cluster/cluster.cc b/src/cluster/cluster.cc index 6c19f11b80d..ff98da876b1 100644 --- a/src/cluster/cluster.cc +++ b/src/cluster/cluster.cc @@ -40,8 +40,8 @@ ClusterNode::ClusterNode(std::string id, std::string host, int port, int role, s std::bitset slots) : id(std::move(id)), host(std::move(host)), port(port), role(role), master_id(std::move(master_id)), slots(slots) {} -Cluster::Cluster(Server *svr, std::vector binds, int port) - : svr_(svr), binds_(std::move(binds)), port_(port), size_(0), version_(-1), myself_(nullptr) { +Cluster::Cluster(Server *srv, std::vector binds, int port) + : srv_(srv), binds_(std::move(binds)), port_(port), size_(0), version_(-1), myself_(nullptr) { for (auto &slots_node : slots_nodes_) { slots_node = nullptr; } @@ -127,7 +127,7 @@ Status Cluster::SetSlotRanges(const std::vector &slot_ranges, const s if (old_node == myself_ && old_node != to_assign_node) { // If slot is migrated from this node if (migrated_slots_.count(slot) > 0) { - auto s = svr_->slot_migrator->ClearKeysOfSlot(kDefaultNamespace, slot); + auto s = srv_->slot_migrator->ClearKeysOfSlot(kDefaultNamespace, slot); if (!s.ok()) { LOG(ERROR) << "failed to clear data of migrated slot: " << s.ToString(); } @@ -212,7 +212,7 @@ Status Cluster::SetClusterNodes(const std::string &nodes_str, int64_t version, b if (!migrated_slots_.empty()) { for (auto &it : migrated_slots_) { if (slots_nodes_[it.first] != myself_) { - auto s = svr_->slot_migrator->ClearKeysOfSlot(kDefaultNamespace, it.first); + auto s = srv_->slot_migrator->ClearKeysOfSlot(kDefaultNamespace, it.first); if (!s.ok()) { LOG(ERROR) << "failed to clear data of migrated slots: " << s.ToString(); } @@ -228,13 +228,13 @@ Status Cluster::SetClusterNodes(const std::string &nodes_str, int64_t version, b // Set replication relationship by cluster topology setting Status Cluster::SetMasterSlaveRepl() { - if (!svr_) return Status::OK(); + if (!srv_) return Status::OK(); if (!myself_) return Status::OK(); if (myself_->role == kClusterMaster) { // Master mode - auto s = svr_->RemoveMaster(); + auto s = srv_->RemoveMaster(); if (!s.IsOK()) { return s.Prefixed("failed to remove master"); } @@ -242,7 +242,7 @@ Status Cluster::SetMasterSlaveRepl() { } else if (nodes_.find(myself_->master_id) != nodes_.end()) { // Replica mode and master node is existing std::shared_ptr master = nodes_[myself_->master_id]; - auto s = svr_->AddMaster(master->host, master->port, false); + auto s = srv_->AddMaster(master->host, master->port, false); if (!s.IsOK()) { LOG(WARNING) << "SLAVE OF " << master->host << ":" << master->port << " wasn't enabled by cluster topology setting, encounter error: " << s.Msg(); @@ -254,7 +254,7 @@ Status Cluster::SetMasterSlaveRepl() { return Status::OK(); } -bool Cluster::IsNotMaster() { return myself_ == nullptr || myself_->role != kClusterMaster || svr_->IsSlave(); } +bool Cluster::IsNotMaster() { return myself_ == nullptr || myself_->role != kClusterMaster || srv_->IsSlave(); } Status Cluster::SetSlotMigrated(int slot, const std::string &ip_port) { if (!IsValidSlot(slot)) { @@ -264,7 +264,7 @@ Status Cluster::SetSlotMigrated(int slot, const std::string &ip_port) { // It is called by slot-migrating thread which is an asynchronous thread. // Therefore, it should be locked when a record is added to 'migrated_slots_' // which will be accessed when executing commands. - auto exclusivity = svr_->WorkExclusivityGuard(); + auto exclusivity = srv_->WorkExclusivityGuard(); migrated_slots_[slot] = ip_port; return Status::OK(); } @@ -306,7 +306,7 @@ Status Cluster::MigrateSlot(int slot, const std::string &dst_node_id, SyncMigrat } const auto &dst = nodes_[dst_node_id]; - Status s = svr_->slot_migrator->PerformSlotMigration(dst_node_id, dst->host, dst->port, slot, blocking_ctx); + Status s = srv_->slot_migrator->PerformSlotMigration(dst_node_id, dst->host, dst->port, slot, blocking_ctx); return s; } @@ -321,7 +321,7 @@ Status Cluster::ImportSlot(redis::Connection *conn, int slot, int state) { switch (state) { case kImportStart: - if (!svr_->slot_import->Start(conn->GetFD(), slot)) { + if (!srv_->slot_import->Start(conn->GetFD(), slot)) { return {Status::NotOK, fmt::format("Can't start importing slot {}", slot)}; } @@ -329,26 +329,26 @@ Status Cluster::ImportSlot(redis::Connection *conn, int slot, int state) { conn->SetImporting(); myself_->importing_slot = slot; // Set link error callback - conn->close_cb = [object_ptr = svr_->slot_import.get(), capture_fd = conn->GetFD()](int fd) { + conn->close_cb = [object_ptr = srv_->slot_import.get(), capture_fd = conn->GetFD()](int fd) { object_ptr->StopForLinkError(capture_fd); }; // Stop forbidding writing slot to accept write commands - if (slot == svr_->slot_migrator->GetForbiddenSlot()) svr_->slot_migrator->ReleaseForbiddenSlot(); + if (slot == srv_->slot_migrator->GetForbiddenSlot()) srv_->slot_migrator->ReleaseForbiddenSlot(); LOG(INFO) << "[import] Start importing slot " << slot; break; case kImportSuccess: - if (!svr_->slot_import->Success(slot)) { + if (!srv_->slot_import->Success(slot)) { LOG(ERROR) << "[import] Failed to set slot importing success, maybe slot is wrong" - << ", received slot: " << slot << ", current slot: " << svr_->slot_import->GetSlot(); + << ", received slot: " << slot << ", current slot: " << srv_->slot_import->GetSlot(); return {Status::NotOK, fmt::format("Failed to set slot {} importing success", slot)}; } LOG(INFO) << "[import] Succeed to import slot " << slot; break; case kImportFailed: - if (!svr_->slot_import->Fail(slot)) { + if (!srv_->slot_import->Fail(slot)) { LOG(ERROR) << "[import] Failed to set slot importing error, maybe slot is wrong" - << ", received slot: " << slot << ", current slot: " << svr_->slot_import->GetSlot(); + << ", received slot: " << slot << ", current slot: " << srv_->slot_import->GetSlot(); return {Status::NotOK, fmt::format("Failed to set slot {} importing error", slot)}; } @@ -395,15 +395,15 @@ Status Cluster::GetClusterInfo(std::string *cluster_infos) { "cluster_my_epoch:" + std::to_string(version_) + "\r\n"; - if (myself_ != nullptr && myself_->role == kClusterMaster && !svr_->IsSlave()) { + if (myself_ != nullptr && myself_->role == kClusterMaster && !srv_->IsSlave()) { // Get migrating status std::string migrate_infos; - svr_->slot_migrator->GetMigrationInfo(&migrate_infos); + srv_->slot_migrator->GetMigrationInfo(&migrate_infos); *cluster_infos += migrate_infos; // Get importing status std::string import_infos; - svr_->slot_import->GetImportInfo(&import_infos); + srv_->slot_import->GetImportInfo(&import_infos); *cluster_infos += import_infos; } @@ -743,7 +743,7 @@ Status Cluster::parseClusterNodes(const std::string &nodes_str, ClusterNodes *no return Status::OK(); } -bool Cluster::IsWriteForbiddenSlot(int slot) { return svr_->slot_migrator->GetForbiddenSlot() == slot; } +bool Cluster::IsWriteForbiddenSlot(int slot) { return srv_->slot_migrator->GetForbiddenSlot() == slot; } Status Cluster::CanExecByMySelf(const redis::CommandAttributes *attributes, const std::vector &cmd_tokens, redis::Connection *conn) { diff --git a/src/cluster/cluster.h b/src/cluster/cluster.h index 8cad0c4f79c..8b8132ab0db 100644 --- a/src/cluster/cluster.h +++ b/src/cluster/cluster.h @@ -68,7 +68,7 @@ class SyncMigrateContext; class Cluster { public: - explicit Cluster(Server *svr, std::vector binds, int port); + explicit Cluster(Server *srv, std::vector binds, int port); Status SetClusterNodes(const std::string &nodes_str, int64_t version, bool force); Status GetClusterNodes(std::string *nodes_str); Status SetNodeId(const std::string &node_id); @@ -99,7 +99,7 @@ class Cluster { SlotInfo genSlotNodeInfo(int start, int end, const std::shared_ptr &n); static Status parseClusterNodes(const std::string &nodes_str, ClusterNodes *nodes, std::unordered_map *slots_nodes); - Server *svr_; + Server *srv_; std::vector binds_; int port_; int size_; diff --git a/src/cluster/slot_import.cc b/src/cluster/slot_import.cc index 91d9381ad08..6696361171d 100644 --- a/src/cluster/slot_import.cc +++ b/src/cluster/slot_import.cc @@ -20,9 +20,9 @@ #include "slot_import.h" -SlotImport::SlotImport(Server *svr) - : Database(svr->storage, kDefaultNamespace), - svr_(svr), +SlotImport::SlotImport(Server *srv) + : Database(srv->storage, kDefaultNamespace), + srv_(srv), import_slot_(-1), import_status_(kImportNone), import_fd_(-1) { @@ -62,7 +62,7 @@ bool SlotImport::Success(int slot) { return false; } - Status s = svr_->cluster->SetSlotImported(import_slot_); + Status s = srv_->cluster->SetSlotImported(import_slot_); if (!s.IsOK()) { LOG(ERROR) << "[import] Failed to set slot, Err: " << s.Msg(); return false; @@ -107,7 +107,7 @@ void SlotImport::StopForLinkError(int fd) { // 4. ClearKeysOfSlot can clear data although server is a slave, because ClearKeysOfSlot // deletes data in rocksdb directly. Therefore, it is necessary to avoid clearing data gotten // from new master. - if (!svr_->IsSlave()) { + if (!srv_->IsSlave()) { // Clean imported slot data auto s = ClearKeysOfSlot(namespace_, import_slot_); if (!s.ok()) { diff --git a/src/cluster/slot_import.h b/src/cluster/slot_import.h index 9700ae9a02e..385aca0f6d1 100644 --- a/src/cluster/slot_import.h +++ b/src/cluster/slot_import.h @@ -39,7 +39,7 @@ enum ImportStatus { class SlotImport : public redis::Database { public: - explicit SlotImport(Server *svr); + explicit SlotImport(Server *srv); ~SlotImport() = default; bool Start(int fd, int slot); @@ -51,7 +51,7 @@ class SlotImport : public redis::Database { void GetImportInfo(std::string *info); private: - Server *svr_ = nullptr; + Server *srv_ = nullptr; std::mutex mutex_; int import_slot_; int import_status_; diff --git a/src/cluster/slot_migrate.cc b/src/cluster/slot_migrate.cc index 3e93d832b31..3dc1f2259eb 100644 --- a/src/cluster/slot_migrate.cc +++ b/src/cluster/slot_migrate.cc @@ -42,8 +42,8 @@ static std::map type_to_cmd = { {kRedisZSet, "zadd"}, {kRedisBitmap, "setbit"}, {kRedisSortedint, "siadd"}, {kRedisStream, "xadd"}, }; -SlotMigrator::SlotMigrator(Server *svr, int max_migration_speed, int max_pipeline_size, int seq_gap_limit) - : Database(svr->storage, kDefaultNamespace), svr_(svr) { +SlotMigrator::SlotMigrator(Server *srv, int max_migration_speed, int max_pipeline_size, int seq_gap_limit) + : Database(srv->storage, kDefaultNamespace), srv_(srv) { // Let metadata_cf_handle_ be nullptr, and get them in real time to avoid accessing invalid pointer, // because metadata_cf_handle_ and db_ will be destroyed if DB is reopened. // [Situation]: @@ -71,7 +71,7 @@ SlotMigrator::SlotMigrator(Server *svr, int max_migration_speed, int max_pipelin seq_gap_limit_ = seq_gap_limit; } - if (svr->IsSlave()) { + if (srv->IsSlave()) { SetStopMigrationFlag(true); } } @@ -92,9 +92,9 @@ Status SlotMigrator::PerformSlotMigration(const std::string &node_id, std::strin migration_state_ = MigrationState::kStarted; - auto speed = svr_->GetConfig()->migrate_speed; - auto seq_gap = svr_->GetConfig()->sequence_gap; - auto pipeline_size = svr_->GetConfig()->pipeline_size; + auto speed = srv_->GetConfig()->migrate_speed; + auto seq_gap = srv_->GetConfig()->sequence_gap; + auto pipeline_size = srv_->GetConfig()->pipeline_size; if (speed <= 0) { speed = 0; @@ -279,7 +279,7 @@ Status SlotMigrator::startMigration() { dst_fd_.Reset(*result); // Auth first - std::string pass = svr_->GetConfig()->requirepass; + std::string pass = srv_->GetConfig()->requirepass; if (!pass.empty()) { auto s = authOnDstNode(*dst_fd_, pass); if (!s.IsOK()) { @@ -396,7 +396,7 @@ Status SlotMigrator::finishSuccessfulMigration() { } std::string dst_ip_port = dst_ip_ + ":" + std::to_string(dst_port_); - s = svr_->cluster->SetSlotMigrated(migrating_slot_, dst_ip_port); + s = srv_->cluster->SetSlotMigrated(migrating_slot_, dst_ip_port); if (!s.IsOK()) { return s.Prefixed(fmt::format("failed to set slot {} as migrated to {}", migrating_slot_.load(), dst_ip_port)); } @@ -896,7 +896,7 @@ void SlotMigrator::setForbiddenSlot(int16_t slot) { // Block server to set forbidden slot uint64_t during = util::GetTimeStampUS(); { - auto exclusivity = svr_->WorkExclusivityGuard(); + auto exclusivity = srv_->WorkExclusivityGuard(); forbidden_slot_ = slot; } during = util::GetTimeStampUS() - during; diff --git a/src/cluster/slot_migrate.h b/src/cluster/slot_migrate.h index 5dc1559ccf0..4ac00ad58d1 100644 --- a/src/cluster/slot_migrate.h +++ b/src/cluster/slot_migrate.h @@ -75,7 +75,7 @@ class SyncMigrateContext; class SlotMigrator : public redis::Database { public: - explicit SlotMigrator(Server *svr, int max_migration_speed = kDefaultMaxMigrationSpeed, + explicit SlotMigrator(Server *srv, int max_migration_speed = kDefaultMaxMigrationSpeed, int max_pipeline_size = kDefaultMaxPipelineSize, int seq_gap_limit = kDefaultSequenceGapLimit); SlotMigrator(const SlotMigrator &other) = delete; SlotMigrator &operator=(const SlotMigrator &other) = delete; @@ -147,7 +147,7 @@ class SlotMigrator : public redis::Database { static const int kMaxItemsInCommand = 16; // number of items in every write command of complex keys static const int kMaxLoopTimes = 10; - Server *svr_; + Server *srv_; int max_migration_speed_; int max_pipeline_size_; int seq_gap_limit_; diff --git a/src/cluster/sync_migrate_context.cc b/src/cluster/sync_migrate_context.cc index 3ad7ee31f2e..0633cecd1de 100644 --- a/src/cluster/sync_migrate_context.cc +++ b/src/cluster/sync_migrate_context.cc @@ -41,7 +41,7 @@ void SyncMigrateContext::Resume(const Status &migrate_result) { } void SyncMigrateContext::OnEvent(bufferevent *bev, int16_t events) { - auto &&slot_migrator = svr_->slot_migrator; + auto &&slot_migrator = srv_->slot_migrator; if (events & (BEV_EVENT_EOF | BEV_EVENT_ERROR)) { timer_.reset(); @@ -52,7 +52,7 @@ void SyncMigrateContext::OnEvent(bufferevent *bev, int16_t events) { } void SyncMigrateContext::TimerCB(int, int16_t events) { - auto &&slot_migrator = svr_->slot_migrator; + auto &&slot_migrator = srv_->slot_migrator; conn_->Reply(redis::NilString()); timer_.reset(); diff --git a/src/cluster/sync_migrate_context.h b/src/cluster/sync_migrate_context.h index 5dd7668f334..818736cb446 100644 --- a/src/cluster/sync_migrate_context.h +++ b/src/cluster/sync_migrate_context.h @@ -25,7 +25,7 @@ class SyncMigrateContext : private EvbufCallbackBase, private EventCallbackBase { public: - SyncMigrateContext(Server *svr, redis::Connection *conn, int timeout) : svr_(svr), conn_(conn), timeout_(timeout){}; + SyncMigrateContext(Server *srv, redis::Connection *conn, int timeout) : srv_(srv), conn_(conn), timeout_(timeout){}; void Suspend(); void Resume(const Status &migrate_result); @@ -34,7 +34,7 @@ class SyncMigrateContext : private EvbufCallbackBase, void TimerCB(int, int16_t events); private: - Server *svr_; + Server *srv_; redis::Connection *conn_; int timeout_ = 0; UniqueEvent timer_; diff --git a/src/commands/cmd_bit.cc b/src/commands/cmd_bit.cc index 4efafdd836e..f0a25d391e9 100644 --- a/src/commands/cmd_bit.cc +++ b/src/commands/cmd_bit.cc @@ -44,9 +44,9 @@ class CommandGetBit : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { bool bit = false; - redis::Bitmap bitmap_db(svr->storage, conn->GetNamespace()); + redis::Bitmap bitmap_db(srv->storage, conn->GetNamespace()); auto s = bitmap_db.GetBit(args_[1], offset_, &bit); if (!s.ok()) return {Status::RedisExecErr, s.ToString()}; @@ -75,9 +75,9 @@ class CommandSetBit : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { bool old_bit = false; - redis::Bitmap bitmap_db(svr->storage, conn->GetNamespace()); + redis::Bitmap bitmap_db(srv->storage, conn->GetNamespace()); auto s = bitmap_db.SetBit(args_[1], offset_, bit_, &old_bit); if (!s.ok()) return {Status::RedisExecErr, s.ToString()}; @@ -115,9 +115,9 @@ class CommandBitCount : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { uint32_t cnt = 0; - redis::Bitmap bitmap_db(svr->storage, conn->GetNamespace()); + redis::Bitmap bitmap_db(srv->storage, conn->GetNamespace()); auto s = bitmap_db.BitCount(args_[1], start_, stop_, &cnt); if (!s.ok()) return {Status::RedisExecErr, s.ToString()}; @@ -167,9 +167,9 @@ class CommandBitPos : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { int64_t pos = 0; - redis::Bitmap bitmap_db(svr->storage, conn->GetNamespace()); + redis::Bitmap bitmap_db(srv->storage, conn->GetNamespace()); auto s = bitmap_db.BitPos(args_[1], bit_, start_, stop_, stop_given_, &pos); if (!s.ok()) return {Status::RedisExecErr, s.ToString()}; @@ -205,7 +205,7 @@ class CommandBitOp : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::vector op_keys; op_keys.reserve(args_.size() - 2); for (uint64_t i = 3; i < args_.size(); i++) { @@ -213,7 +213,7 @@ class CommandBitOp : public Commander { } int64_t dest_key_len = 0; - redis::Bitmap bitmap_db(svr->storage, conn->GetNamespace()); + redis::Bitmap bitmap_db(srv->storage, conn->GetNamespace()); auto s = bitmap_db.BitOp(op_flag_, args_[1], args_[2], op_keys, &dest_key_len); if (!s.ok()) return {Status::RedisExecErr, s.ToString()}; diff --git a/src/commands/cmd_bloom_filter.cc b/src/commands/cmd_bloom_filter.cc index 611d1b9d9bd..e4316a3c05d 100644 --- a/src/commands/cmd_bloom_filter.cc +++ b/src/commands/cmd_bloom_filter.cc @@ -88,8 +88,8 @@ class CommandBFReserve : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::BloomChain bloomfilter_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::BloomChain bloomfilter_db(srv->storage, conn->GetNamespace()); auto s = bloomfilter_db.Reserve(args_[1], capacity_, error_rate_, expansion_); if (!s.ok()) return {Status::RedisExecErr, s.ToString()}; @@ -105,8 +105,8 @@ class CommandBFReserve : public Commander { class CommandBFAdd : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::BloomChain bloom_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::BloomChain bloom_db(srv->storage, conn->GetNamespace()); BloomFilterAddResult ret = BloomFilterAddResult::kOk; auto s = bloom_db.Add(args_[1], args_[2], &ret); if (!s.ok()) return {Status::RedisExecErr, s.ToString()}; @@ -136,8 +136,8 @@ class CommandBFMAdd : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::BloomChain bloom_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::BloomChain bloom_db(srv->storage, conn->GetNamespace()); std::vector rets(items_.size(), BloomFilterAddResult::kOk); auto s = bloom_db.MAdd(args_[1], items_, &rets); if (!s.ok()) return {Status::RedisExecErr, s.ToString()}; @@ -231,8 +231,8 @@ class CommandBFInsert : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::BloomChain bloom_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::BloomChain bloom_db(srv->storage, conn->GetNamespace()); std::vector rets(items_.size(), BloomFilterAddResult::kOk); auto s = bloom_db.InsertCommon(args_[1], items_, insert_options_, &rets); if (s.IsNotFound()) return {Status::RedisExecErr, "key is not found"}; @@ -262,8 +262,8 @@ class CommandBFInsert : public Commander { class CommandBFExists : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::BloomChain bloom_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::BloomChain bloom_db(srv->storage, conn->GetNamespace()); bool exist = false; auto s = bloom_db.Exists(args_[1], args_[2], &exist); if (!s.ok()) return {Status::RedisExecErr, s.ToString()}; @@ -283,8 +283,8 @@ class CommandBFMExists : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::BloomChain bloom_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::BloomChain bloom_db(srv->storage, conn->GetNamespace()); std::vector exists(items_.size(), false); auto s = bloom_db.MExists(args_[1], items_, &exists); if (!s.ok()) return {Status::RedisExecErr, s.ToString()}; @@ -326,8 +326,8 @@ class CommandBFInfo : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::BloomChain bloom_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::BloomChain bloom_db(srv->storage, conn->GetNamespace()); BloomFilterInfo info; auto s = bloom_db.Info(args_[1], &info); if (s.IsNotFound()) return {Status::RedisExecErr, "key is not found"}; @@ -373,8 +373,8 @@ class CommandBFInfo : public Commander { class CommandBFCard : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::BloomChain bloom_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::BloomChain bloom_db(srv->storage, conn->GetNamespace()); BloomFilterInfo info; auto s = bloom_db.Info(args_[1], &info); if (!s.ok() && !s.IsNotFound()) return {Status::RedisExecErr, s.ToString()}; diff --git a/src/commands/cmd_cluster.cc b/src/commands/cmd_cluster.cc index 1ecb01b9a81..4554a3270cf 100644 --- a/src/commands/cmd_cluster.cc +++ b/src/commands/cmd_cluster.cc @@ -50,8 +50,8 @@ class CommandCluster : public Commander { return {Status::RedisParseErr, "CLUSTER command, CLUSTER INFO|NODES|SLOTS|KEYSLOT"}; } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - if (!svr->GetConfig()->cluster_enabled) { + Status Execute(Server *srv, Connection *conn, std::string *output) override { + if (!srv->GetConfig()->cluster_enabled) { return {Status::RedisExecErr, "Cluster mode is not enabled"}; } @@ -64,7 +64,7 @@ class CommandCluster : public Commander { *output = redis::Integer(slot_id); } else if (subcommand_ == "slots") { std::vector infos; - Status s = svr->cluster->GetSlotsInfo(&infos); + Status s = srv->cluster->GetSlotsInfo(&infos); if (s.IsOK()) { output->append(redis::MultiLen(infos.size())); for (const auto &info : infos) { @@ -83,7 +83,7 @@ class CommandCluster : public Commander { } } else if (subcommand_ == "nodes") { std::string nodes_desc; - Status s = svr->cluster->GetClusterNodes(&nodes_desc); + Status s = srv->cluster->GetClusterNodes(&nodes_desc); if (s.IsOK()) { *output = redis::BulkString(nodes_desc); } else { @@ -91,14 +91,14 @@ class CommandCluster : public Commander { } } else if (subcommand_ == "info") { std::string cluster_info; - Status s = svr->cluster->GetClusterInfo(&cluster_info); + Status s = srv->cluster->GetClusterInfo(&cluster_info); if (s.IsOK()) { *output = redis::BulkString(cluster_info); } else { return {Status::RedisExecErr, s.Msg()}; } } else if (subcommand_ == "import") { - Status s = svr->cluster->ImportSlot(conn, static_cast(slot_), state_); + Status s = srv->cluster->ImportSlot(conn, static_cast(slot_), state_); if (s.IsOK()) { *output = redis::SimpleString("OK"); } else { @@ -210,8 +210,8 @@ class CommandClusterX : public Commander { return {Status::RedisParseErr, "CLUSTERX command, CLUSTERX VERSION|SETNODEID|SETNODES|SETSLOT|MIGRATE"}; } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - if (!svr->GetConfig()->cluster_enabled) { + Status Execute(Server *srv, Connection *conn, std::string *output) override { + if (!srv->GetConfig()->cluster_enabled) { return {Status::RedisExecErr, "Cluster mode is not enabled"}; } @@ -221,7 +221,7 @@ class CommandClusterX : public Commander { bool need_persist_nodes_info = false; if (subcommand_ == "setnodes") { - Status s = svr->cluster->SetClusterNodes(nodes_str_, set_version_, force_); + Status s = srv->cluster->SetClusterNodes(nodes_str_, set_version_, force_); if (s.IsOK()) { need_persist_nodes_info = true; *output = redis::SimpleString("OK"); @@ -229,7 +229,7 @@ class CommandClusterX : public Commander { return {Status::RedisExecErr, s.Msg()}; } } else if (subcommand_ == "setnodeid") { - Status s = svr->cluster->SetNodeId(args_[2]); + Status s = srv->cluster->SetNodeId(args_[2]); if (s.IsOK()) { need_persist_nodes_info = true; *output = redis::SimpleString("OK"); @@ -237,7 +237,7 @@ class CommandClusterX : public Commander { return {Status::RedisExecErr, s.Msg()}; } } else if (subcommand_ == "setslot") { - Status s = svr->cluster->SetSlotRanges(slot_ranges_, args_[4], set_version_); + Status s = srv->cluster->SetSlotRanges(slot_ranges_, args_[4], set_version_); if (s.IsOK()) { need_persist_nodes_info = true; *output = redis::SimpleString("OK"); @@ -245,14 +245,14 @@ class CommandClusterX : public Commander { return {Status::RedisExecErr, s.Msg()}; } } else if (subcommand_ == "version") { - int64_t v = svr->cluster->GetVersion(); + int64_t v = srv->cluster->GetVersion(); *output = redis::BulkString(std::to_string(v)); } else if (subcommand_ == "migrate") { if (sync_migrate_) { - sync_migrate_ctx_ = std::make_unique(svr, conn, sync_migrate_timeout_); + sync_migrate_ctx_ = std::make_unique(srv, conn, sync_migrate_timeout_); } - Status s = svr->cluster->MigrateSlot(static_cast(slot_), dst_node_id_, sync_migrate_ctx_.get()); + Status s = srv->cluster->MigrateSlot(static_cast(slot_), dst_node_id_, sync_migrate_ctx_.get()); if (s.IsOK()) { if (sync_migrate_) { return {Status::BlockingCmd}; @@ -264,8 +264,8 @@ class CommandClusterX : public Commander { } else { return {Status::RedisExecErr, "Invalid cluster command options"}; } - if (need_persist_nodes_info && svr->GetConfig()->persist_cluster_nodes_enabled) { - return svr->cluster->DumpClusterNodes(svr->GetConfig()->NodesFilePath()); + if (need_persist_nodes_info && srv->GetConfig()->persist_cluster_nodes_enabled) { + return srv->cluster->DumpClusterNodes(srv->GetConfig()->NodesFilePath()); } return Status::OK(); } diff --git a/src/commands/cmd_geo.cc b/src/commands/cmd_geo.cc index 353b294785a..39854368e66 100644 --- a/src/commands/cmd_geo.cc +++ b/src/commands/cmd_geo.cc @@ -111,9 +111,9 @@ class CommandGeoAdd : public CommandGeoBase { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { uint64_t ret = 0; - redis::Geo geo_db(svr->storage, conn->GetNamespace()); + redis::Geo geo_db(srv->storage, conn->GetNamespace()); auto s = geo_db.Add(args_[1], &geo_points_, &ret); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -139,9 +139,9 @@ class CommandGeoDist : public CommandGeoBase { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { double distance = 0; - redis::Geo geo_db(svr->storage, conn->GetNamespace()); + redis::Geo geo_db(srv->storage, conn->GetNamespace()); auto s = geo_db.Dist(args_[1], args_[2], args_[3], &distance); if (!s.ok() && !s.IsNotFound()) { return {Status::RedisExecErr, s.ToString()}; @@ -165,9 +165,9 @@ class CommandGeoHash : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::vector hashes; - redis::Geo geo_db(svr->storage, conn->GetNamespace()); + redis::Geo geo_db(srv->storage, conn->GetNamespace()); auto s = geo_db.Hash(args_[1], members_, &hashes); if (!s.ok() && !s.IsNotFound()) { return {Status::RedisExecErr, s.ToString()}; @@ -194,9 +194,9 @@ class CommandGeoPos : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::map geo_points; - redis::Geo geo_db(svr->storage, conn->GetNamespace()); + redis::Geo geo_db(srv->storage, conn->GetNamespace()); auto s = geo_db.Pos(args_[1], members_, &geo_points); if (!s.ok() && !s.IsNotFound()) { return {Status::RedisExecErr, s.ToString()}; @@ -302,9 +302,9 @@ class CommandGeoRadius : public CommandGeoBase { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::vector geo_points; - redis::Geo geo_db(svr->storage, conn->GetNamespace()); + redis::Geo geo_db(srv->storage, conn->GetNamespace()); auto s = geo_db.Radius(args_[1], longitude_, latitude_, GetRadiusMeters(radius_), count_, sort_, store_key_, store_distance_, GetUnitConversion(), &geo_points); if (!s.ok()) { @@ -430,9 +430,9 @@ class CommandGeoSearch : public CommandGeoBase { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::vector geo_points; - redis::Geo geo_db(svr->storage, conn->GetNamespace()); + redis::Geo geo_db(srv->storage, conn->GetNamespace()); auto s = geo_db.Search(args_[1], geo_shape_, origin_point_type_, member_, count_, sort_, false, GetUnitConversion(), &geo_points); @@ -593,9 +593,9 @@ class CommandGeoSearchStore : public CommandGeoSearch { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::vector geo_points; - redis::Geo geo_db(svr->storage, conn->GetNamespace()); + redis::Geo geo_db(srv->storage, conn->GetNamespace()); auto s = geo_db.SearchStore(args_[2], geo_shape_, origin_point_type_, member_, count_, sort_, store_key_, store_distance_, GetUnitConversion(), &geo_points); @@ -632,9 +632,9 @@ class CommandGeoRadiusByMember : public CommandGeoRadius { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::vector geo_points; - redis::Geo geo_db(svr->storage, conn->GetNamespace()); + redis::Geo geo_db(srv->storage, conn->GetNamespace()); auto s = geo_db.RadiusByMember(args_[1], args_[2], GetRadiusMeters(radius_), count_, sort_, store_key_, store_distance_, GetUnitConversion(), &geo_points); if (!s.ok()) { diff --git a/src/commands/cmd_hash.cc b/src/commands/cmd_hash.cc index 1e0947e79c2..7ae901919cb 100644 --- a/src/commands/cmd_hash.cc +++ b/src/commands/cmd_hash.cc @@ -29,8 +29,8 @@ namespace redis { class CommandHGet : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Hash hash_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Hash hash_db(srv->storage, conn->GetNamespace()); std::string value; auto s = hash_db.Get(args_[1], args_[2], &value); if (!s.ok() && !s.IsNotFound()) { @@ -54,9 +54,9 @@ class CommandHSetNX : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { uint64_t ret = 0; - redis::Hash hash_db(svr->storage, conn->GetNamespace()); + redis::Hash hash_db(srv->storage, conn->GetNamespace()); auto s = hash_db.MSet(args_[1], field_values_, true, &ret); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -72,8 +72,8 @@ class CommandHSetNX : public Commander { class CommandHStrlen : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Hash hash_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Hash hash_db(srv->storage, conn->GetNamespace()); std::string value; auto s = hash_db.Get(args_[1], args_[2], &value); if (!s.ok() && !s.IsNotFound()) { @@ -87,14 +87,14 @@ class CommandHStrlen : public Commander { class CommandHDel : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::vector fields; for (size_t i = 2; i < args_.size(); i++) { fields.emplace_back(args_[i]); } uint64_t ret = 0; - redis::Hash hash_db(svr->storage, conn->GetNamespace()); + redis::Hash hash_db(srv->storage, conn->GetNamespace()); auto s = hash_db.Delete(args_[1], fields, &ret); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -107,8 +107,8 @@ class CommandHDel : public Commander { class CommandHExists : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Hash hash_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Hash hash_db(srv->storage, conn->GetNamespace()); std::string value; auto s = hash_db.Get(args_[1], args_[2], &value); if (!s.ok() && !s.IsNotFound()) { @@ -122,9 +122,9 @@ class CommandHExists : public Commander { class CommandHLen : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { uint64_t count = 0; - redis::Hash hash_db(svr->storage, conn->GetNamespace()); + redis::Hash hash_db(srv->storage, conn->GetNamespace()); auto s = hash_db.Size(args_[1], &count); if (!s.ok() && !s.IsNotFound()) { return {Status::RedisExecErr, s.ToString()}; @@ -147,9 +147,9 @@ class CommandHIncrBy : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { int64_t ret = 0; - redis::Hash hash_db(svr->storage, conn->GetNamespace()); + redis::Hash hash_db(srv->storage, conn->GetNamespace()); auto s = hash_db.IncrBy(args_[1], args_[2], increment_, &ret); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -174,9 +174,9 @@ class CommandHIncrByFloat : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { double ret = 0; - redis::Hash hash_db(svr->storage, conn->GetNamespace()); + redis::Hash hash_db(srv->storage, conn->GetNamespace()); auto s = hash_db.IncrByFloat(args_[1], args_[2], increment_, &ret); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -192,7 +192,7 @@ class CommandHIncrByFloat : public Commander { class CommandHMGet : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::vector fields; for (size_t i = 2; i < args_.size(); i++) { fields.emplace_back(args_[i]); @@ -200,7 +200,7 @@ class CommandHMGet : public Commander { std::vector values; std::vector statuses; - redis::Hash hash_db(svr->storage, conn->GetNamespace()); + redis::Hash hash_db(srv->storage, conn->GetNamespace()); auto s = hash_db.MGet(args_[1], fields, &values, &statuses); if (!s.ok() && !s.IsNotFound()) { return {Status::RedisExecErr, s.ToString()}; @@ -228,9 +228,9 @@ class CommandHMSet : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { uint64_t ret = 0; - redis::Hash hash_db(svr->storage, conn->GetNamespace()); + redis::Hash hash_db(srv->storage, conn->GetNamespace()); auto s = hash_db.MSet(args_[1], field_values_, false, &ret); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -250,8 +250,8 @@ class CommandHMSet : public Commander { class CommandHKeys : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Hash hash_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Hash hash_db(srv->storage, conn->GetNamespace()); std::vector field_values; auto s = hash_db.GetAll(args_[1], &field_values, HashFetchType::kOnlyKey); if (!s.ok()) { @@ -271,8 +271,8 @@ class CommandHKeys : public Commander { class CommandHVals : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Hash hash_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Hash hash_db(srv->storage, conn->GetNamespace()); std::vector field_values; auto s = hash_db.GetAll(args_[1], &field_values, HashFetchType::kOnlyValue); if (!s.ok()) { @@ -292,8 +292,8 @@ class CommandHVals : public Commander { class CommandHGetAll : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Hash hash_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Hash hash_db(srv->storage, conn->GetNamespace()); std::vector field_values; auto s = hash_db.GetAll(args_[1], &field_values); if (!s.ok()) { @@ -338,8 +338,8 @@ class CommandHRangeByLex : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Hash hash_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Hash hash_db(srv->storage, conn->GetNamespace()); std::vector field_values; rocksdb::Status s = hash_db.RangeByLex(args_[1], spec_, &field_values); if (!s.ok()) { @@ -362,17 +362,17 @@ class CommandHRangeByLex : public Commander { class CommandHScan : public CommandSubkeyScanBase { public: CommandHScan() = default; - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Hash hash_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Hash hash_db(srv->storage, conn->GetNamespace()); std::vector fields; std::vector values; - auto key_name = svr->GetKeyNameFromCursor(cursor_, CursorType::kTypeHash); + auto key_name = srv->GetKeyNameFromCursor(cursor_, CursorType::kTypeHash); auto s = hash_db.Scan(key_, key_name, limit_, prefix_, &fields, &values); if (!s.ok() && !s.IsNotFound()) { return {Status::RedisExecErr, s.ToString()}; } - *output = GenerateOutput(svr, fields, values, CursorType::kTypeHash); + *output = GenerateOutput(srv, fields, values, CursorType::kTypeHash); return Status::OK(); } }; @@ -397,8 +397,8 @@ class CommandHRandField : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Hash hash_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Hash hash_db(srv->storage, conn->GetNamespace()); std::vector field_values; auto s = hash_db.RandField(args_[1], command_count_, &field_values, diff --git a/src/commands/cmd_json.cc b/src/commands/cmd_json.cc index 16678999b41..6c2d40cd53f 100644 --- a/src/commands/cmd_json.cc +++ b/src/commands/cmd_json.cc @@ -30,8 +30,8 @@ namespace redis { class CommandJsonSet : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Json json(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Json json(srv->storage, conn->GetNamespace()); auto s = json.Set(args_[1], args_[2], args_[3]); if (!s.ok()) return {Status::RedisExecErr, s.ToString()}; @@ -77,8 +77,8 @@ class CommandJsonGet : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Json json(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Json json(srv->storage, conn->GetNamespace()); JsonValue result; auto s = json.Get(args_[1], paths_, &result); @@ -102,8 +102,8 @@ class CommandJsonGet : public Commander { class CommandJsonArrAppend : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Json json(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Json json(srv->storage, conn->GetNamespace()); std::vector result_count; @@ -125,8 +125,8 @@ class CommandJsonArrAppend : public Commander { class CommandJsonType : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Json json(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Json json(srv->storage, conn->GetNamespace()); std::vector types; diff --git a/src/commands/cmd_key.cc b/src/commands/cmd_key.cc index 815c98bc2ef..5cea1d70602 100644 --- a/src/commands/cmd_key.cc +++ b/src/commands/cmd_key.cc @@ -32,8 +32,8 @@ namespace redis { class CommandType : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Database redis(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Database redis(srv->storage, conn->GetNamespace()); RedisType type = kRedisNone; auto s = redis.Type(args_[1], &type); if (s.ok()) { @@ -53,9 +53,9 @@ class CommandMove : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { int count = 0; - redis::Database redis(svr->storage, conn->GetNamespace()); + redis::Database redis(srv->storage, conn->GetNamespace()); rocksdb::Status s = redis.Exists({args_[1]}, &count); if (!s.ok()) return {Status::RedisExecErr, s.ToString()}; @@ -66,9 +66,9 @@ class CommandMove : public Commander { class CommandObject : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { if (util::ToLower(args_[1]) == "dump") { - redis::Database redis(svr->storage, conn->GetNamespace()); + redis::Database redis(srv->storage, conn->GetNamespace()); std::vector infos; auto s = redis.Dump(args_[2], &infos); if (!s.ok()) { @@ -88,8 +88,8 @@ class CommandObject : public Commander { class CommandTTL : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Database redis(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Database redis(srv->storage, conn->GetNamespace()); int64_t ttl = 0; auto s = redis.TTL(args_[1], &ttl); if (s.ok()) { @@ -103,8 +103,8 @@ class CommandTTL : public Commander { class CommandPTTL : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Database redis(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Database redis(srv->storage, conn->GetNamespace()); int64_t ttl = 0; auto s = redis.TTL(args_[1], &ttl); if (!s.ok()) return {Status::RedisExecErr, s.ToString()}; @@ -116,7 +116,7 @@ class CommandPTTL : public Commander { class CommandExists : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::vector keys; keys.reserve(args_.size() - 1); for (size_t i = 1; i < args_.size(); i++) { @@ -124,7 +124,7 @@ class CommandExists : public Commander { } int cnt = 0; - redis::Database redis(svr->storage, conn->GetNamespace()); + redis::Database redis(srv->storage, conn->GetNamespace()); auto s = redis.Exists(keys, &cnt); if (!s.ok()) return {Status::RedisExecErr, s.ToString()}; *output = redis::Integer(cnt); @@ -140,8 +140,8 @@ class CommandExpire : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Database redis(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Database redis(srv->storage, conn->GetNamespace()); auto s = redis.Expire(args_[1], ttl_ * 1000 + util::GetTimeStampMS()); if (s.ok()) { *output = redis::Integer(1); @@ -162,8 +162,8 @@ class CommandPExpire : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Database redis(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Database redis(srv->storage, conn->GetNamespace()); auto s = redis.Expire(args_[1], seconds_); if (s.ok()) { *output = redis::Integer(1); @@ -190,8 +190,8 @@ class CommandExpireAt : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Database redis(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Database redis(srv->storage, conn->GetNamespace()); auto s = redis.Expire(args_[1], timestamp_ * 1000); if (s.ok()) { *output = redis::Integer(1); @@ -218,8 +218,8 @@ class CommandPExpireAt : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Database redis(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Database redis(srv->storage, conn->GetNamespace()); auto s = redis.Expire(args_[1], timestamp_); if (s.ok()) { *output = redis::Integer(1); @@ -235,9 +235,9 @@ class CommandPExpireAt : public Commander { class CommandPersist : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { int64_t ttl = 0; - redis::Database redis(svr->storage, conn->GetNamespace()); + redis::Database redis(srv->storage, conn->GetNamespace()); auto s = redis.TTL(args_[1], &ttl); if (!s.ok()) return {Status::RedisExecErr, s.ToString()}; @@ -256,7 +256,7 @@ class CommandPersist : public Commander { class CommandDel : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::vector keys; keys.reserve(args_.size() - 1); for (size_t i = 1; i < args_.size(); i++) { @@ -264,7 +264,7 @@ class CommandDel : public Commander { } uint64_t cnt = 0; - redis::Database redis(svr->storage, conn->GetNamespace()); + redis::Database redis(srv->storage, conn->GetNamespace()); auto s = redis.MDel(keys, &cnt); if (!s.ok()) return {Status::RedisExecErr, s.ToString()}; diff --git a/src/commands/cmd_list.cc b/src/commands/cmd_list.cc index a9612351734..86a0708d51b 100644 --- a/src/commands/cmd_list.cc +++ b/src/commands/cmd_list.cc @@ -33,7 +33,7 @@ class CommandPush : public Commander { public: CommandPush(bool create_if_missing, bool left) : left_(left), create_if_missing_(create_if_missing) {} - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::vector elems; for (size_t i = 2; i < args_.size(); i++) { elems.emplace_back(args_[i]); @@ -41,7 +41,7 @@ class CommandPush : public Commander { uint64_t ret = 0; rocksdb::Status s; - redis::List list_db(svr->storage, conn->GetNamespace()); + redis::List list_db(srv->storage, conn->GetNamespace()); if (create_if_missing_) { s = list_db.Push(args_[1], elems, left_, &ret); } else { @@ -51,7 +51,7 @@ class CommandPush : public Commander { return {Status::RedisExecErr, s.ToString()}; } - svr->WakeupBlockingConns(args_[1], elems.size()); + srv->WakeupBlockingConns(args_[1], elems.size()); *output = redis::Integer(ret); return Status::OK(); @@ -109,8 +109,8 @@ class CommandPop : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::List list_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::List list_db(srv->storage, conn->GetNamespace()); if (with_count_) { std::vector elems; auto s = list_db.PopMulti(args_[1], left_, count_, &elems); @@ -192,8 +192,8 @@ class CommandLMPop : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::List list_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::List list_db(srv->storage, conn->GetNamespace()); std::vector elems; std::string chosen_key; @@ -259,8 +259,8 @@ class CommandBPop : public BlockingCommander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - svr_ = svr; + Status Execute(Server *srv, Connection *conn, std::string *output) override { + srv_ = srv; InitConnection(conn); auto s = TryPopFromList(); @@ -273,18 +273,18 @@ class CommandBPop : public BlockingCommander { void BlockKeys() override { for (const auto &key : keys_) { - svr_->BlockOnKey(key, conn_); + srv_->BlockOnKey(key, conn_); } } void UnblockKeys() override { for (const auto &key : keys_) { - svr_->UnblockOnKey(key, conn_); + srv_->UnblockOnKey(key, conn_); } } rocksdb::Status TryPopFromList() { - redis::List list_db(svr_->storage, conn_->GetNamespace()); + redis::List list_db(srv_->storage, conn_->GetNamespace()); std::string elem; const std::string *last_key_ptr = nullptr; rocksdb::Status s; @@ -321,7 +321,7 @@ class CommandBPop : public BlockingCommander { bool left_ = false; int64_t timeout_ = 0; // microseconds std::vector keys_; - Server *svr_ = nullptr; + Server *srv_ = nullptr; }; class CommandBLPop : public CommandBPop { @@ -379,8 +379,8 @@ class CommandBLMPop : public BlockingCommander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - svr_ = svr; + Status Execute(Server *srv, Connection *conn, std::string *output) override { + srv_ = srv; InitConnection(conn); auto s = ExecuteUnblocked(); @@ -392,7 +392,7 @@ class CommandBLMPop : public BlockingCommander { } rocksdb::Status ExecuteUnblocked() { - redis::List list_db(svr_->storage, conn_->GetNamespace()); + redis::List list_db(srv_->storage, conn_->GetNamespace()); std::vector elems; std::string chosen_key; rocksdb::Status s; @@ -422,13 +422,13 @@ class CommandBLMPop : public BlockingCommander { void BlockKeys() override { for (const auto &key : keys_) { - svr_->BlockOnKey(key, conn_); + srv_->BlockOnKey(key, conn_); } } void UnblockKeys() override { for (const auto &key : keys_) { - svr_->UnblockOnKey(key, conn_); + srv_->UnblockOnKey(key, conn_); } } @@ -454,7 +454,7 @@ class CommandBLMPop : public BlockingCommander { uint32_t count_ = -1; int64_t timeout_ = 0; // microseconds std::vector keys_; - Server *svr_ = nullptr; + Server *srv_ = nullptr; }; class CommandLRem : public Commander { @@ -469,9 +469,9 @@ class CommandLRem : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { uint64_t ret = 0; - redis::List list_db(svr->storage, conn->GetNamespace()); + redis::List list_db(srv->storage, conn->GetNamespace()); auto s = list_db.Rem(args_[1], count_, args_[3], &ret); if (!s.ok() && !s.IsNotFound()) { return {Status::RedisExecErr, s.ToString()}; @@ -498,9 +498,9 @@ class CommandLInsert : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { int ret = 0; - redis::List list_db(svr->storage, conn->GetNamespace()); + redis::List list_db(srv->storage, conn->GetNamespace()); auto s = list_db.Insert(args_[1], args_[3], args_[4], before_, &ret); if (!s.ok() && !s.IsNotFound()) { return {Status::RedisExecErr, s.ToString()}; @@ -528,8 +528,8 @@ class CommandLRange : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::List list_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::List list_db(srv->storage, conn->GetNamespace()); std::vector elems; auto s = list_db.Range(args_[1], start_, stop_, &elems); if (!s.ok() && !s.IsNotFound()) { @@ -546,8 +546,8 @@ class CommandLRange : public Commander { class CommandLLen : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::List list_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::List list_db(srv->storage, conn->GetNamespace()); uint64_t count = 0; auto s = list_db.Size(args_[1], &count); if (!s.ok() && !s.IsNotFound()) { @@ -571,8 +571,8 @@ class CommandLIndex : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::List list_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::List list_db(srv->storage, conn->GetNamespace()); std::string elem; auto s = list_db.Index(args_[1], index_, &elem); if (!s.ok() && !s.IsNotFound()) { @@ -603,8 +603,8 @@ class CommandLSet : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::List list_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::List list_db(srv->storage, conn->GetNamespace()); auto s = list_db.Set(args_[1], index_, args_[3]); if (!s.ok() && !s.IsNotFound()) { return {Status::RedisExecErr, s.ToString()}; @@ -637,8 +637,8 @@ class CommandLTrim : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::List list_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::List list_db(srv->storage, conn->GetNamespace()); auto s = list_db.Trim(args_[1], start_, stop_); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -655,8 +655,8 @@ class CommandLTrim : public Commander { class CommandRPopLPUSH : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::List list_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::List list_db(srv->storage, conn->GetNamespace()); std::string elem; auto s = list_db.LMove(args_[1], args_[2], /*src_left=*/false, /*dst_left=*/true, &elem); if (!s.ok() && !s.IsNotFound()) { @@ -686,8 +686,8 @@ class CommandLMove : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::List list_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::List list_db(srv->storage, conn->GetNamespace()); std::string elem; auto s = list_db.LMove(args_[1], args_[2], src_left_, dst_left_, &elem); if (!s.ok() && !s.IsNotFound()) { @@ -730,11 +730,11 @@ class CommandBLMove : public BlockingCommander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - svr_ = svr; + Status Execute(Server *srv, Connection *conn, std::string *output) override { + srv_ = srv; InitConnection(conn); - redis::List list_db(svr->storage, conn->GetNamespace()); + redis::List list_db(srv->storage, conn->GetNamespace()); std::string elem; auto s = list_db.LMove(args_[1], args_[2], src_left_, dst_left_, &elem); if (!s.ok() && !s.IsNotFound()) { @@ -748,12 +748,12 @@ class CommandBLMove : public BlockingCommander { return StartBlocking(timeout_, output); } - void BlockKeys() override { svr_->BlockOnKey(args_[1], conn_); } + void BlockKeys() override { srv_->BlockOnKey(args_[1], conn_); } - void UnblockKeys() override { svr_->UnblockOnKey(args_[1], conn_); } + void UnblockKeys() override { srv_->UnblockOnKey(args_[1], conn_); } bool OnBlockingWrite() override { - redis::List list_db(svr_->storage, conn_->GetNamespace()); + redis::List list_db(srv_->storage, conn_->GetNamespace()); std::string elem; auto s = list_db.LMove(args_[1], args_[2], src_left_, dst_left_, &elem); if (!s.ok() && !s.IsNotFound()) { @@ -775,7 +775,7 @@ class CommandBLMove : public BlockingCommander { bool src_left_; bool dst_left_; int64_t timeout_ = 0; // microseconds - Server *svr_ = nullptr; + Server *srv_ = nullptr; }; class CommandLPos : public Commander { @@ -815,8 +815,8 @@ class CommandLPos : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::List list_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::List list_db(srv->storage, conn->GetNamespace()); std::vector indexes; auto s = list_db.Pos(args_[1], args_[2], spec_, &indexes); if (!s.ok() && !s.IsNotFound()) { diff --git a/src/commands/cmd_pubsub.cc b/src/commands/cmd_pubsub.cc index fb8c5fbca5e..9ec38beefdb 100644 --- a/src/commands/cmd_pubsub.cc +++ b/src/commands/cmd_pubsub.cc @@ -27,12 +27,12 @@ namespace redis { class CommandPublish : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - if (!svr->IsSlave()) { + Status Execute(Server *srv, Connection *conn, std::string *output) override { + if (!srv->IsSlave()) { // Compromise: can't replicate a message to sub-replicas in a cascading-like structure. // Replication relies on WAL seq; increasing the seq on a replica will break the replication process, // hence the compromise solution - redis::PubSub pubsub_db(svr->storage); + redis::PubSub pubsub_db(srv->storage); auto s = pubsub_db.Publish(args_[1], args_[2]); if (!s.ok()) { @@ -40,7 +40,7 @@ class CommandPublish : public Commander { } } - int receivers = svr->PublishMessage(args_[1], args_[2]); + int receivers = srv->PublishMessage(args_[1], args_[2]); *output = redis::Integer(receivers); @@ -50,12 +50,12 @@ class CommandPublish : public Commander { class CommandMPublish : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { int total_receivers = 0; for (size_t i = 2; i < args_.size(); i++) { - if (!svr->IsSlave()) { - redis::PubSub pubsub_db(svr->storage); + if (!srv->IsSlave()) { + redis::PubSub pubsub_db(srv->storage); auto s = pubsub_db.Publish(args_[1], args_[i]); if (!s.ok()) { @@ -63,7 +63,7 @@ class CommandMPublish : public Commander { } } - int receivers = svr->PublishMessage(args_[1], args_[i]); + int receivers = srv->PublishMessage(args_[1], args_[i]); total_receivers += receivers; } @@ -83,7 +83,7 @@ void SubscribeCommandReply(std::string *output, const std::string &name, const s class CommandSubscribe : public Commander { public: bool IsBlocking() const override { return true; } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { for (unsigned i = 1; i < args_.size(); i++) { conn->SubscribeChannel(args_[i]); SubscribeCommandReply(output, "subscribe", args_[i], conn->SubscriptionsCount() + conn->PSubscriptionsCount()); @@ -94,7 +94,7 @@ class CommandSubscribe : public Commander { class CommandUnSubscribe : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { if (args_.size() == 1) { conn->UnsubscribeAll([output](const std::string &sub_name, int num) { SubscribeCommandReply(output, "unsubscribe", sub_name, num); @@ -113,7 +113,7 @@ class CommandUnSubscribe : public Commander { class CommandPSubscribe : public Commander { public: bool IsBlocking() const override { return true; } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { for (size_t i = 1; i < args_.size(); i++) { conn->PSubscribeChannel(args_[i]); SubscribeCommandReply(output, "psubscribe", args_[i], conn->SubscriptionsCount() + conn->PSubscriptionsCount()); @@ -124,7 +124,7 @@ class CommandPSubscribe : public Commander { class CommandPUnSubscribe : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { if (args_.size() == 1) { conn->PUnsubscribeAll([output](const std::string &sub_name, int num) { SubscribeCommandReply(output, "punsubscribe", sub_name, num); diff --git a/src/commands/cmd_replication.cc b/src/commands/cmd_replication.cc index 23ae269acbe..2a4f074aaea 100644 --- a/src/commands/cmd_replication.cc +++ b/src/commands/cmd_replication.cc @@ -55,18 +55,18 @@ class CommandPSync : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { LOG(INFO) << "Slave " << conn->GetAddr() << ", listening port: " << conn->GetListeningPort() << ", announce ip: " << conn->GetAnnounceIP() << " asks for synchronization" << " with next sequence: " << next_repl_seq_ << " replication id: " << (replica_replid_.length() ? replica_replid_ : "not supported") - << ", and local sequence: " << svr->storage->LatestSeqNumber(); + << ", and local sequence: " << srv->storage->LatestSeqNumber(); bool need_full_sync = false; // Check replication id of the last sequence log - if (new_psync_ && svr->GetConfig()->use_rsid_psync) { - std::string replid_in_wal = svr->storage->GetReplIdFromWalBySeq(next_repl_seq_ - 1); + if (new_psync_ && srv->GetConfig()->use_rsid_psync) { + std::string replid_in_wal = srv->storage->GetReplIdFromWalBySeq(next_repl_seq_ - 1); LOG(INFO) << "Replication id in WAL: " << replid_in_wal; // We check replication id only when WAL has this sequence, since there may be no WAL, @@ -78,13 +78,13 @@ class CommandPSync : public Commander { } // Check Log sequence - if (!need_full_sync && !checkWALBoundary(svr->storage, next_repl_seq_).IsOK()) { + if (!need_full_sync && !checkWALBoundary(srv->storage, next_repl_seq_).IsOK()) { *output = "sequence out of range, please use fullsync"; need_full_sync = true; } if (need_full_sync) { - svr->stats.IncrPSyncErrCounter(); + srv->stats.IncrPSyncErrCounter(); return {Status::RedisExecErr, *output}; } @@ -98,8 +98,8 @@ class CommandPSync : public Commander { return s.Prefixed("failed to set blocking mode on socket"); } - svr->stats.IncrPSyncOKCounter(); - s = svr->AddSlave(conn, next_repl_seq_); + srv->stats.IncrPSyncOKCounter(); + s = srv->AddSlave(conn, next_repl_seq_); if (!s.IsOK()) { std::string err = "-ERR " + s.Msg() + "\r\n"; s = util::SockSend(conn->GetFD(), err, conn->GetBufferEvent()); @@ -185,7 +185,7 @@ class CommandReplConf : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { if (port_ != 0) { conn->SetListeningPort(port_); } @@ -205,7 +205,7 @@ class CommandFetchMeta : public Commander { public: Status Parse(const std::vector &args) override { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { int repl_fd = conn->GetFD(); std::string ip = conn->GetAnnounceIP(); @@ -216,18 +216,18 @@ class CommandFetchMeta : public Commander { conn->NeedNotFreeBufferEvent(); conn->EnableFlag(redis::Connection::kCloseAsync); - svr->stats.IncrFullSyncCounter(); + srv->stats.IncrFullSyncCounter(); // Feed-replica-meta thread - auto t = GET_OR_RET(util::CreateThread("feed-repl-info", [svr, repl_fd, ip, bev = conn->GetBufferEvent()] { - svr->IncrFetchFileThread(); - auto exit = MakeScopeExit([svr, bev] { + auto t = GET_OR_RET(util::CreateThread("feed-repl-info", [srv, repl_fd, ip, bev = conn->GetBufferEvent()] { + srv->IncrFetchFileThread(); + auto exit = MakeScopeExit([srv, bev] { bufferevent_free(bev); - svr->DecrFetchFileThread(); + srv->DecrFetchFileThread(); }); std::string files; - auto s = engine::Storage::ReplDataManager::GetFullReplDataInfo(svr->storage, &files); + auto s = engine::Storage::ReplDataManager::GetFullReplDataInfo(srv->storage, &files); if (!s.IsOK()) { s = util::SockSend(repl_fd, "-ERR can't create db checkpoint", bev); if (!s.IsOK()) { @@ -243,7 +243,7 @@ class CommandFetchMeta : public Commander { LOG(WARNING) << "[replication] Fail to send full data file info " << ip << ", error: " << strerror(errno); } auto now = static_cast(util::GetTimeStamp()); - svr->storage->SetCheckpointAccessTime(now); + srv->storage->SetCheckpointAccessTime(now); })); if (auto s = util::ThreadDetach(t); !s) { @@ -261,7 +261,7 @@ class CommandFetchFile : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::vector files = util::Split(files_str_, ","); int repl_fd = conn->GetFD(); @@ -275,19 +275,19 @@ class CommandFetchFile : public Commander { conn->NeedNotFreeBufferEvent(); // Feed-replica-file thread will close the replica bufferevent conn->EnableFlag(redis::Connection::kCloseAsync); - auto t = GET_OR_RET(util::CreateThread("feed-repl-file", [svr, repl_fd, ip, files, bev = conn->GetBufferEvent()]() { + auto t = GET_OR_RET(util::CreateThread("feed-repl-file", [srv, repl_fd, ip, files, bev = conn->GetBufferEvent()]() { auto exit = MakeScopeExit([bev] { bufferevent_free(bev); }); - svr->IncrFetchFileThread(); + srv->IncrFetchFileThread(); for (const auto &file : files) { - if (svr->IsStopped()) break; + if (srv->IsStopped()) break; uint64_t file_size = 0, max_replication_bytes = 0; - if (svr->GetConfig()->max_replication_mb > 0) { - max_replication_bytes = (svr->GetConfig()->max_replication_mb * MiB) / svr->GetFetchFileThreadNum(); + if (srv->GetConfig()->max_replication_mb > 0) { + max_replication_bytes = (srv->GetConfig()->max_replication_mb * MiB) / srv->GetFetchFileThreadNum(); } auto start = std::chrono::high_resolution_clock::now(); - auto fd = UniqueFD(engine::Storage::ReplDataManager::OpenDataFile(svr->storage, file, &file_size)); + auto fd = UniqueFD(engine::Storage::ReplDataManager::OpenDataFile(srv->storage, file, &file_size)); if (!fd) break; // Send file size and content @@ -312,8 +312,8 @@ class CommandFetchFile : public Commander { } } auto now = static_cast(util::GetTimeStamp()); - svr->storage->SetCheckpointAccessTime(now); - svr->DecrFetchFileThread(); + srv->storage->SetCheckpointAccessTime(now); + srv->DecrFetchFileThread(); })); if (auto s = util::ThreadDetach(t); !s) { @@ -331,8 +331,8 @@ class CommandDBName : public Commander { public: Status Parse(const std::vector &args) override { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - conn->Reply(svr->storage->GetName() + CRLF); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + conn->Reply(srv->storage->GetName() + CRLF); return Status::OK(); } }; diff --git a/src/commands/cmd_script.cc b/src/commands/cmd_script.cc index 88aeb029b62..c7576a6aa28 100644 --- a/src/commands/cmd_script.cc +++ b/src/commands/cmd_script.cc @@ -29,7 +29,7 @@ namespace redis { template class CommandEvalImpl : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { if (evalsha && args_[1].size() != 40) { *output = redis::Error(errNoMatchingScript); return Status::OK(); @@ -63,21 +63,21 @@ class CommandScript : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { // There's a little tricky here since the script command was the write type // command but some subcommands like `exists` were readonly, so we want to allow // executing on slave here. Maybe we should find other way to do this. - if (svr->IsSlave() && subcommand_ != "exists") { + if (srv->IsSlave() && subcommand_ != "exists") { return {Status::NotOK, "READONLY You can't write against a read only slave"}; } if (args_.size() == 2 && subcommand_ == "flush") { - auto s = svr->ScriptFlush(); + auto s = srv->ScriptFlush(); if (!s) { LOG(ERROR) << "Failed to flush scripts: " << s.Msg(); return s; } - s = svr->Propagate(engine::kPropagateScriptCommand, args_); + s = srv->Propagate(engine::kPropagateScriptCommand, args_); if (!s) { LOG(ERROR) << "Failed to propagate script command: " << s.Msg(); return s; @@ -86,7 +86,7 @@ class CommandScript : public Commander { } else if (args_.size() >= 3 && subcommand_ == "exists") { *output = redis::MultiLen(args_.size() - 2); for (size_t j = 2; j < args_.size(); j++) { - if (svr->ScriptExists(args_[j]).IsOK()) { + if (srv->ScriptExists(args_[j]).IsOK()) { *output += redis::Integer(1); } else { *output += redis::Integer(0); @@ -94,7 +94,7 @@ class CommandScript : public Commander { } } else if (args_.size() == 3 && subcommand_ == "load") { std::string sha; - auto s = lua::CreateFunction(svr, args_[2], &sha, svr->Lua(), true); + auto s = lua::CreateFunction(srv, args_[2], &sha, srv->Lua(), true); if (!s.IsOK()) { return s; } diff --git a/src/commands/cmd_server.cc b/src/commands/cmd_server.cc index 808547990e6..95132094c0b 100644 --- a/src/commands/cmd_server.cc +++ b/src/commands/cmd_server.cc @@ -64,9 +64,9 @@ AuthResult AuthenticateUser(Server *srv, Connection *conn, const std::string &us class CommandAuth : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { auto &user_password = args_[1]; - AuthResult result = AuthenticateUser(svr, conn, user_password); + AuthResult result = AuthenticateUser(srv, conn, user_password); switch (result) { case AuthResult::OK: *output = redis::SimpleString("OK"); @@ -82,12 +82,12 @@ class CommandAuth : public Commander { class CommandNamespace : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { if (!conn->IsAdmin()) { return {Status::RedisExecErr, errAdminPermissionRequired}; } - Config *config = svr->GetConfig(); + Config *config = srv->GetConfig(); std::string sub_command = util::ToLower(args_[1]); if (config->repl_namespace_enabled && config->IsSlave() && sub_command != "get") { return {Status::RedisExecErr, "namespace is read-only for slave"}; @@ -95,7 +95,7 @@ class CommandNamespace : public Commander { if (args_.size() == 3 && sub_command == "get") { if (args_[2] == "*") { std::vector namespaces; - auto tokens = svr->GetNamespace()->List(); + auto tokens = srv->GetNamespace()->List(); for (auto &token : tokens) { namespaces.emplace_back(token.second); // namespace namespaces.emplace_back(token.first); // token @@ -104,7 +104,7 @@ class CommandNamespace : public Commander { namespaces.emplace_back(config->requirepass); *output = redis::MultiBulkString(namespaces, false); } else { - auto token = svr->GetNamespace()->Get(args_[2]); + auto token = srv->GetNamespace()->Get(args_[2]); if (token.Is()) { *output = redis::NilString(); } else { @@ -112,17 +112,17 @@ class CommandNamespace : public Commander { } } } else if (args_.size() == 4 && sub_command == "set") { - Status s = svr->GetNamespace()->Set(args_[2], args_[3]); + Status s = srv->GetNamespace()->Set(args_[2], args_[3]); *output = s.IsOK() ? redis::SimpleString("OK") : redis::Error("ERR " + s.Msg()); LOG(WARNING) << "Updated namespace: " << args_[2] << " with token: " << args_[3] << ", addr: " << conn->GetAddr() << ", result: " << s.Msg(); } else if (args_.size() == 4 && sub_command == "add") { - Status s = svr->GetNamespace()->Add(args_[2], args_[3]); + Status s = srv->GetNamespace()->Add(args_[2], args_[3]); *output = s.IsOK() ? redis::SimpleString("OK") : redis::Error("ERR " + s.Msg()); LOG(WARNING) << "New namespace: " << args_[2] << " with token: " << args_[3] << ", addr: " << conn->GetAddr() << ", result: " << s.Msg(); } else if (args_.size() == 3 && sub_command == "del") { - Status s = svr->GetNamespace()->Del(args_[2]); + Status s = srv->GetNamespace()->Del(args_[2]); *output = s.IsOK() ? redis::SimpleString("OK") : redis::Error("ERR " + s.Msg()); LOG(WARNING) << "Deleted namespace: " << args_[2] << ", addr: " << conn->GetAddr() << ", result: " << s.Msg(); } else { @@ -134,10 +134,10 @@ class CommandNamespace : public Commander { class CommandKeys : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::string prefix = args_[1]; std::vector keys; - redis::Database redis(svr->storage, conn->GetNamespace()); + redis::Database redis(srv->storage, conn->GetNamespace()); rocksdb::Status s; if (prefix == "*") { @@ -159,14 +159,14 @@ class CommandKeys : public Commander { class CommandFlushDB : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - if (svr->GetConfig()->cluster_enabled) { - if (svr->slot_migrator->IsMigrationInProgress()) { - svr->slot_migrator->SetStopMigrationFlag(true); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + if (srv->GetConfig()->cluster_enabled) { + if (srv->slot_migrator->IsMigrationInProgress()) { + srv->slot_migrator->SetStopMigrationFlag(true); LOG(INFO) << "Stop migration task for flushdb"; } } - redis::Database redis(svr->storage, conn->GetNamespace()); + redis::Database redis(srv->storage, conn->GetNamespace()); auto s = redis.FlushDB(); LOG(WARNING) << "DB keys in namespace: " << conn->GetNamespace() << " was flushed, addr: " << conn->GetAddr(); if (s.ok()) { @@ -180,19 +180,19 @@ class CommandFlushDB : public Commander { class CommandFlushAll : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { if (!conn->IsAdmin()) { return {Status::RedisExecErr, errAdminPermissionRequired}; } - if (svr->GetConfig()->cluster_enabled) { - if (svr->slot_migrator->IsMigrationInProgress()) { - svr->slot_migrator->SetStopMigrationFlag(true); + if (srv->GetConfig()->cluster_enabled) { + if (srv->slot_migrator->IsMigrationInProgress()) { + srv->slot_migrator->SetStopMigrationFlag(true); LOG(INFO) << "Stop migration task for flushall"; } } - redis::Database redis(svr->storage, conn->GetNamespace()); + redis::Database redis(srv->storage, conn->GetNamespace()); auto s = redis.FlushAll(); if (s.ok()) { LOG(WARNING) << "All DB keys was flushed, addr: " << conn->GetAddr(); @@ -206,7 +206,7 @@ class CommandFlushAll : public Commander { class CommandPing : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { if (args_.size() == 1) { *output = redis::SimpleString("PONG"); } else if (args_.size() == 2) { @@ -220,7 +220,7 @@ class CommandPing : public Commander { class CommandSelect : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { *output = redis::SimpleString("OK"); return Status::OK(); } @@ -228,12 +228,12 @@ class CommandSelect : public Commander { class CommandConfig : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { if (!conn->IsAdmin()) { return {Status::RedisExecErr, errAdminPermissionRequired}; } - Config *config = svr->GetConfig(); + Config *config = srv->GetConfig(); std::string sub_command = util::ToLower(args_[1]); if ((sub_command == "rewrite" && args_.size() != 2) || (sub_command == "get" && args_.size() != 3) || (sub_command == "set" && args_.size() != 4)) { @@ -241,7 +241,7 @@ class CommandConfig : public Commander { } if (args_.size() == 2 && sub_command == "rewrite") { - Status s = config->Rewrite(svr->GetNamespace()->List()); + Status s = config->Rewrite(srv->GetNamespace()->List()); if (!s.IsOK()) return {Status::RedisExecErr, s.Msg()}; *output = redis::SimpleString("OK"); @@ -251,7 +251,7 @@ class CommandConfig : public Commander { config->Get(args_[2], &values); *output = redis::MultiBulkString(values); } else if (args_.size() == 4 && sub_command == "set") { - Status s = config->Set(svr, args_[2], args_[3]); + Status s = config->Set(srv, args_[2], args_[3]); if (!s.IsOK()) { return {Status::RedisExecErr, "CONFIG SET '" + args_[2] + "' error: " + s.Msg()}; } else { @@ -266,7 +266,7 @@ class CommandConfig : public Commander { class CommandInfo : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::string section = "all"; if (args_.size() == 2) { section = util::ToLower(args_[1]); @@ -274,7 +274,7 @@ class CommandInfo : public Commander { return {Status::RedisParseErr, errInvalidSyntax}; } std::string info; - svr->GetInfo(conn->GetNamespace(), section, &info); + srv->GetInfo(conn->GetNamespace(), section, &info); *output = redis::BulkString(info); return Status::OK(); } @@ -288,9 +288,9 @@ class CommandDisk : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { RedisType type = kRedisNone; - redis::Disk disk_db(svr->storage, conn->GetNamespace()); + redis::Disk disk_db(srv->storage, conn->GetNamespace()); auto s = disk_db.Type(args_[2], &type); if (!s.ok()) return {Status::RedisExecErr, s.ToString()}; @@ -314,22 +314,22 @@ class CommandMemory : public CommandDisk {}; class CommandRole : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - svr->GetRoleInfo(output); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + srv->GetRoleInfo(output); return Status::OK(); } }; class CommandDBSize : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::string ns = conn->GetNamespace(); if (args_.size() == 1) { KeyNumStats stats; - svr->GetLatestKeyNumStats(ns, &stats); + srv->GetLatestKeyNumStats(ns, &stats); *output = redis::Integer(stats.n_key); } else if (args_.size() == 2 && args_[1] == "scan") { - Status s = svr->AsyncScanDBSize(ns); + Status s = srv->AsyncScanDBSize(ns); if (s.IsOK()) { *output = redis::SimpleString("OK"); } else { @@ -607,7 +607,7 @@ class CommandDebug : public Commander { class CommandCommand : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { if (args_.size() == 1) { CommandTable::GetAllCommandsInfo(output); } else { @@ -652,7 +652,7 @@ class CommandCommand : public Commander { class CommandEcho : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { *output = redis::BulkString(args_[1]); return Status::OK(); } @@ -660,7 +660,7 @@ class CommandEcho : public Commander { class CommandTime : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { uint64_t now = util::GetTimeStampUS(); uint64_t s = now / 1000 / 1000; // unix time in seconds. uint64_t us = now - (s * 1000 * 1000); // microseconds. @@ -680,7 +680,7 @@ class CommandTime : public Commander { */ class CommandHello final : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { size_t next_arg = 1; if (args_.size() >= 2) { auto parse_result = ParseInt(args_[next_arg], 10); @@ -711,7 +711,7 @@ class CommandHello final : public Commander { next_arg++; } const auto &user_password = args_[next_arg + 1]; - auto auth_result = AuthenticateUser(svr, conn, user_password); + auto auth_result = AuthenticateUser(srv, conn, user_password); switch (auth_result) { case AuthResult::INVALID_PASSWORD: return {Status::NotOK, "invalid password"}; @@ -738,7 +738,7 @@ class CommandHello final : public Commander { output_list.push_back(redis::BulkString("mode")); // Note: sentinel is not supported in kvrocks. - if (svr->GetConfig()->cluster_enabled) { + if (srv->GetConfig()->cluster_enabled) { output_list.push_back(redis::BulkString("cluster")); } else { output_list.push_back(redis::BulkString("standalone")); @@ -774,11 +774,11 @@ class CommandScan : public CommandScanBase { return Commander::Parse(args); } - static std::string GenerateOutput(Server *svr, const std::vector &keys, const std::string &end_cursor) { + static std::string GenerateOutput(Server *srv, const std::vector &keys, const std::string &end_cursor) { std::vector list; if (!end_cursor.empty()) { list.emplace_back( - redis::BulkString(svr->GenerateCursorFromKeyName(end_cursor, CursorType::kTypeBase, kCursorPrefix))); + redis::BulkString(srv->GenerateCursorFromKeyName(end_cursor, CursorType::kTypeBase, kCursorPrefix))); } else { list.emplace_back(redis::BulkString("0")); } @@ -788,9 +788,9 @@ class CommandScan : public CommandScanBase { return redis::Array(list); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Database redis_db(svr->storage, conn->GetNamespace()); - auto key_name = svr->GetKeyNameFromCursor(cursor_, CursorType::kTypeBase); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Database redis_db(srv->storage, conn->GetNamespace()); + auto key_name = srv->GetKeyNameFromCursor(cursor_, CursorType::kTypeBase); std::vector keys; std::string end_key; @@ -798,22 +798,22 @@ class CommandScan : public CommandScanBase { if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; } - *output = GenerateOutput(svr, keys, end_key); + *output = GenerateOutput(srv, keys, end_key); return Status::OK(); } }; class CommandRandomKey : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::string key; - auto cursor = svr->GetLastRandomKeyCursor(); - redis::Database redis(svr->storage, conn->GetNamespace()); + auto cursor = srv->GetLastRandomKeyCursor(); + redis::Database redis(srv->storage, conn->GetNamespace()); auto s = redis.RandomKey(cursor, &key); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; } - svr->SetLastRandomKeyCursor(key); + srv->SetLastRandomKeyCursor(key); *output = redis::BulkString(key); return Status::OK(); } @@ -821,14 +821,14 @@ class CommandRandomKey : public Commander { class CommandCompact : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::string begin_key, end_key; auto ns = conn->GetNamespace(); if (ns != kDefaultNamespace) { std::string prefix = ComposeNamespaceKey(ns, "", false); - redis::Database redis_db(svr->storage, conn->GetNamespace()); + redis::Database redis_db(srv->storage, conn->GetNamespace()); auto s = redis_db.FindKeyRangeWithPrefix(prefix, std::string(), &begin_key, &end_key); if (!s.ok()) { if (s.IsNotFound()) { @@ -840,7 +840,7 @@ class CommandCompact : public Commander { } } - Status s = svr->AsyncCompactDB(begin_key, end_key); + Status s = srv->AsyncCompactDB(begin_key, end_key); if (!s.IsOK()) return s; *output = redis::SimpleString("OK"); @@ -851,12 +851,12 @@ class CommandCompact : public Commander { class CommandBGSave : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { if (!conn->IsAdmin()) { return {Status::RedisExecErr, errAdminPermissionRequired}; } - Status s = svr->AsyncBgSaveDB(); + Status s = srv->AsyncBgSaveDB(); if (!s.IsOK()) return s; *output = redis::SimpleString("OK"); @@ -867,12 +867,12 @@ class CommandBGSave : public Commander { class CommandFlushBackup : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { if (!conn->IsAdmin()) { return {Status::RedisExecErr, errAdminPermissionRequired}; } - Status s = svr->AsyncPurgeOldBackups(0, 0); + Status s = srv->AsyncPurgeOldBackups(0, 0); if (!s.IsOK()) return s; *output = redis::SimpleString("OK"); @@ -883,16 +883,16 @@ class CommandFlushBackup : public Commander { class CommandSlaveOf : public Commander { public: - static Status IsTryingToReplicateItself(Server *svr, const std::string &host, uint32_t port) { + static Status IsTryingToReplicateItself(Server *srv, const std::string &host, uint32_t port) { auto ip_addresses = util::LookupHostByName(host); if (!ip_addresses) { return {Status::NotOK, "Can not resolve hostname: " + host}; } for (auto &ip : *ip_addresses) { - if (util::MatchListeningIP(svr->GetConfig()->binds, ip) && port == svr->GetConfig()->port) { + if (util::MatchListeningIP(srv->GetConfig()->binds, ip) && port == srv->GetConfig()->port) { return {Status::NotOK, "can't replicate itself"}; } - for (std::pair &host_port_pair : svr->GetSlaveHostAndPort()) { + for (std::pair &host_port_pair : srv->GetSlaveHostAndPort()) { if (host_port_pair.first == ip && host_port_pair.second == port) { return {Status::NotOK, "can't replicate your own replicas"}; } @@ -918,12 +918,12 @@ class CommandSlaveOf : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - if (svr->GetConfig()->cluster_enabled) { + Status Execute(Server *srv, Connection *conn, std::string *output) override { + if (srv->GetConfig()->cluster_enabled) { return {Status::RedisExecErr, "can't change to slave in cluster mode"}; } - if (svr->GetConfig()->rocks_db.write_options.disable_wal) { + if (srv->GetConfig()->rocks_db.write_options.disable_wal) { return {Status::RedisExecErr, "slaveof doesn't work with disable_wal option"}; } @@ -932,32 +932,32 @@ class CommandSlaveOf : public Commander { } if (host_.empty()) { - auto s = svr->RemoveMaster(); + auto s = srv->RemoveMaster(); if (!s.IsOK()) { return s.Prefixed("failed to remove master"); } *output = redis::SimpleString("OK"); LOG(WARNING) << "MASTER MODE enabled (user request from '" << conn->GetAddr() << "')"; - if (svr->GetConfig()->cluster_enabled) { - svr->slot_migrator->SetStopMigrationFlag(false); + if (srv->GetConfig()->cluster_enabled) { + srv->slot_migrator->SetStopMigrationFlag(false); LOG(INFO) << "Change server role to master, restart migration task"; } return Status::OK(); } - auto s = IsTryingToReplicateItself(svr, host_, port_); + auto s = IsTryingToReplicateItself(srv, host_, port_); if (!s.IsOK()) { return {Status::RedisExecErr, s.Msg()}; } - s = svr->AddMaster(host_, port_, false); + s = srv->AddMaster(host_, port_, false); if (s.IsOK()) { *output = redis::SimpleString("OK"); LOG(WARNING) << "SLAVE OF " << host_ << ":" << port_ << " enabled (user request from '" << conn->GetAddr() << "')"; - if (svr->GetConfig()->cluster_enabled) { - svr->slot_migrator->SetStopMigrationFlag(true); + if (srv->GetConfig()->cluster_enabled) { + srv->slot_migrator->SetStopMigrationFlag(true); LOG(INFO) << "Change server role to slave, stop migration task"; } } else { @@ -975,8 +975,8 @@ class CommandSlaveOf : public Commander { class CommandStats : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - std::string stats_json = svr->GetRocksDBStatsJson(); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + std::string stats_json = srv->GetRocksDBStatsJson(); *output = redis::BulkString(stats_json); return Status::OK(); } @@ -992,12 +992,12 @@ static uint64_t GenerateConfigFlag(const std::vector &args) { class CommandLastSave : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { if (!conn->IsAdmin()) { return {Status::RedisExecErr, errAdminPermissionRequired}; } - int64_t unix_sec = svr->GetLastBgsaveTime(); + int64_t unix_sec = srv->GetLastBgsaveTime(); *output = redis::Integer(unix_sec); return Status::OK(); } @@ -1032,9 +1032,9 @@ class CommandRestore : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { rocksdb::Status db_status; - redis::Database redis(svr->storage, conn->GetNamespace()); + redis::Database redis(srv->storage, conn->GetNamespace()); if (!replace_) { int count = 0; db_status = redis.Exists({args_[1]}, &count); @@ -1061,7 +1061,7 @@ class CommandRestore : public Commander { } auto stream_ptr = std::make_unique(args_[3]); - RDB rdb(svr->storage, conn->GetNamespace(), std::move(stream_ptr)); + RDB rdb(srv->storage, conn->GetNamespace(), std::move(stream_ptr)); auto s = rdb.Restore(args_[1], args_[3], ttl_ms_); if (!s.IsOK()) return {Status::RedisExecErr, s.Msg()}; *output = redis::SimpleString("OK"); @@ -1099,17 +1099,17 @@ class CommandRdb : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { if (!conn->IsAdmin()) { return {Status::RedisExecErr, errAdminPermissionRequired}; } - redis::Database redis(svr->storage, conn->GetNamespace()); + redis::Database redis(srv->storage, conn->GetNamespace()); auto stream_ptr = std::make_unique(path_); GET_OR_RET(stream_ptr->Open()); - RDB rdb(svr->storage, conn->GetNamespace(), std::move(stream_ptr)); + RDB rdb(srv->storage, conn->GetNamespace(), std::move(stream_ptr)); GET_OR_RET(rdb.LoadRdb(db_index_, overwrite_exist_key_)); *output = redis::SimpleString("OK"); diff --git a/src/commands/cmd_set.cc b/src/commands/cmd_set.cc index 5ec1b7ba45b..f2c60a3ba66 100644 --- a/src/commands/cmd_set.cc +++ b/src/commands/cmd_set.cc @@ -30,14 +30,14 @@ namespace redis { class CommandSAdd : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::vector members; for (unsigned int i = 2; i < args_.size(); i++) { members.emplace_back(args_[i]); } uint64_t ret = 0; - redis::Set set_db(svr->storage, conn->GetNamespace()); + redis::Set set_db(srv->storage, conn->GetNamespace()); auto s = set_db.Add(args_[1], members, &ret); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -50,14 +50,14 @@ class CommandSAdd : public Commander { class CommandSRem : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::vector members; for (size_t i = 2; i < args_.size(); i++) { members.emplace_back(args_[i]); } uint64_t ret = 0; - redis::Set set_db(svr->storage, conn->GetNamespace()); + redis::Set set_db(srv->storage, conn->GetNamespace()); auto s = set_db.Remove(args_[1], members, &ret); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -70,8 +70,8 @@ class CommandSRem : public Commander { class CommandSCard : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Set set_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Set set_db(srv->storage, conn->GetNamespace()); uint64_t ret = 0; auto s = set_db.Card(args_[1], &ret); if (!s.ok()) { @@ -85,8 +85,8 @@ class CommandSCard : public Commander { class CommandSMembers : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Set set_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Set set_db(srv->storage, conn->GetNamespace()); std::vector members; auto s = set_db.Members(args_[1], &members); if (!s.ok()) { @@ -100,8 +100,8 @@ class CommandSMembers : public Commander { class CommandSIsMember : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Set set_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Set set_db(srv->storage, conn->GetNamespace()); bool ret = false; auto s = set_db.IsMember(args_[1], args_[2], &ret); if (!s.ok() && !s.IsNotFound()) { @@ -115,8 +115,8 @@ class CommandSIsMember : public Commander { class CommandSMIsMember : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Set set_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Set set_db(srv->storage, conn->GetNamespace()); std::vector members; for (size_t i = 2; i < args_.size(); i++) { members.emplace_back(args_[i]); @@ -162,8 +162,8 @@ class CommandSPop : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Set set_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Set set_db(srv->storage, conn->GetNamespace()); std::vector members; auto s = set_db.Take(args_[1], &members, count_, true); if (!s.ok()) { @@ -204,8 +204,8 @@ class CommandSRandMember : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Set set_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Set set_db(srv->storage, conn->GetNamespace()); std::vector members; auto s = set_db.Take(args_[1], &members, count_, false); if (!s.ok()) { @@ -221,8 +221,8 @@ class CommandSRandMember : public Commander { class CommandSMove : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Set set_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Set set_db(srv->storage, conn->GetNamespace()); bool ret = false; auto s = set_db.Move(args_[1], args_[2], args_[3], &ret); if (!s.ok()) { @@ -236,14 +236,14 @@ class CommandSMove : public Commander { class CommandSDiff : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::vector keys; for (size_t i = 1; i < args_.size(); i++) { keys.emplace_back(args_[i]); } std::vector members; - redis::Set set_db(svr->storage, conn->GetNamespace()); + redis::Set set_db(srv->storage, conn->GetNamespace()); auto s = set_db.Diff(keys, &members); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -256,14 +256,14 @@ class CommandSDiff : public Commander { class CommandSUnion : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::vector keys; for (size_t i = 1; i < args_.size(); i++) { keys.emplace_back(args_[i]); } std::vector members; - redis::Set set_db(svr->storage, conn->GetNamespace()); + redis::Set set_db(srv->storage, conn->GetNamespace()); auto s = set_db.Union(keys, &members); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -276,14 +276,14 @@ class CommandSUnion : public Commander { class CommandSInter : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::vector keys; for (size_t i = 1; i < args_.size(); i++) { keys.emplace_back(args_[i]); } std::vector members; - redis::Set set_db(svr->storage, conn->GetNamespace()); + redis::Set set_db(srv->storage, conn->GetNamespace()); auto s = set_db.Inter(keys, &members); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -333,13 +333,13 @@ class CommandSInterCard : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::vector keys; for (size_t i = 2; i < numkeys_ + 2; i++) { keys.emplace_back(args_[i]); } - redis::Set set_db(svr->storage, conn->GetNamespace()); + redis::Set set_db(srv->storage, conn->GetNamespace()); uint64_t ret = 0; auto s = set_db.InterCard(keys, limit_, &ret); if (!s.ok()) { @@ -362,14 +362,14 @@ class CommandSInterCard : public Commander { class CommandSDiffStore : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::vector keys; for (size_t i = 2; i < args_.size(); i++) { keys.emplace_back(args_[i]); } uint64_t ret = 0; - redis::Set set_db(svr->storage, conn->GetNamespace()); + redis::Set set_db(srv->storage, conn->GetNamespace()); auto s = set_db.DiffStore(args_[1], keys, &ret); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -382,14 +382,14 @@ class CommandSDiffStore : public Commander { class CommandSUnionStore : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::vector keys; for (size_t i = 2; i < args_.size(); i++) { keys.emplace_back(args_[i]); } uint64_t ret = 0; - redis::Set set_db(svr->storage, conn->GetNamespace()); + redis::Set set_db(srv->storage, conn->GetNamespace()); auto s = set_db.UnionStore(args_[1], keys, &ret); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -402,14 +402,14 @@ class CommandSUnionStore : public Commander { class CommandSInterStore : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::vector keys; for (size_t i = 2; i < args_.size(); i++) { keys.emplace_back(args_[i]); } uint64_t ret = 0; - redis::Set set_db(svr->storage, conn->GetNamespace()); + redis::Set set_db(srv->storage, conn->GetNamespace()); auto s = set_db.InterStore(args_[1], keys, &ret); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -423,16 +423,16 @@ class CommandSInterStore : public Commander { class CommandSScan : public CommandSubkeyScanBase { public: CommandSScan() = default; - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Set set_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Set set_db(srv->storage, conn->GetNamespace()); std::vector members; - auto key_name = svr->GetKeyNameFromCursor(cursor_, CursorType::kTypeSet); + auto key_name = srv->GetKeyNameFromCursor(cursor_, CursorType::kTypeSet); auto s = set_db.Scan(key_, key_name, limit_, prefix_, &members); if (!s.ok() && !s.IsNotFound()) { return {Status::RedisExecErr, s.ToString()}; } - *output = CommandScanBase::GenerateOutput(svr, members, CursorType::kTypeSet); + *output = CommandScanBase::GenerateOutput(srv, members, CursorType::kTypeSet); return Status::OK(); } }; diff --git a/src/commands/cmd_sortedint.cc b/src/commands/cmd_sortedint.cc index 82c81c8f2ae..b668a0a69e6 100644 --- a/src/commands/cmd_sortedint.cc +++ b/src/commands/cmd_sortedint.cc @@ -39,8 +39,8 @@ class CommandSortedintAdd : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Sortedint sortedint_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Sortedint sortedint_db(srv->storage, conn->GetNamespace()); uint64_t ret = 0; auto s = sortedint_db.Add(args_[1], ids_, &ret); if (!s.ok()) { @@ -69,8 +69,8 @@ class CommandSortedintRem : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Sortedint sortedint_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Sortedint sortedint_db(srv->storage, conn->GetNamespace()); uint64_t ret = 0; auto s = sortedint_db.Remove(args_[1], ids_, &ret); if (!s.ok()) { @@ -87,8 +87,8 @@ class CommandSortedintRem : public Commander { class CommandSortedintCard : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Sortedint sortedint_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Sortedint sortedint_db(srv->storage, conn->GetNamespace()); uint64_t ret = 0; auto s = sortedint_db.Card(args_[1], &ret); if (!s.ok()) { @@ -102,8 +102,8 @@ class CommandSortedintCard : public Commander { class CommandSortedintExists : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Sortedint sortedint_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Sortedint sortedint_db(srv->storage, conn->GetNamespace()); std::vector ids; for (size_t i = 2; i < args_.size(); i++) { auto parse_result = ParseInt(args_[i], 10); @@ -162,8 +162,8 @@ class CommandSortedintRange : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Sortedint sortedint_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Sortedint sortedint_db(srv->storage, conn->GetNamespace()); std::vector ids; auto s = sortedint_db.Range(args_[1], cursor_id_, offset_, limit_, reversed_, &ids); if (!s.ok()) { @@ -223,10 +223,10 @@ class CommandSortedintRangeByValue : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::vector ids; int size = 0; - redis::Sortedint sortedint_db(svr->storage, conn->GetNamespace()); + redis::Sortedint sortedint_db(srv->storage, conn->GetNamespace()); auto s = sortedint_db.RangeByValue(args_[1], spec_, &ids, &size); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; diff --git a/src/commands/cmd_stream.cc b/src/commands/cmd_stream.cc index e8607d1c5ce..45ed098a88b 100644 --- a/src/commands/cmd_stream.cc +++ b/src/commands/cmd_stream.cc @@ -131,7 +131,7 @@ class CommandXAdd : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { redis::StreamAddOptions options; options.nomkstream = nomkstream_; if (with_max_len_) { @@ -144,7 +144,7 @@ class CommandXAdd : public Commander { } options.next_id_strategy = std::move(next_id_strategy_); - redis::Stream stream_db(svr->storage, conn->GetNamespace()); + redis::Stream stream_db(srv->storage, conn->GetNamespace()); StreamEntryID entry_id; auto s = stream_db.Add(stream_name_, options, name_value_pairs_, &entry_id); if (!s.ok() && !s.IsNotFound()) { @@ -158,7 +158,7 @@ class CommandXAdd : public Commander { *output = redis::BulkString(entry_id.ToString()); - svr->OnEntryAddedToStream(conn->GetNamespace(), stream_name_, entry_id); + srv->OnEntryAddedToStream(conn->GetNamespace(), stream_name_, entry_id); return Status::OK(); } @@ -189,8 +189,8 @@ class CommandXDel : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Stream stream_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Stream stream_db(srv->storage, conn->GetNamespace()); uint64_t deleted = 0; auto s = stream_db.DeleteEntries(args_[1], ids_, &deleted); if (!s.ok()) { @@ -285,8 +285,8 @@ class CommandXGroup : public Commander { return {Status::RedisParseErr, "unknown subcommand"}; } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Stream stream_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Stream stream_db(srv->storage, conn->GetNamespace()); if (subcommand_ == "create") { auto s = stream_db.CreateGroup(stream_name_, xgroup_create_options_, group_name_); @@ -364,8 +364,8 @@ class CommandXLen : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Stream stream_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Stream stream_db(srv->storage, conn->GetNamespace()); uint64_t len = 0; auto s = stream_db.Len(args_[1], options_, &len); if (!s.ok()) { @@ -404,9 +404,9 @@ class CommandXInfo : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { if (stream_) { - return getStreamInfo(svr, conn, output); + return getStreamInfo(srv, conn, output); } return Status::OK(); } @@ -416,8 +416,8 @@ class CommandXInfo : public Commander { bool stream_ = false; bool full_ = false; - Status getStreamInfo(Server *svr, Connection *conn, std::string *output) { - redis::Stream stream_db(svr->storage, conn->GetNamespace()); + Status getStreamInfo(Server *srv, Connection *conn, std::string *output) { + redis::Stream stream_db(srv->storage, conn->GetNamespace()); redis::StreamInfo info; auto s = stream_db.GetStreamInfo(args_[2], full_, count_, &info); if (!s.ok() && !s.IsNotFound()) { @@ -523,13 +523,13 @@ class CommandXRange : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { if (with_count_ && count_ == 0) { *output = redis::NilString(); return Status::OK(); } - redis::Stream stream_db(svr->storage, conn->GetNamespace()); + redis::Stream stream_db(srv->storage, conn->GetNamespace()); redis::StreamRangeOptions options; options.reverse = false; @@ -616,13 +616,13 @@ class CommandXRevRange : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { if (with_count_ && count_ == 0) { *output = redis::NilString(); return Status::OK(); } - redis::Stream stream_db(svr->storage, conn->GetNamespace()); + redis::Stream stream_db(srv->storage, conn->GetNamespace()); redis::StreamRangeOptions options; options.reverse = true; @@ -745,8 +745,8 @@ class CommandXRead : public Commander, return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Stream stream_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Stream stream_db(srv->storage, conn->GetNamespace()); std::vector results; @@ -781,7 +781,7 @@ class CommandXRead : public Commander, return Status::OK(); // No blocking in multi-exec } - return BlockingRead(svr, conn, &stream_db); + return BlockingRead(srv, conn, &stream_db); } if (!block_ && results.empty()) { @@ -809,7 +809,7 @@ class CommandXRead : public Commander, return Status::OK(); } - Status BlockingRead(Server *svr, Connection *conn, redis::Stream *stream_db) { + Status BlockingRead(Server *srv, Connection *conn, redis::Stream *stream_db) { if (!with_count_) { with_count_ = true; count_ = blocked_default_count_; @@ -827,10 +827,10 @@ class CommandXRead : public Commander, } } - svr_ = svr; + srv_ = srv; conn_ = conn; - svr_->BlockOnStreams(streams_, ids_, conn_); + srv_->BlockOnStreams(streams_, ids_, conn_); auto bev = conn->GetBufferEvent(); SetCB(bev); @@ -861,7 +861,7 @@ class CommandXRead : public Commander, conn_->SetCB(bev); bufferevent_enable(bev, EV_READ); - redis::Stream stream_db(svr_->storage, conn_->GetNamespace()); + redis::Stream stream_db(srv_->storage, conn_->GetNamespace()); std::vector results; @@ -939,7 +939,7 @@ class CommandXRead : public Commander, std::vector streams_; std::vector ids_; std::vector latest_marks_; - Server *svr_ = nullptr; + Server *srv_ = nullptr; Connection *conn_ = nullptr; UniqueEvent timer_; uint64_t count_ = 0; @@ -948,7 +948,7 @@ class CommandXRead : public Commander, bool with_count_ = false; bool block_ = false; - void unblockAll() { svr_->UnblockOnStreams(streams_, conn_); } + void unblockAll() { srv_->UnblockOnStreams(streams_, conn_); } }; class CommandXTrim : public Commander { @@ -1019,8 +1019,8 @@ class CommandXTrim : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Stream stream_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Stream stream_db(srv->storage, conn->GetNamespace()); StreamTrimOptions options; options.strategy = strategy_; @@ -1084,8 +1084,8 @@ class CommandXSetId : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::Stream stream_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::Stream stream_db(srv->storage, conn->GetNamespace()); auto s = stream_db.SetId(stream_name_, last_id_, entries_added_, max_deleted_id_); if (!s.ok()) { diff --git a/src/commands/cmd_string.cc b/src/commands/cmd_string.cc index 557f9e4c2ba..99783172c42 100644 --- a/src/commands/cmd_string.cc +++ b/src/commands/cmd_string.cc @@ -35,17 +35,17 @@ namespace redis { class CommandGet : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::string value; - redis::String string_db(svr->storage, conn->GetNamespace()); + redis::String string_db(srv->storage, conn->GetNamespace()); auto s = string_db.Get(args_[1], &value); // The IsInvalidArgument error means the key type maybe a bitmap // which we need to fall back to the bitmap's GetString according // to the `max-bitmap-to-string-mb` configuration. if (s.IsInvalidArgument()) { - Config *config = svr->GetConfig(); + Config *config = srv->GetConfig(); uint32_t max_btos_size = static_cast(config->max_bitmap_to_string_mb) * MiB; - redis::Bitmap bitmap_db(svr->storage, conn->GetNamespace()); + redis::Bitmap bitmap_db(srv->storage, conn->GetNamespace()); s = bitmap_db.GetString(args_[1], max_btos_size, &value); } if (!s.ok() && !s.IsNotFound()) { @@ -74,18 +74,18 @@ class CommandGetEx : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::string value; - redis::String string_db(svr->storage, conn->GetNamespace()); + redis::String string_db(srv->storage, conn->GetNamespace()); auto s = string_db.GetEx(args_[1], &value, ttl_, persist_); // The IsInvalidArgument error means the key type maybe a bitmap // which we need to fall back to the bitmap's GetString according // to the `max-bitmap-to-string-mb` configuration. if (s.IsInvalidArgument()) { - Config *config = svr->GetConfig(); + Config *config = srv->GetConfig(); uint32_t max_btos_size = static_cast(config->max_bitmap_to_string_mb) * MiB; - redis::Bitmap bitmap_db(svr->storage, conn->GetNamespace()); + redis::Bitmap bitmap_db(srv->storage, conn->GetNamespace()); s = bitmap_db.GetString(args_[1], max_btos_size, &value); if (s.ok()) { if (ttl_ > 0) { @@ -110,9 +110,9 @@ class CommandGetEx : public Commander { class CommandStrlen : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::string value; - redis::String string_db(svr->storage, conn->GetNamespace()); + redis::String string_db(srv->storage, conn->GetNamespace()); auto s = string_db.Get(args_[1], &value); if (!s.ok() && !s.IsNotFound()) { return {Status::RedisExecErr, s.ToString()}; @@ -129,8 +129,8 @@ class CommandStrlen : public Commander { class CommandGetSet : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::String string_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::String string_db(srv->storage, conn->GetNamespace()); std::string old_value; auto s = string_db.GetSet(args_[1], args_[2], &old_value); if (!s.ok() && !s.IsNotFound()) { @@ -148,8 +148,8 @@ class CommandGetSet : public Commander { class CommandGetDel : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::String string_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::String string_db(srv->storage, conn->GetNamespace()); std::string value; auto s = string_db.GetDel(args_[1], &value); if (!s.ok() && !s.IsNotFound()) { @@ -179,9 +179,9 @@ class CommandGetRange : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::string value; - redis::String string_db(svr->storage, conn->GetNamespace()); + redis::String string_db(srv->storage, conn->GetNamespace()); auto s = string_db.Get(args_[1], &value); if (!s.ok() && !s.IsNotFound()) { return {Status::RedisExecErr, s.ToString()}; @@ -226,9 +226,9 @@ class CommandSetRange : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { uint64_t ret = 0; - redis::String string_db(svr->storage, conn->GetNamespace()); + redis::String string_db(srv->storage, conn->GetNamespace()); auto s = string_db.SetRange(args_[1], offset_, args_[3], &ret); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -244,8 +244,8 @@ class CommandSetRange : public Commander { class CommandMGet : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::String string_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::String string_db(srv->storage, conn->GetNamespace()); std::vector keys; for (size_t i = 1; i < args_.size(); i++) { keys.emplace_back(args_[i]); @@ -260,9 +260,9 @@ class CommandMGet : public Commander { class CommandAppend : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { uint64_t ret = 0; - redis::String string_db(svr->storage, conn->GetNamespace()); + redis::String string_db(srv->storage, conn->GetNamespace()); auto s = string_db.Append(args_[1], args_[2], &ret); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -293,9 +293,9 @@ class CommandSet : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { bool ret = false; - redis::String string_db(svr->storage, conn->GetNamespace()); + redis::String string_db(srv->storage, conn->GetNamespace()); if (ttl_ < 0) { auto s = string_db.Del(args_[1]); @@ -347,8 +347,8 @@ class CommandSetEX : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::String string_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::String string_db(srv->storage, conn->GetNamespace()); auto s = string_db.SetEX(args_[1], args_[3], ttl_ * 1000); *output = redis::SimpleString("OK"); return Status::OK(); @@ -373,8 +373,8 @@ class CommandPSetEX : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::String string_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::String string_db(srv->storage, conn->GetNamespace()); auto s = string_db.SetEX(args_[1], args_[3], ttl_); *output = redis::SimpleString("OK"); return Status::OK(); @@ -394,8 +394,8 @@ class CommandMSet : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::String string_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::String string_db(srv->storage, conn->GetNamespace()); std::vector kvs; for (size_t i = 1; i < args_.size(); i += 2) { kvs.emplace_back(StringPair{args_[i], args_[i + 1]}); @@ -413,9 +413,9 @@ class CommandMSet : public Commander { class CommandSetNX : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { bool ret = false; - redis::String string_db(svr->storage, conn->GetNamespace()); + redis::String string_db(srv->storage, conn->GetNamespace()); auto s = string_db.SetNX(args_[1], args_[2], 0, &ret); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -436,10 +436,10 @@ class CommandMSetNX : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { bool ret = false; std::vector kvs; - redis::String string_db(svr->storage, conn->GetNamespace()); + redis::String string_db(srv->storage, conn->GetNamespace()); for (size_t i = 1; i < args_.size(); i += 2) { kvs.emplace_back(StringPair{args_[i], args_[i + 1]}); } @@ -456,9 +456,9 @@ class CommandMSetNX : public Commander { class CommandIncr : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { int64_t ret = 0; - redis::String string_db(svr->storage, conn->GetNamespace()); + redis::String string_db(srv->storage, conn->GetNamespace()); auto s = string_db.IncrBy(args_[1], 1, &ret); if (!s.ok()) return {Status::RedisExecErr, s.ToString()}; @@ -469,9 +469,9 @@ class CommandIncr : public Commander { class CommandDecr : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { int64_t ret = 0; - redis::String string_db(svr->storage, conn->GetNamespace()); + redis::String string_db(srv->storage, conn->GetNamespace()); auto s = string_db.IncrBy(args_[1], -1, &ret); if (!s.ok()) return {Status::RedisExecErr, s.ToString()}; @@ -492,9 +492,9 @@ class CommandIncrBy : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { int64_t ret = 0; - redis::String string_db(svr->storage, conn->GetNamespace()); + redis::String string_db(srv->storage, conn->GetNamespace()); auto s = string_db.IncrBy(args_[1], increment_, &ret); if (!s.ok()) return {Status::RedisExecErr, s.ToString()}; @@ -518,9 +518,9 @@ class CommandIncrByFloat : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { double ret = 0; - redis::String string_db(svr->storage, conn->GetNamespace()); + redis::String string_db(srv->storage, conn->GetNamespace()); auto s = string_db.IncrByFloat(args_[1], increment_, &ret); if (!s.ok()) return {Status::RedisExecErr, s.ToString()}; @@ -550,9 +550,9 @@ class CommandDecrBy : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { int64_t ret = 0; - redis::String string_db(svr->storage, conn->GetNamespace()); + redis::String string_db(srv->storage, conn->GetNamespace()); auto s = string_db.IncrBy(args_[1], -1 * increment_, &ret); if (!s.ok()) return {Status::RedisExecErr, s.ToString()}; @@ -579,8 +579,8 @@ class CommandCAS : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::String string_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::String string_db(srv->storage, conn->GetNamespace()); int ret = 0; auto s = string_db.CAS(args_[1], args_[2], args_[3], ttl_, &ret); if (!s.ok()) { @@ -597,8 +597,8 @@ class CommandCAS : public Commander { class CommandCAD : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::String string_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::String string_db(srv->storage, conn->GetNamespace()); int ret = 0; auto s = string_db.CAD(args_[1], args_[2], &ret); if (!s.ok()) { diff --git a/src/commands/cmd_txn.cc b/src/commands/cmd_txn.cc index b6c94c06a67..c99c6ddc80f 100644 --- a/src/commands/cmd_txn.cc +++ b/src/commands/cmd_txn.cc @@ -29,7 +29,7 @@ namespace redis { class CommandMulti : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { if (conn->IsFlagEnabled(Connection::kMultiExec)) { return {Status::RedisExecErr, "MULTI calls can not be nested"}; } @@ -43,12 +43,12 @@ class CommandMulti : public Commander { class CommandDiscard : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { if (!conn->IsFlagEnabled(Connection::kMultiExec)) { return {Status::RedisExecErr, "DISCARD without MULTI"}; } - auto reset_watch = MakeScopeExit([svr, conn] { svr->ResetWatchedKeys(conn); }); + auto reset_watch = MakeScopeExit([srv, conn] { srv->ResetWatchedKeys(conn); }); conn->ResetMultiExec(); *output = redis::SimpleString("OK"); @@ -59,12 +59,12 @@ class CommandDiscard : public Commander { class CommandExec : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { if (!conn->IsFlagEnabled(Connection::kMultiExec)) { return {Status::RedisExecErr, "EXEC without MULTI"}; } - auto reset_watch = MakeScopeExit([svr, conn] { svr->ResetWatchedKeys(conn); }); + auto reset_watch = MakeScopeExit([srv, conn] { srv->ResetWatchedKeys(conn); }); auto reset_multiexec = MakeScopeExit([conn] { conn->ResetMultiExec(); }); if (conn->IsMultiError()) { @@ -72,12 +72,12 @@ class CommandExec : public Commander { return Status::OK(); } - if (svr->IsWatchedKeysModified(conn)) { + if (srv->IsWatchedKeysModified(conn)) { *output = redis::NilString(); return Status::OK(); } - auto storage = svr->storage; + auto storage = srv->storage; // Reply multi length first conn->Reply(redis::MultiLen(conn->GetMultiExecCommands()->size())); // Execute multi-exec commands @@ -93,18 +93,18 @@ class CommandExec : public Commander { class CommandWatch : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { if (conn->IsFlagEnabled(Connection::kMultiExec)) { return {Status::RedisExecErr, "WATCH inside MULTI is not allowed"}; } // If a conn is already marked as watched_keys_modified, we can skip the watch. - if (svr->IsWatchedKeysModified(conn)) { + if (srv->IsWatchedKeysModified(conn)) { *output = redis::SimpleString("OK"); return Status::OK(); } - svr->WatchKey(conn, std::vector(args_.begin() + 1, args_.end())); + srv->WatchKey(conn, std::vector(args_.begin() + 1, args_.end())); *output = redis::SimpleString("OK"); return Status::OK(); } @@ -112,8 +112,8 @@ class CommandWatch : public Commander { class CommandUnwatch : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { - svr->ResetWatchedKeys(conn); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + srv->ResetWatchedKeys(conn); *output = redis::SimpleString("OK"); return Status::OK(); } diff --git a/src/commands/cmd_zset.cc b/src/commands/cmd_zset.cc index 41493b6e153..ab4909f4c23 100644 --- a/src/commands/cmd_zset.cc +++ b/src/commands/cmd_zset.cc @@ -65,16 +65,16 @@ class CommandZAdd : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { uint64_t ret = 0; double old_score = member_scores_[0].score; - redis::ZSet zset_db(svr->storage, conn->GetNamespace()); + redis::ZSet zset_db(srv->storage, conn->GetNamespace()); auto s = zset_db.Add(args_[1], flags_, &member_scores_, &ret); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; } - svr->WakeupBlockingConns(args_[1], member_scores_.size()); + srv->WakeupBlockingConns(args_[1], member_scores_.size()); if (flags_.HasIncr()) { auto new_score = member_scores_[0].score; @@ -139,9 +139,9 @@ class CommandZCount : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { uint64_t ret = 0; - redis::ZSet zset_db(svr->storage, conn->GetNamespace()); + redis::ZSet zset_db(srv->storage, conn->GetNamespace()); auto s = zset_db.Count(args_[1], spec_, &ret); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -157,9 +157,9 @@ class CommandZCount : public Commander { class CommandZCard : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { uint64_t ret = 0; - redis::ZSet zset_db(svr->storage, conn->GetNamespace()); + redis::ZSet zset_db(srv->storage, conn->GetNamespace()); auto s = zset_db.Card(args_[1], &ret); if (!s.ok() && !s.IsNotFound()) { return {Status::RedisExecErr, s.ToString()}; @@ -181,9 +181,9 @@ class CommandZIncrBy : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { double score = 0; - redis::ZSet zset_db(svr->storage, conn->GetNamespace()); + redis::ZSet zset_db(srv->storage, conn->GetNamespace()); auto s = zset_db.IncrBy(args_[1], args_[3], incr_, &score); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -208,9 +208,9 @@ class CommandZLexCount : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { uint64_t size = 0; - redis::ZSet zset_db(svr->storage, conn->GetNamespace()); + redis::ZSet zset_db(srv->storage, conn->GetNamespace()); auto s = zset_db.RangeByLex(args_[1], spec_, nullptr, &size); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -244,8 +244,8 @@ class CommandZPop : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::ZSet zset_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::ZSet zset_db(srv->storage, conn->GetNamespace()); std::vector member_scores; auto s = zset_db.Pop(args_[1], count_, min_, &member_scores); if (!s.ok()) { @@ -312,14 +312,14 @@ class CommandBZPop : public BlockingCommander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - svr_ = svr; + Status Execute(Server *srv, Connection *conn, std::string *output) override { + srv_ = srv; InitConnection(conn); std::string user_key; std::vector member_scores; - redis::ZSet zset_db(svr->storage, conn->GetNamespace()); + redis::ZSet zset_db(srv->storage, conn->GetNamespace()); auto s = PopFromMultipleZsets(&zset_db, keys_, min_, 1, &user_key, &member_scores); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -337,13 +337,13 @@ class CommandBZPop : public BlockingCommander { void BlockKeys() override { for (const auto &key : keys_) { - svr_->BlockOnKey(key, conn_); + srv_->BlockOnKey(key, conn_); } } void UnblockKeys() override { for (const auto &key : keys_) { - svr_->UnblockOnKey(key, conn_); + srv_->UnblockOnKey(key, conn_); } } @@ -362,7 +362,7 @@ class CommandBZPop : public BlockingCommander { std::string user_key; std::vector member_scores; - redis::ZSet zset_db(svr_->storage, conn_->GetNamespace()); + redis::ZSet zset_db(srv_->storage, conn_->GetNamespace()); auto s = PopFromMultipleZsets(&zset_db, keys_, min_, 1, &user_key, &member_scores); if (!s.ok()) { conn_->Reply(redis::Error("ERR " + s.ToString())); @@ -381,7 +381,7 @@ class CommandBZPop : public BlockingCommander { bool min_; int64_t timeout_ = 0; // microseconds std::vector keys_; - Server *svr_ = nullptr; + Server *srv_ = nullptr; }; class CommandBZPopMin : public CommandBZPop { @@ -436,8 +436,8 @@ class CommandZMPop : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::ZSet zset_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::ZSet zset_db(srv->storage, conn->GetNamespace()); for (auto &user_key : keys_) { std::vector member_scores; auto s = zset_db.Pop(user_key, count_, flag_ == ZSET_MIN, &member_scores); @@ -502,14 +502,14 @@ class CommandBZMPop : public BlockingCommander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - svr_ = svr; + Status Execute(Server *srv, Connection *conn, std::string *output) override { + srv_ = srv; InitConnection(conn); std::string user_key; std::vector member_scores; - redis::ZSet zset_db(svr->storage, conn->GetNamespace()); + redis::ZSet zset_db(srv->storage, conn->GetNamespace()); auto s = PopFromMultipleZsets(&zset_db, keys_, flag_ == ZSET_MIN, count_, &user_key, &member_scores); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -525,13 +525,13 @@ class CommandBZMPop : public BlockingCommander { void BlockKeys() override { for (const auto &key : keys_) { - svr_->BlockOnKey(key, conn_); + srv_->BlockOnKey(key, conn_); } } void UnblockKeys() override { for (const auto &key : keys_) { - svr_->UnblockOnKey(key, conn_); + srv_->UnblockOnKey(key, conn_); } } @@ -541,7 +541,7 @@ class CommandBZMPop : public BlockingCommander { std::string user_key; std::vector member_scores; - redis::ZSet zset_db(svr_->storage, conn_->GetNamespace()); + redis::ZSet zset_db(srv_->storage, conn_->GetNamespace()); auto s = PopFromMultipleZsets(&zset_db, keys_, flag_ == ZSET_MIN, count_, &user_key, &member_scores); if (!s.ok()) { conn_->Reply(redis::Error("ERR " + s.ToString())); @@ -567,7 +567,7 @@ class CommandBZMPop : public BlockingCommander { std::vector keys_; enum { ZSET_MIN, ZSET_MAX, ZSET_NONE } flag_ = ZSET_NONE; int count_ = 0; - Server *svr_ = nullptr; + Server *srv_ = nullptr; }; class CommandZRangeStore : public Commander { @@ -645,8 +645,8 @@ class CommandZRangeStore : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::ZSet zset_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::ZSet zset_db(srv->storage, conn->GetNamespace()); std::vector member_scores; @@ -782,8 +782,8 @@ class CommandZRangeGeneric : public Commander { return Status::OK(); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::ZSet zset_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::ZSet zset_db(srv->storage, conn->GetNamespace()); std::vector member_scores; rocksdb::Status s; @@ -882,10 +882,10 @@ class CommandZRank : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { int rank = 0; double score = 0.0; - redis::ZSet zset_db(svr->storage, conn->GetNamespace()); + redis::ZSet zset_db(srv->storage, conn->GetNamespace()); auto s = zset_db.Rank(args_[1], args_[2], reversed_, &rank, &score); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -921,14 +921,14 @@ class CommandZRevRank : public CommandZRank { class CommandZRem : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::vector members; for (size_t i = 2; i < args_.size(); i++) { members.emplace_back(args_[i]); } uint64_t size = 0; - redis::ZSet zset_db(svr->storage, conn->GetNamespace()); + redis::ZSet zset_db(srv->storage, conn->GetNamespace()); auto s = zset_db.Remove(args_[1], members, &size); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -954,8 +954,8 @@ class CommandZRemRangeByRank : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::ZSet zset_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::ZSet zset_db(srv->storage, conn->GetNamespace()); uint64_t cnt = 0; spec_.with_deletion = true; @@ -983,8 +983,8 @@ class CommandZRemRangeByScore : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::ZSet zset_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::ZSet zset_db(srv->storage, conn->GetNamespace()); uint64_t cnt = 0; spec_.with_deletion = true; @@ -1012,8 +1012,8 @@ class CommandZRemRangeByLex : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::ZSet zset_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::ZSet zset_db(srv->storage, conn->GetNamespace()); uint64_t cnt = 0; spec_.with_deletion = true; @@ -1033,9 +1033,9 @@ class CommandZRemRangeByLex : public Commander { class CommandZScore : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { double score = 0; - redis::ZSet zset_db(svr->storage, conn->GetNamespace()); + redis::ZSet zset_db(srv->storage, conn->GetNamespace()); auto s = zset_db.Score(args_[1], args_[2], &score); if (!s.ok() && !s.IsNotFound()) { return {Status::RedisExecErr, s.ToString()}; @@ -1052,13 +1052,13 @@ class CommandZScore : public Commander { class CommandZMScore : public Commander { public: - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { std::vector members; for (size_t i = 2; i < args_.size(); i++) { members.emplace_back(args_[i]); } std::map mscores; - redis::ZSet zset_db(svr->storage, conn->GetNamespace()); + redis::ZSet zset_db(srv->storage, conn->GetNamespace()); auto s = zset_db.MGet(args_[1], members, &mscores); if (!s.ok() && !s.IsNotFound()) { return {Status::RedisExecErr, s.ToString()}; @@ -1122,8 +1122,8 @@ class CommandZUnion : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::ZSet zset_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::ZSet zset_db(srv->storage, conn->GetNamespace()); std::vector member_scores; auto s = zset_db.Union(keys_weights_, aggregate_method_, &member_scores); if (!s.ok()) { @@ -1207,9 +1207,9 @@ class CommandZUnionStore : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { uint64_t size = 0; - redis::ZSet zset_db(svr->storage, conn->GetNamespace()); + redis::ZSet zset_db(srv->storage, conn->GetNamespace()); auto s = zset_db.UnionStore(args_[1], keys_weights_, aggregate_method_, &size); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -1234,9 +1234,9 @@ class CommandZInterStore : public CommandZUnionStore { public: CommandZInterStore() : CommandZUnionStore() {} - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, std::string *output) override { uint64_t size = 0; - redis::ZSet zset_db(svr->storage, conn->GetNamespace()); + redis::ZSet zset_db(srv->storage, conn->GetNamespace()); auto s = zset_db.InterStore(args_[1], keys_weights_, aggregate_method_, &size); if (!s.ok()) { return {Status::RedisExecErr, s.ToString()}; @@ -1256,11 +1256,11 @@ class CommandZScan : public CommandSubkeyScanBase { public: CommandZScan() = default; - Status Execute(Server *svr, Connection *conn, std::string *output) override { - redis::ZSet zset_db(svr->storage, conn->GetNamespace()); + Status Execute(Server *srv, Connection *conn, std::string *output) override { + redis::ZSet zset_db(srv->storage, conn->GetNamespace()); std::vector members; std::vector scores; - auto key_name = svr->GetKeyNameFromCursor(cursor_, CursorType::kTypeZSet); + auto key_name = srv->GetKeyNameFromCursor(cursor_, CursorType::kTypeZSet); auto s = zset_db.Scan(key_, key_name, limit_, prefix_, &members, &scores); if (!s.ok() && !s.IsNotFound()) { return {Status::RedisExecErr, s.ToString()}; @@ -1271,7 +1271,7 @@ class CommandZScan : public CommandSubkeyScanBase { for (const auto &score : scores) { score_strings.emplace_back(util::Float2String(score)); } - *output = GenerateOutput(svr, members, score_strings, CursorType::kTypeZSet); + *output = GenerateOutput(srv, members, score_strings, CursorType::kTypeZSet); return Status::OK(); } }; diff --git a/src/commands/commander.h b/src/commands/commander.h index 48bdeafa1c5..c37d1866e9a 100644 --- a/src/commands/commander.h +++ b/src/commands/commander.h @@ -73,7 +73,7 @@ class Commander { virtual bool IsBlocking() const { return false; } virtual Status Parse() { return Parse(args_); } virtual Status Parse(const std::vector &args) { return Status::OK(); } - virtual Status Execute(Server *svr, Connection *conn, std::string *output) { + virtual Status Execute(Server *srv, Connection *conn, std::string *output) { return {Status::RedisExecErr, "not implemented"}; } diff --git a/src/commands/scan_base.h b/src/commands/scan_base.h index 069a54e9881..0bfb188b481 100644 --- a/src/commands/scan_base.h +++ b/src/commands/scan_base.h @@ -64,10 +64,10 @@ class CommandScanBase : public Commander { } } - std::string GenerateOutput(Server *svr, const std::vector &keys, CursorType cursor_type) const { + std::string GenerateOutput(Server *srv, const std::vector &keys, CursorType cursor_type) const { std::vector list; if (keys.size() == static_cast(limit_)) { - auto end_cursor = svr->GenerateCursorFromKeyName(keys.back(), cursor_type); + auto end_cursor = srv->GenerateCursorFromKeyName(keys.back(), cursor_type); list.emplace_back(redis::BulkString(end_cursor)); } else { list.emplace_back(redis::BulkString("0")); @@ -111,12 +111,12 @@ class CommandSubkeyScanBase : public CommandScanBase { return Commander::Parse(args); } - std::string GenerateOutput(Server *svr, const std::vector &fields, + std::string GenerateOutput(Server *srv, const std::vector &fields, const std::vector &values, CursorType cursor_type) { std::vector list; auto items_count = fields.size(); if (items_count == static_cast(limit_)) { - auto end_cursor = svr->GenerateCursorFromKeyName(fields.back(), cursor_type); + auto end_cursor = srv->GenerateCursorFromKeyName(fields.back(), cursor_type); list.emplace_back(redis::BulkString(end_cursor)); } else { list.emplace_back(redis::BulkString("0")); diff --git a/src/config/config.cc b/src/config/config.cc index adacc345933..62e48abf639 100644 --- a/src/config/config.cc +++ b/src/config/config.cc @@ -828,7 +828,7 @@ void Config::Get(const std::string &key, std::vector *values) const } } -Status Config::Set(Server *svr, std::string key, const std::string &value) { +Status Config::Set(Server *srv, std::string key, const std::string &value) { key = util::ToLower(key); auto iter = fields_.find(key); if (iter == fields_.end() || iter->second->readonly) { @@ -845,7 +845,7 @@ Status Config::Set(Server *svr, std::string key, const std::string &value) { if (!s.IsOK()) return s.Prefixed("failed to set new value"); if (field->callback) { - return field->callback(svr, key, value); + return field->callback(srv, key, value); } return Status::OK(); diff --git a/src/config/config.h b/src/config/config.h index d78ff5e6a8e..5b5b2632d3e 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -221,7 +221,7 @@ struct Config { Status Rewrite(const std::map &tokens); Status Load(const CLIOptions &path); void Get(const std::string &key, std::vector *values) const; - Status Set(Server *svr, std::string key, const std::string &value); + Status Set(Server *srv, std::string key, const std::string &value); void SetMaster(const std::string &host, uint32_t port); void ClearMaster(); bool IsSlave() const { return !master_host.empty(); } diff --git a/src/server/redis_connection.cc b/src/server/redis_connection.cc index c1ef9707d76..a0b4ad4e9ea 100644 --- a/src/server/redis_connection.cc +++ b/src/server/redis_connection.cc @@ -42,7 +42,7 @@ namespace redis { Connection::Connection(bufferevent *bev, Worker *owner) - : need_free_bev_(true), bev_(bev), req_(owner->svr), owner_(owner), svr_(owner->svr) { + : need_free_bev_(true), bev_(bev), req_(owner->srv), owner_(owner), srv_(owner->srv) { int64_t now = util::GetTimeStamp(); create_time_ = now; last_interaction_ = now; @@ -124,7 +124,7 @@ void Connection::OnEvent(bufferevent *bev, int16_t events) { } void Connection::Reply(const std::string &msg) { - owner_->svr->stats.IncrOutbondBytes(msg.size()); + owner_->srv->stats.IncrOutbondBytes(msg.size()); redis::Reply(bufferevent_get_output(bev_), msg); } @@ -183,14 +183,14 @@ void Connection::SubscribeChannel(const std::string &channel) { } subscribe_channels_.emplace_back(channel); - owner_->svr->SubscribeChannel(channel, this); + owner_->srv->SubscribeChannel(channel, this); } void Connection::UnsubscribeChannel(const std::string &channel) { for (auto iter = subscribe_channels_.begin(); iter != subscribe_channels_.end(); iter++) { if (*iter == channel) { subscribe_channels_.erase(iter); - owner_->svr->UnsubscribeChannel(channel, this); + owner_->srv->UnsubscribeChannel(channel, this); return; } } @@ -204,7 +204,7 @@ void Connection::UnsubscribeAll(const UnsubscribeCallback &reply) { int removed = 0; for (const auto &chan : subscribe_channels_) { - owner_->svr->UnsubscribeChannel(chan, this); + owner_->srv->UnsubscribeChannel(chan, this); removed++; if (reply) { reply(chan, static_cast(subscribe_channels_.size() - removed + subscribe_patterns_.size())); @@ -220,14 +220,14 @@ void Connection::PSubscribeChannel(const std::string &pattern) { if (pattern == p) return; } subscribe_patterns_.emplace_back(pattern); - owner_->svr->PSubscribeChannel(pattern, this); + owner_->srv->PSubscribeChannel(pattern, this); } void Connection::PUnsubscribeChannel(const std::string &pattern) { for (auto iter = subscribe_patterns_.begin(); iter != subscribe_patterns_.end(); iter++) { if (*iter == pattern) { subscribe_patterns_.erase(iter); - owner_->svr->PUnsubscribeChannel(pattern, this); + owner_->srv->PUnsubscribeChannel(pattern, this); return; } } @@ -241,7 +241,7 @@ void Connection::PUnsubscribeAll(const UnsubscribeCallback &reply) { int removed = 0; for (const auto &pattern : subscribe_patterns_) { - owner_->svr->PUnsubscribeChannel(pattern, this); + owner_->srv->PUnsubscribeChannel(pattern, this); removed++; if (reply) { reply(pattern, static_cast(subscribe_patterns_.size() - removed + subscribe_channels_.size())); @@ -253,7 +253,7 @@ void Connection::PUnsubscribeAll(const UnsubscribeCallback &reply) { int Connection::PSubscriptionsCount() { return static_cast(subscribe_patterns_.size()); } bool Connection::IsProfilingEnabled(const std::string &cmd) { - auto config = svr_->GetConfig(); + auto config = srv_->GetConfig(); if (config->profiling_sample_ratio == 0) return false; if (!config->profiling_sample_all_commands && @@ -272,7 +272,7 @@ bool Connection::IsProfilingEnabled(const std::string &cmd) { } void Connection::RecordProfilingSampleIfNeed(const std::string &cmd, uint64_t duration) { - int threshold = svr_->GetConfig()->profiling_sample_record_threshold_ms; + int threshold = srv_->GetConfig()->profiling_sample_record_threshold_ms; if (threshold > 0 && static_cast(duration / 1000) < threshold) { rocksdb::SetPerfLevel(rocksdb::PerfLevel::kDisable); return; @@ -288,11 +288,11 @@ void Connection::RecordProfilingSampleIfNeed(const std::string &cmd, uint64_t du entry->duration = duration; entry->iostats_context = std::move(iostats_context); entry->perf_context = std::move(perf_context); - svr_->GetPerfLog()->PushEntry(std::move(entry)); + srv_->GetPerfLog()->PushEntry(std::move(entry)); } void Connection::ExecuteCommands(std::deque *to_process_cmds) { - Config *config = svr_->GetConfig(); + Config *config = srv_->GetConfig(); std::string reply, password = config->requirepass; while (!to_process_cmds->empty()) { @@ -302,7 +302,7 @@ void Connection::ExecuteCommands(std::deque *to_process_cmds) { bool is_multi_exec = IsFlagEnabled(Connection::kMultiExec); if (IsFlagEnabled(redis::Connection::kCloseAfterReply) && !is_multi_exec) break; - auto s = svr_->LookupAndCreateCommand(cmd_tokens.front(), ¤t_cmd); + auto s = srv_->LookupAndCreateCommand(cmd_tokens.front(), ¤t_cmd); if (!s.IsOK()) { if (is_multi_exec) multi_error_ = true; Reply(redis::Error("ERR unknown command " + cmd_tokens.front())); @@ -335,21 +335,21 @@ void Connection::ExecuteCommands(std::deque *to_process_cmds) { if (is_multi_exec && attributes->name != "exec") { // No lock guard, because 'exec' command has acquired 'WorkExclusivityGuard' } else if (cmd_flags & kCmdExclusive) { - exclusivity = svr_->WorkExclusivityGuard(); + exclusivity = srv_->WorkExclusivityGuard(); // When executing lua script commands that have "exclusive" attribute, we need to know current connection, // but we should set current connection after acquiring the WorkExclusivityGuard to make it thread-safe - svr_->SetCurrentConnection(this); + srv_->SetCurrentConnection(this); } else { - concurrency = svr_->WorkConcurrencyGuard(); + concurrency = srv_->WorkConcurrencyGuard(); } if (cmd_flags & kCmdROScript) { // if executing read only lua script commands, set current connection. - svr_->SetCurrentConnection(this); + srv_->SetCurrentConnection(this); } - if (svr_->IsLoading() && !(cmd_flags & kCmdLoading)) { + if (srv_->IsLoading() && !(cmd_flags & kCmdLoading)) { Reply(redis::Error("LOADING kvrocks is restoring the db from backup")); if (is_multi_exec) multi_error_ = true; continue; @@ -379,7 +379,7 @@ void Connection::ExecuteCommands(std::deque *to_process_cmds) { } if (config->cluster_enabled) { - s = svr_->cluster->CanExecByMySelf(attributes, cmd_tokens, this); + s = srv_->cluster->CanExecByMySelf(attributes, cmd_tokens, this); if (!s.IsOK()) { if (is_multi_exec) multi_error_ = true; Reply(redis::Error("ERR " + s.Msg())); @@ -394,13 +394,13 @@ void Connection::ExecuteCommands(std::deque *to_process_cmds) { continue; } - if (config->slave_readonly && svr_->IsSlave() && (cmd_flags & kCmdWrite)) { + if (config->slave_readonly && srv_->IsSlave() && (cmd_flags & kCmdWrite)) { Reply(redis::Error("READONLY You can't write against a read only slave.")); continue; } - if (!config->slave_serve_stale_data && svr_->IsSlave() && cmd_name != "info" && cmd_name != "slaveof" && - svr_->GetReplicationState() != kReplConnected) { + if (!config->slave_serve_stale_data && srv_->IsSlave() && cmd_name != "info" && cmd_name != "slaveof" && + srv_->GetReplicationState() != kReplConnected) { Reply( redis::Error("MASTERDOWN Link with MASTER is down " "and slave-serve-stale-data is set to 'no'.")); @@ -408,18 +408,18 @@ void Connection::ExecuteCommands(std::deque *to_process_cmds) { } SetLastCmd(cmd_name); - svr_->stats.IncrCalls(cmd_name); + srv_->stats.IncrCalls(cmd_name); auto start = std::chrono::high_resolution_clock::now(); bool is_profiling = IsProfilingEnabled(cmd_name); - s = current_cmd->Execute(svr_, this, &reply); + s = current_cmd->Execute(srv_, this, &reply); auto end = std::chrono::high_resolution_clock::now(); uint64_t duration = std::chrono::duration_cast(end - start).count(); if (is_profiling) RecordProfilingSampleIfNeed(cmd_name, duration); - svr_->SlowlogPushEntryIfNeeded(&cmd_tokens, duration, this); - svr_->stats.IncrLatency(static_cast(duration), cmd_name); - svr_->FeedMonitorConns(this, cmd_tokens); + srv_->SlowlogPushEntryIfNeeded(&cmd_tokens, duration, this); + srv_->stats.IncrLatency(static_cast(duration), cmd_name); + srv_->FeedMonitorConns(this, cmd_tokens); // Break the execution loop when occurring the blocking command like BLPOP or BRPOP, // it will suspend the connection and wait for the wakeup signal. @@ -433,7 +433,7 @@ void Connection::ExecuteCommands(std::deque *to_process_cmds) { continue; } - svr_->UpdateWatchedKeysFromArgs(cmd_tokens, *attributes); + srv_->UpdateWatchedKeysFromArgs(cmd_tokens, *attributes); if (!reply.empty()) Reply(reply); reply.clear(); diff --git a/src/server/redis_connection.h b/src/server/redis_connection.h index 8461cc63f2b..acf2a638c9c 100644 --- a/src/server/redis_connection.h +++ b/src/server/redis_connection.h @@ -96,7 +96,7 @@ class Connection : public EvbufCallbackBase { uint32_t GetAnnouncePort() const { return listening_port_ != 0 ? listening_port_ : port_; } std::string GetAnnounceAddr() const { return GetAnnounceIP() + ":" + std::to_string(GetAnnouncePort()); } uint64_t GetClientType() const; - Server *GetServer() { return svr_; } + Server *GetServer() { return srv_; } bool IsAdmin() const { return is_admin_; } void BecomeAdmin() { is_admin_ = true; } @@ -155,7 +155,7 @@ class Connection : public EvbufCallbackBase { std::vector subscribe_channels_; std::vector subscribe_patterns_; - Server *svr_; + Server *srv_; bool in_exec_ = false; bool multi_error_ = false; std::deque multi_cmds_; diff --git a/src/server/redis_request.cc b/src/server/redis_request.cc index 0f186a8bfb3..9d82d00f792 100644 --- a/src/server/redis_request.cc +++ b/src/server/redis_request.cc @@ -67,7 +67,7 @@ Status Request::Tokenize(evbuffer *input) { } pipeline_size++; - svr_->stats.IncrInbondBytes(line.length); + srv_->stats.IncrInbondBytes(line.length); if (line[0] == '*') { auto parse_result = ParseInt(std::string(line.get() + 1, line.length - 1), 10); if (!parse_result) { @@ -100,7 +100,7 @@ Status Request::Tokenize(evbuffer *input) { UniqueEvbufReadln line(input, EVBUFFER_EOL_CRLF_STRICT); if (!line || line.length <= 0) return Status::OK(); - svr_->stats.IncrInbondBytes(line.length); + srv_->stats.IncrInbondBytes(line.length); if (line[0] != '$') { return {Status::NotOK, "Protocol error: expected '$'"}; } @@ -124,7 +124,7 @@ Status Request::Tokenize(evbuffer *input) { char *data = reinterpret_cast(evbuffer_pullup(input, static_cast(bulk_len_ + 2))); tokens_.emplace_back(data, bulk_len_); evbuffer_drain(input, bulk_len_ + 2); - svr_->stats.IncrInbondBytes(bulk_len_ + 2); + srv_->stats.IncrInbondBytes(bulk_len_ + 2); --multi_bulk_len_; if (multi_bulk_len_ == 0) { state_ = ArrayLen; diff --git a/src/server/redis_request.h b/src/server/redis_request.h index 8d4c8921c52..0734cd9e079 100644 --- a/src/server/redis_request.h +++ b/src/server/redis_request.h @@ -38,7 +38,7 @@ class Connection; class Request { public: - explicit Request(Server *svr) : svr_(svr) {} + explicit Request(Server *srv) : srv_(srv) {} ~Request() = default; // Not copyable @@ -60,7 +60,7 @@ class Request { CommandTokens tokens_; std::deque commands_; - Server *svr_; + Server *srv_; }; } // namespace redis diff --git a/src/server/worker.cc b/src/server/worker.cc index 7515a2f1c0a..94c208f9ad2 100644 --- a/src/server/worker.cc +++ b/src/server/worker.cc @@ -52,7 +52,7 @@ #include "server.h" #include "storage/scripting.h" -Worker::Worker(Server *svr, Config *config) : svr(svr), base_(event_base_new()) { +Worker::Worker(Server *srv, Config *config) : srv(srv), base_(event_base_new()) { if (!base_) throw std::runtime_error{"event base failed to be created"}; timer_.reset(NewEvent(base_, -1, EV_PERSIST)); @@ -72,7 +72,7 @@ Worker::Worker(Server *svr, Config *config) : svr(svr), base_(event_base_new()) LOG(INFO) << "[worker] Listening on: " << bind << ":" << *port; } } - lua_ = lua::CreateState(svr, true); + lua_ = lua::CreateState(srv, true); } Worker::~Worker() { @@ -101,7 +101,7 @@ Worker::~Worker() { } void Worker::TimerCB(int, int16_t events) { - auto config = svr->GetConfig(); + auto config = srv->GetConfig(); if (config->timeout == 0) return; KickoutIdleClients(config->timeout); } @@ -131,8 +131,8 @@ void Worker::newTCPConnection(evconnlistener *listener, evutil_socket_t fd, sock bufferevent *bev = nullptr; ssl_st *ssl = nullptr; #ifdef ENABLE_OPENSSL - if (uint32_t(local_port) == svr->GetConfig()->tls_port) { - ssl = SSL_new(svr->ssl_ctx.get()); + if (uint32_t(local_port) == srv->GetConfig()->tls_port) { + ssl = SSL_new(srv->ssl_ctx.get()); if (!ssl) { LOG(ERROR) << "Failed to construct SSL structure for new connection: " << SSLErrors{}; evutil_closesocket(fd); @@ -157,7 +157,7 @@ void Worker::newTCPConnection(evconnlistener *listener, evutil_socket_t fd, sock return; } #ifdef ENABLE_OPENSSL - if (uint32_t(local_port) == svr->GetConfig()->tls_port) { + if (uint32_t(local_port) == srv->GetConfig()->tls_port) { bufferevent_openssl_set_allow_dirty_shutdown(bev, 1); } #endif @@ -187,7 +187,7 @@ void Worker::newTCPConnection(evconnlistener *listener, evutil_socket_t fd, sock } void Worker::newUnixSocketConnection(evconnlistener *listener, evutil_socket_t fd, sockaddr *address, int socklen) { - DLOG(INFO) << "[worker] New connection: fd=" << fd << " from unixsocket: " << svr->GetConfig()->unixsocket + DLOG(INFO) << "[worker] New connection: fd=" << fd << " from unixsocket: " << srv->GetConfig()->unixsocket << " thread #" << tid_; event_base *base = evconnlistener_get_base(listener); auto ev_thread_safe_flags = @@ -209,7 +209,7 @@ void Worker::newUnixSocketConnection(evconnlistener *listener, evutil_socket_t f return; } - conn->SetAddr(svr->GetConfig()->unixsocket, 0); + conn->SetAddr(srv->GetConfig()->unixsocket, 0); if (rate_limit_group_) { bufferevent_add_to_rate_limit_group(bev, rate_limit_group_); } @@ -309,14 +309,14 @@ Status Worker::AddConnection(redis::Connection *c) { return {Status::NotOK, "connection was exists"}; } - int max_clients = svr->GetConfig()->maxclients; - if (svr->IncrClientNum() >= max_clients) { - svr->DecrClientNum(); + int max_clients = srv->GetConfig()->maxclients; + if (srv->IncrClientNum() >= max_clients) { + srv->DecrClientNum(); return {Status::NotOK, "max number of clients reached"}; } conns_.emplace(c->GetFD(), c); - uint64_t id = svr->GetClientID(); + uint64_t id = srv->GetClientID(); c->SetID(id); return Status::OK(); @@ -330,15 +330,15 @@ redis::Connection *Worker::removeConnection(int fd) { if (iter != conns_.end()) { conn = iter->second; conns_.erase(iter); - svr->DecrClientNum(); + srv->DecrClientNum(); } iter = monitor_conns_.find(fd); if (iter != monitor_conns_.end()) { conn = iter->second; monitor_conns_.erase(iter); - svr->DecrClientNum(); - svr->DecrMonitorClientNum(); + srv->DecrClientNum(); + srv->DecrMonitorClientNum(); } return conn; @@ -387,7 +387,7 @@ void Worker::FreeConnection(redis::Connection *conn) { if (!conn) return; removeConnection(conn->GetFD()); - svr->ResetWatchedKeys(conn); + srv->ResetWatchedKeys(conn); if (rate_limit_group_) { bufferevent_remove_from_rate_limit_group(conn->GetBufferEvent()); } @@ -403,15 +403,15 @@ void Worker::FreeConnectionByID(int fd, uint64_t id) { } delete iter->second; conns_.erase(iter); - svr->DecrClientNum(); + srv->DecrClientNum(); } iter = monitor_conns_.find(fd); if (iter != monitor_conns_.end() && iter->second->GetID() == id) { delete iter->second; monitor_conns_.erase(iter); - svr->DecrClientNum(); - svr->DecrMonitorClientNum(); + srv->DecrClientNum(); + srv->DecrMonitorClientNum(); } } @@ -445,7 +445,7 @@ void Worker::BecomeMonitorConn(redis::Connection *conn) { conns_.erase(conn->GetFD()); monitor_conns_[conn->GetFD()] = conn; } - svr->IncrMonitorClientNum(); + srv->IncrMonitorClientNum(); conn->EnableFlag(redis::Connection::kMonitor); } diff --git a/src/server/worker.h b/src/server/worker.h index a9fe7dd2a7f..96a6c7cddcb 100644 --- a/src/server/worker.h +++ b/src/server/worker.h @@ -44,7 +44,7 @@ class Server; class Worker : EventCallbackBase, EvconnlistenerBase { public: - Worker(Server *svr, Config *config); + Worker(Server *srv, Config *config); ~Worker(); Worker(const Worker &) = delete; Worker(Worker &&) = delete; @@ -74,7 +74,7 @@ class Worker : EventCallbackBase, EvconnlistenerBase { lua_State *Lua() { return lua_; } std::map GetConnections() const { return conns_; } - Server *svr; + Server *srv; private: Status listenTCP(const std::string &host, uint32_t port, int backlog); diff --git a/src/storage/scripting.cc b/src/storage/scripting.cc index 54aac26de87..3f1bcdde1fe 100644 --- a/src/storage/scripting.cc +++ b/src/storage/scripting.cc @@ -56,13 +56,13 @@ enum { namespace lua { -lua_State *CreateState(Server *svr, bool read_only) { +lua_State *CreateState(Server *srv, bool read_only) { lua_State *lua = lua_open(); LoadLibraries(lua); RemoveUnsupportedFunctions(lua); LoadFuncs(lua, read_only); - lua_pushlightuserdata(lua, svr); + lua_pushlightuserdata(lua, srv); lua_setglobal(lua, REDIS_LUA_SERVER_PTR); EnableGlobalsProtection(lua); diff --git a/src/storage/scripting.h b/src/storage/scripting.h index 4c72f930353..9e8c45f23d3 100644 --- a/src/storage/scripting.h +++ b/src/storage/scripting.h @@ -36,7 +36,7 @@ inline constexpr const char REDIS_FUNCTION_LIBRARIES[] = "REDIS_FUNCTION_LIBRARI namespace lua { -lua_State *CreateState(Server *svr, bool read_only = false); +lua_State *CreateState(Server *srv, bool read_only = false); void DestroyState(lua_State *lua); Server *GetServer(lua_State *lua); diff --git a/tests/gocase/unit/expire/expire_test.go b/tests/gocase/unit/expire/expire_test.go index 9f56d8bc525..9986afaf3ec 100644 --- a/tests/gocase/unit/expire/expire_test.go +++ b/tests/gocase/unit/expire/expire_test.go @@ -30,11 +30,11 @@ import ( ) func TestExpire(t *testing.T) { - svr := util.StartServer(t, map[string]string{}) - defer svr.Close() + srv := util.StartServer(t, map[string]string{}) + defer srv.Close() ctx := context.Background() - rdb := svr.NewClient() + rdb := srv.NewClient() defer func() { require.NoError(t, rdb.Close()) }() t.Run("EXPIRE - set timeouts multiple times", func(t *testing.T) {