Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
2bbc8919
Commit
2bbc8919
authored
Nov 21, 2022
by
Viktor Söderqvist
Browse files
Move stat_active_defrag_hits increment to activeDefragAlloc
instead of passing it around to every defrag function
parent
b60d33c9
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
src/defrag.c
View file @
2bbc8919
This diff is collapsed.
Click to expand it.
src/module.c
View file @
2bbc8919
...
...
@@ -12562,7 +12562,6 @@ const char *RM_GetCurrentCommandName(RedisModuleCtx *ctx) {
* defrag callback.
*/
struct RedisModuleDefragCtx {
long defragged;
long long int endtime;
unsigned long *cursor;
struct redisObject *key; /* Optional name of key processed, NULL when unknown. */
...
...
@@ -12651,11 +12650,8 @@ int RM_DefragCursorGet(RedisModuleDefragCtx *ctx, unsigned long *cursor) {
* be used again.
*/
void *RM_DefragAlloc(RedisModuleDefragCtx *ctx, void *ptr) {
void *newptr = activeDefragAlloc(ptr);
if (newptr)
ctx->defragged++;
return newptr;
UNUSED(ctx);
return activeDefragAlloc(ptr);
}
/* Defrag a RedisModuleString previously allocated by RM_Alloc, RM_Calloc, etc.
...
...
@@ -12669,7 +12665,8 @@ void *RM_DefragAlloc(RedisModuleDefragCtx *ctx, void *ptr) {
* on the Redis side is dropped as soon as the command callback returns).
*/
RedisModuleString *RM_DefragRedisModuleString(RedisModuleDefragCtx *ctx, RedisModuleString *str) {
return activeDefragStringOb(str, &ctx->defragged);
UNUSED(ctx);
return activeDefragStringOb(str);
}
...
...
@@ -12678,11 +12675,11 @@ RedisModuleString *RM_DefragRedisModuleString(RedisModuleDefragCtx *ctx, RedisMo
* 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,
long long *defragged,
int dbid) {
int moduleLateDefrag(robj *key, robj *value, unsigned long *cursor, long long endtime, int dbid) {
moduleValue *mv = value->ptr;
moduleType *mt = mv->type;
RedisModuleDefragCtx defrag_ctx = {
0,
endtime, cursor, key, dbid};
RedisModuleDefragCtx defrag_ctx = { endtime, cursor, key, dbid};
/* Invoke callback. Note that the callback may be missing if the key has been
* replaced with a different type since our last visit.
...
...
@@ -12691,7 +12688,6 @@ int moduleLateDefrag(robj *key, robj *value, unsigned long *cursor, long long en
if (mt->defrag)
ret = mt->defrag(&defrag_ctx, key, &mv->value);
*defragged += defrag_ctx.defragged;
if (!ret) {
*cursor = 0; /* No more work to do */
return 0;
...
...
@@ -12706,7 +12702,7 @@ int moduleLateDefrag(robj *key, robj *value, unsigned long *cursor, long long en
* Returns 1 if the operation has been completed or 0 if it needs to
* be scheduled for late defrag.
*/
int moduleDefragValue(robj *key, robj *value,
long *defragged,
int dbid) {
int moduleDefragValue(robj *key, robj *value, int dbid) {
moduleValue *mv = value->ptr;
moduleType *mt = mv->type;
...
...
@@ -12715,7 +12711,6 @@ int moduleDefragValue(robj *key, robj *value, long *defragged, int dbid) {
*/
moduleValue *newmv = activeDefragAlloc(mv);
if (newmv) {
(*defragged)++;
value->ptr = mv = newmv;
}
...
...
@@ -12733,29 +12728,24 @@ int moduleDefragValue(robj *key, robj *value, long *defragged, int dbid) {
return 0; /* Defrag later */
}
RedisModuleDefragCtx defrag_ctx = { 0,
0,
NULL, key, dbid};
RedisModuleDefragCtx defrag_ctx = { 0, NULL, key, dbid
};
mt->defrag(&defrag_ctx, key, &mv->value);
(*defragged) += defrag_ctx.defragged;
return 1;
}
/* Call registered module API defrag functions */
long
moduleDefragGlobals(void) {
void
moduleDefragGlobals(void) {
dictIterator *di = dictGetIterator(modules);
dictEntry *de;
long defragged = 0;
while ((de = dictNext(di)) != NULL) {
struct RedisModule *module = dictGetVal(de);
if (!module->defrag_cb)
continue;
RedisModuleDefragCtx defrag_ctx = { 0,
0,
NULL, NULL, -1};
RedisModuleDefragCtx defrag_ctx = { 0, NULL, NULL, -1};
module->defrag_cb(&defrag_ctx);
defragged += defrag_ctx.defragged;
}
dictReleaseIterator(di);
return defragged;
}
/* Returns the name of the key currently being processed.
...
...
src/server.h
View file @
2bbc8919
...
...
@@ -2442,9 +2442,9 @@ void moduleNotifyKeyUnlink(robj *key, robj *val, int dbid, int flags);
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
,
long
*
defragged
,
int
dbid
);
int
moduleLateDefrag
(
robj
*
key
,
robj
*
value
,
unsigned
long
*
cursor
,
long
long
endtime
,
long
long
*
defragged
,
int
dbid
);
long
moduleDefragGlobals
(
void
);
int
moduleDefragValue
(
robj
*
key
,
robj
*
obj
,
int
dbid
);
int
moduleLateDefrag
(
robj
*
key
,
robj
*
value
,
unsigned
long
*
cursor
,
long
long
endtime
,
int
dbid
);
void
moduleDefragGlobals
(
void
);
void
*
moduleGetHandleByName
(
char
*
modulename
);
int
moduleIsModuleCommand
(
void
*
module_handle
,
struct
redisCommand
*
cmd
);
...
...
@@ -2988,7 +2988,7 @@ void checkChildrenDone(void);
int
setOOMScoreAdj
(
int
process_class
);
void
rejectCommandFormat
(
client
*
c
,
const
char
*
fmt
,
...);
void
*
activeDefragAlloc
(
void
*
ptr
);
robj
*
activeDefragStringOb
(
robj
*
ob
,
long
*
defragged
);
robj
*
activeDefragStringOb
(
robj
*
ob
);
void
dismissSds
(
sds
s
);
void
dismissMemory
(
void
*
ptr
,
size_t
size_hint
);
void
dismissMemoryInChild
(
void
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment