Add max_retries flag for gpload
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.
@@ -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,
