[Zodb-checkins] CVS: Zope3/src/zodb - db.py:1.2.4.1 interfaces.py:1.3.2.1
Jeremy Hylton
jeremy@zope.com
Tue, 21 Jan 2003 11:21:11 -0500
Update of /cvs-repository/Zope3/src/zodb
In directory cvs.zope.org:/tmp/cvs-serv25266/src/zodb
Modified Files:
Tag: new-pickle-branch
db.py interfaces.py
Log Message:
Add database version information to the storage.
Only handled for file storage so far. A file storage now has two
version identifiers. The first identifies the storage format and is
independent of the pickle format. The second identifies the object
format used by the database. The intent of the database format is to
allow future migration from old versions of the database. (If we'd
ever change the pickle format again, a script could use the database
version to detect old pickles.)
=== Zope3/src/zodb/db.py 1.2 => 1.2.4.1 ===
--- Zope3/src/zodb/db.py:1.2 Wed Dec 25 09:12:16 2002
+++ Zope3/src/zodb/db.py Tue Jan 21 11:20:38 2003
@@ -24,7 +24,7 @@
from types import StringType
import logging
-from zodb.interfaces import StorageError
+from zodb.interfaces import StorageError, StorageVersionError
from zodb.connection import Connection
from zodb.serialize import getDBRoot
from zodb.ztransaction import Transaction
@@ -40,17 +40,17 @@
or more connections, which manage object spaces. Most of the actual work
of managing objects is done by the connections.
"""
- def __init__(self, storage,
- pool_size=7,
- cache_size=400,
- ):
+
+ # the database version number
+ version = (4, 0, 0, "alpha", 2)
+
+ def __init__(self, storage, pool_size=7, cache_size=400):
"""Create an object database.
The storage for the object database must be passed in.
Optional arguments are:
pool_size -- The size of the pool of object spaces.
-
"""
# Allocate locks:
@@ -69,6 +69,7 @@
# Setup storage
self._storage = storage
+ self._checkVersion()
storage.registerDB(self)
try:
storage.load(z64, "")
@@ -84,6 +85,17 @@
for m in ('history', 'supportsVersions', 'undoInfo', 'versionEmpty',
'versions', 'modifiedInVersion', 'versionEmpty'):
setattr(self, m, getattr(storage, m))
+
+ def _checkVersion(self):
+ # Make sure the database version that created the storage is
+ # compatible with this version of the database. If the storage
+ # doesn't have a database version, it's brand-new so set it.
+ ver = self._storage.getVersion()
+ if ver is None:
+ self._storage.setVersion(self.version)
+ else:
+ # No version compatibility checking yet ...
+ pass
def _closeConnection(self, connection):
"""Return a connection to the pool"""
=== Zope3/src/zodb/interfaces.py 1.3 => 1.3.2.1 ===
--- Zope3/src/zodb/interfaces.py:1.3 Wed Jan 15 17:59:06 2003
+++ Zope3/src/zodb/interfaces.py Tue Jan 21 11:20:38 2003
@@ -16,11 +16,14 @@
$Id$
"""
-from transaction.interfaces \
- import TransactionError, RollbackError, ConflictError as _ConflictError
-
from types import StringType, DictType
+
import zodb.utils
+from zope.interface import Interface, Attribute
+
+from transaction.interfaces import ITransaction as _ITransaction
+from transaction.interfaces \
+ import TransactionError, RollbackError, ConflictError as _ConflictError
def _fmt_oid(oid):
return "%016x" % zodb.utils.u64(oid)
@@ -184,6 +187,19 @@
class StorageError(POSError):
"""Base class for storage based exceptions."""
+class StorageVersionError(StorageError):
+ """The storage version doesn't match the database version."""
+
+ def __init__(self, db_ver, storage_ver):
+ self.db_ver = db_ver
+ self.storage_ver = storage_ver
+
+ def __str__(self):
+ db = ".".join(self.db_ver)
+ storage = ".".join(self.storage_ver)
+ return ("Storage version %s passed to database version %s"
+ % (storage, db))
+
class StorageTransactionError(StorageError):
"""An operation was invoked for an invalid transaction or state."""
@@ -214,12 +230,6 @@
o A reference to an object in a different database connection.
"""
-
-
-from zope.interface import Interface
-from zope.interface import Attribute
-
-from transaction.interfaces import ITransaction as _ITransaction
class IConnection(Interface):
"""Interface required of Connection by ZODB DB.