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

Small optimizations & cleanups

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