MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / RM_Fork

Function RM_Fork

src/module.cpp:8056–8072  ·  view source on GitHub ↗

Create a background child process with the current frozen snaphost of the * main process where you can do some processing in the background without * affecting / freezing the traffic and no need for threads and GIL locking. * Note that Redis allows for only one concurrent fork. * When the child wants to exit, it should call RedisModule_ExitFromChild. * If the parent wants to kill the child it

Source from the content-addressed store, hash-verified

8054 * of the child, and the child process will get 0.
8055 */
8056int RM_Fork(RedisModuleForkDoneHandler cb, void *user_data) {
8057 pid_t childpid;
8058
8059 if ((childpid = redisFork(CHILD_TYPE_MODULE)) == 0) {
8060 /* Child */
8061 redisSetProcTitle("redis-module-fork");
8062 } else if (childpid == -1) {
8063 serverLog(LL_WARNING,"Can't fork for module: %s", strerror(errno));
8064 } else {
8065 /* Parent */
8066 moduleForkInfo.done_handler = cb;
8067 moduleForkInfo.done_handler_user_data = user_data;
8068 updateDictResizePolicy();
8069 serverLog(LL_VERBOSE, "Module fork started pid: %ld ", (long) childpid);
8070 }
8071 return childpid;
8072}
8073
8074/* The module is advised to call this function from the fork child once in a while,
8075 * so that it can report progress and COW memory to the parent which will be

Callers

nothing calls this directly

Calls 4

redisForkFunction · 0.85
redisSetProcTitleFunction · 0.85
serverLogFunction · 0.85
updateDictResizePolicyFunction · 0.85

Tested by

no test coverage detected