Skip to content

Commit

Permalink
fix: PkPatternMatchDel inconsistent between rediscache and db
Browse files Browse the repository at this point in the history
  • Loading branch information
haiyang426 authored and brother-jin committed Aug 1, 2024
1 parent e729b0c commit fa414f1
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 9 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,6 @@ ExternalProject_Add(rediscache
set(REDISCACHE_INCLUDE_DIR ${INSTALL_INCLUDEDIR})
set(REDISCACHE_LIBRARY ${INSTALL_LIBDIR}/librediscache.a)


option(USE_PIKA_TOOLS "compile pika-tools" OFF)
if (USE_PIKA_TOOLS)
ExternalProject_Add(hiredis
Expand Down
5 changes: 1 addition & 4 deletions conf/pika.conf
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,9 @@ slave-priority : 100
# The disable_auto_compactions option is [true | false]
disable_auto_compactions : false

<<<<<<< HEAD
=======
# Rocksdb max_subcompactions, increasing this value can accelerate the exec speed of a single compaction task
# it's recommended to increase it's value if large compaction is found in you instance
max-subcompactions : 1
>>>>>>> f95f867c (fix: Revised RocksDB-Related Parameters in Pika (#2728))
# The minimum disk usage ratio for checking resume.
# If the disk usage ratio is lower than min-check-resume-ratio, it will not check resume, only higher will check resume.
# Its default value is 0.7.
Expand Down Expand Up @@ -496,7 +493,7 @@ default-slot-num : 1024
# [USED BY SLAVE] The transmitting speed(Rsync Rate) In full replication is controlled BY SLAVE NODE, You should modify the throttle-bytes-per-second in slave's pika.conf if you wanna change the rsync rate limit.
# [Dynamic Change Supported] send command 'config set throttle-bytes-per-second new_value' to SLAVE NODE can dynamically adjust rsync rate during full sync(use config rewrite can persist the changes).
throttle-bytes-per-second : 207200000
<<<<<<< HEAD

# Rsync timeout in full sync stage[Default value is 1000 ms], unnecessary retries will happen if this value is too small.
# [Dynamic Change Supported] similar to throttle-bytes-per-second, rsync-timeout-ms can be dynamically changed by configset command
# [USED BY SLAVE] Similar to throttle-bytes-per-second, you should change rsync-timeout-ms's value in slave's conf file if it is needed to adjust.
Expand Down
5 changes: 5 additions & 0 deletions include/pika_admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,13 +479,18 @@ class PKPatternMatchDelCmd : public Cmd {
PKPatternMatchDelCmd(const std::string& name, int arity, uint32_t flag)
: Cmd(name, arity, flag, static_cast<uint32_t>(AclCategory::ADMIN)) {}
void Do() override;
void DoThroughDB() override;
void DoUpdateCache() override;
void Split(const HintKeys& hint_keys) override {};
void Merge() override {};
Cmd* Clone() override { return new PKPatternMatchDelCmd(*this); }
void DoBinlog() override;

private:
storage::DataType type_ = storage::kAll;
std::vector<std::string> remove_keys_;
std::string pattern_;
int64_t max_count_;
void DoInitial() override;
};

Expand Down
28 changes: 28 additions & 0 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3110,6 +3110,34 @@ void PKPatternMatchDelCmd::Do() {
}
}

void PKPatternMatchDelCmd::DoThroughDB() {
Do();
}

void PKPatternMatchDelCmd::DoUpdateCache() {
if(s_.ok()) {
std::vector<std::string> v;
for (auto key : remove_keys_) {
v.emplace_back(PCacheKeyPrefixK + key);
v.emplace_back(PCacheKeyPrefixL + key);
v.emplace_back(PCacheKeyPrefixZ + key);
v.emplace_back(PCacheKeyPrefixS + key);
v.emplace_back(PCacheKeyPrefixH + key);
}
db_->cache()->Del(v);
}
}

void PKPatternMatchDelCmd::DoBinlog() {
std::string opt = "del";
for(auto& key: remove_keys_) {
argv_.clear();
argv_.emplace_back(opt);
argv_.emplace_back(key);
Cmd::DoBinlog();
}
}

void DummyCmd::DoInitial() {}

void DummyCmd::Do() {}
Expand Down
2 changes: 1 addition & 1 deletion src/pika_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void InitCmdTable(CmdTable* cmd_table) {
cmd_table->insert(std::pair<std::string, std::unique_ptr<Cmd>>(kCmdNamePadding, std::move(paddingptr)));

std::unique_ptr<Cmd> pkpatternmatchdelptr =
std::make_unique<PKPatternMatchDelCmd>(kCmdNamePKPatternMatchDel, 3, kCmdFlagsWrite | kCmdFlagsAdmin);
std::make_unique<PKPatternMatchDelCmd>(kCmdNamePKPatternMatchDel, -2, kCmdFlagsWrite | kCmdFlagsAdmin);
cmd_table->insert(
std::pair<std::string, std::unique_ptr<Cmd>>(kCmdNamePKPatternMatchDel, std::move(pkpatternmatchdelptr)));
std::unique_ptr<Cmd> dummyptr = std::make_unique<DummyCmd>(kCmdDummy, 0, kCmdFlagsWrite);
Expand Down
2 changes: 1 addition & 1 deletion src/storage/src/redis.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Redis {
virtual Status Expireat(const Slice& key, int32_t timestamp) = 0;
virtual Status Persist(const Slice& key) = 0;
virtual Status TTL(const Slice& key, int64_t* timestamp) = 0;

Status PKPatternMatchDelWithRemoveKeys(const std::string& pattern, int64_t* ret, std::vector<std::string>* remove_keys, const int64_t& max_count);
Status SetMaxCacheStatisticKeys(size_t max_cache_statistic_keys);
Status SetSmallCompactionThreshold(uint64_t small_compaction_threshold);
Status SetSmallCompactionDurationThreshold(uint64_t small_compaction_duration_threshold);
Expand Down
1 change: 0 additions & 1 deletion src/storage/src/redis_strings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1477,5 +1477,4 @@ void RedisStrings::ScanDatabase() {
}
delete iter;
}

} // namespace storage
2 changes: 1 addition & 1 deletion src/storage/tests/keys_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2062,7 +2062,6 @@ for (const auto& kv : kvs) {
// int32_t delete_count;
// std::vector<std::string> keys;
// std::map<DataType, Status> type_status;

// //=============================== Strings ===============================

// // ***************** Group 1 Test *****************
Expand Down Expand Up @@ -2461,6 +2460,7 @@ for (const auto& kv : kvs) {

// //=============================== List ===============================


// // ***************** Group 1 Test *****************
// db.LPush("GP1_PKPATTERNMATCHDEL_LIST_KEY1", {"VALUE"}, &ret64);
// db.LPush("GP1_PKPATTERNMATCHDEL_LIST_KEY2", {"VALUE"}, &ret64);
Expand Down

0 comments on commit fa414f1

Please sign in to comment.