Skip to content

Commit

Permalink
fix(rdb_load): fix appending to an expired key (#3829)
Browse files Browse the repository at this point in the history
  • Loading branch information
andydunstall authored and romange committed Sep 30, 2024
1 parent 8e6ecc5 commit 4785767
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/server/rdb_load.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2549,7 +2549,12 @@ void RdbLoader::LoadItemsBuffer(DbIndex db_ind, const ItemsBuf& ib) {
if (item->load_config.append) {
auto res = db_slice.FindMutable(db_cntx, item->key);
if (!IsValid(res.it)) {
LOG(ERROR) << "Count not to find append key '" << item->key << "' in DB " << db_ind;
// If the item has expired we may not find the key. Note if the key
// is found, but expired since we started loading, we still append to
// avoid an inconsistent state where only part of the key is loaded.
if (item->expire_ms == 0 || db_cntx.time_now_ms < item->expire_ms) {
LOG(ERROR) << "Count not to find append key '" << item->key << "' in DB " << db_ind;
}
continue;
}
pv_ptr = &res.it->second;
Expand Down Expand Up @@ -2578,8 +2583,10 @@ void RdbLoader::LoadItemsBuffer(DbIndex db_ind, const ItemsBuf& ib) {
continue;
}

if (item->expire_ms > 0 && db_cntx.time_now_ms >= item->expire_ms)
if (item->expire_ms > 0 && db_cntx.time_now_ms >= item->expire_ms) {
VLOG(1) << "Expire key on load: " << item->key;
continue;
}

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

Expand Down

0 comments on commit 4785767

Please sign in to comment.