Commit 3e226350 authored by Julien Muchembled's avatar Julien Muchembled

client: optimize generation of new oids

parent edefaca7
......@@ -80,7 +80,7 @@ class Application(object):
self.uuid = None
self._cache = ClientCache()
self._loading_oid = None
self.new_oid_list = []
self.new_oid_list = ()
self.last_oid = '\0' * 8
self.last_tid = None
self.storage_event_handler = storage.StorageEventHandler(self)
......@@ -246,7 +246,7 @@ class Application(object):
with self._connecting_to_master_node:
result = self.master_conn
if result is None:
self.new_oid_list = []
self.new_oid_list = ()
result = self.master_conn = self._connectToPrimaryNode()
return result
......@@ -324,16 +324,16 @@ class Application(object):
"""Get a new OID."""
self._oid_lock_acquire()
try:
if len(self.new_oid_list) == 0:
if not self.new_oid_list:
# Get new oid list from master node
# we manage a list of oid here to prevent
# from asking too many time new oid one by one
# from master node
self._askPrimary(Packets.AskNewOIDs(100))
if len(self.new_oid_list) <= 0:
if not self.new_oid_list:
raise NEOStorageError('new_oid failed')
self.last_oid = self.new_oid_list.pop(0)
return self.last_oid
self.last_oid = oid = self.new_oid_list.pop()
return oid
finally:
self._oid_lock_release()
......
......@@ -189,6 +189,7 @@ class PrimaryAnswersHandler(AnswerBaseHandler):
self.app.setHandlerData(ttid)
def answerNewOIDs(self, conn, oid_list):
oid_list.reverse()
self.app.new_oid_list = oid_list
def answerTransactionFinished(self, conn, _, tid):
......
......@@ -168,7 +168,7 @@ class MasterAnswersHandlerTests(MasterHandlerTests):
conn = self.getFakeConnection()
oid1, oid2, oid3 = self.getOID(0), self.getOID(1), self.getOID(2)
self.handler.answerNewOIDs(conn, [oid1, oid2, oid3])
self.assertEqual(self.app.new_oid_list, [oid1, oid2, oid3])
self.assertEqual(self.app.new_oid_list, [oid3, oid2, oid1])
def test_answerTransactionFinished(self):
conn = self.getFakeConnection()
......
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