[Zope3-checkins] CVS: Zope3/src/zodb/storage - bdbfull.py:1.21

Barry Warsaw barry@wooz.org
Thu, 3 Apr 2003 17:16:48 -0500


Update of /cvs-repository/Zope3/src/zodb/storage
In directory cvs.zope.org:/tmp/cvs-serv12507

Modified Files:
	bdbfull.py 
Log Message:
Various cleanups.  Turn __nextvid and __ltid into single-underscore
attributes so they can be used in derived classes better.

_doabort(): Don't wrap in a try/except since we should never delete
currentVerson entries unless vid <> ZERO.

Use True/False in a couple of places.

lastSerial(): Added.

_doundo(): Fix the currentVersion() record we put here.  It should be
a vid->revid mapping.

ZODB3 bug fix candidate.


=== Zope3/src/zodb/storage/bdbfull.py 1.20 => 1.21 ===
--- Zope3/src/zodb/storage/bdbfull.py:1.20	Thu Mar 20 17:54:52 2003
+++ Zope3/src/zodb/storage/bdbfull.py	Thu Apr  3 17:16:48 2003
@@ -278,9 +278,9 @@
             # Convert to a Python long integer.  Note that cursor.last()
             # returns key/value, and we want the key (which for the
             # versions table is the vid).
-            self.__nextvid = u64(rec[0])
+            self._nextvid = u64(rec[0])
         else:
-            self.__nextvid = 0L
+            self._nextvid = 0L
         # Initialize the last transaction
         c = self._txnoids.cursor()
         try:
@@ -288,9 +288,9 @@
         finally:
             c.close()
         if rec:
-            self.__ltid = rec[0]
+            self._ltid = rec[0]
         else:
-            self.__ltid = ZERO
+            self._ltid = ZERO
 
     def _make_autopacker(self, event):
         config = self._config
@@ -340,11 +340,8 @@
                 else:
                     cr.delete()
                 # Now we have to clean up the currentVersions table
-                try:
+                if vid <> ZERO:
                     cv.set_both(vid, revid)
-                except db.DBNotFoundError:
-                    pass
-                else:
                     cv.delete()
         finally:
             # There's a small window of opportunity for leaking cursors here,
@@ -355,17 +352,17 @@
             if cv: cv.close()
             if cr: cr.close()
         # Now clean up the vids and versions tables
-        cv = self._pvids.cursor(txn=txn)
+        cpv = self._pvids.cursor(txn=txn)
         try:
-            rec = cv.first()
+            rec = cpv.first()
             while rec:
                 vid = rec[0]
-                rec = cv.next()
+                rec = cpv.next()
                 version = self._versions[vid]
                 self._versions.delete(vid, txn=txn)
                 self._vids.delete(version, txn=txn)
         finally:
-            cv.close()
+            cpv.close()
         # Now clean up the tid indexed table, and the temporary log tables
         self._txnMetadata.delete(tid, txn=txn)
         self._oids.truncate(txn)
@@ -474,7 +471,7 @@
 
     def _finish(self, tid, u, d, e):
         self._withtxn(self._docommit, self._serial)
-        self.__ltid = tid
+        self._ltid = tid
 
     #
     # Storing an object revision in a transaction
@@ -682,9 +679,9 @@
         # progress gets aborted.
         vid = self._vids.get(version)
         if vid is None:
-            self.__nextvid += 1
+            self._nextvid += 1
             # Convert the version id into an 8-byte string
-            vid = p64(self.__nextvid)
+            vid = p64(self._nextvid)
             # Now update the vids/versions tables, along with the log table
             self._vids.put(version, vid, txn=txn)
             self._versions.put(vid, version, txn=txn)
@@ -717,7 +714,7 @@
                     rec = c.next()
                     continue
                 # This object was modified
-                rtnoids[oid] = 1
+                rtnoids[oid] = True
                 # Calculate the values for the new transaction metadata
                 serial, tid = self._getSerialAndTid(oid)
                 meta = self._metadata[oid+tid]
@@ -791,7 +788,7 @@
         if not dest:
             dvid = ZERO
         else:
-            # Find the vid for the dest version, or create on eif necessary.
+            # Find the vid for the dest version, or create one if necessary.
             dvid = self._findcreatevid(dest, txn)
         c = self._currentVersions.cursor(txn)
         try:
@@ -811,14 +808,14 @@
                     rec = c.next()
                     continue
                 # This object was modified
-                rtnoids[oid] = 1
+                rtnoids[oid] = True
                 # Calculate the values for the new transaction metadata
                 serial, tid = self._getSerialAndTid(oid)
                 meta = self._metadata[oid+tid]
                 curvid, nvrevid, lrevid = unpack('>8s8s8s', meta[:24])
                 assert curvid == svid
                 # If we're committing to the non-version, then the nvrevid
-                # ougt to be ZERO too, regardless of what it was for the
+                # ought to be ZERO too, regardless of what it was for the
                 # source version.
                 if not dest:
                     nvrevid = ZERO
@@ -892,10 +889,7 @@
             vid = self._vids.get(version, missing)
             if vid is missing:
                 return True
-            if self._currentVersions.has_key(vid):
-                return False
-            else:
-                return True
+            return not self._currentVersions.has_key(vid)
         finally:
             self._lock_release()
 
@@ -1069,7 +1063,15 @@
 
     def lastTransaction(self):
         """Return transaction id for last committed transaction"""
-        return self.__ltid
+        return self._ltid
+
+    def lastSerial(self, oid):
+        """Return last serialno committed for object oid.
+
+        If there is no serialno for this oid -- which can only occur
+        if it is a new object -- return None.
+        """
+        return self._getSerialAndTidMissingOk(oid)[0]
 
     #
     # Transactional undo
@@ -1213,7 +1215,7 @@
                 self._prevrevids.put(oid, prevrevid, txn=txn)
                 self._txnoids.put(newserial, oid, txn=txn)
                 if vid <> ZERO:
-                    self._currentVersions.put(oid, vid, txn=txn)
+                    self._currentVersions.put(vid, revid, txn=txn)
             self._oids.put(oid, PRESENT, txn=txn)
             rtnoids[oid] = True
             # Add this object revision to the autopack table