gpdeletesystem: fix hangs on error
This commit moves some cleanup code to finally blocks to prevent
gpdeletesystem hanging on error cases.
@@ -236,12 +236,14 @@ def delete_cluster(options):
logger.warn('Warnings were generated while stopping the database.')
g_warnings_generated = True
+ try:
# From this point on we don't want ctrl-c to happen
signal.signal(signal.SIGINT, signal.SIG_IGN)
# create pool
pool = base.WorkerPool(numWorkers=options.batch_size)
+ try:
logger.info('Deleting tablespace directories...')
# getSegmentsByHostName(segments)
segmentHosts = gparray.GpArray.getSegmentsByHostName(segments).keys()
@@ -254,6 +256,7 @@ def delete_cluster(options):
pool.addCommand(cmd)
logger.info('Waiting for worker threads to delete tablespace dirs...')
+ finally:
pool.join()
pool.haltWork()
pool.joinWorkers()
@@ -261,6 +264,7 @@ def delete_cluster(options):
# create pool
pool = base.WorkerPool(numWorkers=options.batch_size)
+ try:
logger.info('Deleting segments and removing data directories...')
for segdb in segments:
segmentDataDirectory = segdb.getSegmentDataDirectory()
@@ -271,10 +275,12 @@ def delete_cluster(options):
pool.addCommand(cmd)
logger.info('Waiting for worker threads to complete...')
+ finally:
pool.join()
pool.haltWork()
pool.joinWorkers()
+ finally:
# Re-enable ctrl-c
signal.signal(signal.SIGINT, signal.default_int_handler)
