Commit 79ea07c8 authored by Julien Muchembled's avatar Julien Muchembled

Small optimizations & cleanups

parent 0d36de7b
......@@ -83,9 +83,8 @@ class MasterHandler(EventHandler):
conn.answer(Packets.AnswerNodeInformation())
def askPartitionTable(self, conn):
ptid = self.app.pt.getID()
row_list = self.app.pt.getRowList()
conn.answer(Packets.AnswerPartitionTable(ptid, row_list))
pt = self.app.pt
conn.answer(Packets.AnswerPartitionTable(pt.getID(), pt.getRowList()))
DISCONNECTED_STATE_DICT = {
......
......@@ -43,13 +43,11 @@ class IdentificationHandler(MasterHandler):
if node_type == NodeTypes.CLIENT:
if app.cluster_state != ClusterStates.RUNNING:
raise NotReadyError
node_ctor = app.nm.createClient
handler = app.client_service_handler
human_readable_node_type = ' client '
elif node_type == NodeTypes.STORAGE:
if app.cluster_state == ClusterStates.STOPPING_BACKUP:
raise NotReadyError
node_ctor = app.nm.createStorage
manager = app._current_manager
if manager is None:
manager = app
......@@ -57,11 +55,9 @@ class IdentificationHandler(MasterHandler):
uuid is not None and node is not None)
human_readable_node_type = ' storage (%s) ' % (state, )
elif node_type == NodeTypes.MASTER:
node_ctor = app.nm.createMaster
handler = app.secondary_master_handler
human_readable_node_type = ' master '
elif node_type == NodeTypes.ADMIN:
node_ctor = app.nm.createAdmin
handler = app.administration_handler
human_readable_node_type = 'n admin '
else:
......@@ -70,7 +66,8 @@ class IdentificationHandler(MasterHandler):
uuid = app.getNewUUID(uuid, address, node_type)
logging.info('Accept a' + human_readable_node_type + uuid_str(uuid))
if node is None:
node = node_ctor(uuid=uuid, address=address)
node = app.nm.createFromNodeType(node_type,
uuid=uuid, address=address)
node.setUUID(uuid)
node.setState(state)
node.setConnection(conn)
......
......@@ -190,7 +190,8 @@ class TransactionManager(object):
return oid_list
def setLastOID(self, oid):
self._last_oid = max(oid, self._last_oid)
if self._last_oid < oid:
self._last_oid = oid
def getLastOID(self):
return self._last_oid
......@@ -245,7 +246,8 @@ class TransactionManager(object):
"""
Set the last TID, keep the previous if lower
"""
self._last_tid = max(self._last_tid, tid)
if self._last_tid < tid:
self._last_tid = tid
def reset(self):
"""
......@@ -340,9 +342,7 @@ class TransactionManager(object):
instanciation time.
"""
logging.debug('Lock TXN %s for %s', dump(ttid), uuid_str(uuid))
assert ttid in self._ttid_dict, "Transaction not started"
txn = self._ttid_dict[ttid]
if txn.lock(uuid) and self._queue[0][1] == ttid:
if self._ttid_dict[ttid].lock(uuid) and self._queue[0][1] == ttid:
# all storage are locked and we unlock the commit queue
self._unlockPending()
......@@ -352,8 +352,7 @@ class TransactionManager(object):
current transactions
"""
unlock = False
# iterate over a copy because _unlockPending may alter the dict
for ttid, txn in self._ttid_dict.items():
for ttid, txn in self._ttid_dict.iteritems():
if txn.forget(uuid) and self._queue[0][1] == ttid:
unlock = True
if unlock:
......@@ -365,12 +364,11 @@ class TransactionManager(object):
pop = queue.pop
insert = queue.insert
on_commit = self._on_commit
get = self._ttid_dict.get
ttid_dict = self._ttid_dict
while queue:
uuid, ttid = pop(0)
txn = get(ttid, None)
# _queue can contain un-prepared transactions
if txn is not None and txn.locked():
txn = ttid_dict[ttid]
if txn.locked():
on_commit(txn)
else:
insert(0, (uuid, ttid))
......
......@@ -180,7 +180,7 @@ class DatabaseManager(object):
"""
ptid = self.getConfiguration('ptid')
if ptid is not None:
return long(ptid)
return int(ptid)
def setPTID(self, ptid):
"""
......
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