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