Modules: Add event for fork child birth and termination (#8289)
Useful to avoid doing background jobs that can cause excessive COW
This commit is contained in:
parent
a16739a3ac
commit
01cbf17ba2
10
src/module.c
10
src/module.c
@ -7899,6 +7899,14 @@ void ModuleForkDoneHandler(int exitcode, int bysignal) {
|
|||||||
* * `REDISMODULE_SUBEVENT_REPL_BACKUP_RESTORE`
|
* * `REDISMODULE_SUBEVENT_REPL_BACKUP_RESTORE`
|
||||||
* * `REDISMODULE_SUBEVENT_REPL_BACKUP_DISCARD`
|
* * `REDISMODULE_SUBEVENT_REPL_BACKUP_DISCARD`
|
||||||
*
|
*
|
||||||
|
* * RedisModuleEvent_ForkChild
|
||||||
|
*
|
||||||
|
* Called when a fork child (AOFRW, RDBSAVE, module fork...) is born/dies
|
||||||
|
* The following sub events are available:
|
||||||
|
*
|
||||||
|
* * `REDISMODULE_SUBEVENT_FORK_CHILD_BORN`
|
||||||
|
* * `REDISMODULE_SUBEVENT_FORK_CHILD_DIED`
|
||||||
|
*
|
||||||
* The function returns REDISMODULE_OK if the module was successfully subscribed
|
* The function returns REDISMODULE_OK if the module was successfully subscribed
|
||||||
* for the specified event. If the API is called from a wrong context or unsupported event
|
* for the specified event. If the API is called from a wrong context or unsupported event
|
||||||
* is given then REDISMODULE_ERR is returned. */
|
* is given then REDISMODULE_ERR is returned. */
|
||||||
@ -7971,6 +7979,8 @@ int RM_IsSubEventSupported(RedisModuleEvent event, int64_t subevent) {
|
|||||||
return subevent < _REDISMODULE_SUBEVENT_SWAPDB_NEXT;
|
return subevent < _REDISMODULE_SUBEVENT_SWAPDB_NEXT;
|
||||||
case REDISMODULE_EVENT_REPL_BACKUP:
|
case REDISMODULE_EVENT_REPL_BACKUP:
|
||||||
return subevent < _REDISMODULE_SUBEVENT_REPL_BACKUP_NEXT;
|
return subevent < _REDISMODULE_SUBEVENT_REPL_BACKUP_NEXT;
|
||||||
|
case REDISMODULE_EVENT_FORK_CHILD:
|
||||||
|
return subevent < _REDISMODULE_SUBEVENT_FORK_CHILD_NEXT;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -230,9 +230,8 @@ typedef uint64_t RedisModuleTimerID;
|
|||||||
#define REDISMODULE_EVENT_LOADING_PROGRESS 10
|
#define REDISMODULE_EVENT_LOADING_PROGRESS 10
|
||||||
#define REDISMODULE_EVENT_SWAPDB 11
|
#define REDISMODULE_EVENT_SWAPDB 11
|
||||||
#define REDISMODULE_EVENT_REPL_BACKUP 12
|
#define REDISMODULE_EVENT_REPL_BACKUP 12
|
||||||
|
#define REDISMODULE_EVENT_FORK_CHILD 13
|
||||||
/* Next event flag, should be updated if a new event added. */
|
#define _REDISMODULE_EVENT_NEXT 14 /* Next event flag, should be updated if a new event added. */
|
||||||
#define _REDISMODULE_EVENT_NEXT 13
|
|
||||||
|
|
||||||
typedef struct RedisModuleEvent {
|
typedef struct RedisModuleEvent {
|
||||||
uint64_t id; /* REDISMODULE_EVENT_... defines. */
|
uint64_t id; /* REDISMODULE_EVENT_... defines. */
|
||||||
@ -295,6 +294,10 @@ static const RedisModuleEvent
|
|||||||
RedisModuleEvent_ReplBackup = {
|
RedisModuleEvent_ReplBackup = {
|
||||||
REDISMODULE_EVENT_REPL_BACKUP,
|
REDISMODULE_EVENT_REPL_BACKUP,
|
||||||
1
|
1
|
||||||
|
},
|
||||||
|
RedisModuleEvent_ForkChild = {
|
||||||
|
REDISMODULE_EVENT_FORK_CHILD,
|
||||||
|
1
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Those are values that are used for the 'subevent' callback argument. */
|
/* Those are values that are used for the 'subevent' callback argument. */
|
||||||
@ -345,6 +348,10 @@ static const RedisModuleEvent
|
|||||||
#define REDISMODULE_SUBEVENT_REPL_BACKUP_DISCARD 2
|
#define REDISMODULE_SUBEVENT_REPL_BACKUP_DISCARD 2
|
||||||
#define _REDISMODULE_SUBEVENT_REPL_BACKUP_NEXT 3
|
#define _REDISMODULE_SUBEVENT_REPL_BACKUP_NEXT 3
|
||||||
|
|
||||||
|
#define REDISMODULE_SUBEVENT_FORK_CHILD_BORN 0
|
||||||
|
#define REDISMODULE_SUBEVENT_FORK_CHILD_DIED 1
|
||||||
|
#define _REDISMODULE_SUBEVENT_FORK_CHILD_NEXT 2
|
||||||
|
|
||||||
#define _REDISMODULE_SUBEVENT_SHUTDOWN_NEXT 0
|
#define _REDISMODULE_SUBEVENT_SHUTDOWN_NEXT 0
|
||||||
#define _REDISMODULE_SUBEVENT_CRON_LOOP_NEXT 0
|
#define _REDISMODULE_SUBEVENT_CRON_LOOP_NEXT 0
|
||||||
#define _REDISMODULE_SUBEVENT_SWAPDB_NEXT 0
|
#define _REDISMODULE_SUBEVENT_SWAPDB_NEXT 0
|
||||||
|
@ -1600,6 +1600,9 @@ void resetChildState() {
|
|||||||
server.stat_current_cow_bytes = 0;
|
server.stat_current_cow_bytes = 0;
|
||||||
updateDictResizePolicy();
|
updateDictResizePolicy();
|
||||||
closeChildInfoPipe();
|
closeChildInfoPipe();
|
||||||
|
moduleFireServerEvent(REDISMODULE_EVENT_FORK_CHILD,
|
||||||
|
REDISMODULE_SUBEVENT_FORK_CHILD_DIED,
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return if child type is mutual exclusive with other fork children */
|
/* Return if child type is mutual exclusive with other fork children */
|
||||||
@ -5567,6 +5570,9 @@ int redisFork(int purpose) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateDictResizePolicy();
|
updateDictResizePolicy();
|
||||||
|
moduleFireServerEvent(REDISMODULE_EVENT_FORK_CHILD,
|
||||||
|
REDISMODULE_SUBEVENT_FORK_CHILD_BORN,
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
return childpid;
|
return childpid;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user