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