[Zodb-checkins] CVS: Packages/ZODB - BaseStorage.py:1.34.4.3 FileStorage.py:1.135.6.8

Tim Peters tim.one at comcast.net
Mon Feb 28 16:21:12 EST 2005


Update of /cvs-repository/Packages/ZODB
In directory cvs.zope.org:/tmp/cvs-serv8391/ZODB

Modified Files:
      Tag: Zope-2_7-branch
	BaseStorage.py FileStorage.py 
Log Message:
Change FileStorage .restore() and .store() to update max oid in use.

This is the last of the checkins to fix critical bugs involving rare cases
where a FileStorage could end up reusing old oids for new objects.


=== Packages/ZODB/BaseStorage.py 1.34.4.2 => 1.34.4.3 ===
--- Packages/ZODB/BaseStorage.py:1.34.4.2	Thu May 13 15:50:45 2004
+++ Packages/ZODB/BaseStorage.py	Mon Feb 28 16:20:41 2005
@@ -106,6 +106,17 @@
             if d < 255: return last[:-1]+chr(d+1)+'\0'*(8-len(last))
             else:       return self.new_oid(last[:-1])
 
+    # Update the maximum oid in use, under protection of a lock.  The
+    # maximum-in-use attribute is changed only if possible_new_max_oid is
+    # larger than its current value.
+    def set_max_oid(self, possible_new_max_oid):
+        self._lock_acquire()
+        try:
+            if possible_new_max_oid > self._oid:
+                self._oid = possible_new_max_oid
+        finally:
+            self._lock_release()
+
     def registerDB(self, db, limit):
         pass # we don't care
 
@@ -280,10 +291,7 @@
         # using store().  However, if we use store, then
         # copyTransactionsFrom() may fail with VersionLockError or
         # ConflictError.
-        if hasattr(self, 'restore'):
-            restoring = 1
-        else:
-            restoring = 0
+        restoring = hasattr(self, 'restore')
         fiter = other.iterator()
         for transaction in fiter:
             tid=transaction.tid


=== Packages/ZODB/FileStorage.py 1.135.6.7 => 1.135.6.8 ===
--- Packages/ZODB/FileStorage.py:1.135.6.7	Fri Feb 25 15:31:04 2005
+++ Packages/ZODB/FileStorage.py	Mon Feb 28 16:20:41 2005
@@ -762,6 +762,8 @@
 
         self._lock_acquire()
         try:
+            if oid > self._oid:
+                self.set_max_oid(oid)
             old = self._index_get(oid, 0)
             cached_serial = None
             pnv = None
@@ -909,6 +911,8 @@
 
         self._lock_acquire()
         try:
+            if oid > self._oid:
+                self.set_max_oid(oid)
             prev_pos = 0
             if prev_txn is not None:
                 prev_txn_pos = self._txn_find(prev_txn, 0)



More information about the Zodb-checkins mailing list