Commit b1dd4d80 authored by Shane Hathaway's avatar Shane Hathaway

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.
parent 92a97b25
...@@ -29,7 +29,7 @@ class TmpStore: ...@@ -29,7 +29,7 @@ class TmpStore:
self._file = tempfile.TemporaryFile() self._file = tempfile.TemporaryFile()
# _pos: current file position # _pos: current file position
# _tpos: file position at last commit point # _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 # _index: map oid to pos of last committed version
self._index = {} self._index = {}
# _tindex: map oid to pos for new updates # _tindex: map oid to pos for new updates
...@@ -55,11 +55,14 @@ class TmpStore: ...@@ -55,11 +55,14 @@ class TmpStore:
if pos is None: if pos is None:
return self._storage.load(oid, self._bver) return self._storage.load(oid, self._bver)
self._file.seek(pos) self._file.seek(pos)
h = self._file.read(24) h = self._file.read(8)
if h[:8] != oid: oidlen = u64(h)
read_oid = self._file.read(oidlen)
if read_oid != oid:
raise POSException.StorageSystemError('Bad temporary storage') raise POSException.StorageSystemError('Bad temporary storage')
size = u64(h[16:]) h = self._file.read(16)
serial = h[8:16] size = u64(h[8:])
serial = h[:8]
return self._file.read(size), serial return self._file.read(size), serial
# XXX clarify difference between self._storage & self._db._storage # XXX clarify difference between self._storage & self._db._storage
...@@ -83,10 +86,11 @@ class TmpStore: ...@@ -83,10 +86,11 @@ class TmpStore:
l = len(data) l = len(data)
if serial is None: if serial is None:
serial = z64 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._file.write(data)
self._tindex[oid] = self._pos self._tindex[oid] = self._pos
self._pos += l + 24 self._pos += l + len(header)
return serial return serial
def tpc_abort(self, transaction): def tpc_abort(self, transaction):
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
############################################################################## ##############################################################################
"""Transaction management """Transaction management
$Id: Transaction.py,v 1.45 2002/12/02 22:42:05 jeremy Exp $ $Id: Transaction.py,v 1.46 2003/01/02 18:05:47 shane Exp $
""" """
import time, sys, struct, POSException import time, sys, struct, POSException
...@@ -21,7 +21,6 @@ from struct import pack ...@@ -21,7 +21,6 @@ from struct import pack
from string import split, strip, join from string import split, strip, join
from zLOG import LOG, ERROR, PANIC, INFO, BLATHER, WARNING from zLOG import LOG, ERROR, PANIC, INFO, BLATHER, WARNING
from POSException import ConflictError from POSException import ConflictError
from ZODB import utils
# Flag indicating whether certain errors have occurred. # Flag indicating whether certain errors have occurred.
hosed=0 hosed=0
...@@ -138,8 +137,8 @@ class Transaction: ...@@ -138,8 +137,8 @@ class Transaction:
if t is None: if t is None:
t, v, tb = sys.exc_info() t, v, tb = sys.exc_info()
else: else:
self.log("Failed to abort object %016x" % self.log("Failed to abort object %s" %
utils.U64(o._p_oid), error=sys.exc_info()) repr(o._p_oid), error=sys.exc_info())
# tpc_begin() was never called, so tpc_abort() should not be # tpc_begin() was never called, so tpc_abort() should not be
# called. # called.
...@@ -390,7 +389,7 @@ class Transaction: ...@@ -390,7 +389,7 @@ class Transaction:
j.abort(o, self) j.abort(o, self)
except: except:
# nothing to do but log the error # 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()) error=sys.exc_info())
# Abort the two-phase commit. It's only necessary to abort the # Abort the two-phase commit. It's only necessary to abort the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment