Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:Binlog is written repeatedly && not delete cache #2485

Merged
merged 4 commits into from
Mar 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/pika_slot_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -772,12 +772,12 @@ std::string GetSlotsTagKey(uint32_t crc) {
return SlotTagPrefix + std::to_string(crc);
}

// delete key from db
// delete key from db && cache
int DeleteKey(const std::string& key, const char key_type, const std::shared_ptr<DB>& db) {
int32_t res = 0;
std::string slotKey = GetSlotKey(GetSlotID(g_pika_conf->default_slot_num(), key));

// delete key from slot
// delete slotkey
std::vector<std::string> members;
members.emplace_back(key_type + key);
rocksdb::Status s = db->storage()->SRem(slotKey, members, &res);
Expand All @@ -791,6 +791,12 @@ 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()
&& PIKA_CACHE_STATUS_OK == db->cache()->CacheStatus()) {
db->cache()->Del(members);
}

// delete key from db
members.clear();
members.emplace_back(key);
Expand All @@ -800,7 +806,6 @@ int DeleteKey(const std::string& key, const char key_type, const std::shared_ptr
LOG(WARNING) << "Del key: " << key << " at slot " << GetSlotID(g_pika_conf->default_slot_num(), key) << " error";
return -1;
}
WriteDelKeyToBinlog(key, db);

return 1;
}
Expand Down
Loading