feat: add support for sticky keys in rdb #251 (#2166)

* feat: add support for sticky keys in rdb
This commit is contained in:
Borys 2023-11-14 14:02:14 +02:00 committed by GitHub
parent 87ee4f486c
commit 1ec1b997a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 19 deletions

View file

@ -1796,9 +1796,12 @@ struct RdbLoader::ObjSettings {
bool has_expired = false;
bool is_sticky = false;
void Reset() {
expiretime = 0;
has_expired = false;
is_sticky = false;
}
void SetExpire(int64_t val) {
@ -1892,6 +1895,13 @@ error_code RdbLoader::Load(io::Source* src) {
continue; /* Read next opcode. */
}
if (type == RDB_OPCODE_DF_MASK) {
uint32_t mask;
SET_OR_RETURN(FetchInt<uint32_t>(), mask);
settings.is_sticky = mask & DF_MASK_FLAG_STICKY;
continue; /* Read next opcode. */
}
if (type == RDB_OPCODE_FREQ) {
/* FREQ: LFU frequency. */
FetchInt<uint8_t>(); // IGNORE
@ -2289,6 +2299,7 @@ void RdbLoader::LoadItemsBuffer(DbIndex db_ind, const ItemsBuf& ib) {
try {
auto [it, added] = db_slice.AddOrUpdate(db_cntx, item->key, std::move(pv), item->expire_ms);
it->first.SetSticky(item->is_sticky);
if (!added) {
LOG(WARNING) << "RDB has duplicated key '" << item->key << "' in DB " << db_ind;
}
@ -2345,6 +2356,8 @@ error_code RdbLoader::LoadKeyValPair(int type, ObjSettings* settings) {
return kOk;
}
item->is_sticky = settings->is_sticky;
ShardId sid = Shard(item->key, shard_set->size());
item->expire_ms = settings->expiretime;