[Zodb-checkins] CVS: Zope/lib/python/ZODB - ConflictResolution.py:1.14.12.1 FileStorage.py:1.110.4.1 __init__.py:1.18.10.1 utils.py:1.12.26.1

Andreas Jung andreas@andreas-jung.com
Sat, 9 Nov 2002 03:43:32 -0500


Update of /cvs-repository/Zope/lib/python/ZODB
In directory cvs.zope.org:/tmp/cvs-serv26094/lib/python/ZODB

Modified Files:
      Tag: ajung-restructuredtext-integration-branch
	ConflictResolution.py FileStorage.py __init__.py utils.py 
Log Message:
merge from trunk


=== Zope/lib/python/ZODB/ConflictResolution.py 1.14 => 1.14.12.1 ===
--- Zope/lib/python/ZODB/ConflictResolution.py:1.14	Fri Sep 27 14:35:09 2002
+++ Zope/lib/python/ZODB/ConflictResolution.py	Sat Nov  9 03:42:59 2002
@@ -116,6 +116,15 @@
         return file.getvalue(1)
     except ConflictError:
         return 0
+    except:
+        # If anything else went wrong, catch it here and avoid passing an
+        # arbitrary exception back to the client.  The error here will mask
+        # the original ConflictError.  A client can recover from a
+        # ConflictError, but not necessarily from other errors.  But log
+        # the error so that any problems can be fixed.
+        zLOG.LOG("Conflict Resolution", zLOG.ERROR,
+                 "Unexpected error", error=sys.exc_info())
+        return 0
 
 class ConflictResolvingStorage:
     "Mix-in class that provides conflict resolution handling for storages"


=== Zope/lib/python/ZODB/FileStorage.py 1.110 => 1.110.4.1 ===
--- Zope/lib/python/ZODB/FileStorage.py:1.110	Fri Oct 18 20:04:37 2002
+++ Zope/lib/python/ZODB/FileStorage.py	Sat Nov  9 03:42:59 2002
@@ -145,7 +145,6 @@
         return {}
 
 from zLOG import LOG, BLATHER, WARNING, ERROR, PANIC, register_subsystem
-register_subsystem('ZODB FS')
 
 z64='\0'*8
 # the struct formats for the headers
@@ -176,7 +175,11 @@
     LOG('ZODB FS', PANIC, "%s ERROR: %s\n" % (packed_version, message))
     raise CorruptedTransactionError, message
 
-class FileStorageError(POSException.StorageError): pass
+class FileStorageError(POSException.StorageError):
+    pass
+
+class PackError(FileStorageError):
+    pass
 
 class FileStorageFormatError(FileStorageError):
     """Invalid file format
@@ -617,7 +620,7 @@
         # will get checked when we store.
         return _loadBack(file, oid, pnv)[0], serial
 
-    def load(self, oid, version, _stuff=None):
+    def load(self, oid, version):
         self._lock_acquire()
         try:
             return self._load(oid, version, self._index, self._file)
@@ -862,9 +865,6 @@
         finally:
             self._lock_release()
 
-    def supportsUndo(self):
-        return 1
-
     def supportsVersions(self):
         return 1
 
@@ -958,56 +958,6 @@
             self._file.truncate(self._pos)
             self._nextpos=0
 
-    def undo(self, transaction_id):
-        if self._is_read_only:
-            raise POSException.ReadOnlyError()
-        self._lock_acquire()
-        try:
-            self._clear_index()
-            transaction_id=base64.decodestring(transaction_id + '\n')
-            tid, tpos = transaction_id[:8], U64(transaction_id[8:])
-            packt=self._packt
-            if packt is None or packt > tid:
-                raise UndoError, (
-                    'Undo is currently disabled for database maintenance.<p>')
-
-            file=self._file
-            seek=file.seek
-            read=file.read
-            index_get=self._index_get
-            unpack=struct.unpack
-            seek(tpos)
-            h=read(TRANS_HDR_LEN)
-            if len(h) != TRANS_HDR_LEN or h[:8] != tid:
-                raise UndoError('Invalid undo transaction id')
-            if h[16] == 'u': return
-            if h[16] != ' ': raise UndoError
-            tl=U64(h[8:16])
-            ul,dl,el=unpack(">HHH", h[17:TRANS_HDR_LEN])
-            tend=tpos+tl
-            pos=tpos+(TRANS_HDR_LEN+ul+dl+el)
-            t={}
-            while pos < tend:
-                # Read the data records for this transaction
-                seek(pos)
-                h=read(DATA_HDR_LEN)
-                oid,serial,sprev,stloc,vlen,splen = unpack(DATA_HDR, h)
-                plen=U64(splen)
-                prev=U64(sprev)
-                dlen=DATA_HDR_LEN+(plen or 8)
-                if vlen: dlen=dlen+(16+vlen)
-                if index_get(oid, 0) != pos: raise UndoError
-                pos=pos+dlen
-                if pos > tend: raise UndoError
-                t[oid]=prev
-
-            seek(tpos+16)
-            file.write('u')
-            file.flush()
-            self._index.update(t)
-            return t.keys()
-        finally: self._lock_release()
-
     def supportsTransactionalUndo(self):
         return 1
 
@@ -1045,18 +995,20 @@
 
     def _getVersion(self, oid, pos):
         self._file.seek(pos)
-        read=self._file.read
-        h=read(DATA_HDR_LEN)
-        doid,serial,sprev,stloc,vlen,splen = unpack(DATA_HDR, h)
+        h = self._file.read(DATA_HDR_LEN)
+        doid, serial, sprev, stloc, vlen, splen = unpack(DATA_HDR, h)
+        assert doid == oid
         if vlen:
-            h=read(16)
-            return read(vlen), h[:8]
+            h = self._file.read(16)
+            return self._file.read(vlen), h[:8]
         else:
-            return '',''
+            return '', ''
 
     def _getSerial(self, oid, pos):
-        self._file.seek(pos+8)
-        return self._file.read(8)
+        self._file.seek(pos)
+        h = self._file.read(16)
+        assert oid == h[:8]
+        return h[8:]
 
     def _transactionalUndoRecord(self, oid, pos, serial, pre, version):
         """Get the indo information for a data record
