[Neo-report] r2706 jm - in /trunk/neo: client/app.py client/mq.py lib/node.py master/app.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Thu Apr 7 15:03:09 CEST 2011
Author: jm
Date: Thu Apr 7 15:03:09 2011
New Revision: 2706
Log:
Small optimizations
Modified:
trunk/neo/client/app.py
trunk/neo/client/mq.py
trunk/neo/lib/node.py
trunk/neo/master/app.py
Modified: trunk/neo/client/app.py
==============================================================================
--- trunk/neo/client/app.py [iso-8859-1] (original)
+++ trunk/neo/client/app.py [iso-8859-1] Thu Apr 7 15:03:09 2011
@@ -433,11 +433,9 @@ class Application(object):
self._load_lock_acquire()
try:
try:
- result = self._loadFromCache(oid, serial, tid)
+ return self._loadFromCache(oid, serial, tid)
except KeyError:
pass
- else:
- return result
data, start_serial, end_serial = self._loadFromStorage(oid, serial,
tid)
self._cache_lock_acquire()
Modified: trunk/neo/client/mq.py
==============================================================================
--- trunk/neo/client/mq.py [iso-8859-1] (original)
+++ trunk/neo/client/mq.py [iso-8859-1] Thu Apr 7 15:03:09 2011
@@ -187,13 +187,11 @@ class MQ(object):
if reindex:
# Index existing entries
add = index.add
- for key in self._data.iterkeys():
+ for key in self._data:
add(key)
self._index_list.append(index)
- def _mapIndexes(self, method_id, args=(), kw=None):
- if kw is None:
- kw = {}
+ def _mapIndexes(self, method_id, args=(), kw={}):
for index in self._index_list:
getattr(index, method_id)(*args, **kw)
Modified: trunk/neo/lib/node.py
==============================================================================
--- trunk/neo/lib/node.py [iso-8859-1] (original)
+++ trunk/neo/lib/node.py [iso-8859-1] Thu Apr 7 15:03:09 2011
@@ -306,11 +306,10 @@ class NodeManager(object):
def _updateIdentified(self, node):
uuid = node.getUUID()
- identified = node.isIdentified()
- if not identified and uuid in self._identified_dict:
- del self._identified_dict[uuid]
- elif identified:
+ if node.isIdentified():
self._identified_dict[uuid] = node
+ else:
+ self._identified_dict.pop(uuid, None)
def _updateAddress(self, node, old_address):
self.__update(self._address_dict, old_address, node.getAddress(), node)
Modified: trunk/neo/master/app.py
==============================================================================
--- trunk/neo/master/app.py [iso-8859-1] (original)
+++ trunk/neo/master/app.py [iso-8859-1] Thu Apr 7 15:03:09 2011
@@ -192,8 +192,8 @@ class Application(object):
t = 0
while True:
current_time = time()
- if current_time >= t + 1:
- t = current_time
+ if current_time >= t:
+ t = current_time + 1
for node in self.nm.getMasterList():
if not node.isRunning() and node.getLastStateChange() + \
expiration < current_time:
@@ -203,16 +203,14 @@ class Application(object):
node.getAddress())
# Try to connect to master nodes.
- for addr in list(self.unconnected_master_node_set):
- current_connections = [x.getAddress() for x in
- self.em.getClientList()]
- if addr not in current_connections:
- ClientConnection(self.em, client_handler, addr=addr,
- connector=self.connector_handler())
+ for addr in self.unconnected_master_node_set.difference(
+ x.getAddress() for x in self.em.getClientList()):
+ ClientConnection(self.em, client_handler, addr=addr,
+ connector=self.connector_handler())
self.em.poll(1)
- if len(self.unconnected_master_node_set |
- self.negotiating_master_node_set) == 0:
+ if not (self.unconnected_master_node_set or
+ self.negotiating_master_node_set):
break
def _announcePrimary(self):
@@ -527,7 +525,6 @@ class Application(object):
def identifyNode(self, node_type, uuid, node):
state = NodeStates.RUNNING
- handler = identification.IdentificationHandler(self)
if node_type == NodeTypes.ADMIN:
# always accept admin nodes
@@ -552,13 +549,14 @@ class Application(object):
neo.lib.logging.info('Accept a client %s' % (dump(uuid), ))
elif node_type == NodeTypes.STORAGE:
node_ctor = self.nm.createStorage
- if self._current_manager is not None:
- identify = self._current_manager.identifyStorageNode
- (uuid, state, handler) = identify(uuid, node)
- else:
- (uuid, state, handler) = self.identifyStorageNode(uuid, node)
+ manager = self._current_manager
+ if manager is None:
+ manager = self
+ (uuid, state, handler) = manager.identifyStorageNode(uuid, node)
neo.lib.logging.info('Accept a storage %s (%s)' %
(dump(uuid), state))
+ else:
+ handler = identification.IdentificationHandler(self)
return (uuid, node, state, handler, node_ctor)
def onTransactionCommitted(self, txn):
More information about the Neo-report
mailing list