Commit bd8fbd11 authored by Shane Hathaway's avatar Shane Hathaway

Merged shane-oid-length-branch.

ZODB now makes no assumptions about the length of OIDs (although
storages can make such assumptions if they need to.)  Added an
oid_repr utility function to print both 8-byte OIDs and other OIDs in
a reasonable way.
parent 4b822c41
......@@ -13,7 +13,7 @@
##############################################################################
"""Handy standard storage machinery
$Id: BaseStorage.py,v 1.33 2003/02/04 17:17:29 bwarsaw Exp $
$Id: BaseStorage.py,v 1.34 2003/06/10 15:46:31 shane Exp $
"""
import cPickle
import ThreadLock, bpthread
......@@ -303,7 +303,7 @@ class BaseStorage(UndoLogCompatible.UndoLogCompatible):
self.tpc_begin(transaction, tid, transaction.status)
for r in transaction:
oid=r.oid
if verbose: print `oid`, r.version, len(r.data)
if verbose: print oid_repr(oid), r.version, len(r.data)
if restoring:
self.restore(oid, r.serial, r.data, r.version,
r.data_txn, transaction)
......
......@@ -13,19 +13,14 @@
##############################################################################
"""ZODB-defined exceptions
$Id: POSException.py,v 1.19 2003/01/15 23:00:05 jeremy Exp $"""
$Id: POSException.py,v 1.20 2003/06/10 15:46:31 shane Exp $"""
from types import StringType, DictType
import ZODB.utils
def _fmt_oid(oid):
if oid:
return "%016x" % ZODB.utils.u64(oid)
return oid
from ZODB.utils import oid_repr, serial_repr
def _fmt_undo(oid, reason):
s = reason and (": %s" % reason) or ""
return "Undo error %s%s" % (_fmt_oid(oid), s)
return "Undo error %s%s" % (oid_repr(oid), s)
class POSError(StandardError):
"""Persistent object system error."""
......@@ -34,7 +29,7 @@ class POSKeyError(KeyError, POSError):
"""Key not found in database."""
def __str__(self):
return _fmt_oid(self.args[0])
return oid_repr(self.args[0])
class TransactionError(POSError):
"""An error occured due to normal transaction processing."""
......@@ -85,12 +80,12 @@ class ConflictError(TransactionError):
def __str__(self):
extras = []
if self.oid:
extras.append("oid %s" % _fmt_oid(self.oid))
extras.append("oid %s" % oid_repr(self.oid))
if self.class_name:
extras.append("class %s" % self.class_name)
if self.serials:
extras.append("serial was %s, now %s" %
tuple(map(_fmt_oid, self.serials)))
tuple(map(serial_repr, self.serials)))
if extras:
return "%s (%s)" % (self.message, ", ".join(extras))
else:
......@@ -150,8 +145,8 @@ class DanglingReferenceError(TransactionError):
self.missing = Boid
def __str__(self):
return "from %s to %s" % (_fmt_oid(self.referer),
_fmt_oid(self.missing))
return "from %s to %s" % (oid_repr(self.referer),
oid_repr(self.missing))
class VersionError(POSError):
"""An error in handling versions occurred."""
......
......@@ -13,14 +13,14 @@
##############################################################################
"""Transaction management
$Id: Transaction.py,v 1.48 2003/03/07 00:11:10 jeremy Exp $
$Id: Transaction.py,v 1.49 2003/06/10 15:46:31 shane Exp $
"""
import time, sys, struct, POSException
from struct import pack
from string import split, strip, join
from zLOG import LOG, ERROR, PANIC, INFO, BLATHER, WARNING
from POSException import ConflictError
from utils import oid_repr
# Flag indicating whether certain errors have occurred.
hosed=0
......@@ -138,7 +138,7 @@ class Transaction:
t, v, tb = sys.exc_info()
else:
self.log("Failed to abort object %s" %
repr(o._p_oid), error=sys.exc_info())
oid_repr(o._p_oid), error=sys.exc_info())
# tpc_begin() was never called, so tpc_abort() should not be
# called.
......@@ -390,7 +390,7 @@ class Transaction:
j.abort(o, self)
except:
# nothing to do but log the error
self.log("Failed to abort object %s" % repr(o._p_oid),
self.log("Failed to abort object %s" % oid_repr(o._p_oid),
error=sys.exc_info())
# Abort the two-phase commit. It's only necessary to abort the
......
......@@ -16,6 +16,7 @@ import sys
import TimeStamp, time
from struct import pack, unpack
from types import StringType
z64 = '\0'*8
t32 = 1L << 32
......@@ -86,3 +87,13 @@ def newTimeStamp(old=None,
if old is not None:
return ts.laterThan(old)
return ts
def oid_repr(oid):
if isinstance(oid, StringType) and len(oid) == 8:
return '%016x' % U64(oid)
else:
return repr(oid)
serial_repr = oid_repr
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