Skip to content

Commit

Permalink
fix:change cache-model to cache-mode (#2585)
Browse files Browse the repository at this point in the history
* fix:change cache-model to cache-mode

---------

Co-authored-by: chejinge <chejinge@360.cn>
  • Loading branch information
chejinge and brother-jin committed Apr 16, 2024
1 parent 5aa04db commit 83903a9
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 17 deletions.
6 changes: 3 additions & 3 deletions include/pika_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class PikaConf : public pstd::BaseConf {
std::shared_lock l(rwlock_);
return network_interface_;
}
int cache_model() { return cache_model_; }
int cache_mode() { return cache_mode_; }
int sync_window_size() { return sync_window_size_.load(); }
int max_conn_rbuf_size() { return max_conn_rbuf_size_.load(); }
int consensus_level() { return consensus_level_.load(); }
Expand Down Expand Up @@ -337,7 +337,7 @@ class PikaConf : public pstd::BaseConf {
int GetCacheBit() { return cache_bit_; }
int GetCacheNum() { return cache_num_; }
void SetCacheNum(const int value) { cache_num_ = value; }
void SetCacheModel(const int value) { cache_model_ = value; }
void SetCacheMode(const int value) { cache_mode_ = value; }
void SetCacheStartDirection(const int value) { zset_cache_start_direction_ = value; }
void SetCacheItemsPerKey(const int value) { zset_cache_field_num_per_key_ = value; }
void SetCacheMaxmemory(const int64_t value) { cache_maxmemory_ = value; }
Expand Down Expand Up @@ -785,7 +785,7 @@ class PikaConf : public pstd::BaseConf {
std::atomic_bool tmp_cache_disable_flag_;
std::atomic_int64_t cache_maxmemory_;
std::atomic_int cache_num_;
std::atomic_int cache_model_;
std::atomic_int cache_mode_;
std::atomic_int cache_string_;
std::atomic_int cache_set_;
std::atomic_int cache_zset_;
Expand Down
2 changes: 1 addition & 1 deletion include/pika_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ const int PIKA_ROLE_SLAVE = 1;
const int PIKA_ROLE_MASTER = 2;

/*
* cache model
* cache mode
*/
constexpr int PIKA_CACHE_NONE = 0;
constexpr int PIKA_CACHE_READ = 1;
Expand Down
12 changes: 6 additions & 6 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ void FlushallCmd::DoThroughDB() {

void FlushallCmd::DoUpdateCache(std::shared_ptr<DB> db) {
// clear cache
if (PIKA_CACHE_NONE != g_pika_conf->cache_model()) {
if (PIKA_CACHE_NONE != g_pika_conf->cache_mode()) {
g_pika_server->ClearCacheDbAsync(db);
}
}
Expand Down Expand Up @@ -629,7 +629,7 @@ void FlushdbCmd::DoThroughDB() {

void FlushdbCmd::DoUpdateCache() {
// clear cache
if (g_pika_conf->cache_model() != PIKA_CACHE_NONE) {
if (g_pika_conf->cache_mode() != PIKA_CACHE_NONE) {
g_pika_server->ClearCacheDbAsync(db_);
}
}
Expand Down Expand Up @@ -1373,7 +1373,7 @@ void InfoCmd::InfoCommandStats(std::string& info) {
void InfoCmd::InfoCache(std::string& info, std::shared_ptr<DB> db) {
std::stringstream tmp_stream;
tmp_stream << "# Cache" << "\r\n";
if (PIKA_CACHE_NONE == g_pika_conf->cache_model()) {
if (PIKA_CACHE_NONE == g_pika_conf->cache_mode()) {
tmp_stream << "cache_status:Disable" << "\r\n";
} else {
auto cache_info = db->GetCacheInfo();
Expand Down Expand Up @@ -2027,7 +2027,7 @@ void ConfigCmd::ConfigGet(std::string& ret) {
if (pstd::stringmatch(pattern.data(), "cache-model", 1)) {
elements += 2;
EncodeString(&config_body, "cache-model");
EncodeNumber(&config_body, g_pika_conf->cache_model());
EncodeNumber(&config_body, g_pika_conf->cache_mode());
}

if (pstd::stringmatch(pattern.data(), "cache-type", 1)) {
Expand Down Expand Up @@ -2510,7 +2510,7 @@ void ConfigCmd::ConfigSet(std::shared_ptr<DB> db) {
if (PIKA_CACHE_NONE > ival || PIKA_CACHE_READ < ival) {
res_.AppendStringRaw("-ERR Invalid cache model\r\n");
} else {
g_pika_conf->SetCacheModel(ival);
g_pika_conf->SetCacheMode(ival);
if (PIKA_CACHE_NONE == ival) {
g_pika_server->ClearCacheDbAsync(db);
}
Expand Down Expand Up @@ -3184,7 +3184,7 @@ void ClearCacheCmd::DoInitial() {

void ClearCacheCmd::Do() {
// clean cache
if (PIKA_CACHE_NONE != g_pika_conf->cache_model()) {
if (PIKA_CACHE_NONE != g_pika_conf->cache_mode()) {
g_pika_server->ClearCacheDbAsync(db_);
}
res_.SetRes(CmdRes::kOk, "Cache is cleared");
Expand Down
2 changes: 1 addition & 1 deletion src/pika_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ void Cmd::DoCommand(const HintKeys& hint_keys) {
}
};
if (IsNeedCacheDo()
&& PIKA_CACHE_NONE != g_pika_conf->cache_model()
&& PIKA_CACHE_NONE != g_pika_conf->cache_mode()
&& db_->cache()->CacheStatus() == PIKA_CACHE_STATUS_OK) {
if (IsNeedReadCache()) {
ReadCache();
Expand Down
8 changes: 4 additions & 4 deletions src/pika_conf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,9 @@ int PikaConf::Load() {
GetConfInt("cache-num", &cache_num);
cache_num_ = (0 >= cache_num || 48 < cache_num) ? 16 : cache_num;

int cache_model = 0;
GetConfInt("cache-model", &cache_model);
cache_model_ = (PIKA_CACHE_NONE > cache_model || PIKA_CACHE_READ < cache_model) ? PIKA_CACHE_NONE : cache_model;
int cache_mode = 0;
GetConfInt("cache-model", &cache_mode);
cache_mode_ = (PIKA_CACHE_NONE > cache_mode || PIKA_CACHE_READ < cache_mode) ? PIKA_CACHE_NONE : cache_mode;

std::string cache_type;
GetConfStr("cache-type", &cache_type);
Expand Down Expand Up @@ -694,7 +694,7 @@ int PikaConf::ConfigRewrite() {
SetConfStr("slaveof", slaveof_);
// cache config
SetConfStr("cache-index-and-filter-blocks", cache_index_and_filter_blocks_ ? "yes" : "no");
SetConfInt("cache-model", cache_model_);
SetConfInt("cache-model", cache_mode_);
SetConfInt("zset-cache-start-direction", zset_cache_start_direction_);
SetConfInt("zset_cache_field_num_per_key", zset_cache_field_num_per_key_);

Expand Down
2 changes: 1 addition & 1 deletion src/pika_repl_bgworker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ void PikaReplBgWorker::HandleBGWorkerWriteDB(void* arg) {
c_ptr->GetDB()->DBLockShared();
}
if (c_ptr->IsNeedCacheDo()
&& PIKA_CACHE_NONE != g_pika_conf->cache_model()
&& PIKA_CACHE_NONE != g_pika_conf->cache_mode()
&& c_ptr->GetDB()->cache()->CacheStatus() == PIKA_CACHE_STATUS_OK) {
if (c_ptr->is_write()) {
c_ptr->DoThroughDB();
Expand Down
2 changes: 1 addition & 1 deletion src/pika_slot_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ int DeleteKey(const std::string& key, const char key_type, const std::shared_ptr
}

// delete from cache
if (PIKA_CACHE_NONE != g_pika_conf->cache_model()
if (PIKA_CACHE_NONE != g_pika_conf->cache_mode()
&& PIKA_CACHE_STATUS_OK == db->cache()->CacheStatus()) {
db->cache()->Del(members);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ var _ = Describe("admin test", func() {
})

AfterEach(func() {
Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred())
time.Sleep(1 * time.Second)
Expect(client.Close()).NotTo(HaveOccurred())
})

Expand Down

0 comments on commit 83903a9

Please sign in to comment.