@@ -1068,6 +1020,8 @@
         """
 
         copy=1 # Can we just copy a data pointer
+
+        # First check if it is possible to undo this record.
         tpos=self._tindex.get(oid, 0)
         ipos=self._index.get(oid, 0)
         tipos=tpos or ipos
@@ -1102,6 +1056,12 @@
                     # LoadBack gave us a key error. Bail.
                     raise UndoError
 
+        # Return the data that should be written in the undo record.
+        if not pre:
+            # There is no previous revision, because the object creation
+            # is being undone.
+            return '', 0, '', '', ipos
+
         version, snv = self._getVersion(oid, pre)
         if copy:
             # we can just copy our previous-record pointer forward
@@ -1178,7 +1138,7 @@
         tid = base64.decodestring(transaction_id + '\n')
         assert len(tid) == 8
         tpos = self._txn_find(tid)
-        tindex = self._txn_undo_write(tpos, tid)
+        tindex = self._txn_undo_write(tpos)
         self._tindex.update(tindex)
         return tindex.keys()
 
@@ -1198,7 +1158,7 @@
                 break
         raise UndoError("Invalid transaction id")
 
-    def _txn_undo_write(self, tpos, tid):
+    def _txn_undo_write(self, tpos):
         # a helper function to write the data records for transactional undo
 
         ostloc = p64(self._pos)
@@ -1261,7 +1221,7 @@
                 tindex[oid] = here
                 here += odlen
 
-            pos=pos+dlen
+            pos += dlen
             if pos > tend:
                 raise UndoError, 'non-undoable transaction'
 
@@ -1338,8 +1298,7 @@
                 prev=U64(prev)
 
                 if vlen:
-                    nv = read(8) != z64
-                    file.seek(8,1) # Skip previous version record pointer
+                    read(16)
                     version=read(vlen)
                     if wantver is not None and version != wantver:
                         if prev:
@@ -1455,8 +1414,6 @@
                     pindex[oid]=0
                     error('Bad reference to %s', `(oid,v)`)
 
-            spackpos=p64(packpos)
-
             ##################################################################
             # Step 2, copy data and compute new index based on new positions.
             index, vindex, tindex, tvindex = self._newIndexes()
@@ -1549,7 +1506,7 @@
                 thl=ul+dl+el
                 h=read(thl)
                 if len(h) != thl:
-                    raise 'Pack Error', opos
+                    raise PackError(opos)
                 write(h)
                 thl=TRANS_HDR_LEN+thl
                 pos=tpos+thl
@@ -1814,7 +1771,6 @@
     p1=opos
     p2=pos
     offset=p2-p1
-    packpos=opos
 
     # Copy the data in two stages.  In the packing stage,
     # we skip records that are non-current or that are for
@@ -1841,7 +1797,8 @@
 
         thl=ul+dl+el
         h2=read(thl)
-        if len(h2) != thl: raise 'Pack Error', opos
+        if len(h2) != thl:
+            raise PackError(opos)
 
         # write out the transaction record
         seek(opos)
@@ -1993,11 +1950,9 @@
         return 4L, maxoid, ltid
 
     index_get=index.get
-    vndexpos=vindex.get
 
     pos=start
     seek(start)
-    unpack=struct.unpack
     tid='\0'*7+'\1'
 
     while 1:
@@ -2088,13 +2043,8 @@
 
             if vlen:
                 dlen=dlen+(16+vlen)
-                seek(8,1)
-                pv=U64(read(8))
+                read(16)
                 version=read(vlen)
-                # Jim says: "It's just not worth the bother."
-                #if vndexpos(version, 0) != pv:
-                #    panic("%s incorrect previous version pointer at %s",
-                #          name, pos)
                 vindex[version]=pos
 
             if pos+dlen > tend or tloc != tpos:
@@ -2138,6 +2088,7 @@
     while 1:
         old = U64(back)
         if not old:
+            # If the backpointer is 0, the object does not currently exist.
             raise POSKeyError(oid)
         file.seek(old)
         h = file.read(DATA_HDR_LEN)
@@ -2383,16 +2334,13 @@
             self._file.seek(pos)
             h = self._file.read(DATA_HDR_LEN)
             oid, serial, sprev, stloc, vlen, splen = unpack(DATA_HDR, h)
-            prev = U64(sprev)
             tloc = U64(stloc)
             plen = U64(splen)
-
             dlen = DATA_HDR_LEN + (plen or 8)
 
             if vlen:
                 dlen += (16 + vlen)
-                tmp = self._file.read(16)
-                pv = U64(tmp[8:16])
+                self._file.read(16) # move to the right location
                 version = self._file.read(vlen)
             else:
                 version = ''


=== Zope/lib/python/ZODB/__init__.py 1.18 => 1.18.10.1 ===
--- Zope/lib/python/ZODB/__init__.py:1.18	Fri Oct  4 20:40:37 2002
+++ Zope/lib/python/ZODB/__init__.py	Sat Nov  9 03:43:00 2002
@@ -12,12 +12,11 @@
 #
 ##############################################################################
 
-__version__ = '3.1b2'
+__version__ = '3.1+'
 
 import sys
 import cPersistence, Persistence
 from zLOG import register_subsystem
-register_subsystem('ZODB')
 
 # This is lame. Don't look. :(
 sys.modules['cPersistence'] = cPersistence


=== Zope/lib/python/ZODB/utils.py 1.12 => 1.12.26.1 ===
--- Zope/lib/python/ZODB/utils.py:1.12	Wed Aug 14 18:07:09 2002
+++ Zope/lib/python/ZODB/utils.py	Sat Nov  9 03:43:00 2002
@@ -13,18 +13,20 @@
 ##############################################################################
 
 import sys
-import TimeStamp, time, struct
+import TimeStamp, time
+
+from struct import pack, unpack
 
 if sys.version >= (2, 2):
 
     # Note that the distinction between ints and longs is blurred in
     # Python 2.2.  So make u64() and U64() the same.
 
-    def p64(v, pack=struct.pack):
+    def p64(v):
         """Pack an integer or long into a 8-byte string"""
         return pack(">Q", v)
 
-    def u64(v, unpack=struct.unpack):
+    def u64(v):
         """Unpack an 8-byte string into a 64-bit long integer."""
         return unpack(">Q", v)[0]
 
@@ -34,7 +36,7 @@
 
     t32 = 1L << 32
 
-    def p64(v, pack=struct.pack):
+    def p64(v):
         """Pack an integer or long into a 8-byte string"""
         if v < t32:
             h = 0
@@ -42,7 +44,7 @@
             h, v = divmod(v, t32)
         return pack(">II", h, v)
 
-    def u64(v, unpack=struct.unpack):
+    def u64(v):
         """Unpack an 8-byte string into a 64-bit (or long) integer."""
         h, v = unpack(">ii", v)
         if v < 0:
@@ -53,7 +55,7 @@
             v = (long(h) << 32) + v
         return v
 
-    def U64(v, unpack=struct.unpack):
+    def U64(v):
         """Same as u64 but always returns a long."""
         h, v = unpack(">II", v)
         if h: