[Zope-Checkins] CVS: ZODB3/BDBStorage - BDBFullStorage.py:1.44.4.4 BDBMinimalStorage.py:1.12.6.3 BerkeleyBase.py:1.19.4.3 __init__.py:1.8.6.3

Barry Warsaw barry@wooz.org
Mon, 27 Jan 2003 18:19:34 -0500


Update of /cvs-repository/ZODB3/BDBStorage
In directory cvs.zope.org:/tmp/cvs-serv9345/BDBStorage

Modified Files:
      Tag: ZODB3-3_1-branch
	BDBFullStorage.py BDBMinimalStorage.py BerkeleyBase.py 
	__init__.py 
Log Message:
Backport Berkeley storage fixes from the 3.2 trunk.


=== ZODB3/BDBStorage/BDBFullStorage.py 1.44.4.3 => 1.44.4.4 ===
--- ZODB3/BDBStorage/BDBFullStorage.py:1.44.4.3	Tue Jan 21 17:28:36 2003
+++ ZODB3/BDBStorage/BDBFullStorage.py	Mon Jan 27 18:19:01 2003
@@ -53,6 +53,8 @@
     True = 1
     False = 0
 
+BDBFULL_SCHEMA_VERSION = 'BF01'
+
 
 
 class BDBFullStorage(BerkeleyBase, ConflictResolvingStorage):
@@ -185,7 +187,10 @@
         #         packtime - time of the last pack.  It is illegal to undo to
         #         before the last pack time.
         #
-        #         version - the version of the database (reserved for ZODB4)
+        #         dbversion - the version of the database serialization
+        #         protocol (reserved for ZODB4)
+        #
+        #         version - the underlying Berkeley database schema version
         #
         # objrevs -- {newserial+oid -> oldserial}
         #     This table collects object revision information for packing
@@ -234,6 +239,13 @@
         self._delqueue = self._setupDB('delqueue', 0, db.DB_QUEUE, 8)
         # Do recovery and consistency checks
         self._withlock(self._dorecovery)
+
+    def _version_check(self, txn):
+        version = self._info.get('version')
+        if version is None:
+            self._info.put('version', BDBFULL_SCHEMA_VERSION, txn=txn)
+        elif version <> BDBFULL_SCHEMA_VERSION:
+            raise StorageSystemError, 'incompatible storage version'
 
     def _make_autopacker(self, event):
         config = self._config


=== ZODB3/BDBStorage/BDBMinimalStorage.py 1.12.6.2 => 1.12.6.3 ===
--- ZODB3/BDBStorage/BDBMinimalStorage.py:1.12.6.2	Tue Jan 21 17:29:34 2003
+++ ZODB3/BDBStorage/BDBMinimalStorage.py	Mon Jan 27 18:19:01 2003
@@ -13,10 +13,10 @@
 ##############################################################################
 
 """Berkeley storage without undo or versioning.
-
-$Revision$
 """
 
+__version__ = '$Revision$'[-2:][0]
+
 from ZODB import POSException
 from ZODB.utils import p64, U64
 from ZODB.referencesf import referencesf
@@ -35,6 +35,8 @@
     True = 1
     False = 0
 
+BDBMINIMAL_SCHEMA_VERSION = 'BM01'
+
 
 
 class BDBMinimalStorage(BerkeleyBase, ConflictResolvingStorage):
@@ -124,6 +126,13 @@
             finally:
                 self._lock_release()
 
+    def _version_check(self, txn):
+        version = self._info.get('version')
+        if version is None:
+            self._info.put('version', BDBMINIMAL_SCHEMA_VERSION, txn=txn)
+        elif version <> BDBMINIMAL_SCHEMA_VERSION:
+            raise StorageSystemError, 'incompatible storage version'
+
     def _make_autopacker(self, event):
         return _Autopack(self, event, self._config.frequency)
 
@@ -269,6 +278,12 @@
         self._serials.put(oid, newserial, txn=txn)
         self._pickles.put(oid+newserial, data, txn=txn)
         self._oids.put(oid, PRESENT, txn=txn)
+        # If we're in the middle of a pack, we need to add these objects to
+        # the packmark, so a specific race condition won't collect them.
+        # E.g. we do a mark, then we do a store, then we sweep.  The objects
+        # stored between the mark and sweep would get collected away.
+        if self._packing:
+            self._packmark.put(oid, PRESENT, txn=txn)
         # Return the new serial number for the object
         if conflictresolved:
             return ResolvedSerial


=== ZODB3/BDBStorage/BerkeleyBase.py 1.19.4.2 => 1.19.4.3 ===
--- ZODB3/BDBStorage/BerkeleyBase.py:1.19.4.2	Tue Jan 21 17:31:18 2003
+++ ZODB3/BDBStorage/BerkeleyBase.py	Mon Jan 27 18:19:01 2003
@@ -13,8 +13,6 @@
 ##############################################################################
 
 """Base class for BerkeleyStorage implementations.
-
-$Revision$
 """
 
 import os
@@ -221,6 +219,7 @@
         # procedure
         self._tables = []
         self._setupDBs()
+        self._withtxn(self._version_check)
         # Initialize the object id counter.
         self._init_oid()
         # Set up the checkpointing thread
@@ -239,6 +238,9 @@
         else:
             self._autopacker = None
         self.log('ready')
+
+    def _version_check(self, txn):
+        raise NotImplementedError
 
     def _make_autopacker(self, event):
         raise NotImplementedError


=== ZODB3/BDBStorage/__init__.py 1.8.6.2 => 1.8.6.3 ===
--- ZODB3/BDBStorage/__init__.py:1.8.6.2	Tue Jan 21 17:31:56 2003
+++ ZODB3/BDBStorage/__init__.py	Mon Jan 27 18:19:01 2003
@@ -27,7 +27,7 @@
         return not not x
 
 try:
-    from bsddb import _db as db
+    from bsddb import db
 except ImportError:
     try:
         from bsddb3 import db