-
Notifications
You must be signed in to change notification settings - Fork 701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incr expired_keys if the expiration time is already expired #1517
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## unstable #1517 +/- ##
============================================
+ Coverage 70.82% 70.85% +0.03%
============================================
Files 120 120
Lines 64911 64915 +4
============================================
+ Hits 45972 45995 +23
+ Misses 18939 18920 -19
|
The core of this issue is whether we should consider setting an expired time for a key as a delete operation or an expiration. I believe it should be considered as expiration because the user's intended action is to set an expire time for the key. However, due to some reasons (such as operational delays), the time has already passed. Nonetheless, the key is still deleted due to expiration. Therefore, in terms of statistics and notifications, it should be counted as expiration-based deletion. Additionally, we have already sent notifications regarding the expiration for the module: void deleteExpiredKeyFromOverwriteAndPropagate(client *c, robj *keyobj) {
int deleted = dbGenericDelete(c->db, keyobj, server.lazyfree_lazy_expire, DB_FLAG_KEY_EXPIRED);
int dbGenericDelete(serverDb *db, robj *key, int async, int flags) {
int dict_index = getKVStoreIndexForKey(key->ptr);
return dbGenericDeleteWithDictIndex(db, key, async, flags, dict_index);
}
int dbGenericDeleteWithDictIndex(serverDb *db, robj *key, int async, int flags, int dict_index) {
hashtablePosition pos;
void **ref = kvstoreHashtableTwoPhasePopFindRef(db->keys, dict_index, key->ptr, &pos);
if (ref != NULL) {
robj *val = *ref;
/* VM_StringDMA may call dbUnshareStringValue which may free val, so we
* need to incr to retain val */
incrRefCount(val);
/* Tells the module that the key has been unlinked from the database. */
moduleNotifyKeyUnlink(key, val, db->id, flags); However, there is a change here: the notification has been changed from |
Signed-off-by: Ray Cao <[email protected]>
18efebb
to
aafe746
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall make sense to me.
Signed-off-by: Ray Cao <[email protected]>
Yeah, I think at the very least this needs to be marked as a breaking change, since we are changing the event type. Even if the new behavior is more correct, it's such a long standing behavior someone might have coded around it. |
since it's a breaking change (very small), @valkey-io/core-team please vote |
@@ -1860,7 +1860,8 @@ void deleteExpiredKeyFromOverwriteAndPropagate(client *c, robj *keyobj) { | |||
robj *aux = server.lazyfree_lazy_expire ? shared.unlink : shared.del; | |||
rewriteClientCommandVector(c, 2, aux, keyobj); | |||
signalModifiedKey(c, c->db, keyobj); | |||
notifyKeyspaceEvent(NOTIFY_GENERIC, "del", keyobj, c->db->id); | |||
notifyKeyspaceEvent(NOTIFY_EXPIRED, "expired", keyobj, c->db->id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the difference between I think the difference between "expire" and "expired" is clear in the docs.expire
and expired
event?
In the docs I can find for "expired":
- Every time a key with a time to live associated is removed from the data set because it expired, an expired event is generated.
and for "expire" event:
- EXPIRE and all its variants (PEXPIRE, EXPIREAT, PEXPIREAT) generate an expire event when called with a positive timeout (or a future timestamp). Note that when these com‐
mands are called with a negative timeout value or timestamp in the past, the key is deleted and only a del event is generated instead.
This seems to me like a bug fix. A key expiration is supposed to trigger an expired
event. A del
event seems like a bug. Or am I missing anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can find "expired" in active expire path: activeExpireCycleTryExpire
-> deleteExpiredKeyAndPropagate
-> deleteExpiredKeyAndPropagateWithDictIndex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Yes I found it.
Shall we postpone the breaking change to 9.0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think 8.1 is ok, it's a very very small change maybe even not breaking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do it in 8.1, we can describe it as a bug fix. It looks better than a breaking change in a minor version.
But let's be sure we know what we are doing. We have done some mistakes before such as #1537 and #1228. We often think that small things like that will not be a problem.
@madolson said
Even if the new behavior is more correct, it's such a long standing behavior someone might have coded around it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm very sure what it is : )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm very sure what it is : )
What is it exactly?
If it's a breaking change, we shouldn't release it in a minor version.
- Breaking change → release in 9.0.
- Not breaking change → release in 8.1 and remove the breaking-change label.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bugfix, but it might also introduce a breaking change. These two are not mutually exclusive, and I don't understand why it has to be an either-or situation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we use semantic versioning. It's the only reason.
Major version must be incremented if we introduce backward incompatible API changes.
If the public documented API is not changed, then we are just fixing incorrect behaviour. Then a patch release is enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, this PR doesn't introduce API changes, I removed the breaking-change flag, and 8.1 is the right way
Added the client-changes-needed since it MIGHT impact some client code managing client side caching |
The change totally makes sense to me. Approved |
…d other commands(valkey-io#1517) Some commands that use unix-time, such as `EXPIREAT` and `SET EXAT`, should include the deleted keys in the `expired_keys` statistics if the specified time has already expired, and notifications should be sent in the manner of expired. --------- Signed-off-by: Ray Cao <[email protected]>
This PR modifies two parts of the
deleteExpiredKeyFromOverwriteAndPropagate
function, which is called when the expiration time has already expired.GENERIC-del
toEXPIRED-expired
.Since this delete operation is triggered by EXPIRE, and the flag pass to
dbGenericDeleteWithDictIndex
isDB_FLAG_KEY_EXPIRED
, which is used to notify module, maybe we should align the behavior and send Keyspace Event notify likedeleteExpiredKeyAndPropagateWithDictIndex
did.server.stat_expiredkeys
in this case could more accurately reflect the number of keys deleted due to expiration.