diff --git a/src/base_cmd.cc b/src/base_cmd.cc old mode 100755 new mode 100644 index f576899b1..dd990ba94 --- a/src/base_cmd.cc +++ b/src/base_cmd.cc @@ -110,8 +110,8 @@ void BaseCmd::ServeAndUnblockConns(PClient* client) { auto& key_to_conns = g_pikiwidb->GetMapFromKeyToConns(); auto it = key_to_conns.find(key); if (it == key_to_conns.end()) { - // no client is waitting for this key - return; + // no client is waitting for this key + return; } read_latch.unlock(); diff --git a/src/base_cmd.h b/src/base_cmd.h old mode 100755 new mode 100644 index f34fa7a28..6c19eb850 --- a/src/base_cmd.h +++ b/src/base_cmd.h @@ -318,7 +318,7 @@ class BaseCmd : public std::enable_shared_from_this { uint32_t GetCmdID() const; - void ServeAndUnblockConns(PClient* client); + void ServeAndUnblockConns(PClient* client); protected: // Execute a specific command @@ -370,10 +370,9 @@ class BaseCmdGroup : public BaseCmd { class BlockedConnNode { public: virtual ~BlockedConnNode() {} - BlockedConnNode(int64_t expire_time, PClient* client) - : expire_time_(expire_time), client_(client) {} + BlockedConnNode(int64_t expire_time, PClient* client) : expire_time_(expire_time), client_(client) {} bool IsExpired(); - PClient* GetBlockedClient() {return client_;} + PClient* GetBlockedClient() { return client_; } private: int64_t expire_time_; diff --git a/src/cmd_list.cc b/src/cmd_list.cc old mode 100755 new mode 100644 index 541319cf9..4936d3b6d --- a/src/cmd_list.cc +++ b/src/cmd_list.cc @@ -6,9 +6,9 @@ */ #include "cmd_list.h" +#include "pikiwidb.h" #include "pstd_string.h" #include "store.h" -#include "pikiwidb.h" namespace pikiwidb { LPushCmd::LPushCmd(const std::string& name, int16_t arity) @@ -141,7 +141,7 @@ bool BLPopCmd::DoInitial(PClient* client) { constexpr int64_t seconds_of_ten_years = 10 * 365 * 24 * 3600; if (timeout < 0 || timeout > seconds_of_ten_years) { client->SetRes(CmdRes::kErrOther, - "timeout can't be a negative value and can't exceed the number of seconds in 10 years"); + "timeout can't be a negative value and can't exceed the number of seconds in 10 years"); return false; } @@ -161,13 +161,13 @@ void BLPopCmd::DoCmd(PClient* client) { client->AppendString(client->Key()); client->AppendString(elements[0]); return; - } else if (s.IsNotFound()){ + } else if (s.IsNotFound()) { BlockThisClientToWaitLRPush(elements, expire_time_, client); } else { client->SetRes(CmdRes::kErrOther, s.ToString()); return; } -} +} void BLPopCmd::BlockThisClientToWaitLRPush(std::vector& keys, int64_t expire_time, PClient* client) { std::unique_lock latch(g_pikiwidb->GetBlockMtx()); diff --git a/src/pikiwidb.cc b/src/pikiwidb.cc old mode 100755 new mode 100644 index 7e3874b68..c19cf3ac0 --- a/src/pikiwidb.cc +++ b/src/pikiwidb.cc @@ -188,8 +188,8 @@ bool PikiwiDB::Init() { event_server_->InitTimer(10); - //auto task = std::bind(&PikiwiDB::ScanExpiredBlockedConnsOfBlrpop, this); - //loop->ScheduleRepeatedly(250, task); + // auto task = std::bind(&PikiwiDB::ScanExpiredBlockedConnsOfBlrpop, this); + // loop->ScheduleRepeatedly(250, task); auto timerTask = std::make_shared(1000); timerTask->SetCallback([]() { PREPL.Cron(); }); diff --git a/src/pikiwidb.h b/src/pikiwidb.h old mode 100755 new mode 100644 index a77d230d1..2080a1b4d --- a/src/pikiwidb.h +++ b/src/pikiwidb.h @@ -50,7 +50,8 @@ class PikiwiDB final { event_server_->SendPacket(client, std::move(msg)); } - std::unordered_map>, pikiwidb::BlockKeyHash>& GetMapFromKeyToConns() { + std::unordered_map>, pikiwidb::BlockKeyHash>& + GetMapFromKeyToConns() { return key_to_blocked_conns_; } @@ -58,7 +59,6 @@ class PikiwiDB final { void ScanExpiredBlockedConnsOfBlrpop(); - inline void SendPacket2Client(const std::shared_ptr& client, std::string&& msg) { event_server_->SendPacket(client, std::move(msg)); } @@ -84,7 +84,7 @@ class PikiwiDB final { private: pikiwidb::CmdThreadPool cmd_threads_; - + /* * Blpop/BRpop used */ @@ -92,7 +92,8 @@ class PikiwiDB final { * mapping from key to a list that stored the nodes of client-connections that * were blocked by command blpop/brpop with key. */ - std::unordered_map>, pikiwidb::BlockKeyHash> key_to_blocked_conns_; + std::unordered_map>, pikiwidb::BlockKeyHash> + key_to_blocked_conns_; /* * latch of above map.