Skip to content

Commit

Permalink
Apply slash::lock MultiRecordLock in pika (OpenAtomFoundation#700)
Browse files Browse the repository at this point in the history
Commands which need to lock multiple keys may have great performance improvement.
  • Loading branch information
whoiami committed Aug 6, 2019
1 parent 84c8470 commit 9f89d27
Show file tree
Hide file tree
Showing 14 changed files with 489 additions and 111 deletions.
24 changes: 20 additions & 4 deletions include/pika_bit.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ class BitGetCmd : public Cmd {
public:
BitGetCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag) {};
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr) override;
private:
std::string key_;
Expand All @@ -34,7 +38,11 @@ class BitSetCmd : public Cmd {
public:
BitSetCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag) {};
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr) override;
private:
std::string key_;
Expand All @@ -52,7 +60,11 @@ class BitCountCmd : public Cmd {
public:
BitCountCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag) {};
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr) override;
private:
std::string key_;
Expand All @@ -72,7 +84,11 @@ class BitPosCmd : public Cmd {
public:
BitPosCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag) {};
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr) override;
private:
std::string key_;
Expand Down
2 changes: 1 addition & 1 deletion include/pika_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ class Cmd {
: name_(name), arity_(arity), flag_(flag) {}
virtual ~Cmd() {}

virtual std::string current_key() const;
virtual std::vector<std::string> current_key() const;
virtual void Execute();
virtual void ProcessFlushDBCmd();
virtual void ProcessFlushAllCmd();
Expand Down
24 changes: 20 additions & 4 deletions include/pika_geo.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ class GeoAddCmd : public Cmd {
public:
GeoAddCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag) {}
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
private:
std::string key_;
Expand All @@ -64,7 +68,11 @@ class GeoPosCmd : public Cmd {
public:
GeoPosCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag) {}
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
private:
std::string key_;
Expand All @@ -76,7 +84,11 @@ class GeoDistCmd : public Cmd {
public:
GeoDistCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag) {}
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
private:
std::string key_, first_pos_, second_pos_, unit_;
Expand All @@ -87,7 +99,11 @@ class GeoHashCmd : public Cmd {
public:
GeoHashCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag) {}
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
private:
std::string key_;
Expand Down
108 changes: 90 additions & 18 deletions include/pika_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ class HDelCmd : public Cmd {
public:
HDelCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag) {}
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
private:
std::string key_;
Expand All @@ -30,7 +34,11 @@ class HGetCmd : public Cmd {
public:
HGetCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag) {}
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
private:
std::string key_, field_;
Expand All @@ -41,7 +49,11 @@ class HGetallCmd : public Cmd {
public:
HGetallCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag) {}
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
private:
std::string key_;
Expand All @@ -52,7 +64,11 @@ class HSetCmd : public Cmd {
public:
HSetCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag) {}
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
private:
std::string key_, field_, value_;
Expand All @@ -63,7 +79,11 @@ class HExistsCmd : public Cmd {
public:
HExistsCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag) {}
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
private:
std::string key_, field_;
Expand All @@ -74,7 +94,11 @@ class HIncrbyCmd : public Cmd {
public:
HIncrbyCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag) {}
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
private:
std::string key_, field_;
Expand All @@ -86,7 +110,11 @@ class HIncrbyfloatCmd : public Cmd {
public:
HIncrbyfloatCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag) {}
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
private:
std::string key_, field_, by_;
Expand All @@ -97,7 +125,11 @@ class HKeysCmd : public Cmd {
public:
HKeysCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag) {}
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
private:
std::string key_;
Expand All @@ -108,7 +140,11 @@ class HLenCmd : public Cmd {
public:
HLenCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag) {}
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
private:
std::string key_;
Expand All @@ -119,7 +155,11 @@ class HMgetCmd : public Cmd {
public:
HMgetCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag) {}
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
private:
std::string key_;
Expand All @@ -131,7 +171,11 @@ class HMsetCmd : public Cmd {
public:
HMsetCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag) {}
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
private:
std::string key_;
Expand All @@ -143,7 +187,11 @@ class HSetnxCmd : public Cmd {
public:
HSetnxCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag) {}
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
private:
std::string key_, field_, value_;
Expand All @@ -154,7 +202,11 @@ class HStrlenCmd : public Cmd {
public:
HStrlenCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag) {}
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
private:
std::string key_, field_;
Expand All @@ -165,7 +217,11 @@ class HValsCmd : public Cmd {
public:
HValsCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag) {}
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
private:
std::string key_, field_;
Expand All @@ -176,7 +232,11 @@ class HScanCmd : public Cmd {
public:
HScanCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag), pattern_("*"), count_(10) {}
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
private:
std::string key_, pattern_;
Expand All @@ -192,7 +252,11 @@ class HScanxCmd : public Cmd {
public:
HScanxCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag), pattern_("*"), count_(10) {}
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
private:
std::string key_, start_field_, pattern_;
Expand All @@ -208,7 +272,11 @@ class PKHScanRangeCmd : public Cmd {
public:
PKHScanRangeCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag), pattern_("*"), limit_(10) {}
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
private:
std::string key_;
Expand All @@ -227,7 +295,11 @@ class PKHRScanRangeCmd : public Cmd {
public:
PKHRScanRangeCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag), pattern_("*"), limit_(10) {}
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
private:
std::string key_;
Expand Down
6 changes: 5 additions & 1 deletion include/pika_hyperloglog.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ class PfAddCmd : public Cmd {
public:
PfAddCmd(const std::string& name, int arity, uint16_t flag)
: Cmd(name, arity, flag) {}
virtual std::string current_key() const { return key_; }
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
private:
std::string key_;
Expand Down
Loading

0 comments on commit 9f89d27

Please sign in to comment.