Implement flush locking for nodes
Implements a locking mechanism to prevent clobbering of node flushes. When a flush begins, a global cluster lock is placed which is freed once the flush completes. While the lock is in place, other flush events queue waiting for the lock to free before proceeding. Modifies the CLI output flow when the `--wait` option is specified. First, if a lock exists when running the command, the message is tweaked to indicate this, and the client will wait first for the lock to free, and then for the flush as normal. Second, the wait depends on the active lock rather than the domain_status for consistency purposes. Closes #32
This commit is contained in:
@ -316,6 +316,17 @@ class NodeInstance(object):
|
||||
|
||||
# Flush all VMs on the host
|
||||
def flush(self):
|
||||
# Wait indefinitely for the flush_lock to be freed
|
||||
time.sleep(0.5)
|
||||
while zkhandler.readdata(self.zk_conn, '/locks/flush_lock') == 'True':
|
||||
time.sleep(2)
|
||||
|
||||
# Acquire the flush lock
|
||||
zkhandler.writedata(self.zk_conn, {
|
||||
'/locks/flush_lock'.format(node): 'True'
|
||||
})
|
||||
|
||||
# Begin flush
|
||||
self.inflush = True
|
||||
self.logger.out('Flushing node "{}" of running VMs'.format(self.name), state='i')
|
||||
self.logger.out('Domain list: {}'.format(', '.join(self.domain_list)))
|
||||
@ -347,6 +358,11 @@ class NodeInstance(object):
|
||||
zkhandler.writedata(self.zk_conn, { '/nodes/{}/domainstate'.format(self.name): 'flushed' })
|
||||
self.inflush = False
|
||||
|
||||
# Release the flush lock
|
||||
zkhandler.writedata(self.zk_conn, {
|
||||
'/locks/flush_lock'.format(node): 'False'
|
||||
})
|
||||
|
||||
def unflush(self):
|
||||
self.inflush = True
|
||||
self.logger.out('Restoring node {} to active service.'.format(self.name), state='i')
|
||||
|
Reference in New Issue
Block a user