mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 10:25:47 +02:00
* feat: add support for sticky keys in rdb
This commit is contained in:
parent
87ee4f486c
commit
1ec1b997a0
5 changed files with 59 additions and 19 deletions
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue