[Zope3-checkins] CVS: Zope3/src/zodb/storage - base.py:1.11.4.1 bdbfull.py:1.10.4.1 bdbminimal.py:1.10.4.1 file.py:1.7.4.1 interfaces.py:1.3.2.1 mapping.py:1.2.8.1

Jeremy Hylton jeremy@zope.com
Tue, 4 Feb 2003 17:54:45 -0500


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

Modified Files:
      Tag: storage-interface-branch
	base.py bdbfull.py bdbminimal.py file.py interfaces.py 
	mapping.py 
Log Message:
Refactor storage interfaces.

Move a bunch of exceptions related to storages from zodb.interfaces to
zodb.storages.interfaces.

Add __implements__ statements in all the concrete storage classes.

Add a simple (good?) mechanism to propagate __implements__ values from
a ZEO storage to its clients.

Remove all use of supportsXXX() methods in favor of
ISomeInterface.isImplementedBy().


=== Zope3/src/zodb/storage/base.py 1.11 => 1.11.4.1 ===
--- Zope3/src/zodb/storage/base.py:1.11	Mon Feb  3 18:00:45 2003
+++ Zope3/src/zodb/storage/base.py	Tue Feb  4 17:54:11 2003
@@ -40,9 +40,9 @@
     db = None
     berkeley_is_available = False
 
-from zodb import interfaces
 from zodb.timestamp import newTimeStamp, TimeStamp
 from zodb.interfaces import ITransactionAttrs
+from zodb.storage.interfaces import StorageTransactionError, ReadOnlyError
 # BaseStorage provides primitives for lock acquisition and release, and a host
 # of other methods, some of which are overridden here, some of which are not.
 from zodb.lockfile import lock_file
@@ -84,12 +84,12 @@
 
     def abortVersion(self, src, transaction):
         if transaction is not self._transaction:
-            raise interfaces.StorageTransactionError(self, transaction)
+            raise StorageTransactionError(self, transaction)
         return []
 
     def commitVersion(self, src, dest, transaction):
         if transaction is not self._transaction:
-            raise interfaces.StorageTransactionError(self, transaction)
+            raise StorageTransactionError(self, transaction)
         return []
 
     def close(self):
@@ -116,7 +116,7 @@
     def new_oid(self, last=None):
          # 'last' is only for internal use, not part of the public API
         if self._is_read_only:
-            raise interfaces.ReadOnlyError()
+            raise ReadOnlyError()
         if last is None:
             self._lock_acquire()
             try:
@@ -143,9 +143,6 @@
     def isReadOnly(self):
         return self._is_read_only
 
-    def supportsVersions(self):
-        return False
-
     def _clear_temp(self):
         # Called by tpc_begin(), tpc_abort(), and tpc_finish(), this should be
         # overridden in storages to clear out any temporary state.
@@ -170,7 +167,7 @@
     def tpc_begin(self, transaction, tid=None, status=' '):
         assert ITransactionAttrs.isImplementedBy(transaction)
         if self._is_read_only:
-            raise interfaces.ReadOnlyError()
+            raise ReadOnlyError()
         self._lock_acquire()
         try:
             if self._transaction is transaction:
@@ -282,7 +279,7 @@
 
     def pack(self, t):
         if self._is_read_only:
-            raise interfaces.ReadOnlyError()
+            raise ReadOnlyError()
 
     def getSerial(self, oid):
         self._lock_acquire()
@@ -294,8 +291,7 @@
             self._lock_release()
 
     def loadSerial(self, oid, serial):
