[Zope3-checkins] CVS: Zope3/src/zodb/storage - base.py:1.1.2.2 bdbfull.py:1.1.2.2 bdbminimal.py:1.1.2.2 file.py:1.1.2.2 mapping.py:1.1.2.2

Barry Warsaw barry@wooz.org
Mon, 23 Dec 2002 16:53:24 -0500


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

Modified Files:
      Tag: NameGeddon-branch
	base.py bdbfull.py bdbminimal.py file.py mapping.py 
Log Message:
Deunfrakificationlinessification


=== Zope3/src/zodb/storage/base.py 1.1.2.1 => 1.1.2.2 === (691/791 lines abridged)
--- Zope3/src/zodb/storage/base.py:1.1.2.1	Mon Dec 23 14:30:49 2002
+++ Zope3/src/zodb/storage/base.py	Mon Dec 23 16:52:52 2002
@@ -12,110 +12,411 @@
 #
 ##############################################################################
 
-"""Base class for BerkeleyStorage implementations.
+
+
+"""Handy standard storage machinery
+
+$Id$
 """
-__version__ = '$Revision$'.split()[-2:][0]
 
-import os
-import time
-import errno
-import shutil
+__metaclass__ = type
+
 import threading
-from types import StringType
-import logging
+from zodb import interfaces
+from zodb.timestamp import newTimeStamp, TimeStamp
+from zodb.interfaces import ITransactionAttrs
+z64='\0'*8
 
-# This uses the Dunn/Kuchling PyBSDDB v3 extension module available from
-# http://pybsddb.sourceforge.net
-from bsddb3 import db
+class BaseStorage:
+    _transaction = None # Transaction that is being committed
+    _serial = z64       # Transaction serial number
+    _tstatus = ' '      # Transaction status, used for copying data
+    _is_read_only = False
 
-# 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
+    def __init__(self, name, base=None):
+        self._name = name
 
-from zodb.serialize import findrefs
+        # Allocate locks:
+        l=threading.RLock()
+        self._lock_acquire = l.acquire
+        self._lock_release = l.release
+        l=threading.Lock()

[-=- -=- -=- 691 lines omitted -=- -=- -=-]

-        to proxy in addition to the standard storage methods.
-        Dictionary values should be None; this will be a handy place
-        for extra marshalling information, should we need it
-        """
-	return {}
-
-    def copyTransactionsFrom(self, other, verbose=0):
-        """Copy transactions from another storage.
-
-        This is typically used for converting data from one storage to
-        another.
-        """
-        _ts = None
-        ok = True
-        for transaction in other.iterator():
-            tid = transaction.tid
-            if _ts is None:
-                _ts = TimeStamp(tid)
-            else:
-                t = TimeStamp(tid)
-                if t <= _ts:
-                    if ok:
-                        print ('Time stamps out of order %s, %s' % (_ts, t))
-                    ok = False
-                    _ts = t.laterThan(_ts)
-                    tid = _ts.raw()
-                else:
-                    _ts = t
-                    if not ok:
-                        print ('Time stamps back in order %s' % (t))
-                        ok = True
-
-            if verbose:
-                print _ts
-
-            self.tpc_begin(transaction, tid, transaction.status)
-            for r in transaction:
-                if verbose: print `r.oid`, r.version, len(r.data)
-                self.restore(r.oid, r.serial, r.data, r.version,
-                             r.data_txn, transaction)
-            self.tpc_vote(transaction)
-            self.tpc_finish(transaction)
-
-class TransactionRecord:
-    """Abstract base class for iterator protocol."""
-
-    __implements__ = ITransactionAttrs
-
-class DataRecord:
-    """Abstract base class for iterator protocol."""


=== Zope3/src/zodb/storage/bdbfull.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zodb/storage/bdbfull.py:1.1.2.1	Mon Dec 23 14:30:49 2002
+++ Zope3/src/zodb/storage/bdbfull.py	Mon Dec 23 16:52:52 2002
@@ -26,7 +26,7 @@
 # PyBSDDB3.  The only recommended version of BerkeleyDB is 4.0.14.
 from bsddb3 import db
 
-from zodb import POSException
+from zodb import interfaces
 from zodb.utils import p64, u64
 from zodb.serialize import findrefs
 from zodb.timestamp import TimeStamp
@@ -476,7 +476,7 @@
             if data:
                 conflictresolved = True
             else:
-                raise POSException.ConflictError(serials=(oserial, serial))
+                raise interfaces.ConflictError(serials=(oserial, serial))
         # Do we already know about this version?  If not, we need to record
         # the fact that a new version is being created.  version will be the
         # empty string when the transaction is storing on the non-version
@@ -502,7 +502,7 @@
                 oversion = self._versions[ovid]
                 # We're trying to make a change on a version that's different
                 # than the version the current revision is on.  Nuh uh.
-                raise POSException.VersionLockError(oid, oversion)
+                raise interfaces.VersionLockError(oid, oversion)
             else:
                 # We're making another change to this object on this version.
                 # The non-version revid is the same as for the previous
@@ -532,7 +532,7 @@
     def store(self, oid, serial, data, version, transaction):
         # Lock and transaction wrapper
         if transaction is not self._transaction:
-            raise POSException.StorageTransactionError(self, transaction)
+            raise interfaces.StorageTransactionError(self, transaction)
         self._lock_acquire()
         try:
             return self._withtxn(self._dostore, oid, serial, data, version)
@@ -633,7 +633,7 @@
         # should be considered just a hint, and is ignored if the transaction
         # doesn't exist.
         if transaction is not self._transaction:
-            raise POSException.StorageTransactionError(self, transaction)
+            raise interfaces.StorageTransactionError(self, transaction)
         self._lock_acquire()
         try:
             self._withtxn(
@@ -664,7 +664,7 @@
     def _doAbortVersion(self, txn, version):
         vid = self._vids.get(version)
         if vid is None:
-            raise POSException.VersionError, 'not a version: %s' % version
+            raise interfaces.VersionError, 'not a version: %s' % version
         # We need to keep track of the oids that are affected by the abort so
         # that we can return it to the connection, which must invalidate the
         # objects so they can be reloaded.
@@ -743,10 +743,10 @@
         # Abort the version, but retain enough information to make the abort
         # undoable.
         if transaction is not self._transaction:
-            raise POSException.StorageTransactionError(self, transaction)
+            raise interfaces.StorageTransactionError(self, transaction)
         # We can't abort the empty version, because it's not a version!
         if not version:
-            raise POSException.VersionError
+            raise interfaces.VersionError
         self._lock_acquire()
         try:
             return self._withtxn(self._doAbortVersion, version)
@@ -818,10 +818,10 @@
         # 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 POSException.StorageTransactionError(self, transaction)
+            raise interfaces.StorageTransactionError(self, transaction)
         # Sanity checks
         if not src or src == dest:
-            raise POSException.VersionCommitError
+            raise interfaces.VersionCommitError
         self._lock_acquire()
         try:
             return self._withtxn(self._doCommitVersion, src, dest)
@@ -1089,7 +1089,7 @@
             # The object's revision is in it's initial creation state but
             # we're asking for an undo of something other than the initial
             # creation state.  No, no.
-            raise POSException.UndoError, 'Undoing mismatched zombification'
+            raise interfaces.UndoError, 'Undoing mismatched zombification'
         last_lrevid     = self._metadata[oid+last_prevrevid][16:24]
         target_metadata = self._metadata[oid+target_prevrevid]
         target_lrevid   = target_metadata[16:24]
@@ -1109,13 +1109,13 @@
             if data:
                 return oid, target_metadata, data
             else:
-                raise POSException.UndoError, 'Cannot undo transaction'
+                raise interfaces.UndoError, 'Cannot undo transaction'
 
     def _dotxnundo(self, txn, tid):
         # First, make sure the transaction isn't protected by a pack.
         packtime = self._last_packtime()
         if tid <= packtime:
-            raise POSException.UndoError, 'Transaction cannot be undone'
+            raise interfaces.UndoError, 'Transaction cannot be undone'
         # Calculate all the oids of objects modified in this transaction
         newrevs = []
         c = self._txnoids.cursor(txn=txn)
@@ -1175,7 +1175,7 @@
 
     def transactionalUndo(self, tid, transaction):
         if transaction is not self._transaction:
-            raise POSException.StorageTransactionError(self, transaction)
+            raise interfaces.StorageTransactionError(self, transaction)
         self._lock_acquire()
         try:
             return self._withtxn(self._dotxnundo, tid)


=== Zope3/src/zodb/storage/bdbminimal.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zodb/storage/bdbminimal.py:1.1.2.1	Mon Dec 23 14:30:49 2002
+++ Zope3/src/zodb/storage/bdbminimal.py	Mon Dec 23 16:52:52 2002
@@ -22,7 +22,7 @@
 # PyBSDDB3.
 from bsddb3 import db
 
-from zodb import POSException
+from zodb import interfaces
 from zodb.utils import p64, u64
 from zodb.serialize import findrefs
 from zodb.conflict import ConflictResolvingStorage, ResolvedSerial
@@ -245,7 +245,7 @@
             if data:
                 conflictresolved = True
             else:
-                raise POSException.ConflictError(serials=(oserial, serial))
+                raise interfaces.ConflictError(serials=(oserial, serial))
         # Optimistically write to the serials and pickles table.  Be sure
         # to also update the oids table for this object too.
         newserial = self._serial
@@ -259,10 +259,10 @@
 
     def store(self, oid, serial, data, version, transaction):
         if transaction is not self._transaction:
-            raise POSException.StorageTransactionError(self, transaction)
+            raise interfaces.StorageTransactionError(self, transaction)
         # We don't support versions
         if version <> '':
-            raise POSException.Unsupported, 'versions are not supported'
+            raise interfaces.Unsupported, 'versions are not supported'
         # All updates must be done with the application lock acquired
         self._lock_acquire()
         try:
@@ -319,7 +319,7 @@
 
     def load(self, oid, version):
         if version <> '':
-            raise POSException.Unsupported, 'versions are not supported'
+            raise interfaces.Unsupported, 'versions are not supported'
         self._lock_acquire()
         try:
             # Get the current serial number for this object


=== Zope3/src/zodb/storage/file.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zodb/storage/file.py:1.1.2.1	Mon Dec 23 14:30:49 2002
+++ Zope3/src/zodb/storage/file.py	Mon Dec 23 16:52:52 2002
@@ -134,7 +134,7 @@
     fsync = None
 
 import zodb.db
-from zodb import BaseStorage, ConflictResolution, POSException
+from zodb import BaseStorage, ConflictResolution, interfaces
 from zodb.interfaces import UndoError, POSKeyError, MultipleUndoErrors
 from zodb.serialize import findrefs
 from zodb.timestamp import TimeStamp, newTimeStamp, timeStampFromTime
@@ -165,7 +165,7 @@
     logger.critical(message, *data)
     raise CorruptedTransactionError(message % data)
 
-class FileStorageError(POSException.StorageError):
+class FileStorageError(interfaces.StorageError):
     pass
 
 class PackError(FileStorageError):
@@ -178,7 +178,7 @@
     """
 
 class CorruptedFileStorageError(FileStorageError,
-                                POSException.StorageSystemError):
+                                interfaces.StorageSystemError):
     """Corrupted file storage."""
 
 class CorruptedTransactionError(CorruptedFileStorageError):
@@ -197,7 +197,7 @@
             return "Error reading unknown oid.  Found %r" % self.buf
 
 class FileStorageQuotaError(FileStorageError,
-                            POSException.StorageSystemError):
+                            interfaces.StorageSystemError):
     """File storage quota exceeded."""
 
 def DB(file_name, create=0, read_only=0, stop=None, quota=None,
@@ -465,21 +465,21 @@
     def commitVersion(self, src, dest, transaction, abort=None):
         # We are going to commit by simply storing back pointers.
         if self._is_read_only:
-            raise POSException.ReadOnlyError()
+            raise interfaces.ReadOnlyError()
         if not (src and isinstance(src, StringType)
                 and isinstance(dest, StringType)):
-            raise POSException.VersionCommitError('Invalid source version')
+            raise interfaces.VersionCommitError('Invalid source version')
 
         if src == dest:
-            raise POSException.VersionCommitError(
+            raise interfaces.VersionCommitError(
                 "Can't commit to same version: %s" % repr(src))
 
         if dest and abort:
-            raise POSException.VersionCommitError(
+            raise interfaces.VersionCommitError(
                 "Internal error, can't abort to a version")
 
         if transaction is not self._transaction:
-            raise POSException.StorageTransactionError(self, transaction)
+            raise interfaces.StorageTransactionError(self, transaction)
 
         self._lock_acquire()
         try:
@@ -611,9 +611,9 @@
 
     def store(self, oid, serial, data, version, transaction):
         if self._is_read_only:
-            raise POSException.ReadOnlyError()
+            raise interfaces.ReadOnlyError()
         if transaction is not self._transaction:
-            raise POSException.StorageTransactionError(self, transaction)
+            raise interfaces.StorageTransactionError(self, transaction)
 
         self._lock_acquire()
         try:
@@ -623,14 +623,14 @@
                 h = self._read_data_header(old)
                 if h.version:
                     if version != h.version:
-                        raise POSException.VersionLockError(oid, version)
+                        raise interfaces.VersionLockError(oid, version)
                     pnv = h.pnv
 
                 if serial != h.serial:
                     data = self.tryToResolveConflict(oid, h.serial, serial,
                                                      data)
                     if data is None:
-                        raise POSException.ConflictError(oid=oid,
+                        raise interfaces.ConflictError(oid=oid,
                                                 serials=(h.serial, serial))
 
             pos = self._pos
@@ -721,9 +721,9 @@
         # should be considered just a hint, and is ignored if the transaction
         # doesn't exist.
         if self._is_read_only:
-            raise POSException.ReadOnlyError()
+            raise interfaces.ReadOnlyError()
         if transaction is not self._transaction:
-            raise POSException.StorageTransactionError(self, transaction)
+            raise interfaces.StorageTransactionError(self, transaction)
 
         self._lock_acquire()
         try:
@@ -1070,9 +1070,9 @@
         """
 
         if self._is_read_only:
-            raise POSException.ReadOnlyError()
+            raise interfaces.ReadOnlyError()
         if transaction is not self._transaction:
-            raise POSException.StorageTransactionError(self, transaction)
+            raise interfaces.StorageTransactionError(self, transaction)
 
         self._lock_acquire()
         try:
@@ -1178,7 +1178,7 @@
             # be an error, but Barry thinks this should return 1 if we have
             # any non-version data. This would be excruciatingly painful to
             # test, so I must be right. ;)
-            raise POSException.VersionError(
+            raise interfaces.VersionError(
                 'The version must be an non-empty string')
         self._lock_acquire()
         try:
@@ -1284,7 +1284,7 @@
         """
 
         if self._is_read_only:
-            raise POSException.ReadOnlyError()
+            raise interfaces.ReadOnlyError()
 
         stop = timeStampFromTime(t).raw()
         if stop == z64:
@@ -2018,7 +2018,7 @@
                 break
     except:
         error("couldn\'t write truncated data for %s", name)
-        raise POSException.StorageSystemError, (
+        raise interfaces.StorageSystemError, (
             "Couldn't save truncated data")
 
     seek(pos)


=== Zope3/src/zodb/storage/mapping.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zodb/storage/mapping.py:1.1.2.1	Mon Dec 23 14:30:49 2002
+++ Zope3/src/zodb/storage/mapping.py	Mon Dec 23 16:52:52 2002
@@ -90,7 +90,8 @@
 """
 
 import zodb.db
-from zodb import BaseStorage, POSException, utils
+from zodb import interfaces, utils
+from zodb.storage import base
 from zodb.serialize import findrefs
 from zodb.timestamp import TimeStamp
 from zodb.utils import z64
@@ -101,11 +102,11 @@
     db = ZODB.DB.DB(ms, pool_size, cache_size)
     return db
 
-class MappingStorage(BaseStorage.BaseStorage):
+class MappingStorage(base.BaseStorage):
 
     def __init__(self, name='Mapping Storage'):
 
-        BaseStorage.BaseStorage.__init__(self, name)
+        base.BaseStorage.__init__(self, name)
 
         self._index={}
         self._tindex=[]
@@ -124,10 +125,10 @@
 
     def store(self, oid, serial, data, version, transaction):
         if transaction is not self._transaction:
-            raise POSException.StorageTransactionError(self, transaction)
+            raise interfaces.StorageTransactionError(self, transaction)
 
         if version:
-            raise POSException.Unsupported, "Versions aren't supported"
+            raise interfaces.Unsupported, "Versions aren't supported"
 
         self._lock_acquire()
         try:
@@ -135,7 +136,7 @@
                 old=self._index[oid]
                 oserial=old[:8]
                 if serial != oserial:
-                    raise POSException.ConflictError(serials=(oserial, serial))
+                    raise interfaces.ConflictError(serials=(oserial, serial))
                 
             serial=self._serial
             self._tindex.append((oid,serial+data))