[Zodb-checkins] CVS: ZODB3/bsddb3Storage/bsddb3Storage - Full.py:1.44.2.10

Barry Warsaw barry@wooz.org
Tue, 5 Nov 2002 16:50:04 -0500


Update of /cvs-repository/ZODB3/bsddb3Storage/bsddb3Storage
In directory cvs.zope.org:/tmp/cvs-serv15079

Modified Files:
      Tag: bdb-nolocks
	Full.py 
Log Message:
_withtxn(): Add **kws.

_dopack(): Call _sweep(), via _withtxn() passing in the packtid as the
`end' argument.  Setting things up for sharing code with autopack().

_sweep(): Add `start' and `end' arguments, since think the bulk of
this method can be used with autopack().  Also, set zap=False only if
we're looking at an object's current serial number /and/ the object is
root reachable.  This helps us pass all the existing pack tests.

_collect(): This doesn't use the packtid argument, so get rid of it.
Also, the iterator over the txnoids cursor has to be inside a while
loop.


=== ZODB3/bsddb3Storage/bsddb3Storage/Full.py 1.44.2.9 => 1.44.2.10 ===
--- ZODB3/bsddb3Storage/bsddb3Storage/Full.py:1.44.2.9	Fri Nov  1 00:25:02 2002
+++ ZODB3/bsddb3Storage/bsddb3Storage/Full.py	Tue Nov  5 16:50:02 2002
@@ -241,7 +241,7 @@
         self._txnMetadata     = self._setupDB('txnMetadata')
         self._txnoids         = self._setupDB('txnoids', db.DB_DUP)
         self._pickleRefcounts = self._setupDB('pickleRefcounts')
-        # Tables to support packing.  oidqueue makes more sense as a Queue
+        # Table to support packing.
         self._packmark = self._setupDB('packmark')
         self._oidqueue = db.DB(self._env)
         self._oidqueue.set_re_len(8)
@@ -311,10 +311,10 @@
         self._zaptids.close()
         BerkeleyBase.close(self)
 
-    def _withtxn(self, meth, *args):
+    def _withtxn(self, meth, *args, **kws):
         txn = self._env.txn_begin()
         try:
-            ret = meth(txn, *args)
+            ret = meth(txn, *args, **kws)
         except:
             #import traceback ; traceback.print_exc()
             txn.abort()
@@ -1331,14 +1331,14 @@
         # non-current revisions of reachable objects.
         self._lock_acquire()
         try:
-            self._withtxn(self._sweep, packtid)
+            self._withtxn(self._sweep, end=packtid)
         finally:
             self._lock_release()
         # Now we have the zaptids table which contains a list of all the
         # transactions tha can get packed away.  So zap 'em.
         self._lock_acquire()
         try:
-            self._withtxn(self._collect, packtid)
+            self._withtxn(self._collect)
         finally:
             self._lock_release()
 
@@ -1382,16 +1382,20 @@
             oid = rec and rec[1]
         assert len(self._oidqueue) == 0
 
-    def _sweep(self, txn, packtid):
+    def _sweep(self, txn, start=None, end=None):
         cm = self._txnMetadata.cursor(txn=txn)
         try:
             # Cruise forward through transactions from the first to the pack
             # time looking for unpacked transactions that have no current
             # records for their objects.
-            mrec = cm.first()
+            mrec = None
+            if start is not None:
+                mrec = cm.set(start)
+            if mrec is None:
+                mrec = cm.first()
             while mrec:
                 tid, metadata = mrec
-                if tid > packtid:
+                if tid > end:
                     break
                 mrec = cm.next()
                 if metadata[0] == PROTECTED_TRANSACTION:
@@ -1406,11 +1410,11 @@
                         rec = ct.next_dup()
                         if ctid <> tid:
                             break
-                        serial, otid = self._getSerialAndTid(oid)
-                        if serial == tid:
+                        serial, otid = self._getSerialAndTid(coid)
+                        if serial == tid and self._packmark.has_key(coid):
                             # This transaction matches the current serial
-                            # number for this object, so we can't pack this
-                            # transaction.
+                            # number for an object that is reachable from the
+                            # root, so we can't pack this transaction.
                             zap = False
                             break
                     if zap:
@@ -1422,7 +1426,7 @@
         # We're done with the mark table
         self._packmark.truncate(txn=txn)
 
-    def _collect(self, txn, packtid):
+    def _collect(self, txn):
         rec = self._zaptids.consume()
         while rec:
             tid = rec[1]
@@ -1430,17 +1434,16 @@
             c = self._txnoids.cursor(txn)
             try:
                 trec = c.set(tid)
-                if trec[0] <> tid:
-                    break
-                # We can get rid of this txnoids entry
-                c.delete()
-                trec = c.next_dup()
-                # Delete the metadata record
-                oid = trec[1]
-                metadata = self._metadata[oid+tid]
-                self._metadata.delete(oid+tid, txn=txn)
-                # Decref the pickle
-                self._decrefPickle(oid, metadata[16:24], txn)
+                while trec and trec[0] == tid:
+                    oid = trec[1]
+                    # We can get rid of this txnoids entry
+                    c.delete()
+                    trec = c.next_dup()
+                    # Delete the metadata record
+                    metadata = self._metadata[oid+tid]
+                    self._metadata.delete(oid+tid, txn=txn)
+                    # Decref the pickle
+                    self._decrefPickle(oid, metadata[16:24], txn)
             finally:
                 c.close()
             # Set the status flag on the transaction metadata for this txn