-        raise interfaces.Unsupported, (
-            "Retrieval of historical revisions is not supported")
+        raise NotImplementedError
 
     def getExtensionMethods(self):
         """getExtensionMethods


=== Zope3/src/zodb/storage/bdbfull.py 1.10 => 1.10.4.1 ===
--- Zope3/src/zodb/storage/bdbfull.py:1.10	Fri Jan 24 13:54:12 2003
+++ Zope3/src/zodb/storage/bdbfull.py	Tue Feb  4 17:54:11 2003
@@ -22,11 +22,13 @@
 from struct import pack, unpack
 
 from zodb import interfaces
+from zodb.storage.interfaces import *
 from zodb.utils import p64, u64
 from zodb.serialize import findrefs
 from zodb.timestamp import TimeStamp
 from zodb.conflict import ConflictResolvingStorage, ResolvedSerial
-from zodb.interfaces import ITransactionAttrs, StorageSystemError
+from zodb.interfaces import ITransactionAttrs
+from zodb.storage.interfaces import StorageSystemError
 from zodb.storage.base import db, ZERO, BerkeleyBase, PackStop, _WorkThread
 from zodb.storage._helper import incr
 
@@ -52,6 +54,9 @@
 
 
 class BDBFullStorage(BerkeleyBase, ConflictResolvingStorage):
+    
+    __implements__ = IStorage, IUndoStorage, IVersionStorage
+    
     def _init(self):
         # Data Type Assumptions:
         #
@@ -546,7 +551,7 @@
     def store(self, oid, serial, data, version, transaction):
         # Lock and transaction wrapper
         if transaction is not self._transaction:
-            raise interfaces.StorageTransactionError(self, transaction)
+            raise StorageTransactionError(self, transaction)
         self._lock_acquire()
         try:
             return self._withtxn(self._dostore, oid, serial, data, version)
@@ -647,7 +652,7 @@
         # should be considered just a hint, and is ignored if the transaction
         # doesn't exist.
         if transaction is not self._transaction:
-            raise interfaces.StorageTransactionError(self, transaction)
+            raise StorageTransactionError(self, transaction)
         self._lock_acquire()
         try:
             self._withtxn(
@@ -757,7 +762,7 @@
         # Abort the version, but retain enough information to make the abort
         # undoable.
         if transaction is not self._transaction:
-            raise interfaces.StorageTransactionError(self, transaction)
+            raise StorageTransactionError(self, transaction)
         # We can't abort the empty version, because it's not a version!
         if not version:
             raise interfaces.VersionError
@@ -832,7 +837,7 @@
         # and dest are version strings, and if we're committing to a
         # non-version, dest will be empty.
         if transaction is not self._transaction:
-            raise interfaces.StorageTransactionError(self, transaction)
+            raise StorageTransactionError(self, transaction)
         # Sanity checks
         if not src or src == dest:
             raise interfaces.VersionCommitError
@@ -1183,7 +1188,7 @@
 
     def transactionalUndo(self, tid, transaction):
         if transaction is not self._transaction:
-            raise interfaces.StorageTransactionError(self, transaction)
+            raise StorageTransactionError(self, transaction)
         self._lock_acquire()
         try:
             return self._withtxn(self._dotxnundo, tid)
@@ -1727,17 +1732,6 @@
         finally:
             c.close()
             self._lock_release()
-
-    # Other interface assertions
-    def supportsTransactionalUndo(self):
-        return True
-
-    def supportsUndo(self):
-        return True
-
-    def supportsVersions(self):
-        return True
-
 
 
 class _GetItemBase:


=== Zope3/src/zodb/storage/bdbminimal.py 1.10 => 1.10.4.1 ===
--- Zope3/src/zodb/storage/bdbminimal.py:1.10	Thu Jan 30 18:17:43 2003
+++ Zope3/src/zodb/storage/bdbminimal.py	Tue Feb  4 17:54:11 2003
@@ -17,7 +17,7 @@
 $Revision$
 """
 
-from zodb import interfaces
+from zodb.storage.interfaces import *
 from zodb.utils import p64, u64
 from zodb.serialize import findrefs
 from zodb.conflict import ConflictResolvingStorage, ResolvedSerial
@@ -40,6 +40,9 @@
 
 
 class BDBMinimalStorage(BerkeleyBase, ConflictResolvingStorage):
+
+    __implements__ = IStorage
+    
     def _init(self):
         # Data Type Assumptions:
         #
@@ -283,10 +286,10 @@
 
     def store(self, oid, serial, data, version, transaction):
         if transaction is not self._transaction:
-            raise interfaces.StorageTransactionError(self, transaction)
+            raise StorageTransactionError(self, transaction)
         # We don't support versions
         if version <> '':
-            raise interfaces.Unsupported, 'versions are not supported'
+            raise NotImplementedError
         # All updates must be done with the application lock acquired
         self._lock_acquire()
         try:
@@ -343,7 +346,7 @@
 
     def load(self, oid, version):
         if version <> '':
-            raise interfaces.Unsupported, 'versions are not supported'
+            raise NotImplementedError
         self._lock_acquire()
         try:
             # Get the current serial number for this object
@@ -512,30 +515,7 @@
             orec = self._oidqueue.consume(txn)
         assert len(self._oidqueue) == 0
 
-    #
-    # Stuff we don't support
-    #
-
-    def supportsTransactionalUndo(self):
-        return False
-
-    def supportsUndo(self):
-        return False
-
-    def supportsVersions(self):
-        return False
-
-    # Don't implement these
-    #
-    # versionEmpty(self, version)
-    # versions(self, max=None)
-    # loadSerial(self, oid, serial)
     # getSerial(self, oid)
-    # transactionalUndo(self, tid, transaction)
-    # undoLog(self, first=0, last=-20, filter=None)
-    # history(self, oid, version=None, size=1, filter=None)
-    # iterator(self, start=None, stop=None)
-
 
 
 class _Autopack(_WorkThread):


