[Neo-report] r2364 gregory - in /trunk/neo/storage: handlers/replication.py replicator.py

nobody at svn.erp5.org nobody at svn.erp5.org
Fri Oct 29 17:37:39 CEST 2010


Author: gregory
Date: Fri Oct 29 17:37:38 2010
New Revision: 2364

Log:
Don't access replicator's attributes directly.

Modified:
    trunk/neo/storage/handlers/replication.py
    trunk/neo/storage/replicator.py

Modified: trunk/neo/storage/handlers/replication.py
==============================================================================
--- trunk/neo/storage/handlers/replication.py [iso-8859-1] (original)
+++ trunk/neo/storage/handlers/replication.py [iso-8859-1] Fri Oct 29 17:37:38 2010
@@ -66,7 +66,7 @@ Both part follow the same mechanism:
 
 def checkConnectionIsReplicatorConnection(func):
     def decorator(self, conn, *args, **kw):
-        if self.app.replicator.current_connection is conn:
+        if self.app.replicator.isCurrentConnection(conn):
             result = func(self, conn, *args, **kw)
         else:
             # Should probably raise & close connection...
@@ -152,30 +152,24 @@ class ReplicationHandler(EventHandler):
         del data
 
     def _doAskCheckSerialRange(self, min_oid, min_tid, length=RANGE_LENGTH):
-        replicator = self.app.replicator
-        partition = replicator.current_partition.getRID()
+        partition = self.replicator.getCurrentRID()
         replicator.checkSerialRange(min_oid, min_tid, length, partition)
         return Packets.AskCheckSerialRange(min_oid, min_tid, length, partition)
 
     def _doAskCheckTIDRange(self, min_tid, length=RANGE_LENGTH):
-        replicator = self.app.replicator
-        partition = replicator.current_partition.getRID()
+        partition = self.replicator.getCurrentRID()
         replicator.checkTIDRange(min_tid, length, partition)
         return Packets.AskCheckTIDRange(min_tid, length, partition)
 
     def _doAskTIDsFrom(self, min_tid, length):
-        replicator = self.app.replicator
-        partition = replicator.current_partition
-        partition_id = partition.getRID()
-        max_tid = partition.getCriticalTID()
+        partition_id = self.replicator.getCurrentRID()
+        max_tid = self.replicator.getCurrentCriticalTID()
         replicator.getTIDsFrom(min_tid, max_tid, length, partition_id)
         return Packets.AskTIDsFrom(min_tid, max_tid, length, partition_id)
 
     def _doAskObjectHistoryFrom(self, min_oid, min_serial, length):
-        replicator = self.app.replicator
-        partition = replicator.current_partition
-        partition_id = partition.getRID()
-        max_serial = partition.getCriticalTID()
+        partition_id = self.replicator.getCurrentRID()
+        max_serial = self.replicator.getCurrentCriticalTID()
         replicator.getObjectHistoryFrom(min_oid, min_serial, max_serial,
             length, partition_id)
         return Packets.AskObjectHistoryFrom(min_oid, min_serial, max_serial,
@@ -206,7 +200,7 @@ class ReplicationHandler(EventHandler):
                     count + 1))
         if p is None:
             if count == length and \
-                    max_tid < replicator.current_partition.getCriticalTID():
+                    max_tid < self.replicator.getCurrentCriticalTID():
                 # Go on with next chunk
                 p = self._doAskCheckTIDRange(add64(max_tid, 1))
             else:
@@ -247,7 +241,7 @@ class ReplicationHandler(EventHandler):
             else:
                 # Nothing remains, so the replication for this partition is
                 # finished.
-                replicator.replication_done = True
+                replicator.setReplicationDone()
         if p is not None:
             conn.ask(p)
 

Modified: trunk/neo/storage/replicator.py
==============================================================================
--- trunk/neo/storage/replicator.py [iso-8859-1] (original)
+++ trunk/neo/storage/replicator.py [iso-8859-1] Fri Oct 29 17:37:38 2010
@@ -123,13 +123,11 @@ class Replicator(object):
     # critical_tid_dict
     #   outdated partitions for which a critical tid was asked to primary
     #   master, but not answered so far
-    #   XXX: could probably be made a list/set rather than a dict
     # partition_dict
     #   outdated partitions (with or without a critical tid - if without, it
     #   was asked to primary master)
     # current_partition
     #   partition being currently synchronised
-    #   XXX: accessed (r) directly by ReplicationHandler
     # current_connection
     #   connection to a storage node we are replicating from
     #   XXX: accessed (r) directory by ReplicationHandler
@@ -142,7 +140,6 @@ class Replicator(object):
     #   False if we know there is something to replicate.
     #   True when current_partition is replicated, or we don't know yet if
     #   there is something to replicate
-    #   XXX: accessed (w) directly by ReplicationHandler
 
     new_partition_dict = None
     critical_tid_dict = None
@@ -192,6 +189,21 @@ class Replicator(object):
         """Return whether there is any pending partition."""
         return len(self.partition_dict) or len(self.new_partition_dict)
 
+    def getCurrentRID(self):
+        assert self.current_partition is not None
+        return self.current_partition.getRID()
+
+    def getCurrentCriticalTID(self):
+        assert self.current_partition is not None
+        return self.current_partition.getCriticalTID()
+
+    def setReplicationDone(self):
+        """ Callback from ReplicationHandler """
+        self.replication_done = True
+
+    def isCurrentConnection(self, conn):
+        return self.current_connection is conn
+
     def setCriticalTID(self, uuid, tid):
         """This is a callback from MasterOperationHandler."""
         try:





More information about the Neo-report mailing list