Skip to content

Commit 4785767

Browse files
andydunstallromange
authored andcommitted
fix(rdb_load): fix appending to an expired key (#3829)
1 parent 8e6ecc5 commit 4785767

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/server/rdb_load.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,7 +2549,12 @@ void RdbLoader::LoadItemsBuffer(DbIndex db_ind, const ItemsBuf& ib) {
25492549
if (item->load_config.append) {
25502550
auto res = db_slice.FindMutable(db_cntx, item->key);
25512551
if (!IsValid(res.it)) {
2552-
LOG(ERROR) << "Count not to find append key '" << item->key << "' in DB " << db_ind;
2552+
// If the item has expired we may not find the key. Note if the key
2553+
// is found, but expired since we started loading, we still append to
2554+
// avoid an inconsistent state where only part of the key is loaded.
2555+
if (item->expire_ms == 0 || db_cntx.time_now_ms < item->expire_ms) {
2556+
LOG(ERROR) << "Count not to find append key '" << item->key << "' in DB " << db_ind;
2557+
}
25532558
continue;
25542559
}
25552560
pv_ptr = &res.it->second;
@@ -2578,8 +2583,10 @@ void RdbLoader::LoadItemsBuffer(DbIndex db_ind, const ItemsBuf& ib) {
25782583
continue;
25792584
}
25802585

2581-
if (item->expire_ms > 0 && db_cntx.time_now_ms >= item->expire_ms)
2586+
if (item->expire_ms > 0 && db_cntx.time_now_ms >= item->expire_ms) {
2587+
VLOG(1) << "Expire key on load: " << item->key;
25822588
continue;
2589+
}
25832590

25842591
auto op_res = db_slice.AddOrUpdate(db_cntx, item->key, std::move(pv), item->expire_ms);
25852592
if (!op_res) {
@@ -2701,7 +2708,7 @@ bool RdbLoader::ShouldDiscardKey(std::string_view key, ObjSettings* settings) co
27012708
* load all the keys as they are, since the log of operations later
27022709
* assume to work in an exact keyspace state. */
27032710
if (ServerState::tlocal()->is_master && settings->has_expired) {
2704-
VLOG(2) << "Expire key: " << key;
2711+
VLOG(2) << "Expire key on read: " << key;
27052712
return true;
27062713
}
27072714

0 commit comments

Comments
 (0)