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

Function sentinelScheduleScriptExecution

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

Source from the content-addressed store, hash-verified

777
778#define SENTINEL_SCRIPT_MAX_ARGS 16
779void sentinelScheduleScriptExecution(char *path, ...) {
780 va_list ap;
781 char *argv[SENTINEL_SCRIPT_MAX_ARGS+1];
782 int argc = 1;
783 sentinelScriptJob *sj;
784
785 va_start(ap, path);
786 while(argc < SENTINEL_SCRIPT_MAX_ARGS) {
787 argv[argc] = va_arg(ap,char*);
788 if (!argv[argc]) break;
789 argv[argc] = sdsnew(argv[argc]); /* Copy the string. */
790 argc++;
791 }
792 va_end(ap);
793 argv[0] = sdsnew(path);
794
795 sj = zmalloc(sizeof(*sj));
796 sj->flags = SENTINEL_SCRIPT_NONE;
797 sj->retry_num = 0;
798 sj->argv = zmalloc(sizeof(char*)*(argc+1));
799 sj->start_time = 0;
800 sj->pid = 0;
801 memcpy(sj->argv,argv,sizeof(char*)*(argc+1));
802
803 listAddNodeTail(sentinel.scripts_queue,sj);
804
805 /* Remove the oldest non running script if we already hit the limit. */
806 if (listLength(sentinel.scripts_queue) > SENTINEL_SCRIPT_MAX_QUEUE) {
807 listNode *ln;
808 listIter li;
809
810 listRewind(sentinel.scripts_queue,&li);
811 while ((ln = listNext(&li)) != NULL) {
812 sj = ln->value;
813
814 if (sj->flags & SENTINEL_SCRIPT_RUNNING) continue;
815 /* The first node is the oldest as we add on tail. */
816 listDelNode(sentinel.scripts_queue,ln);
817 sentinelReleaseScriptJob(sj);
818 break;
819 }
820 serverAssert(listLength(sentinel.scripts_queue) <=
821 SENTINEL_SCRIPT_MAX_QUEUE);
822 }
823}
824
825/* Lookup a script in the scripts queue via pid, and returns the list node
826 * (so that we can easily remove it from the queue if needed). */

Callers 2

sentinelEventFunction · 0.85

Calls 8

sdsnewFunction · 0.85
zmallocFunction · 0.85
listAddNodeTailFunction · 0.85
listRewindFunction · 0.85
listNextFunction · 0.85
listDelNodeFunction · 0.85
sentinelReleaseScriptJobFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected