[Zodb-checkins] CVS: Zope/lib/python/ZODB - TmpStore.py:1.9 Transaction.py:1.46

Shane Hathaway shane@zope.com
Thu, 2 Jan 2003 13:05:51 -0500


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

Modified Files:
	TmpStore.py Transaction.py 
Log Message:
Corrected code that assumed OIDs are always 8 bytes long.  It's OK
that OIDs are required to be strings, but AdaptableStorage permits any
length, and so might other storages.


=== Zope/lib/python/ZODB/TmpStore.py 1.8 => 1.9 ===
--- Zope/lib/python/ZODB/TmpStore.py:1.8	Tue Dec  3 16:26:38 2002
+++ Zope/lib/python/ZODB/TmpStore.py	Thu Jan  2 13:05:47 2003
@@ -29,7 +29,7 @@
         self._file = tempfile.TemporaryFile()
         # _pos: current file position
         # _tpos: file position at last commit point
-        self._pos = self._tpos = 0
+        self._pos = self._tpos = 0L
         # _index: map oid to pos of last committed version
         self._index = {}
         # _tindex: map oid to pos for new updates
@@ -55,11 +55,14 @@
         if pos is None:
             return self._storage.load(oid, self._bver)
         self._file.seek(pos)
-        h = self._file.read(24)
-        if h[:8] != oid:
+        h = self._file.read(8)
+        oidlen = u64(h)
+        read_oid = self._file.read(oidlen)
+        if read_oid != oid:
             raise POSException.StorageSystemError('Bad temporary storage')
-        size = u64(h[16:])
-        serial = h[8:16]
+        h = self._file.read(16)
+        size = u64(h[8:])
+        serial = h[:8]
         return self._file.read(size), serial
 
     # XXX clarify difference between self._storage & self._db._storage
@@ -83,10 +86,11 @@
         l = len(data)
         if serial is None:
             serial = z64
-        self._file.write(oid + serial + p64(l))
+        header = p64(len(oid)) + oid + serial + p64(l)
+        self._file.write(header)
         self._file.write(data)
         self._tindex[oid] = self._pos
-        self._pos += l + 24
+        self._pos += l + len(header)
         return serial
 
     def tpc_abort(self, transaction):


=== Zope/lib/python/ZODB/Transaction.py 1.45 => 1.46 ===
--- Zope/lib/python/ZODB/Transaction.py:1.45	Mon Dec  2 17:42:05 2002
+++ Zope/lib/python/ZODB/Transaction.py	Thu Jan  2 13:05:47 2003
@@ -21,7 +21,6 @@
 from string import split, strip, join
 from zLOG import LOG, ERROR, PANIC, INFO, BLATHER, WARNING
 from POSException import ConflictError
-from ZODB import utils
 
 # Flag indicating whether certain errors have occurred.
 hosed=0
@@ -138,8 +137,8 @@
                     if t is None:
                         t, v, tb = sys.exc_info()
                     else:
-                        self.log("Failed to abort object %016x" %
-                                 utils.U64(o._p_oid), error=sys.exc_info())
+                        self.log("Failed to abort object %s" %
+                                 repr(o._p_oid), error=sys.exc_info())
 
             # tpc_begin() was never called, so tpc_abort() should not be
             # called.
@@ -390,7 +389,7 @@
                     j.abort(o, self)
             except:
                 # nothing to do but log the error
-                self.log("Failed to abort object %016x" % utils.U64(o._p_oid),
+                self.log("Failed to abort object %s" % repr(o._p_oid),
                          error=sys.exc_info())
 
         # Abort the two-phase commit.  It's only necessary to abort the