Skip to content

Commit

Permalink
defrag: use monotime in module interface (valkey-io#1388)
Browse files Browse the repository at this point in the history
The recent PR (valkey-io#1242) converted
Active Defrag to use `monotime`. In that change, a conversion was
performed to continue to use `ustime()` as part of the module interface.
Since this time is only used internally, and never actually exposed to
the module, we can convert this to use `monotime` directly.

Signed-off-by: Jim Brunner <[email protected]>
  • Loading branch information
JimB123 authored Dec 3, 2024
1 parent 9f8b174 commit 349bc75
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/defrag.c
Original file line number Diff line number Diff line change
Expand Up @@ -905,8 +905,7 @@ static int defragLaterItem(dictEntry *de, unsigned long *cursor, monotime endtim
} else if (ob->type == OBJ_STREAM) {
return scanLaterStreamListpacks(ob, cursor, endtime);
} else if (ob->type == OBJ_MODULE) {
long long endtimeWallClock = ustime() + (endtime - getMonotonicUs());
return moduleLateDefrag(dictGetKey(de), ob, cursor, endtimeWallClock, dbid);
return moduleLateDefrag(dictGetKey(de), ob, cursor, endtime, dbid);
} else {
*cursor = 0; /* object type may have changed since we schedule it for later */
}
Expand Down
6 changes: 3 additions & 3 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -13344,7 +13344,7 @@ const char *VM_GetCurrentCommandName(ValkeyModuleCtx *ctx) {
* defrag callback.
*/
struct ValkeyModuleDefragCtx {
long long int endtime;
monotime endtime;
unsigned long *cursor;
struct serverObject *key; /* Optional name of key processed, NULL when unknown. */
int dbid; /* The dbid of the key being processed, -1 when unknown. */
Expand Down Expand Up @@ -13373,7 +13373,7 @@ int VM_RegisterDefragFunc(ValkeyModuleCtx *ctx, ValkeyModuleDefragFunc cb) {
* so it generally makes sense to do small batches of work in between calls.
*/
int VM_DefragShouldStop(ValkeyModuleDefragCtx *ctx) {
return (ctx->endtime != 0 && ctx->endtime < ustime());
return (ctx->endtime != 0 && ctx->endtime <= getMonotonicUs());
}

/* Store an arbitrary cursor value for future re-use.
Expand Down Expand Up @@ -13455,7 +13455,7 @@ ValkeyModuleString *VM_DefragValkeyModuleString(ValkeyModuleDefragCtx *ctx, Valk
* Returns a zero value (and initializes the cursor) if no more needs to be done,
* or a non-zero value otherwise.
*/
int moduleLateDefrag(robj *key, robj *value, unsigned long *cursor, long long endtime, int dbid) {
int moduleLateDefrag(robj *key, robj *value, unsigned long *cursor, monotime endtime, int dbid) {
moduleValue *mv = value->ptr;
moduleType *mt = mv->type;

Expand Down
2 changes: 1 addition & 1 deletion src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -2732,7 +2732,7 @@ size_t moduleGetFreeEffort(robj *key, robj *val, int dbid);
size_t moduleGetMemUsage(robj *key, robj *val, size_t sample_size, int dbid);
robj *moduleTypeDupOrReply(client *c, robj *fromkey, robj *tokey, int todb, robj *value);
int moduleDefragValue(robj *key, robj *obj, int dbid);
int moduleLateDefrag(robj *key, robj *value, unsigned long *cursor, long long endtime, int dbid);
int moduleLateDefrag(robj *key, robj *value, unsigned long *cursor, monotime endtime, int dbid);
void moduleDefragGlobals(void);
void *moduleGetHandleByName(char *modulename);
int moduleIsModuleCommand(void *module_handle, struct serverCommand *cmd);
Expand Down

0 comments on commit 349bc75

Please sign in to comment.