MCPcopy Create free account
hub / github.com/F-Stack/f-stack / redisFork

Function redisFork

app/redis-6.2.6/src/server.c:5859–5909  ·  view source on GitHub ↗

purpose is one of CHILD_TYPE_ types */

Source from the content-addressed store, hash-verified

5857
5858/* purpose is one of CHILD_TYPE_ types */
5859int redisFork(int purpose) {
5860 if (isMutuallyExclusiveChildType(purpose)) {
5861 if (hasActiveChildProcess())
5862 return -1;
5863
5864 openChildInfoPipe();
5865 }
5866
5867 int childpid;
5868 long long start = ustime();
5869 if ((childpid = fork()) == 0) {
5870 /* Child */
5871 server.in_fork_child = purpose;
5872 setOOMScoreAdj(CONFIG_OOM_BGCHILD);
5873 setupChildSignalHandlers();
5874 closeChildUnusedResourceAfterFork();
5875 } else {
5876 /* Parent */
5877 server.stat_total_forks++;
5878 server.stat_fork_time = ustime()-start;
5879 server.stat_fork_rate = (double) zmalloc_used_memory() * 1000000 / server.stat_fork_time / (1024*1024*1024); /* GB per second. */
5880 latencyAddSampleIfNeeded("fork",server.stat_fork_time/1000);
5881 if (childpid == -1) {
5882 if (isMutuallyExclusiveChildType(purpose)) closeChildInfoPipe();
5883 return -1;
5884 }
5885
5886 /* The child_pid and child_type are only for mutual exclusive children.
5887 * other child types should handle and store their pid's in dedicated variables.
5888 *
5889 * Today, we allows CHILD_TYPE_LDB to run in parallel with the other fork types:
5890 * - it isn't used for production, so it will not make the server be less efficient
5891 * - used for debugging, and we don't want to block it from running while other
5892 * forks are running (like RDB and AOF) */
5893 if (isMutuallyExclusiveChildType(purpose)) {
5894 server.child_pid = childpid;
5895 server.child_type = purpose;
5896 server.stat_current_cow_bytes = 0;
5897 server.stat_current_cow_updated = 0;
5898 server.stat_current_save_keys_processed = 0;
5899 server.stat_module_progress = 0;
5900 server.stat_current_save_keys_total = dbTotalServerKeyCount();
5901 }
5902
5903 updateDictResizePolicy();
5904 moduleFireServerEvent(REDISMODULE_EVENT_FORK_CHILD,
5905 REDISMODULE_SUBEVENT_FORK_CHILD_BORN,
5906 NULL);
5907 }
5908 return childpid;
5909}
5910
5911void sendChildCowInfo(childInfoType info_type, char *pname) {
5912 sendChildInfoGeneric(info_type, 0, -1, pname);

Callers 5

ldbStartSessionFunction · 0.85
rdbSaveBackgroundFunction · 0.85
rdbSaveToSlavesSocketsFunction · 0.85
RM_ForkFunction · 0.85

Calls 12

hasActiveChildProcessFunction · 0.85
openChildInfoPipeFunction · 0.85
setOOMScoreAdjFunction · 0.85
setupChildSignalHandlersFunction · 0.85
zmalloc_used_memoryFunction · 0.85
closeChildInfoPipeFunction · 0.85
dbTotalServerKeyCountFunction · 0.85
updateDictResizePolicyFunction · 0.85
moduleFireServerEventFunction · 0.85
ustimeFunction · 0.70

Tested by

no test coverage detected