Commit f04a71ff authored by Vincent Pelletier's avatar Vincent Pelletier

Use exception to notify non-ready nodes.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2636 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 23848822
......@@ -113,7 +113,6 @@ class ThreadContext(object):
'txn_info': 0,
'history': None,
'node_tids': {},
'node_ready': False,
'asked_object': 0,
'undo_object_tid_dict': {},
'involved_nodes': set(),
......@@ -1160,15 +1159,6 @@ class Application(object):
def invalidationBarrier(self):
self._askPrimary(Packets.AskBarrier())
def setNodeReady(self):
self.local_var.node_ready = True
def setNodeNotReady(self):
self.local_var.node_ready = False
def isNodeReady(self):
return self.local_var.node_ready
def setTID(self, value):
self.local_var.tid = value
......
......@@ -29,7 +29,6 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
def notReady(self, conn, message):
app = self.app
app.trying_master_node = None
app.setNodeNotReady()
def acceptIdentification(self, conn, node_type,
uuid, num_partitions, num_replicas, your_uuid):
......
......@@ -24,6 +24,7 @@ from neo.lib.protocol import NodeTypes, ProtocolError, LockState
from neo.lib.util import dump
from neo.client.exception import NEOStorageError, NEOStorageNotFoundError
from neo.client.exception import NEOStorageDoesNotExistError
from neo.lib.exception import NodeNotReady
class StorageEventHandler(BaseHandler):
......@@ -45,7 +46,7 @@ class StorageBootstrapHandler(AnswerBaseHandler):
""" Handler used when connecting to a storage node """
def notReady(self, conn, message):
self.app.setNodeNotReady()
raise NodeNotReady(message)
def acceptIdentification(self, conn, node_type,
uuid, num_partitions, num_replicas, your_uuid):
......
......@@ -24,6 +24,7 @@ from neo.lib.protocol import NodeTypes, Packets
from neo.lib.connection import MTClientConnection, ConnectionClosed
from neo.client.exception import NEOStorageError
from neo.lib.profiling import profiler_decorator
from neo.lib.exception import NodeNotReady
# How long before we might retry a connection to a node to which connection
# failed in the past.
......@@ -60,7 +61,6 @@ class ConnectionPool(object):
addr = node.getAddress()
assert addr is not None
app = self.app
app.setNodeReady()
neo.lib.logging.debug('trying to connect to %s - %s', node,
node.getState())
conn = MTClientConnection(app.em, app.storage_event_handler, addr,
......@@ -74,15 +74,14 @@ class ConnectionPool(object):
except ConnectionClosed:
neo.lib.logging.error('Connection to %r failed', node)
self.notifyFailure(node)
return None
if app.isNodeReady():
neo.lib.logging.info('Connected %r', node)
return conn
else:
conn = None
except NodeNotReady:
neo.lib.logging.info('%r not ready', node)
self.notifyFailure(node)
return NOT_READY
conn = NOT_READY
else:
neo.lib.logging.info('Connected %r', node)
return conn
@profiler_decorator
def _dropConnections(self):
......
......@@ -29,3 +29,7 @@ class OperationFailure(NeoException):
class DatabaseFailure(NeoException):
pass
class NodeNotReady(NeoException):
pass
......@@ -1027,7 +1027,6 @@ class ClientApplicationTests(NeoUnitTestBase):
app._waitMessage = _waitMessage6
# third iteration : node not ready
def _waitMessage4(conn, msg_id, handler=None):
app.setNodeNotReady()
app.trying_master_node = None
app._waitMessage = _waitMessage5
# second iteration : master node changed
......
......@@ -50,7 +50,6 @@ class MasterBootstrapHandlerTests(MasterHandlerTests):
conn = self.getConnection()
self.handler.notReady(conn, 'message')
self.assertEqual(self.app.trying_master_node, None)
self.checkCalledOnApp('setNodeNotReady')
def test_acceptIdentification1(self):
""" Non-master node """
......
......@@ -24,6 +24,7 @@ from neo.client.handlers.storage import StorageBootstrapHandler, \
from neo.client.exception import NEOStorageError, NEOStorageNotFoundError
from neo.client.exception import NEOStorageDoesNotExistError
from ZODB.POSException import ConflictError
from neo.lib.exception import NodeNotReady
MARKER = []
......@@ -39,9 +40,7 @@ class StorageBootstrapHandlerTests(NeoUnitTestBase):
def test_notReady(self):
conn = self.getConnection()
self.handler.notReady(conn, 'message')
calls = self.app.mockGetNamedCalls('setNodeNotReady')
self.assertEqual(len(calls), 1)
self.assertRaises(NodeNotReady, self.handler.notReady, conn, 'message')
def test_acceptIdentification1(self):
""" Not a storage node """
......
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