[Zope-Checkins] CVS: StandaloneZODB/Tools - timeiter.py:1.1.2.10

Jeremy Hylton jeremy@zope.com
Fri, 18 Jan 2002 13:45:03 -0500


Update of /cvs-repository/StandaloneZODB/Tools
In directory cvs.zope.org:/tmp/cvs-serv25841

Modified Files:
      Tag: Standby-branch
	timeiter.py 
Log Message:
Update store() and tpc_vote() handling to support ZEO-version of storage API.


=== StandaloneZODB/Tools/timeiter.py 1.1.2.9 => 1.1.2.10 ===
         objects = 0
         size = 0
+        newrevids = RevidAccumulator()
         t0 = time.time()
         dstdb.tpc_begin(txn, tid, txn.status)
         t1 = time.time()
@@ -257,11 +258,13 @@
                     vstr = r.version
                 print utils.U64(oid), vstr, len(r.data)
             oldrevid = prevrevids.get(oid, ZERO)
-            newrevid = dstdb.store(oid, oldrevid, r.data, r.version, txn)
-            prevrevids[oid] = newrevid
+            result = dstdb.store(oid, oldrevid, r.data, r.version, txn)
+            newrevids.store(oid, result)
         t2 = time.time()
-        dstdb.tpc_vote(txn)
+        result = dstdb.tpc_vote(txn)
         t3 = time.time()
+        newrevids.tpc_vote(result)
+        prevrevids.update(newrevids.get_dict())
         # Profile every 100 transactions
         if prof:
             prof.runcall(dstdb.tpc_finish, txn)
@@ -291,6 +294,36 @@
     print >> outfp, "Total pickle size: %14d" % total_pickle_size
     print >> outfp, "Total object count:      %8d" % total_object_count
 
+
+
+# helper to deal with differences between old-style store() return and
+# new-style store() return that supports ZEO
+import types
+
+class RevidAccumulator:
+
+    def __init__(self):
+        self.data = {}
+
+    def _update_from_list(self, list):
+        for oid, serial in list:
+            if not isinstance(serial, types.StringType):
+                raise serial
+            self.data[oid] = serial
+
+    def store(self, oid, result):
+        if isinstance(result, types.StringType):
+            self.data[oid] = result
+        elif result is not None:
+            self._update_from_list(result)
+
+    def tpc_vote(self, result):
+        if result is not None:
+            self._update_from_list(result)
+
+    def get_dict(self):
+        return self.data
+    
 
 
 # This cruft is necessary because otherwise, it's just too dang hard to get