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

Function sentinelCollectTerminatedScripts

app/redis-6.2.6/src/sentinel.c:908–951  ·  view source on GitHub ↗

Check for scripts that terminated, and remove them from the queue if the * script terminated successfully. If instead the script was terminated by * a signal, or returned exit code "1", it is scheduled to run again if * the max number of retries did not already elapsed. */

Source from the content-addressed store, hash-verified

906 * a signal, or returned exit code "1", it is scheduled to run again if
907 * the max number of retries did not already elapsed. */
908void sentinelCollectTerminatedScripts(void) {
909 int statloc;
910 pid_t pid;
911
912 while ((pid = waitpid(-1, &statloc, WNOHANG)) > 0) {
913 int exitcode = WEXITSTATUS(statloc);
914 int bysignal = 0;
915 listNode *ln;
916 sentinelScriptJob *sj;
917
918 if (WIFSIGNALED(statloc)) bysignal = WTERMSIG(statloc);
919 sentinelEvent(LL_DEBUG,"-script-child",NULL,"%ld %d %d",
920 (long)pid, exitcode, bysignal);
921
922 ln = sentinelGetScriptListNodeByPid(pid);
923 if (ln == NULL) {
924 serverLog(LL_WARNING,"waitpid() returned a pid (%ld) we can't find in our scripts execution queue!", (long)pid);
925 continue;
926 }
927 sj = ln->value;
928
929 /* If the script was terminated by a signal or returns an
930 * exit code of "1" (that means: please retry), we reschedule it
931 * if the max number of retries is not already reached. */
932 if ((bysignal || exitcode == 1) &&
933 sj->retry_num != SENTINEL_SCRIPT_MAX_RETRY)
934 {
935 sj->flags &= ~SENTINEL_SCRIPT_RUNNING;
936 sj->pid = 0;
937 sj->start_time = mstime() +
938 sentinelScriptRetryDelay(sj->retry_num);
939 } else {
940 /* Otherwise let's remove the script, but log the event if the
941 * execution did not terminated in the best of the ways. */
942 if (bysignal || exitcode != 0) {
943 sentinelEvent(LL_WARNING,"-script-error",NULL,
944 "%s %d %d", sj->argv[0], bysignal, exitcode);
945 }
946 listDelNode(sentinel.scripts_queue,ln);
947 sentinelReleaseScriptJob(sj);
948 }
949 sentinel.running_scripts--;
950 }
951}
952
953/* Kill scripts in timeout, they'll be collected by the
954 * sentinelCollectTerminatedScripts() function. */

Callers 1

sentinelTimerFunction · 0.85

Calls 6

sentinelEventFunction · 0.85
sentinelScriptRetryDelayFunction · 0.85
listDelNodeFunction · 0.85
sentinelReleaseScriptJobFunction · 0.85
mstimeFunction · 0.70

Tested by

no test coverage detected