Commit 82c142c4 authored by Julien Muchembled's avatar Julien Muchembled

Introduce extra node properties

Explicit fields in RequestIdentification are only suitable for the actual
identification or for properties that most nodes have.

But some current (and future) features require to pass values (always and
as soon as possible) for tasks that are unrelated to identification.
parent 2b9e14e8
...@@ -228,7 +228,7 @@ class Application(ThreadedApplication): ...@@ -228,7 +228,7 @@ class Application(ThreadedApplication):
node=node, node=node,
dispatcher=self.dispatcher) dispatcher=self.dispatcher)
p = Packets.RequestIdentification(NodeTypes.CLIENT, p = Packets.RequestIdentification(NodeTypes.CLIENT,
self.uuid, None, self.name, None, (), ()) self.uuid, None, self.name, None, {})
try: try:
ask(conn, p, handler=handler) ask(conn, p, handler=handler)
except ConnectionClosed: except ConnectionClosed:
...@@ -270,7 +270,7 @@ class Application(ThreadedApplication): ...@@ -270,7 +270,7 @@ class Application(ThreadedApplication):
conn = MTClientConnection(self, self.storage_event_handler, node, conn = MTClientConnection(self, self.storage_event_handler, node,
dispatcher=self.dispatcher) dispatcher=self.dispatcher)
p = Packets.RequestIdentification(NodeTypes.CLIENT, p = Packets.RequestIdentification(NodeTypes.CLIENT,
self.uuid, None, self.name, self.id_timestamp, (), ()) self.uuid, None, self.name, self.id_timestamp, {})
try: try:
self._ask(conn, p, handler=self.storage_bootstrap_handler) self._ask(conn, p, handler=self.storage_bootstrap_handler)
except ConnectionClosed: except ConnectionClosed:
......
...@@ -26,15 +26,14 @@ class BootstrapManager(EventHandler): ...@@ -26,15 +26,14 @@ class BootstrapManager(EventHandler):
Manage the bootstrap stage, lookup for the primary master then connect to it Manage the bootstrap stage, lookup for the primary master then connect to it
""" """
def __init__(self, app, node_type, server=None, devpath=(), new_nid=()): def __init__(self, app, node_type, server=None, **extra):
""" """
Manage the bootstrap stage of a non-master node, it lookup for the Manage the bootstrap stage of a non-master node, it lookup for the
primary master node, connect to it then returns when the master node primary master node, connect to it then returns when the master node
is ready. is ready.
""" """
self.server = server self.server = server
self.devpath = devpath self.extra = extra
self.new_nid = new_nid
self.node_type = node_type self.node_type = node_type
app.nm.reset() app.nm.reset()
...@@ -43,7 +42,7 @@ class BootstrapManager(EventHandler): ...@@ -43,7 +42,7 @@ class BootstrapManager(EventHandler):
def connectionCompleted(self, conn): def connectionCompleted(self, conn):
EventHandler.connectionCompleted(self, conn) EventHandler.connectionCompleted(self, conn)
conn.ask(Packets.RequestIdentification(self.node_type, self.uuid, conn.ask(Packets.RequestIdentification(self.node_type, self.uuid,
self.server, self.app.name, None, self.devpath, self.new_nid)) self.server, self.app.name, None, self.extra))
def connectionFailed(self, conn): def connectionFailed(self, conn):
EventHandler.connectionFailed(self, conn) EventHandler.connectionFailed(self, conn)
......
...@@ -28,7 +28,7 @@ class Node(object): ...@@ -28,7 +28,7 @@ class Node(object):
_connection = None _connection = None
_identified = False _identified = False
devpath = () extra = {}
id_timestamp = None id_timestamp = None
def __init__(self, manager, address=None, uuid=None, state=NodeStates.DOWN): def __init__(self, manager, address=None, uuid=None, state=NodeStates.DOWN):
......
...@@ -24,7 +24,7 @@ from ..app import monotonic_time ...@@ -24,7 +24,7 @@ from ..app import monotonic_time
class IdentificationHandler(EventHandler): class IdentificationHandler(EventHandler):
def requestIdentification(self, conn, node_type, uuid, def requestIdentification(self, conn, node_type, uuid,
address, name, id_timestamp, devpath, new_nid): address, name, id_timestamp, extra):
app = self.app app = self.app
self.checkClusterName(name) self.checkClusterName(name)
if address == app.server: if address == app.server:
...@@ -60,6 +60,7 @@ class IdentificationHandler(EventHandler): ...@@ -60,6 +60,7 @@ class IdentificationHandler(EventHandler):
# cloned/evil/buggy node connecting to us # cloned/evil/buggy node connecting to us
raise ProtocolError('already connected') raise ProtocolError('already connected')
new_nid = extra.pop('new_nid', None)
state = NodeStates.RUNNING state = NodeStates.RUNNING
if node_type == NodeTypes.CLIENT: if node_type == NodeTypes.CLIENT:
if app.cluster_state == ClusterStates.RUNNING: if app.cluster_state == ClusterStates.RUNNING:
...@@ -111,8 +112,7 @@ class IdentificationHandler(EventHandler): ...@@ -111,8 +112,7 @@ class IdentificationHandler(EventHandler):
uuid=uuid, address=address) uuid=uuid, address=address)
else: else:
node.setUUID(uuid) node.setUUID(uuid)
if devpath: node.extra = extra
node.devpath = tuple(devpath)
node.id_timestamp = monotonic_time() node.id_timestamp = monotonic_time()
node.setState(state) node.setState(state)
app.broadcastNodesInformation([node]) app.broadcastNodesInformation([node])
...@@ -135,7 +135,7 @@ class IdentificationHandler(EventHandler): ...@@ -135,7 +135,7 @@ class IdentificationHandler(EventHandler):
class SecondaryIdentificationHandler(EventHandler): class SecondaryIdentificationHandler(EventHandler):
def requestIdentification(self, conn, node_type, uuid, def requestIdentification(self, conn, node_type, uuid,
address, name, id_timestamp, devpath, new_nid): address, name, id_timestamp, extra):
app = self.app app = self.app
self.checkClusterName(name) self.checkClusterName(name)
if address == app.server: if address == app.server:
......
...@@ -40,7 +40,7 @@ class ElectionHandler(SecondaryHandler): ...@@ -40,7 +40,7 @@ class ElectionHandler(SecondaryHandler):
super(ElectionHandler, self).connectionCompleted(conn) super(ElectionHandler, self).connectionCompleted(conn)
app = self.app app = self.app
conn.ask(Packets.RequestIdentification(NodeTypes.MASTER, conn.ask(Packets.RequestIdentification(NodeTypes.MASTER,
app.uuid, app.server, app.name, app.election, (), ())) app.uuid, app.server, app.name, app.election, {}))
def connectionFailed(self, conn): def connectionFailed(self, conn):
super(ElectionHandler, self).connectionFailed(conn) super(ElectionHandler, self).connectionFailed(conn)
......
...@@ -250,7 +250,7 @@ class PartitionTable(neo.lib.pt.PartitionTable): ...@@ -250,7 +250,7 @@ class PartitionTable(neo.lib.pt.PartitionTable):
devpath_max = [] devpath_max = []
devpaths = [()] * node_count devpaths = [()] * node_count
if repeats > 1: if repeats > 1:
_devpaths = [x[0].devpath for x in node_list] _devpaths = [x[0].extra.get('devpath', ()) for x in node_list]
max_depth = min(map(len, _devpaths)) max_depth = min(map(len, _devpaths))
depth = 0 depth = 0
while 1: while 1:
......
...@@ -252,7 +252,7 @@ class Application(BaseApplication): ...@@ -252,7 +252,7 @@ class Application(BaseApplication):
# search, find, connect and identify to the primary master # search, find, connect and identify to the primary master
bootstrap = BootstrapManager(self, NodeTypes.STORAGE, bootstrap = BootstrapManager(self, NodeTypes.STORAGE,
None if self.new_nid else self.server, None if self.new_nid else self.server,
self.devpath, self.new_nid) devpath=self.devpath, new_nid=self.new_nid)
self.master_node, self.master_conn = bootstrap.getPrimaryConnection() self.master_node, self.master_conn = bootstrap.getPrimaryConnection()
self.dm.setUUID(self.uuid) self.dm.setUUID(self.uuid)
......
...@@ -51,7 +51,7 @@ class Checker(object): ...@@ -51,7 +51,7 @@ class Checker(object):
else: else:
conn = ClientConnection(app, StorageOperationHandler(app), node) conn = ClientConnection(app, StorageOperationHandler(app), node)
conn.ask(Packets.RequestIdentification(NodeTypes.STORAGE, conn.ask(Packets.RequestIdentification(NodeTypes.STORAGE,
uuid, app.server, name, app.id_timestamp, (), ())) uuid, app.server, name, app.id_timestamp, {}))
self.conn_dict[conn] = node.isIdentified() self.conn_dict[conn] = node.isIdentified()
conn_set = set(self.conn_dict) conn_set = set(self.conn_dict)
conn_set.discard(None) conn_set.discard(None)
......
...@@ -32,7 +32,7 @@ class IdentificationHandler(EventHandler): ...@@ -32,7 +32,7 @@ class IdentificationHandler(EventHandler):
return self.app.nm return self.app.nm
def requestIdentification(self, conn, node_type, uuid, address, name, def requestIdentification(self, conn, node_type, uuid, address, name,
id_timestamp, devpath, new_nid): id_timestamp, extra):
self.checkClusterName(name) self.checkClusterName(name)
app = self.app app = self.app
# reject any incoming connections if not ready # reject any incoming connections if not ready
......
...@@ -350,7 +350,7 @@ class Replicator(object): ...@@ -350,7 +350,7 @@ class Replicator(object):
try: try:
conn.ask(Packets.RequestIdentification(NodeTypes.STORAGE, conn.ask(Packets.RequestIdentification(NodeTypes.STORAGE,
None if name else app.uuid, app.server, name or app.name, None if name else app.uuid, app.server, name or app.name,
app.id_timestamp, (), ())) app.id_timestamp, {}))
except ConnectionClosed: except ConnectionClosed:
if previous_node is self.current_node: if previous_node is self.current_node:
return return
......
...@@ -325,7 +325,7 @@ class MasterPartitionTableTests(NeoUnitTestBase): ...@@ -325,7 +325,7 @@ class MasterPartitionTableTests(NeoUnitTestBase):
pt.make(sn) pt.make(sn)
pt.log() pt.log()
for i, s in enumerate(sn, sn_count): for i, s in enumerate(sn, sn_count):
s.devpath = tuple(bin(i)[3:-1]) s.extra = {'devpath': tuple(bin(i)[3:-1])}
self.assertEqual(Counter(x[2] for x in self.tweak(pt)), { self.assertEqual(Counter(x[2] for x in self.tweak(pt)), {
CellStates.OUT_OF_DATE: 96, CellStates.OUT_OF_DATE: 96,
CellStates.FEEDING: 96, CellStates.FEEDING: 96,
...@@ -360,12 +360,12 @@ class MasterPartitionTableTests(NeoUnitTestBase): ...@@ -360,12 +360,12 @@ class MasterPartitionTableTests(NeoUnitTestBase):
assert len(topo) <= sn_count assert len(topo) <= sn_count
sn2 = sn[:len(topo)] sn2 = sn[:len(topo)]
for s in sn2: for s in sn2:
s.devpath = () s.extra = {}
k = (1,7)[even] k = (1,7)[even]
pt = PartitionTable(np*k, i) pt = PartitionTable(np*k, i)
pt.make(sn2) pt.make(sn2)
for devpath, s in zip(topo, sn2): for devpath, s in zip(topo, sn2):
s.devpath = tuple(devpath) s.extra = {'devpath': tuple(devpath)}
if type(expected) is tuple: if type(expected) is tuple:
self.assertTrue(self.tweak(pt)) self.assertTrue(self.tweak(pt))
self.update(pt) self.update(pt)
......
...@@ -89,7 +89,7 @@ Ping() ...@@ -89,7 +89,7 @@ Ping()
Pong() Pong()
Repair([int],bool) Repair([int],bool)
Replicate(p64,bin,{int:?(bin,int)}) Replicate(p64,bin,{int:?(bin,int)})
RequestIdentification(NodeTypes,?int,?(bin,int),bin,?float,any,[int]) RequestIdentification(NodeTypes,?int,?(bin,int),bin,?float,{bin:any})
SendPartitionTable(?int,int,[[(int,CellStates)]]) SendPartitionTable(?int,int,[[(int,CellStates)]])
SetClusterState(ClusterStates) SetClusterState(ClusterStates)
SetNodeState(int,NodeStates) SetNodeState(int,NodeStates)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment