mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 18:35:46 +02:00
fix(server): fix getex command with persist can get time overflow (#707)
Signed-off-by: Boaz Sade <boaz@dragonflydb.io> Signed-off-by: Boaz Sade <boaz@dragonflydb.io>
This commit is contained in:
parent
086edd9707
commit
5af6ee9b27
2 changed files with 12 additions and 6 deletions
|
@ -599,23 +599,29 @@ pair<int64_t, int64_t> DbSlice::ExpireParams::Calculate(int64_t now_ms) const {
|
|||
|
||||
OpResult<int64_t> DbSlice::UpdateExpire(const Context& cntx, PrimeIterator prime_it,
|
||||
ExpireIterator expire_it, const ExpireParams& params) {
|
||||
constexpr uint64_t kPersistValue = 0;
|
||||
DCHECK(params.IsDefined());
|
||||
DCHECK(IsValid(prime_it));
|
||||
// If this need to persist, then only set persist value and return
|
||||
if (params.persist) {
|
||||
RemoveExpire(cntx.db_index, prime_it);
|
||||
return kPersistValue;
|
||||
}
|
||||
|
||||
auto [rel_msec, abs_msec] = params.Calculate(cntx.time_now_ms);
|
||||
if (rel_msec > kMaxExpireDeadlineSec * 1000) {
|
||||
return OpStatus::OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
if (rel_msec <= 0 && !params.persist) {
|
||||
if (rel_msec <= 0) { // implicit - don't persist
|
||||
CHECK(Del(cntx.db_index, prime_it));
|
||||
return -1;
|
||||
} else if (IsValid(expire_it) && !params.persist) {
|
||||
expire_it->second = FromAbsoluteTime(abs_msec);
|
||||
return abs_msec;
|
||||
} else {
|
||||
UpdateExpire(cntx.db_index, prime_it, params.persist ? 0 : abs_msec);
|
||||
return params.persist ? 0 : abs_msec;
|
||||
AddExpire(cntx.db_index, prime_it, abs_msec);
|
||||
return abs_msec;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -403,8 +403,8 @@ OpStatus SetCmd::Set(const SetParams& params, string_view key, string_view value
|
|||
db_slice.PostUpdate(op_args_.db_cntx.db_index, it, key, false);
|
||||
|
||||
if (params.expire_after_ms) {
|
||||
db_slice.UpdateExpire(op_args_.db_cntx.db_index, it,
|
||||
params.expire_after_ms + op_args_.db_cntx.time_now_ms);
|
||||
db_slice.AddExpire(op_args_.db_cntx.db_index, it,
|
||||
params.expire_after_ms + op_args_.db_cntx.time_now_ms);
|
||||
}
|
||||
|
||||
if (params.memcache_flags)
|
||||
|
@ -447,7 +447,7 @@ OpStatus SetCmd::SetExisting(const SetParams& params, PrimeIterator it, ExpireIt
|
|||
if (!(params.flags & SET_KEEP_EXPIRE)) {
|
||||
if (at_ms) { // Command has an expiry paramater.
|
||||
if (IsValid(e_it)) {
|
||||
// Updated exisitng expiry information.
|
||||
// Updated existing expiry information.
|
||||
e_it->second = db_slice.FromAbsoluteTime(at_ms);
|
||||
} else {
|
||||
// Add new expiry information.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue