From 7aa82cc2670345fea0f4c9c779706e077b9b28ac Mon Sep 17 00:00:00 2001 From: wangrui_rui <1159843747@qq.com> Date: Wed, 24 Feb 2021 11:03:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?gs=5Fbasebackup=20timeout=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=20&&=20=E6=96=AD=E8=A8=80=E4=BF=A1=E6=81=AF=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bin/pg_basebackup/pg_basebackup.cpp | 27 +++++++++++++++++++++---- src/bin/pg_basebackup/streamutil.cpp | 3 ++- src/bin/pg_basebackup/streamutil.h | 1 + 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/bin/pg_basebackup/pg_basebackup.cpp b/src/bin/pg_basebackup/pg_basebackup.cpp index 252eedb8fc..c1bd968f21 100644 --- a/src/bin/pg_basebackup/pg_basebackup.cpp +++ b/src/bin/pg_basebackup/pg_basebackup.cpp @@ -205,6 +205,8 @@ static void usage(void) printf(_(" -F, --format=p|t output format (plain (default), tar)\n")); printf(_(" -T, --tablespace-mapping=OLDDIR=NEWDIR\n" " relocate tablespace in OLDDIR to NEWDIR\n")); + printf(_(" -t, --rw_timeout=TIME rw_timeout limit\n" + " the value range from 60 to 3600 (s) (default 120s)\n")); printf(_(" -x, --xlog include required WAL files in backup (fetch mode)\n")); printf(_(" -X, --xlog-method=fetch|stream\n" " include required WAL files with specified method\n")); @@ -1855,7 +1857,8 @@ static int GsBaseBackup(int argc, char** argv) {"format", required_argument, NULL, 'F'}, {"checkpoint", required_argument, NULL, 'c'}, {"tablespace-mapping", required_argument, NULL, 'T'}, - {"xlog", no_argument, NULL, 'x'}, + {"rw_timeout", required_argument, NULL, 't'}, + {"xlog", no_argument, NULL, 'x'}, {"xlog-method", required_argument, NULL, 'X'}, {"gzip", no_argument, NULL, 'z'}, {"compress", required_argument, NULL, 'Z'}, @@ -1884,7 +1887,7 @@ static int GsBaseBackup(int argc, char** argv) } } - while ((c = getopt_long(argc, argv, "D:l:c:h:p:U:s:X:F:T:Z:wWvPxz", long_options, &option_index)) != -1) { + while ((c = getopt_long(argc, argv, "D:l:c:h:p:U:s:X:F:T:t:Z:wWvPxz", long_options, &option_index)) != -1) { switch (c) { case 'D': { GS_FREE(basedir); @@ -1918,7 +1921,23 @@ static int GsBaseBackup(int argc, char** argv) } tablespace_list_append(optarg); break; - case 'x': + case 't': { + /* set length limit for preventing para out of int range */ + if (strspn(optarg, "0123456789") != strlen(optarg) || strlen(optarg) > 4) { + fprintf(stderr, _("%s: invalid value:%s\n"), progname, optarg); + exit(1); + } + int baseBackupPara = atoi(optarg); + + /* the timeout range is between 1min and 60mins */ + if (baseBackupPara < 60 || baseBackupPara > 3600) { + fprintf(stderr, _("%s: invalid value:%s\n"), progname, optarg); + exit(1); + } + baseBackupTimeout = xstrdup(optarg); + break; + } + case 'x': streamwal = false; break; case 'X': @@ -2067,7 +2086,7 @@ static int GsBaseBackup(int argc, char** argv) free_basebackup(); - fprintf(stderr, _("%s: base backup successfully\n"), progname); + fprintf(stderr, _("%s: base backup successfully\n"), progname); return 0; } diff --git a/src/bin/pg_basebackup/streamutil.cpp b/src/bin/pg_basebackup/streamutil.cpp index b86c60027b..561759584e 100644 --- a/src/bin/pg_basebackup/streamutil.cpp +++ b/src/bin/pg_basebackup/streamutil.cpp @@ -31,6 +31,7 @@ char* dbhost = NULL; char* dbuser = NULL; char* dbport = NULL; char* dbname = NULL; +char* baseBackupTimeout = "120"; /* default value */ int dbgetpassword = 0; /* 0=auto, -1=never, 1=always */ static char* dbpassword = NULL; PGconn* conn = NULL; @@ -165,7 +166,7 @@ PGconn* GetConnection(void) keywords[3] = "connect_timeout"; /* param connect_time */ values[3] = "120"; /* default connect_time */ keywords[4] = "rw_timeout"; /* param rw_timeout */ - values[4] = "120"; /* default rw_timeout */ + values[4] = baseBackupTimeout; /* value rw_timeout */ int i = 5; if (dbhost != NULL) { keywords[i] = "host"; diff --git a/src/bin/pg_basebackup/streamutil.h b/src/bin/pg_basebackup/streamutil.h index 0b12267530..ecf67a8bfc 100644 --- a/src/bin/pg_basebackup/streamutil.h +++ b/src/bin/pg_basebackup/streamutil.h @@ -8,6 +8,7 @@ extern char* dbhost; extern char* dbuser; extern char* dbport; extern char* dbname; +extern char* baseBackupTimeout; extern int dbgetpassword; extern char* replication_slot; extern int standby_message_timeout; -- Gitee From fa4284e46fa00a6c1ae7694f0272d2e946ddd1f8 Mon Sep 17 00:00:00 2001 From: wangrui_rui <1159843747@qq.com> Date: Fri, 26 Feb 2021 15:06:07 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=BC=96=E7=A0=81=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bin/pg_basebackup/pg_basebackup.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/pg_basebackup/pg_basebackup.cpp b/src/bin/pg_basebackup/pg_basebackup.cpp index c1bd968f21..23fe7e6f99 100644 --- a/src/bin/pg_basebackup/pg_basebackup.cpp +++ b/src/bin/pg_basebackup/pg_basebackup.cpp @@ -1936,7 +1936,7 @@ static int GsBaseBackup(int argc, char** argv) } baseBackupTimeout = xstrdup(optarg); break; - } + } case 'x': streamwal = false; break; -- Gitee