diff --git a/node-daemon/pvcd/Daemon.py b/node-daemon/pvcd/Daemon.py index db7bb294..7cab9dfc 100644 --- a/node-daemon/pvcd/Daemon.py +++ b/node-daemon/pvcd/Daemon.py @@ -540,6 +540,28 @@ def update_nodes(new_node_list): # Alias for our local node (passed to network and domain objects) this_node = d_node[myhostname] +# Primary node +@zk_conn.DataWatch('/primary_node') +def update_primart(new_primary, stat, event=''): + try: + new_primary = new_primary.decode('ascii') + except AttributeError: + new_primary = 'none' + + if new_primary != this_node.primary_node: + if config['daemon_mode'] == 'coordinator': + # We're a coordinator and there is no primary + if new_primary == 'none': + if this_node.daemon_state == 'run' and this_node.router_state != 'primary': + logger.out('Contending for primary routing state', state='i') + zkhandler.writedata(zk_conn, {'/primary_node': myhostname}) + elif new_primary == myhostname: + zkhandler.writedata(zk_conn, {'/nodes/{}/routerstate'.format(myhostname): 'primary'}) + else: + zkhandler.writedata(zk_conn, {'/nodes/{}/routerstate'.format(myhostname): 'secondary'}) + for node in d_node: + d_node[node].primary_node = new_primary + # Network objects @zk_conn.ChildrenWatch('/networks') def update_networks(new_network_list): diff --git a/node-daemon/pvcd/NodeInstance.py b/node-daemon/pvcd/NodeInstance.py index 00e4860f..ed8d0082 100644 --- a/node-daemon/pvcd/NodeInstance.py +++ b/node-daemon/pvcd/NodeInstance.py @@ -138,40 +138,6 @@ class NodeInstance(object): if self.domain_state == 'unflush' and self.inflush == False: self.unflush() - @self.zk_conn.DataWatch('/primary_node') - def watch_primary_node(data, stat, event=''): - if event and event.type == 'DELETED': - # The key has been deleted after existing before; terminate this watcher - # because this class instance is about to be reaped in Daemon.py - return False - - try: - data = data.decode('ascii') - except AttributeError: - data = 'none' - - if data != self.primary_node: - if self.daemon_mode == 'coordinator': - # We're a coordinator so we care about networking - if data == 'none': - # Toggle state management of routing functions - if self.name == self.this_node: - if self.daemon_state == 'run' and self.router_state != 'primary': - # Contend for primary - self.logger.out('Contending for primary routing state', state='i') - zkhandler.writedata(self.zk_conn, {'/primary_node': self.name }) - elif data == self.this_node: - if self.name == self.this_node: - zkhandler.writedata(self.zk_conn, { '/nodes/{}/routerstate'.format(self.name): 'primary' }) - self.primary_node = data - else: - if self.name == self.this_node: - zkhandler.writedata(self.zk_conn, { '/nodes/{}/routerstate'.format(self.name): 'secondary' }) - self.primary_node = data - else: - self.primary_node = data - - @self.zk_conn.DataWatch('/nodes/{}/memfree'.format(self.name)) def watch_node_memfree(data, stat, event=''): if event and event.type == 'DELETED':