Reorder cleanup and gracefully wait for flushes

This commit is contained in:
Joshua Boniface 2020-04-08 21:58:19 -04:00
parent b3a75d8069
commit fee1c7dd6c
1 changed files with 10 additions and 5 deletions

View File

@ -547,13 +547,18 @@ zk_conn.add_listener(zk_listener)
def cleanup(): def cleanup():
global zk_conn, update_timer, d_domain global zk_conn, update_timer, d_domain
logger.out('Performing final keepalive update', state='s') logger.out('Terminating pvcnoded and cleaning up', state='s')
update_zookeeper()
# Set shutdown state in Zookeeper # Set shutdown state in Zookeeper
zkhandler.writedata(zk_conn, { '/nodes/{}/daemonstate'.format(myhostname): 'shutdown' }) zkhandler.writedata(zk_conn, { '/nodes/{}/daemonstate'.format(myhostname): 'shutdown' })
logger.out('Terminating pvcnoded and cleaning up', state='s') # Waiting for any flushes to complete
logger.out('Wait for any flushes', state='s')
while this_node.flush_thread is not None:
time.sleep(0.5)
logger.out('Performing final keepalive update', state='s')
update_zookeeper()
# Stop keepalive thread # Stop keepalive thread
try: try:
@ -574,7 +579,7 @@ def cleanup():
except AttributeError as e: except AttributeError as e:
pass pass
# Force into secondary network state if needed # Force into secondary coordinator state if needed
try: try:
if this_node.router_state == 'primary': if this_node.router_state == 'primary':
is_primary = True is_primary = True
@ -583,7 +588,7 @@ def cleanup():
}) })
logger.out('Waiting for primary migration', state='s') logger.out('Waiting for primary migration', state='s')
while this_node.router_state != 'secondary': while this_node.router_state != 'secondary':
time.sleep(1) time.sleep(0.5)
except: except:
pass pass