Commit 81c93b67 authored by Julien Muchembled's avatar Julien Muchembled

Coding style changes and small optimizations

With the change in TransactionManager, there's 1 comparison less.
parent b2f51e77
......@@ -170,13 +170,13 @@ class SocketConnector:
raise NotImplementedError
class SocketConnectorIPv4(SocketConnector):
" Wrapper for IPv4 sockets"
af_type = socket.AF_INET
" Wrapper for IPv4 sockets"
af_type = socket.AF_INET
def _accept(self):
return self.socket.accept()
def _accept(self):
return self.socket.accept()
def getAddress(self):
def getAddress(self):
return self.socket.getsockname()
class SocketConnectorIPv6(SocketConnector):
......@@ -185,13 +185,10 @@ class SocketConnectorIPv6(SocketConnector):
def _accept(self):
new_s, addr = self.socket.accept()
addr = (addr[0], addr[1])
return (new_s, addr)
return new_s, addr[:2]
def getAddress(self):
addr = self.socket.getsockname()
addr = (addr[0], addr[1])
return addr
return self.socket.getsockname()[:2]
registerConnectorHandler(SocketConnectorIPv4)
registerConnectorHandler(SocketConnectorIPv6)
......
......@@ -78,11 +78,8 @@ class EpollEventManager(object):
del self.connection_dict[fd]
def _getPendingConnection(self):
if len(self._pending_processing):
result = self._pending_processing.pop(0)
else:
result = None
return result
if self._pending_processing:
return self._pending_processing.pop(0)
def _addPendingConnection(self, conn):
pending_processing = self._pending_processing
......
......@@ -357,7 +357,7 @@ class TransactionManager(object):
# will be finished
for txn in self._ttid_dict.itervalues():
txn.registerForNotification(uuid)
return set(self._ttid_dict.keys())
return set(self._ttid_dict)
def begin(self, node, tid=None):
"""
......
......@@ -187,7 +187,7 @@ class Replicator(object):
def pending(self):
"""Return whether there is any pending partition."""
return len(self.partition_dict) or len(self.new_partition_set)
return bool(self.partition_dict or self.new_partition_set)
def getCurrentOffset(self):
assert self.current_partition is not None
......
......@@ -247,31 +247,17 @@ class TransactionManager(object):
self._app.executeQueuedEvents()
# Attemp to acquire lock again.
locking_tid = self._store_lock_dict.get(oid)
if locking_tid in (None, ttid):
# check if this is generated from the latest revision.
if locking_tid == ttid:
# If previous store was an undo, next store must be based on
# undo target.
_, _, _, _, previous_serial = self._transaction_dict[
ttid].getObject(oid)
if previous_serial is None:
# XXX: use some special serial when previous store was not
# an undo ? Maybe it should just not happen.
neo.lib.logging.info('Transaction %s storing %s more than '
'once', dump(ttid), dump(oid))
else:
previous_serial = None
if locking_tid is None:
previous_serial = None
elif locking_tid == ttid:
# If previous store was an undo, next store must be based on
# undo target.
previous_serial = self._transaction_dict[ttid].getObject(oid)[4]
if previous_serial is None:
history_list = self._app.dm.getObjectHistory(oid)
if history_list:
previous_serial = history_list[0][0]
if previous_serial is not None and previous_serial != serial:
neo.lib.logging.info('Resolvable conflict on %r:%r',
dump(oid), dump(ttid))
raise ConflictError(previous_serial)
neo.lib.logging.debug('Transaction %s storing %s',
dump(ttid), dump(oid))
self._store_lock_dict[oid] = ttid
# XXX: use some special serial when previous store was not
# an undo ? Maybe it should just not happen.
neo.lib.logging.info('Transaction %s storing %s more than '
'once', dump(ttid), dump(oid))
elif locking_tid < ttid:
# We have a bigger TTID than locking transaction, so we are younger:
# enter waiting queue so we are handled when lock gets released.
......@@ -289,6 +275,17 @@ class TransactionManager(object):
neo.lib.logging.info('Possible deadlock on %r:%r with %r',
dump(oid), dump(ttid), dump(locking_tid))
raise ConflictError(ZERO_TID)
if previous_serial is None:
history_list = self._app.dm.getObjectHistory(oid)
if history_list:
previous_serial = history_list[0][0]
if previous_serial is not None and previous_serial != serial:
neo.lib.logging.info('Resolvable conflict on %r:%r',
dump(oid), dump(ttid))
raise ConflictError(previous_serial)
neo.lib.logging.debug('Transaction %s storing %s',
dump(ttid), dump(oid))
self._store_lock_dict[oid] = ttid
def checkCurrentSerial(self, ttid, serial, oid):
self.lockObject(ttid, serial, oid, unlock=True)
......
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