Skip to content

Commit

Permalink
fix cache layer crash and data confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
lqxhub committed Dec 17, 2023
1 parent ba0d5ce commit 77cbc2f
Show file tree
Hide file tree
Showing 17 changed files with 580 additions and 497 deletions.
68 changes: 34 additions & 34 deletions include/pika_admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
class SlaveofCmd : public Cmd {
public:
SlaveofCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
SlaveofCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand All @@ -45,7 +45,7 @@ class SlaveofCmd : public Cmd {

class DbSlaveofCmd : public Cmd {
public:
DbSlaveofCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
DbSlaveofCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand All @@ -69,7 +69,7 @@ class DbSlaveofCmd : public Cmd {

class AuthCmd : public Cmd {
public:
AuthCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
AuthCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand All @@ -82,7 +82,7 @@ class AuthCmd : public Cmd {

class BgsaveCmd : public Cmd {
public:
BgsaveCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
BgsaveCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand All @@ -96,7 +96,7 @@ class BgsaveCmd : public Cmd {

class CompactCmd : public Cmd {
public:
CompactCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
CompactCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand All @@ -115,7 +115,7 @@ class CompactCmd : public Cmd {
// we can use pika/tests/helpers/test_queue.py to test this command
class CompactRangeCmd : public Cmd {
public:
CompactRangeCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
CompactRangeCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand All @@ -137,7 +137,7 @@ class CompactRangeCmd : public Cmd {

class PurgelogstoCmd : public Cmd {
public:
PurgelogstoCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
PurgelogstoCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand All @@ -151,7 +151,7 @@ class PurgelogstoCmd : public Cmd {

class PingCmd : public Cmd {
public:
PingCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
PingCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand All @@ -163,7 +163,7 @@ class PingCmd : public Cmd {

class SelectCmd : public Cmd {
public:
SelectCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
SelectCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand All @@ -178,7 +178,7 @@ class SelectCmd : public Cmd {

class FlushallCmd : public Cmd {
public:
FlushallCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
FlushallCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void DoThroughDB(std::shared_ptr<Slot> slot = nullptr) override;
void DoUpdateCache(std::shared_ptr<Slot> slot = nullptr) override;
Expand All @@ -195,7 +195,7 @@ class FlushallCmd : public Cmd {

class FlushdbCmd : public Cmd {
public:
FlushdbCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
FlushdbCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void DoThroughDB(std::shared_ptr<Slot> slot = nullptr) override;
void DoUpdateCache(std::shared_ptr<Slot> slot = nullptr) override;
Expand All @@ -215,7 +215,7 @@ class FlushdbCmd : public Cmd {

class ClientCmd : public Cmd {
public:
ClientCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
ClientCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
const static std::string CLIENT_LIST_S;
const static std::string CLIENT_KILL_S;
Expand Down Expand Up @@ -249,7 +249,7 @@ class InfoCmd : public Cmd {
kInfoCache
};

InfoCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
InfoCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand Down Expand Up @@ -305,7 +305,7 @@ class InfoCmd : public Cmd {

class ShutdownCmd : public Cmd {
public:
ShutdownCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
ShutdownCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand All @@ -317,7 +317,7 @@ class ShutdownCmd : public Cmd {

class ConfigCmd : public Cmd {
public:
ConfigCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
ConfigCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand All @@ -336,7 +336,7 @@ class ConfigCmd : public Cmd {

class MonitorCmd : public Cmd {
public:
MonitorCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
MonitorCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand All @@ -348,7 +348,7 @@ class MonitorCmd : public Cmd {

class DbsizeCmd : public Cmd {
public:
DbsizeCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
DbsizeCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand All @@ -360,7 +360,7 @@ class DbsizeCmd : public Cmd {

class TimeCmd : public Cmd {
public:
TimeCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
TimeCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand All @@ -372,7 +372,7 @@ class TimeCmd : public Cmd {

class LastsaveCmd : public Cmd {
public:
LastsaveCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
LastsaveCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand All @@ -384,7 +384,7 @@ class LastsaveCmd : public Cmd {

class DelbackupCmd : public Cmd {
public:
DelbackupCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
DelbackupCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand All @@ -396,7 +396,7 @@ class DelbackupCmd : public Cmd {

class EchoCmd : public Cmd {
public:
EchoCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
EchoCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Merge() override {};
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
Expand All @@ -409,7 +409,7 @@ class EchoCmd : public Cmd {

class ScandbCmd : public Cmd {
public:
ScandbCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
ScandbCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand All @@ -424,7 +424,7 @@ class ScandbCmd : public Cmd {
class SlowlogCmd : public Cmd {
public:
enum SlowlogCondition { kGET, kLEN, kRESET };
SlowlogCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
SlowlogCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand All @@ -442,7 +442,7 @@ class SlowlogCmd : public Cmd {

class PaddingCmd : public Cmd {
public:
PaddingCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
PaddingCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand All @@ -455,7 +455,7 @@ class PaddingCmd : public Cmd {

class PKPatternMatchDelCmd : public Cmd {
public:
PKPatternMatchDelCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
PKPatternMatchDelCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand All @@ -470,7 +470,7 @@ class PKPatternMatchDelCmd : public Cmd {
class DummyCmd : public Cmd {
public:
DummyCmd() : Cmd("", 0, 0) {}
DummyCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
DummyCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand All @@ -482,7 +482,7 @@ class DummyCmd : public Cmd {

class QuitCmd : public Cmd {
public:
QuitCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
QuitCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand All @@ -494,7 +494,7 @@ class QuitCmd : public Cmd {

class HelloCmd : public Cmd {
public:
HelloCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
HelloCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand All @@ -506,7 +506,7 @@ class HelloCmd : public Cmd {

class DiskRecoveryCmd : public Cmd {
public:
DiskRecoveryCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
DiskRecoveryCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand All @@ -519,7 +519,7 @@ class DiskRecoveryCmd : public Cmd {

class ClearReplicationIDCmd : public Cmd {
public:
ClearReplicationIDCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
ClearReplicationIDCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand All @@ -532,7 +532,7 @@ class ClearReplicationIDCmd : public Cmd {

class DisableWalCmd : public Cmd {
public:
DisableWalCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
DisableWalCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand All @@ -545,7 +545,7 @@ class DisableWalCmd : public Cmd {
class CacheCmd : public Cmd {
public:
enum CacheCondition {kCLEAR_DB, kCLEAR_HITRATIO, kDEL_KEYS, kRANDOM_KEY};
CacheCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
CacheCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override{};
void Merge() override{};
Expand All @@ -563,7 +563,7 @@ class CacheCmd : public Cmd {

class ClearCacheCmd : public Cmd {
public:
ClearCacheCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
ClearCacheCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override{};
void Merge() override{};
Expand All @@ -576,7 +576,7 @@ class ClearCacheCmd : public Cmd {
#ifdef WITH_COMMAND_DOCS
class CommandCmd : public Cmd {
public:
CommandCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
CommandCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {}
void Do(std::shared_ptr<Slot> slot = nullptr) override;
void Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) override {};
void Merge() override {};
Expand Down
10 changes: 5 additions & 5 deletions include/pika_bit.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
class BitGetCmd : public Cmd {
public:
BitGetCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){};
BitGetCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag){};
std::vector<std::string> current_key() const override {
std::vector<std::string> res;
res.push_back(key_);
Expand All @@ -44,7 +44,7 @@ class BitGetCmd : public Cmd {

class BitSetCmd : public Cmd {
public:
BitSetCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){};
BitSetCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag){};
std::vector<std::string> current_key() const override {
std::vector<std::string> res;
res.push_back(key_);
Expand Down Expand Up @@ -72,7 +72,7 @@ class BitSetCmd : public Cmd {

class BitCountCmd : public Cmd {
public:
BitCountCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){};
BitCountCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag){};
std::vector<std::string> current_key() const override {
std::vector<std::string> res;
res.push_back(key_);
Expand Down Expand Up @@ -103,7 +103,7 @@ class BitCountCmd : public Cmd {

class BitPosCmd : public Cmd {
public:
BitPosCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){};
BitPosCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag){};
std::vector<std::string> current_key() const override {
std::vector<std::string> res;
res.push_back(key_);
Expand Down Expand Up @@ -138,7 +138,7 @@ class BitPosCmd : public Cmd {

class BitOpCmd : public Cmd {
public:
BitOpCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {
BitOpCmd(const std::string& name, int arity, uint32_t flag) : Cmd(name, arity, flag) {
set_cmd_ = std::make_shared<SetCmd>(kCmdNameSet, -3, kCmdFlagsWrite | kCmdFlagsSingleSlot | kCmdFlagsKv);
};
BitOpCmd(const BitOpCmd& other)
Expand Down
6 changes: 4 additions & 2 deletions include/pika_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ class PikaCache : public pstd::noncopyable, public std::enable_shared_from_this<
rocksdb::Status ZCard(std::string &key, uint32_t *len, const std::shared_ptr<Slot> &slot);
rocksdb::Status ZCount(std::string &key, std::string &min, std::string &max, uint64_t *len, ZCountCmd *cmd);
rocksdb::Status ZIncrby(std::string &key, std::string &member, double increment);
rocksdb::Status ZIncrbyIfKeyExist(std::string &key, std::string &member, double increment, ZIncrbyCmd *cmd);
rocksdb::Status ZIncrbyIfKeyExist(std::string &key, std::string &member, double increment, ZIncrbyCmd *cmd,
const std::shared_ptr<Slot> &slot);
rocksdb::Status ZRange(std::string &key, int64_t start, int64_t stop, std::vector<storage::ScoreMember> *score_members,
const std::shared_ptr<Slot> &slot);
rocksdb::Status ZRangebyscore(std::string &key, std::string &min, std::string &max,
Expand All @@ -160,7 +161,8 @@ class PikaCache : public pstd::noncopyable, public std::enable_shared_from_this<
rocksdb::Status ZRevrange(std::string &key, int64_t start, int64_t stop, std::vector<storage::ScoreMember> *score_members,
const std::shared_ptr<Slot> &slot);
rocksdb::Status ZRevrangebyscore(std::string &key, std::string &min, std::string &max,
std::vector<storage::ScoreMember> *score_members, ZRevrangebyscoreCmd *cmd);
std::vector<storage::ScoreMember> *score_members, ZRevrangebyscoreCmd *cmd,
const std::shared_ptr<Slot> &slot);
rocksdb::Status ZRevrangebylex(std::string &key, std::string &min, std::string &max, std::vector<std::string> *members,
const std::shared_ptr<Slot> &slot);
rocksdb::Status ZRevrank(std::string &key, std::string &member, int64_t *rank, const std::shared_ptr<Slot> &slot);
Expand Down
Loading

0 comments on commit 77cbc2f

Please sign in to comment.