mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-25 16:16:29 +00:00
basic min_recovery_apply_delay support
This commit is contained in:
78
repmgr.c
78
repmgr.c
@@ -109,13 +109,15 @@ main(int argc, char **argv)
|
|||||||
{"force", no_argument, NULL, 'F'},
|
{"force", no_argument, NULL, 'F'},
|
||||||
{"wait", no_argument, NULL, 'W'},
|
{"wait", no_argument, NULL, 'W'},
|
||||||
{"ignore-rsync-warning", no_argument, NULL, 'I'},
|
{"ignore-rsync-warning", no_argument, NULL, 'I'},
|
||||||
|
{"min-recovery-apply-delay", required_argument, NULL, 'r'},
|
||||||
{"verbose", no_argument, NULL, 'v'},
|
{"verbose", no_argument, NULL, 'v'},
|
||||||
{NULL, 0, NULL, 0}
|
{NULL, 0, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
int optindex;
|
int optindex;
|
||||||
int c;
|
int c, targ;
|
||||||
int action = NO_ACTION;
|
int action = NO_ACTION;
|
||||||
|
char *ptr = NULL;
|
||||||
|
|
||||||
progname = get_progname(argv[0]);
|
progname = get_progname(argv[0]);
|
||||||
|
|
||||||
@@ -134,7 +136,7 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, "d:h:p:U:D:l:f:R:w:k:FWIv", long_options,
|
while ((c = getopt_long(argc, argv, "d:h:p:U:D:l:f:R:w:k:FWIvr:", long_options,
|
||||||
&optindex)) != -1)
|
&optindex)) != -1)
|
||||||
{
|
{
|
||||||
switch (c)
|
switch (c)
|
||||||
@@ -184,6 +186,25 @@ main(int argc, char **argv)
|
|||||||
case 'I':
|
case 'I':
|
||||||
runtime_options.ignore_rsync_warn = true;
|
runtime_options.ignore_rsync_warn = true;
|
||||||
break;
|
break;
|
||||||
|
case 'r':
|
||||||
|
targ = strtol(optarg, &ptr, 10);
|
||||||
|
|
||||||
|
if(targ < 0) {
|
||||||
|
usage();
|
||||||
|
exit(ERR_BAD_CONFIG);
|
||||||
|
}
|
||||||
|
if(ptr && *ptr) {
|
||||||
|
if(strcmp(ptr, "ms") != 0 && strcmp(ptr, "s") != 0 &&
|
||||||
|
strcmp(ptr, "min") != 0 && strcmp(ptr, "h") != 0 &&
|
||||||
|
strcmp(ptr, "d") != 0)
|
||||||
|
{
|
||||||
|
usage();
|
||||||
|
exit(ERR_BAD_CONFIG);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
strncpy(runtime_options.min_recovery_apply_delay, optarg, MAXLEN);
|
||||||
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
runtime_options.verbose = true;
|
runtime_options.verbose = true;
|
||||||
break;
|
break;
|
||||||
@@ -1853,6 +1874,7 @@ help(const char *progname)
|
|||||||
printf(_(" -F, --force force potentially dangerous operations\n" \
|
printf(_(" -F, --force force potentially dangerous operations\n" \
|
||||||
" to happen\n"));
|
" to happen\n"));
|
||||||
printf(_(" -W, --wait wait for a master to appear\n"));
|
printf(_(" -W, --wait wait for a master to appear\n"));
|
||||||
|
printf(_(" -r, --min-recovery-apply-delay=VALUE enable recovery time delay, value has to be a valid time atom (e.g. 5min)"));
|
||||||
|
|
||||||
printf(_("\n%s performs some tasks like clone a node, promote it or making follow\n"), progname);
|
printf(_("\n%s performs some tasks like clone a node, promote it or making follow\n"), progname);
|
||||||
printf(_("another node and then exits.\n\n"));
|
printf(_("another node and then exits.\n\n"));
|
||||||
@@ -1905,6 +1927,19 @@ create_recovery_file(const char *data_dir)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(*runtime_options.min_recovery_apply_delay)
|
||||||
|
{
|
||||||
|
maxlen_snprintf(line, "\nmin_recovery_apply_delay = %s\n",
|
||||||
|
runtime_options.min_recovery_apply_delay);
|
||||||
|
|
||||||
|
if (fputs(line, recovery_file) == EOF)
|
||||||
|
{
|
||||||
|
log_err(_("recovery file could not be written, it could be necessary to create it manually\n"));
|
||||||
|
fclose(recovery_file);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* FreeFile(recovery_file); */
|
/* FreeFile(recovery_file); */
|
||||||
fclose(recovery_file);
|
fclose(recovery_file);
|
||||||
|
|
||||||
@@ -1915,25 +1950,34 @@ static int
|
|||||||
test_ssh_connection(char *host, char *remote_user)
|
test_ssh_connection(char *host, char *remote_user)
|
||||||
{
|
{
|
||||||
char script[MAXLEN];
|
char script[MAXLEN];
|
||||||
int r;
|
int r = 1, i;
|
||||||
|
|
||||||
/* On some OS, true is located in a different place than in Linux */
|
/* On some OS, true is located in a different place than in Linux
|
||||||
#ifdef __FreeBSD__
|
* we have to try them all until all alternatives are gone or we
|
||||||
#define TRUEBIN_PATH "/usr/bin/true"
|
* found `true' because the target OS may differ from the source
|
||||||
#else
|
* OS
|
||||||
#define TRUEBIN_PATH "/bin/true"
|
*/
|
||||||
#endif
|
const char *truebin_pathes[] = {
|
||||||
|
"/bin/true",
|
||||||
|
"/usr/bin/true",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
/* Check if we have ssh connectivity to host before trying to rsync */
|
/* Check if we have ssh connectivity to host before trying to rsync */
|
||||||
if (!remote_user[0])
|
for(i = 0; truebin_pathes[i] && r != 0; ++i)
|
||||||
maxlen_snprintf(script, "ssh -o Batchmode=yes %s %s %s",
|
{
|
||||||
options.ssh_options, host, TRUEBIN_PATH);
|
if (!remote_user[0])
|
||||||
else
|
maxlen_snprintf(script, "ssh -o Batchmode=yes %s %s %s",
|
||||||
maxlen_snprintf(script, "ssh -o Batchmode=yes %s %s -l %s %s",
|
options.ssh_options, host, truebin_pathes[i]);
|
||||||
options.ssh_options, host, remote_user, TRUEBIN_PATH);
|
else
|
||||||
|
maxlen_snprintf(script, "ssh -o Batchmode=yes %s %s -l %s %s",
|
||||||
|
options.ssh_options, host, remote_user,
|
||||||
|
truebin_pathes[i]);
|
||||||
|
|
||||||
|
log_debug(_("command is: %s\n"), script);
|
||||||
|
r = system(script);
|
||||||
|
}
|
||||||
|
|
||||||
log_debug(_("command is: %s\n"), script);
|
|
||||||
r = system(script);
|
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
log_info(_("Can not connect to the remote host (%s)\n"), host);
|
log_info(_("Can not connect to the remote host (%s)\n"), host);
|
||||||
return r;
|
return r;
|
||||||
|
|||||||
4
repmgr.h
4
repmgr.h
@@ -67,8 +67,10 @@ typedef struct
|
|||||||
|
|
||||||
/* parameter used by CLUSTER CLEANUP */
|
/* parameter used by CLUSTER CLEANUP */
|
||||||
int keep_history;
|
int keep_history;
|
||||||
|
|
||||||
|
char min_recovery_apply_delay[MAXLEN];
|
||||||
} t_runtime_options;
|
} t_runtime_options;
|
||||||
|
|
||||||
#define T_RUNTIME_OPTIONS_INITIALIZER { "", "", "", "", "", "", DEFAULT_WAL_KEEP_SEGMENTS, false, false, false, false, "", "", 0 }
|
#define T_RUNTIME_OPTIONS_INITIALIZER { "", "", "", "", "", "", DEFAULT_WAL_KEEP_SEGMENTS, false, false, false, false, "", "", 0, "" }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user