-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(server): expiry notifications #3154
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
#include "base/flags.h" | ||
#include "base/logging.h" | ||
#include "generic_family.h" | ||
#include "server/channel_store.h" | ||
#include "server/cluster/cluster_defs.h" | ||
#include "server/engine_shard_set.h" | ||
#include "server/error.h" | ||
|
@@ -33,6 +34,8 @@ ABSL_FLAG(double, table_growth_margin, 0.4, | |
"Prevents table from growing if number of free slots x average object size x this ratio " | ||
"is larger than memory budget."); | ||
|
||
ABSL_FLAG(bool, expiration_keyspace_events, false, "Send keyspace events for expiration"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to what setting is it equivalent for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but it's configured with it's own flag syntax, so not sure if we take over it, just keep the name with a boolean flag or use a differently named flag There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my question is what is the setting of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setting true is equvalent to using Ke in notify-keyspace-events There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, please add it to the help string There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about 'x' ? we do not handle it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eviction? No, we don't, but we can if needed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'x' is expiry and 'e' is eviction. So which one we support? :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, Kx then, I forgot the naming 😅 |
||
|
||
namespace dfly { | ||
|
||
using namespace std; | ||
|
@@ -204,9 +207,7 @@ unsigned PrimeEvictionPolicy::Evict(const PrimeTable::HotspotBuckets& eb, PrimeT | |
|
||
// log the evicted keys to journal. | ||
if (auto journal = db_slice_->shard_owner()->journal(); journal) { | ||
ArgSlice delete_args(&key, 1); | ||
journal->RecordEntry(0, journal::Op::EXPIRED, cntx_.db_index, 1, cluster::KeySlot(key), | ||
Payload("DEL", delete_args), false); | ||
RecordExpiry(cntx_.db_index, key); | ||
} | ||
|
||
db_slice_->PerformDeletion(DbSlice::Iterator(last_slot_it, StringOrView::FromView(key)), table); | ||
|
@@ -268,6 +269,7 @@ DbSlice::DbSlice(uint32_t index, bool caching_mode, EngineShard* owner) | |
CreateDb(0); | ||
expire_base_[0] = expire_base_[1] = 0; | ||
soft_budget_limit_ = (0.3 * max_memory_limit / shard_set->size()); | ||
expired_keys_events_recording_ = GetFlag(FLAGS_expiration_keyspace_events); | ||
} | ||
|
||
DbSlice::~DbSlice() { | ||
|
@@ -1047,11 +1049,15 @@ DbSlice::PrimeItAndExp DbSlice::ExpireIfNeeded(const Context& cntx, PrimeIterato | |
<< ", expire table size: " << db->expire.size() | ||
<< ", prime table size: " << db->prime.size() << util::fb2::GetStacktrace(); | ||
} | ||
|
||
// Replicate expiry | ||
if (auto journal = owner_->journal(); journal) { | ||
RecordExpiry(cntx.db_index, key); | ||
} | ||
|
||
if (expired_keys_events_recording_) | ||
db->expired_keys_events_.emplace_back(key); | ||
|
||
auto obj_type = it->second.ObjType(); | ||
if (doc_del_cb_ && (obj_type == OBJ_JSON || obj_type == OBJ_HASH)) { | ||
doc_del_cb_(key, cntx, it->second); | ||
|
@@ -1157,6 +1163,13 @@ auto DbSlice::DeleteExpiredStep(const Context& cntx, unsigned count) -> DeleteEx | |
} | ||
} | ||
|
||
// Send and clear accumulated expired key events | ||
if (auto& events = db_arr_[cntx.db_index]->expired_keys_events_; !events.empty()) { | ||
ChannelStore* store = ServerState::tlocal()->channel_store(); | ||
store->SendMessages(absl::StrCat("__keyevent@", cntx.db_index, "__:expired"), events); | ||
events.clear(); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
|
@@ -1185,6 +1198,8 @@ void DbSlice::FreeMemWithEvictionStep(DbIndex db_ind, size_t increase_goal_bytes | |
string tmp; | ||
int32_t starting_segment_id = rand() % num_segments; | ||
size_t used_memory_before = owner_->UsedMemory(); | ||
|
||
bool record_keys = owner_->journal() != nullptr || expired_keys_events_recording_; | ||
vector<string> keys_to_journal; | ||
|
||
{ | ||
|
@@ -1213,9 +1228,8 @@ void DbSlice::FreeMemWithEvictionStep(DbIndex db_ind, size_t increase_goal_bytes | |
if (lt.Find(LockTag(key)).has_value()) | ||
continue; | ||
|
||
if (auto journal = owner_->journal(); journal) { | ||
keys_to_journal.push_back(string(key)); | ||
} | ||
if (record_keys) | ||
keys_to_journal.emplace_back(key); | ||
|
||
PerformDeletion(Iterator(evict_it, StringOrView::FromView(key)), db_table.get()); | ||
++evicted; | ||
|
@@ -1233,12 +1247,12 @@ void DbSlice::FreeMemWithEvictionStep(DbIndex db_ind, size_t increase_goal_bytes | |
finish: | ||
// send the deletion to the replicas. | ||
// fiber preemption could happen in this phase. | ||
if (auto journal = owner_->journal(); journal) { | ||
for (string_view key : keys_to_journal) { | ||
ArgSlice delete_args(&key, 1); | ||
journal->RecordEntry(0, journal::Op::EXPIRED, db_ind, 1, cluster::KeySlot(key), | ||
Payload("DEL", delete_args), false); | ||
} | ||
for (string_view key : keys_to_journal) { | ||
if (auto journal = owner_->journal(); journal) | ||
RecordExpiry(db_ind, key); | ||
|
||
if (expired_keys_events_recording_) | ||
db_table->expired_keys_events_.emplace_back(key); | ||
} | ||
|
||
auto time_finish = absl::GetCurrentTimeNanos(); | ||
|
Uh oh!
There was an error while loading. Please reload this page.