Improve fence locking; use consistent ZK lock names

This commit is contained in:
Joshua Boniface 2018-11-20 21:21:23 -05:00
parent 3ff4e9da29
commit 52a9a0e075
1 changed files with 42 additions and 38 deletions

View File

@ -682,8 +682,8 @@ def cmd(data, stat, event=''):
node, device, weight = args.split(',') node, device, weight = args.split(',')
if node == this_node.name: if node == this_node.name:
# Lock the command queue # Lock the command queue
lock = zkhandler.writelock(zk_conn, '/ceph/cmd') zk_lock = zkhandler.writelock(zk_conn, '/ceph/cmd')
with lock: with zk_lock:
# Add the OSD # Add the OSD
result = CephInstance.add_osd(zk_conn, logger, node, device, weight) result = CephInstance.add_osd(zk_conn, logger, node, device, weight)
# Command succeeded # Command succeeded
@ -703,8 +703,8 @@ def cmd(data, stat, event=''):
# Verify osd_id is in the list # Verify osd_id is in the list
if d_osd[osd_id] and d_osd[osd_id].node == this_node.name: if d_osd[osd_id] and d_osd[osd_id].node == this_node.name:
# Lock the command queue # Lock the command queue
lock = zkhandler.writelock(zk_conn, '/ceph/cmd') zk_lock = zkhandler.writelock(zk_conn, '/ceph/cmd')
with lock: with zk_lock:
# Remove the OSD # Remove the OSD
result = CephInstance.remove_osd(zk_conn, logger, osd_id, d_osd[osd_id]) result = CephInstance.remove_osd(zk_conn, logger, osd_id, d_osd[osd_id])
# Command succeeded # Command succeeded
@ -724,8 +724,8 @@ def cmd(data, stat, event=''):
# Verify osd_id is in the list # Verify osd_id is in the list
if d_osd[osd_id] and d_osd[osd_id].node == this_node.name: if d_osd[osd_id] and d_osd[osd_id].node == this_node.name:
# Lock the command queue # Lock the command queue
lock = zkhandler.writelock(zk_conn, '/ceph/cmd') zk_lock = zkhandler.writelock(zk_conn, '/ceph/cmd')
with lock: with zk_lock:
# Online the OSD # Online the OSD
result = CephInstance.in_osd(zk_conn, logger, osd_id) result = CephInstance.in_osd(zk_conn, logger, osd_id)
# Command succeeded # Command succeeded
@ -745,8 +745,8 @@ def cmd(data, stat, event=''):
# Verify osd_id is in the list # Verify osd_id is in the list
if d_osd[osd_id] and d_osd[osd_id].node == this_node.name: if d_osd[osd_id] and d_osd[osd_id].node == this_node.name:
# Lock the command queue # Lock the command queue
lock = zkhandler.writelock(zk_conn, '/ceph/cmd') zk_lock = zkhandler.writelock(zk_conn, '/ceph/cmd')
with lock: with zk_lock:
# Offline the OSD # Offline the OSD
result = CephInstance.out_osd(zk_conn, logger, osd_id) result = CephInstance.out_osd(zk_conn, logger, osd_id)
# Command succeeded # Command succeeded
@ -765,8 +765,8 @@ def cmd(data, stat, event=''):
if this_node.router_state == 'primary': if this_node.router_state == 'primary':
# Lock the command queue # Lock the command queue
lock = zkhandler.writelock(zk_conn, '/ceph/cmd') zk_lock = zkhandler.writelock(zk_conn, '/ceph/cmd')
with lock: with zk_lock:
# Set the property # Set the property
result = CephInstance.set_property(zk_conn, logger, option) result = CephInstance.set_property(zk_conn, logger, option)
# Command succeeded # Command succeeded
@ -785,8 +785,8 @@ def cmd(data, stat, event=''):
if this_node.router_state == 'primary': if this_node.router_state == 'primary':
# Lock the command queue # Lock the command queue
lock = zkhandler.writelock(zk_conn, '/ceph/cmd') zk_lock = zkhandler.writelock(zk_conn, '/ceph/cmd')
with lock: with zk_lock:
# Unset the property # Unset the property
result = CephInstance.unset_property(zk_conn, logger, option) result = CephInstance.unset_property(zk_conn, logger, option)
# Command succeeded # Command succeeded
@ -805,8 +805,8 @@ def cmd(data, stat, event=''):
name, pgs = args.split(',') name, pgs = args.split(',')
if this_node.router_state == 'primary': if this_node.router_state == 'primary':
# Lock the command queue # Lock the command queue
lock = zkhandler.writelock(zk_conn, '/ceph/cmd') zk_lock = zkhandler.writelock(zk_conn, '/ceph/cmd')
with lock: with zk_lock:
# Add the pool # Add the pool
result = CephInstance.add_pool(zk_conn, logger, name, pgs) result = CephInstance.add_pool(zk_conn, logger, name, pgs)
# Command succeeded # Command succeeded
@ -825,8 +825,8 @@ def cmd(data, stat, event=''):
if this_node.router_state == 'primary': if this_node.router_state == 'primary':
# Lock the command queue # Lock the command queue
lock = zkhandler.writelock(zk_conn, '/ceph/cmd') zk_lock = zkhandler.writelock(zk_conn, '/ceph/cmd')
with lock: with zk_lock:
# Remove the pool # Remove the pool
result = CephInstance.remove_pool(zk_conn, logger, name) result = CephInstance.remove_pool(zk_conn, logger, name)
# Command succeeded # Command succeeded
@ -1088,10 +1088,8 @@ def update_zookeeper():
# Close the Libvirt connection # Close the Libvirt connection
lv_conn.close() lv_conn.close()
# Update our local node lists # Look for dead nodes and fence them
flushed_node_list = [] if config['daemon_mode'] == 'coordinator':
active_node_list = []
inactive_node_list = []
for node_name in d_node: for node_name in d_node:
try: try:
node_daemon_state = zkhandler.readdata(zk_conn, '/nodes/{}/daemonstate'.format(node_name)) node_daemon_state = zkhandler.readdata(zk_conn, '/nodes/{}/daemonstate'.format(node_name))
@ -1108,9 +1106,15 @@ def update_zookeeper():
node_deadtime = int(time.time()) - ( int(config['keepalive_interval']) * int(config['fence_intervals']) ) node_deadtime = int(time.time()) - ( int(config['keepalive_interval']) * int(config['fence_intervals']) )
if node_keepalive < node_deadtime and node_daemon_state == 'run': if node_keepalive < node_deadtime and node_daemon_state == 'run':
logger.out('Node {} seems dead - starting monitor for fencing'.format(node_name), state='w') logger.out('Node {} seems dead - starting monitor for fencing'.format(node_name), state='w')
zkhandler.writedata(zk_conn, { '/nodes/{}/daemonstate'.format(node_name): 'dead' }) zk_lock = zkhandler.writelock(zk_conn, '/nodes/{}/daemonstate')
with zk_lock:
# Ensures that, if we lost the lock race and come out of waiting,
# we won't try to trigger our own fence thread.
if zkhandler.readdata(zk_conn, '/nodes/{}/daemonstate') != 'dead':
fence_thread = threading.Thread(target=fencing.fenceNode, args=(node_name, zk_conn, config, logger), kwargs={}) fence_thread = threading.Thread(target=fencing.fenceNode, args=(node_name, zk_conn, config, logger), kwargs={})
fence_thread.start() fence_thread.start()
# Write the updated data after we start the fence thread
zkhandler.writedata(zk_conn, { '/nodes/{}/daemonstate'.format(node_name): 'dead' })
# Display node information to the terminal # Display node information to the terminal
logger.out( logger.out(