summaryrefslogtreecommitdiff
path: root/src/module.c
diff options
context:
space:
mode:
authorYaacovHazan <yaacov.hazan@redislabs.com>2020-12-16 15:14:04 +0200
committerOran Agra <oran@redislabs.com>2021-01-07 16:14:29 +0200
commitf9dacf8aacc8af7fdcb41bc9f927b42390557f7d (patch)
treec334d3faf4dc8174f611a60e5afaf33df3d9e66b /src/module.c
parentb5029dfdadb387ba8a3b8517ec4a7117bf4070f4 (diff)
downloadredis-f9dacf8aacc8af7fdcb41bc9f927b42390557f7d.tar.gz
Refactory fork child related infra, Unify child pid
This is a refactory commit, isn't suppose to have any actual impact. it does the following: - keep just one server struct fork child pid variable instead of 3 - have one server struct variable indicating the purpose of the current fork child. - redisFork is now responsible of updating the server struct with the pid, which means it can be the one that calls updateDictResizePolicy - move child info pipe handling into redisFork instead of having them repeated outside - there are two classes of fork purposes, mutually exclusive group (AOF, RDB, Module), and one that can create several forks to coexist in parallel (LDB, but maybe Modules some day too, Module API allows for that). - minor fix to killRDBChild: unlike killAppendOnlyChild and TerminateModuleForkChild, the killRDBChild doesn't clear the pid variable or call wait4, so checkChildrenDone does the cleanup for it. This commit removes the explicit calls to rdbRemoveTempFile, closeChildInfoPipe, updateDictResizePolicy, which didn't do any harm, but where unnecessary.
Diffstat (limited to 'src/module.c')
-rw-r--r--src/module.c27
1 files changed, 9 insertions, 18 deletions
diff --git a/src/module.c b/src/module.c
index 56ff63869..2de6bee2f 100644
--- a/src/module.c
+++ b/src/module.c
@@ -7065,23 +7065,16 @@ int RM_ScanKey(RedisModuleKey *key, RedisModuleScanCursor *cursor, RedisModuleSc
*/
int RM_Fork(RedisModuleForkDoneHandler cb, void *user_data) {
pid_t childpid;
- if (hasActiveChildProcess()) {
- return -1;
- }
- openChildInfoPipe();
if ((childpid = redisFork(CHILD_TYPE_MODULE)) == 0) {
/* Child */
redisSetProcTitle("redis-module-fork");
} else if (childpid == -1) {
- closeChildInfoPipe();
serverLog(LL_WARNING,"Can't fork for module: %s", strerror(errno));
} else {
/* Parent */
- server.module_child_pid = childpid;
moduleForkInfo.done_handler = cb;
moduleForkInfo.done_handler_user_data = user_data;
- updateDictResizePolicy();
serverLog(LL_VERBOSE, "Module fork started pid: %ld ", (long) childpid);
}
return childpid;
@@ -7101,22 +7094,20 @@ int RM_ExitFromChild(int retcode) {
* child or the pid does not match, return C_ERR without doing anything. */
int TerminateModuleForkChild(int child_pid, int wait) {
/* Module child should be active and pid should match. */
- if (server.module_child_pid == -1 ||
- server.module_child_pid != child_pid) return C_ERR;
+ if (server.child_type != CHILD_TYPE_MODULE ||
+ server.child_pid != child_pid) return C_ERR;
int statloc;
serverLog(LL_VERBOSE,"Killing running module fork child: %ld",
- (long) server.module_child_pid);
- if (kill(server.module_child_pid,SIGUSR1) != -1 && wait) {
- while(wait4(server.module_child_pid,&statloc,0,NULL) !=
- server.module_child_pid);
+ (long) server.child_pid);
+ if (kill(server.child_pid,SIGUSR1) != -1 && wait) {
+ while(wait4(server.child_pid,&statloc,0,NULL) !=
+ server.child_pid);
}
/* Reset the buffer accumulating changes while the child saves. */
- server.module_child_pid = -1;
+ resetChildState();
moduleForkInfo.done_handler = NULL;
moduleForkInfo.done_handler_user_data = NULL;
- closeChildInfoPipe();
- updateDictResizePolicy();
return C_OK;
}
@@ -7133,12 +7124,12 @@ int RM_KillForkChild(int child_pid) {
void ModuleForkDoneHandler(int exitcode, int bysignal) {
serverLog(LL_NOTICE,
"Module fork exited pid: %ld, retcode: %d, bysignal: %d",
- (long) server.module_child_pid, exitcode, bysignal);
+ (long) server.child_pid, exitcode, bysignal);
if (moduleForkInfo.done_handler) {
moduleForkInfo.done_handler(exitcode, bysignal,
moduleForkInfo.done_handler_user_data);
}
- server.module_child_pid = -1;
+
moduleForkInfo.done_handler = NULL;
moduleForkInfo.done_handler_user_data = NULL;
}