Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
01cbf17b
Unverified
Commit
01cbf17b
authored
Jan 28, 2021
by
guybe7
Committed by
GitHub
Jan 28, 2021
Browse files
Modules: Add event for fork child birth and termination (#8289)
Useful to avoid doing background jobs that can cause excessive COW
parent
a16739a3
Changes
3
Show whitespace changes
Inline
Side-by-side
src/module.c
View file @
01cbf17b
...
@@ -7899,6 +7899,14 @@ void ModuleForkDoneHandler(int exitcode, int bysignal) {
...
@@ -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) {
...
@@ -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;
}
}
...
...
src/redismodule.h
View file @
01cbf17b
...
@@ -230,9 +230,8 @@ typedef uint64_t RedisModuleTimerID;
...
@@ -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
...
@@ -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
...
@@ -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
...
...
src/server.c
View file @
01cbf17b
...
@@ -1600,6 +1600,9 @@ void resetChildState() {
...
@@ -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) {
...
@@ -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
;
}
}
...
...
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