From 1bb52ea807dbbd2f457009a08a710d0c38feca93 Mon Sep 17 00:00:00 2001 From: "Huiliang.liu" Date: Fri, 28 Feb 2020 17:13:33 +0800 Subject: [PATCH] Add max_retries flag for gpload (#9606) Add max_retries flag for gpload. It indicates the max times on connecting to GPDB timed out. max_retries default value is 0 which means no retry. If max_retries is -1 or other negative value, it means retry forever. Test has been done manually. ( cherry pick from master commit: b891b85ba075c0be22c6215f82923e6d950c062c) --- gpMgmt/bin/gpload.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/gpMgmt/bin/gpload.py b/gpMgmt/bin/gpload.py index 7f18cd01aa..e88e1fc6a7 100755 --- a/gpMgmt/bin/gpload.py +++ b/gpMgmt/bin/gpload.py @@ -18,6 +18,7 @@ Options: -l logfile: log output to logfile --no_auto_trans: do not wrap gpload in transaction --gpfdist_timeout timeout: gpfdist timeout value + --max_retries retry_times: max retry times on gpdb connection timed out. 0 means disabled, -1 means forever --version: print version number and exit -?: help ''' @@ -1157,6 +1158,7 @@ class gpload: self.startTimestamp = time.time() self.error_table = False self.gpdb_version = "" + self.options.max_retries = 0 seenv = False seenq = False @@ -1217,6 +1219,9 @@ class gpload: elif argv[0]=='-f': configFilename = argv[1] argv = argv[2:] + elif argv[0]=='--max_retries': + self.options.max_retries = int(argv[1]) + argv = argv[2:] elif argv[0]=='--no_auto_trans': self.options.no_auto_trans = True argv = argv[1:] @@ -1841,6 +1846,18 @@ class gpload: if recurse > 10: self.log(self.ERROR, "too many login attempt failures") self.setup_connection(recurse) + elif errorMessage.find("Connection timed out") != -1 and self.options.max_retries != 0: + recurse += 1 + if self.options.max_retries > 0: + if recurse > self.options.max_retries: # retry failed + self.log(self.ERROR, "could not connect to database after retry %d times, " \ + "error message:\n %s" % (recurse-1, errorMessage)) + else: + self.log(self.INFO, "retry to connect to database, %d of %d times" % (recurse, + self.options.max_retries)) + else: # max_retries < 0, retry forever + self.log(self.INFO, "retry to connect to database.") + self.setup_connection(recurse) else: self.log(self.ERROR, "could not connect to database: %s. Is " \ "the Greenplum Database running on port %i?" % (errorMessage, -- GitLab