Skip to content

Commit

Permalink
fix:cache support config rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
brother-jin committed Dec 14, 2023
1 parent 0b6bd8d commit 8b95e4e
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
6 changes: 6 additions & 0 deletions include/pika_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,12 @@ class PikaConf : public pstd::BaseConf {
max_rsync_parallel_num_ = value;
}

const std::string scache_type() {
std::lock_guard l(rwlock_);
return pstd::StringConcat(cache_type_, COMMA);
}


void SetCacheType(const std::string &value);
void SetCacheDisableFlag() { tmp_cache_disable_flag_ = true; }
int zset_cache_start_pos() { return zset_cache_start_pos_; }
Expand Down
63 changes: 63 additions & 0 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2049,6 +2049,60 @@ void ConfigCmd::ConfigGet(std::string& ret) {
EncodeString(&config_body, g_pika_conf->replication_id());
}

if (pstd::stringmatch(pattern.data(), "cache-num", 1)) {
elements += 2;
EncodeString(&config_body, "cache-num");
EncodeNumber(&config_body, g_pika_conf->GetCacheNum());
}

if (pstd::stringmatch(pattern.data(), "cache-model", 1)) {
elements += 2;
EncodeString(&config_body, "cache-model");
EncodeNumber(&config_body, g_pika_conf->cache_model());
}

if (pstd::stringmatch(pattern.data(), "cache-type", 1)) {
elements += 2;
EncodeString(&config_body, "cache-type");
EncodeString(&config_body, g_pika_conf->scache_type());
}

if (pstd::stringmatch(pattern.data(), "cache-start-direction", 1)) {
elements += 2;
EncodeString(&config_body, "cache-start-direction");
EncodeNumber(&config_body, g_pika_conf->zset_cache_start_pos());
}

if (pstd::stringmatch(pattern.data(), "cache-items-per-key", 1)) {
elements += 2;
EncodeString(&config_body, "cache-items-per-key");
EncodeNumber(&config_body, g_pika_conf->zset_cache_field_num_per_key());
}

if (pstd::stringmatch(pattern.data(), "cache-maxmemory", 1)) {
elements += 2;
EncodeString(&config_body, "cache-maxmemory");
EncodeNumber(&config_body, g_pika_conf->cache_maxmemory());
}

if (pstd::stringmatch(pattern.data(), "cache-maxmemory-policy", 1)) {
elements += 2;
EncodeString(&config_body, "cache-maxmemory-policy");
EncodeNumber(&config_body, g_pika_conf->cache_maxmemory_policy());
}

if (pstd::stringmatch(pattern.data(), "cache-maxmemory-samples", 1)) {
elements += 2;
EncodeString(&config_body, "cache-maxmemory-samples");
EncodeNumber(&config_body, g_pika_conf->cache_maxmemory_samples());
}

if (pstd::stringmatch(pattern.data(), "cache-lfu-decay-time", 1)) {
elements += 2;
EncodeString(&config_body, "cache-lfu-decay-time");
EncodeNumber(&config_body, g_pika_conf->cache_lfu_decay_time());
}

std::stringstream resp;
resp << "*" << std::to_string(elements) << "\r\n" << config_body;
ret = resp.str();
Expand Down Expand Up @@ -2095,6 +2149,15 @@ void ConfigCmd::ConfigSet(std::string& ret, std::shared_ptr<Slot> slot) {
EncodeString(&ret, "arena-block-size");
EncodeString(&ret, "throttle-bytes-per-second");
EncodeString(&ret, "max-rsync-parallel-num");
EncodeString(&ret, "cache-num");
EncodeString(&ret, "cache-model");
EncodeString(&ret, "cache-type");
EncodeString(&ret, "zset-cache-start-direction");
EncodeString(&ret, "cache-items-per-key");
EncodeString(&ret, "cache-maxmemory");
EncodeString(&ret, "cache-maxmemory-policy");
EncodeString(&ret, "cache-maxmemory-samples");
EncodeString(&ret, "disable-auto-compactions");
return;
}
long int ival = 0;
Expand Down
1 change: 0 additions & 1 deletion src/pika_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,6 @@ void Cmd::DoBinlog(const std::shared_ptr<SyncMasterSlot>& slot) {
res().SetRes(CmdRes::kErrOther);
return;
}

Status s =
slot->ConsensusProposeLog(shared_from_this(), std::dynamic_pointer_cast<PikaClientConn>(conn_ptr), resp_ptr);
if (!s.ok()) {
Expand Down
11 changes: 11 additions & 0 deletions src/pika_conf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,17 @@ int PikaConf::ConfigRewrite() {
SetConfInt64("slotmigrate", slotmigrate_);
// slaveof config item is special
SetConfStr("slaveof", slaveof_);
SetConfInt("max-bytes-for-level-multiplier", max_bytes_for_level_multiplier_);
SetConfStr("share-block-cache", share_block_cache_ ? "yes" : "no");
SetConfStr("cache-index-and-filter-blocks", cache_index_and_filter_blocks_ ? "yes" : "no");
SetConfStr("optimize-filters-for-hits", optimize_filters_for_hits_ ? "yes" : "no");
SetConfStr("level-compaction-dynamic-level-bytes", level_compaction_dynamic_level_bytes_ ? "yes" : "no");
SetConfInt("cache-model", cache_model_);
SetConfStr("cache-type", scache_type());
SetConfInt("zset_cache_start_pos", zset_cache_start_pos_);
SetConfInt("zset_cache_field_num_per_key", zset_cache_field_num_per_key_);
SetConfInt("block-size", block_size_);
SetConfInt("block-cache", block_cache_);

if (!diff_commands_.empty()) {
std::vector<pstd::BaseConf::Rep::ConfItem> filtered_items;
Expand Down

0 comments on commit 8b95e4e

Please sign in to comment.