Commit 0be7e00c authored by Julien Muchembled's avatar Julien Muchembled

Small optimizations

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2706 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 96a7a90e
...@@ -433,11 +433,9 @@ class Application(object): ...@@ -433,11 +433,9 @@ class Application(object):
self._load_lock_acquire() self._load_lock_acquire()
try: try:
try: try:
result = self._loadFromCache(oid, serial, tid) return self._loadFromCache(oid, serial, tid)
except KeyError: except KeyError:
pass pass
else:
return result
data, start_serial, end_serial = self._loadFromStorage(oid, serial, data, start_serial, end_serial = self._loadFromStorage(oid, serial,
tid) tid)
self._cache_lock_acquire() self._cache_lock_acquire()
......
...@@ -187,13 +187,11 @@ class MQ(object): ...@@ -187,13 +187,11 @@ class MQ(object):
if reindex: if reindex:
# Index existing entries # Index existing entries
add = index.add add = index.add
for key in self._data.iterkeys(): for key in self._data:
add(key) add(key)
self._index_list.append(index) self._index_list.append(index)
def _mapIndexes(self, method_id, args=(), kw=None): def _mapIndexes(self, method_id, args=(), kw={}):
if kw is None:
kw = {}
for index in self._index_list: for index in self._index_list:
getattr(index, method_id)(*args, **kw) getattr(index, method_id)(*args, **kw)
......
...@@ -306,11 +306,10 @@ class NodeManager(object): ...@@ -306,11 +306,10 @@ class NodeManager(object):
def _updateIdentified(self, node): def _updateIdentified(self, node):
uuid = node.getUUID() uuid = node.getUUID()
identified = node.isIdentified() if node.isIdentified():
if not identified and uuid in self._identified_dict:
del self._identified_dict[uuid]
elif identified:
self._identified_dict[uuid] = node self._identified_dict[uuid] = node
else:
self._identified_dict.pop(uuid, None)
def _updateAddress(self, node, old_address): def _updateAddress(self, node, old_address):
self.__update(self._address_dict, old_address, node.getAddress(), node) self.__update(self._address_dict, old_address, node.getAddress(), node)
......
...@@ -192,8 +192,8 @@ class Application(object): ...@@ -192,8 +192,8 @@ class Application(object):
t = 0 t = 0
while True: while True:
current_time = time() current_time = time()
if current_time >= t + 1: if current_time >= t:
t = current_time t = current_time + 1
for node in self.nm.getMasterList(): for node in self.nm.getMasterList():
if not node.isRunning() and node.getLastStateChange() + \ if not node.isRunning() and node.getLastStateChange() + \
expiration < current_time: expiration < current_time:
...@@ -203,16 +203,14 @@ class Application(object): ...@@ -203,16 +203,14 @@ class Application(object):
node.getAddress()) node.getAddress())
# Try to connect to master nodes. # Try to connect to master nodes.
for addr in list(self.unconnected_master_node_set): for addr in self.unconnected_master_node_set.difference(
current_connections = [x.getAddress() for x in x.getAddress() for x in self.em.getClientList()):
self.em.getClientList()]
if addr not in current_connections:
ClientConnection(self.em, client_handler, addr=addr, ClientConnection(self.em, client_handler, addr=addr,
connector=self.connector_handler()) connector=self.connector_handler())
self.em.poll(1) self.em.poll(1)
if len(self.unconnected_master_node_set | if not (self.unconnected_master_node_set or
self.negotiating_master_node_set) == 0: self.negotiating_master_node_set):
break break
def _announcePrimary(self): def _announcePrimary(self):
...@@ -527,7 +525,6 @@ class Application(object): ...@@ -527,7 +525,6 @@ class Application(object):
def identifyNode(self, node_type, uuid, node): def identifyNode(self, node_type, uuid, node):
state = NodeStates.RUNNING state = NodeStates.RUNNING
handler = identification.IdentificationHandler(self)
if node_type == NodeTypes.ADMIN: if node_type == NodeTypes.ADMIN:
# always accept admin nodes # always accept admin nodes
...@@ -552,13 +549,14 @@ class Application(object): ...@@ -552,13 +549,14 @@ class Application(object):
neo.lib.logging.info('Accept a client %s' % (dump(uuid), )) neo.lib.logging.info('Accept a client %s' % (dump(uuid), ))
elif node_type == NodeTypes.STORAGE: elif node_type == NodeTypes.STORAGE:
node_ctor = self.nm.createStorage node_ctor = self.nm.createStorage
if self._current_manager is not None: manager = self._current_manager
identify = self._current_manager.identifyStorageNode if manager is None:
(uuid, state, handler) = identify(uuid, node) manager = self
else: (uuid, state, handler) = manager.identifyStorageNode(uuid, node)
(uuid, state, handler) = self.identifyStorageNode(uuid, node)
neo.lib.logging.info('Accept a storage %s (%s)' % neo.lib.logging.info('Accept a storage %s (%s)' %
(dump(uuid), state)) (dump(uuid), state))
else:
handler = identification.IdentificationHandler(self)
return (uuid, node, state, handler, node_ctor) return (uuid, node, state, handler, node_ctor)
def onTransactionCommitted(self, txn): def onTransactionCommitted(self, txn):
......
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