=== Zope3/src/zodb/storage/file.py 1.7 => 1.7.4.1 ===
--- Zope3/src/zodb/storage/file.py:1.7	Mon Feb  3 18:00:45 2003
+++ Zope3/src/zodb/storage/file.py	Tue Feb  4 17:54:11 2003
@@ -153,6 +153,8 @@
 from zodb.lockfile import lock_file
 from zodb.utils import p64, u64, cp, z64
 from zodb.storage.fsindex import fsIndex
+from zodb.storage.interfaces import *
+from zodb.interfaces import ITransactionAttrs
 
 t32 = 1L << 32
 # the struct formats for the headers
@@ -175,7 +177,7 @@
     logger.critical(message, *data)
     raise CorruptedTransactionError(message % data)
 
-class FileStorageError(interfaces.StorageError):
+class FileStorageError(StorageError):
     pass
 
 class PackError(FileStorageError):
@@ -187,8 +189,7 @@
     The format of the given file is not valid.
     """
 
-class CorruptedFileStorageError(FileStorageError,
-                                interfaces.StorageSystemError):
+class CorruptedFileStorageError(FileStorageError, StorageSystemError):
     """Corrupted file storage."""
 
 class CorruptedTransactionError(CorruptedFileStorageError):
@@ -206,8 +207,7 @@
         else:
             return "Error reading unknown oid.  Found %r" % self.buf
 
-class FileStorageQuotaError(FileStorageError,
-                            interfaces.StorageSystemError):
+class FileStorageQuotaError(FileStorageError, StorageSystemError):
     """File storage quota exceeded."""
 
 def DB(file_name, create=0, read_only=0, stop=None, quota=None,
@@ -486,6 +486,8 @@
     # default pack time is 0
     _packt = z64
 
+    __implements__ = IStorage, IUndoStorage, IVersionStorage
+
     def __init__(self, file_name, create=0, read_only=0, stop=None,
                  quota=None):
 
@@ -674,7 +676,7 @@
     def commitVersion(self, src, dest, transaction, abort=None):
         # We are going to commit by simply storing back pointers.
         if self._is_read_only:
-            raise interfaces.ReadOnlyError()
+            raise ReadOnlyError()
         if not (src and isinstance(src, StringType)
                 and isinstance(dest, StringType)):
             raise interfaces.VersionCommitError('Invalid source version')
@@ -688,7 +690,7 @@
                 "Internal error, can't abort to a version")
 
         if transaction is not self._transaction:
-            raise interfaces.StorageTransactionError(self, transaction)
+            raise StorageTransactionError(self, transaction)
 
         self._lock_acquire()
         try:
@@ -820,9 +822,9 @@
 
     def store(self, oid, serial, data, version, transaction):
         if self._is_read_only:
-            raise interfaces.ReadOnlyError()
+            raise ReadOnlyError()
         if transaction is not self._transaction:
-            raise interfaces.StorageTransactionError(self, transaction)
+            raise StorageTransactionError(self, transaction)
 
         self._lock_acquire()
         try:
@@ -927,9 +929,9 @@
         # should be considered just a hint, and is ignored if the transaction
         # doesn't exist.
         if self._is_read_only:
-            raise interfaces.ReadOnlyError()
+            raise ReadOnlyError()
         if transaction is not self._transaction:
-            raise interfaces.StorageTransactionError(self, transaction)
+            raise StorageTransactionError(self, transaction)
 
         self._lock_acquire()
         try:
@@ -1009,12 +1011,6 @@
                      "at %d or %d", prev, bp)
                 return None
 
-    def supportsUndo(self):
-        return 1
-
-    def supportsVersions(self):
-        return 1
-
     def _clear_temp(self):
         self._tindex.clear()
         self._tvindex.clear()
@@ -1104,9 +1100,6 @@
             self._file.truncate(self._pos)
             self._nextpos=0
 
-    def supportsTransactionalUndo(self):
-        return 1
-
     def _undoDataInfo(self, oid, pos, tpos):
         """Return the serial, data pointer, data, and version for the oid
         record at pos"""
@@ -1280,9 +1273,9 @@
         """
 
         if self._is_read_only:
-            raise interfaces.ReadOnlyError()
+            raise ReadOnlyError()
         if transaction is not self._transaction:
-            raise interfaces.StorageTransactionError(self, transaction)
+            raise StorageTransactionError(self, transaction)
 
         self._lock_acquire()
         try:
