From b30398bf2a4fd189001275e78d30746c9d4520ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Villemain?= Date: Mon, 28 Mar 2011 16:26:48 +0200 Subject: [PATCH] Add --ignore-rsync-warning command line option This fix the rsync return code in case there are vanished files. Common situation are DROPed tables and TEMPorary object deletion and are handled by PostgreSQL. But as it may exist situation where an external process delete files in the PGDATA the flag is off by default. XXX 2 items : * is -I a good choice ? maybe we need to prevent future --ignore-foo and add something like : --ignore=rsync_warning -I rsync_warning * the warning message is not enough explicit with the risk involved by --force usage --- HISTORY | 2 ++ repmgr.c | 29 ++++++++++++++++++++++++----- repmgr.h | 1 + 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/HISTORY b/HISTORY index 3a6b8913..bb6ddadc 100644 --- a/HISTORY +++ b/HISTORY @@ -31,3 +31,5 @@ 1.1.0 2011-03-09 Make options -U, -R and -p not mandatory (Jaime) +X.X.X 2011-XX-XX + Add --ignore-rsync-warning (Cédric) diff --git a/repmgr.c b/repmgr.c index 18889588..432ccab8 100644 --- a/repmgr.c +++ b/repmgr.c @@ -71,7 +71,7 @@ bool need_a_node = true; bool require_password = false; /* Initialization of runtime options */ -t_runtime_options runtime_options = { "", "", "", "", "", "", DEFAULT_WAL_KEEP_SEGMENTS, false, false, "" }; +t_runtime_options runtime_options = { "", "", "", "", "", "", DEFAULT_WAL_KEEP_SEGMENTS, false, false, false, "" }; t_configuration_options options = { "", -1, "", "", "" }; static char *server_mode = NULL; @@ -91,6 +91,7 @@ main(int argc, char **argv) {"remote-user", required_argument, NULL, 'R'}, {"wal-keep-segments", required_argument, NULL, 'w'}, {"force", no_argument, NULL, 'F'}, + {"ignore-rsync-warning", no_argument, NULL, 'I'}, {"verbose", no_argument, NULL, 'v'}, {NULL, 0, NULL, 0} }; @@ -150,6 +151,9 @@ main(int argc, char **argv) case 'F': runtime_options.force = true; break; + case 'I': + runtime_options.ignore_rsync_warn = true; + break; case 'v': runtime_options.verbose = true; break; @@ -1337,6 +1341,7 @@ void help(const char *progname) printf(_(" -R, --remote-user=USERNAME database server username for rsync\n")); printf(_(" -w, --wal-keep-segments=VALUE minimum value for the GUC wal_keep_segments (default: 5000)\n")); printf(_(" -F, --force force potentially dangerous operations to happen\n")); + printf(_(" -I, --ignore-rsync-warning Ignore partial transfert warning\n")); printf(_("\n%s performs some tasks like clone a node, promote it "), progname); printf(_("or making follow another node and then exits.\n")); @@ -1475,13 +1480,27 @@ copy_remote_files(char *host, char *remote_user, char *remote_path, /* * If we are transfering a directory (ie: data directory, tablespace directories) - * then we can ignore some rsync errors, so if we get some of those errors we - * treat them as 0 + * then we can ignore some rsync warning, so if we get some of those errors we + * treat them as 0 if we have --ignore-rsync-warning commandline option set * List of ignorable rsync errors: * 24 Partial transfer due to vanished source files */ - if (is_directory && (r == 24)) - r = 0; + if ((r == 24) && is_directory) + { + if (!runtime_options.ignore_rsync_warn) + { + log_warning( _("\nrsync completed with return code 24 " + "\"Partial transfer due to vanished source files\".\n" + "This can happen because of normal operation " + "on the master server, but it may indicate an " + "issue during cloning. If you are certain no " + "changes were made to the master, try cloning " + "again using \"repmgr --force --ignore-rsync-warning\".")); + exit(ERR_BAD_RSYNC); + } + else + r = 0; + } if (r != 0) log_err(_("Can't rsync from remote file or directory (%s:%s)\n"), diff --git a/repmgr.h b/repmgr.h index c2c96fab..bd219692 100644 --- a/repmgr.h +++ b/repmgr.h @@ -55,6 +55,7 @@ typedef struct char wal_keep_segments[MAXLEN]; bool verbose; bool force; + bool ignore_rsync_warn; char masterport[MAXLEN];