@@ -1445,7 +1438,7 @@
         """
 
         if self._is_read_only:
-            raise interfaces.ReadOnlyError()
+            raise ReadOnlyError()
 
         stop = timeStampFromTime(t).raw()
         if stop == z64:
@@ -2180,8 +2173,7 @@
                 break
     except:
         error("couldn\'t write truncated data for %s", name)
-        raise interfaces.StorageSystemError, (
-            "Couldn't save truncated data")
+        raise StorageSystemError("Couldn't save truncated data")
 
     seek(pos)
     file.truncate()
@@ -2207,6 +2199,8 @@
     _ltid = z64
     _file = None
 
+    __implements__ = IStorageIterator
+
     def __init__(self, file, start=None, stop=None):
         if isinstance(file, StringType):
             file = open(file, 'rb')
@@ -2355,6 +2349,8 @@
 class RecordIterator(Iterator, FileStorageFormatter, TransactionRecord):
     """Iterate over the transactions in a FileStorage file."""
 
+    __implements__ = ITransactionRecordIterator, ITransactionAttrs
+
     def __init__(self, tid, status, user, desc, ext, pos, tend, file, tpos):
         self.tid = tid
         self.status = status
@@ -2403,6 +2399,9 @@
 
 class Record(DataRecord):
     """An abstract database record."""
+
+    __implements__ = IDataRecord
+    
     def __init__(self, *args):
         self.oid, self.serial, self.version, self.data, self.data_txn = args
 


=== Zope3/src/zodb/storage/interfaces.py 1.3 => 1.3.2.1 ===
--- Zope3/src/zodb/storage/interfaces.py:1.3	Tue Feb  4 10:45:26 2003
+++ Zope3/src/zodb/storage/interfaces.py	Tue Feb  4 17:54:11 2003
@@ -17,6 +17,7 @@
 """
 
 from zope.interface import Interface, Attribute
+from zodb.interfaces import POSError
 
 __all__ = ["IStorage",
            "IUndoStorage",
@@ -24,6 +25,14 @@
            "IStorageIterator",
            "ITransactionRecordIterator",
            "IDataRecord",
+           # the rest are exceptions
+           "StorageError",
+           "StorageVersionError",
+           "StorageTransactionError",
+           "StorageSystemError",
+           "MountedStorageError",
+           "ReadOnlyError",
+           "TransactionTooLargeError",
            ]
 
 class IStorage(Interface):
@@ -137,9 +146,6 @@
     def copyTransactionsFrom(other, versbose=False):
         pass
 
-    def iterator(start=None, stop=None):
-        pass
-
     def lastTransaction():
         pass
 
@@ -177,9 +183,6 @@
     def getSerial(oid):
         pass
 
-    def loadSerial(oid, serial):
-        pass
-
 class IUndoStorage(Interface):
     
     def pack(t):
@@ -197,6 +200,9 @@
     def undoLog(first, last, filter=None):
         """deprecated, using undoInfo instead"""
 
+    def iterator(start=None, stop=None):
+        pass
+
 class IVersionStorage(Interface):
     # XXX should be renamed
     def abortVersion(version):
@@ -255,3 +261,35 @@
                          wrote the data.  The current transaction contains
                          a logical copy of that data.
                          """)
+
+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."""
+
+class StorageSystemError(StorageError):
+    """Panic! Internal storage error!"""
+
+class MountedStorageError(StorageError):
+    """Unable to access mounted storage."""
+
+class ReadOnlyError(StorageError):
+    """Unable to modify objects in a read-only storage."""
+
+class TransactionTooLargeError(StorageTransactionError):
+    """The transaction exhausted some finite storage resource."""
+


=== Zope3/src/zodb/storage/mapping.py 1.2 => 1.2.8.1 ===
--- Zope3/src/zodb/storage/mapping.py:1.2	Wed Dec 25 09:12:19 2002
+++ Zope3/src/zodb/storage/mapping.py	Tue Feb  4 17:54:11 2003
@@ -92,6 +92,7 @@
 import zodb.db
 from zodb import interfaces, utils
 from zodb.storage import base
+from zodb.storage.interfaces import *
 from zodb.serialize import findrefs
 from zodb.timestamp import TimeStamp
 from zodb.utils import z64
@@ -104,6 +105,8 @@
 
 class MappingStorage(base.BaseStorage):
 
+    __implements__ = IStorage
+
     def __init__(self, name='Mapping Storage'):
 
         base.BaseStorage.__init__(self, name)
@@ -125,10 +128,10 @@
 
     def store(self, oid, serial, data, version, transaction):
         if transaction is not self._transaction:
-            raise interfaces.StorageTransactionError(self, transaction)
+            raise StorageTransactionError(self, transaction)
 
         if version:
-            raise interfaces.Unsupported, "Versions aren't supported"
+            raise NotImplementedError
 
         self._lock_acquire()
         try: