Commit a2381f21 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 032de7a1
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
############################################################################## ##############################################################################
"""Handy standard storage machinery """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 cPickle
import ThreadLock, bpthread import ThreadLock, bpthread
...@@ -303,7 +303,7 @@ class BaseStorage(UndoLogCompatible.UndoLogCompatible): ...@@ -303,7 +303,7 @@ class BaseStorage(UndoLogCompatible.UndoLogCompatible):
self.tpc_begin(transaction, tid, transaction.status) self.tpc_begin(transaction, tid, transaction.status)
for r in transaction: for r in transaction:
oid=r.oid 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: if restoring:
self.restore(oid, r.serial, r.data, r.version, self.restore(oid, r.serial, r.data, r.version,
r.data_txn, transaction) r.data_txn, transaction)
......
...@@ -13,19 +13,14 @@ ...@@ -13,19 +13,14 @@
############################################################################## ##############################################################################
"""ZODB-defined exceptions """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 from types import StringType, DictType
import ZODB.utils from ZODB.utils import oid_repr, serial_repr
def _fmt_oid(oid):
if oid:
return "%016x" % ZODB.utils.u64(oid)
return oid
def _fmt_undo(oid, reason): def _fmt_undo(oid, reason):
s = reason and (": %s" % reason) or "" 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): class POSError(StandardError):
"""Persistent object system error.""" """Persistent object system error."""
...@@ -34,7 +29,7 @@ class POSKeyError(KeyError, POSError): ...@@ -34,7 +29,7 @@ class POSKeyError(KeyError, POSError):
"""Key not found in database.""" """Key not found in database."""
def __str__(self): def __str__(self):
return _fmt_oid(self.args[0]) return oid_repr(self.args[0])
class TransactionError(POSError): class TransactionError(POSError):
"""An error occured due to normal transaction processing.""" """An error occured due to normal transaction processing."""
...@@ -85,12 +80,12 @@ class ConflictError(TransactionError): ...@@ -85,12 +80,12 @@ class ConflictError(TransactionError):
def __str__(self): def __str__(self):
extras = [] extras = []
if self.oid: if self.oid:
extras.append("oid %s" % _fmt_oid(self.oid)) extras.append("oid %s" % oid_repr(self.oid))
if self.class_name: if self.class_name:
extras.append("class %s" % self.class_name) extras.append("class %s" % self.class_name)
if self.serials: if self.serials:
extras.append("serial was %s, now %s" % extras.append("serial was %s, now %s" %
tuple(map(_fmt_oid, self.serials))) tuple(map(serial_repr, self.serials)))
if extras: if extras:
return "%s (%s)" % (self.message, ", ".join(extras)) return "%s (%s)" % (self.message, ", ".join(extras))
else: else:
...@@ -150,8 +145,8 @@ class DanglingReferenceError(TransactionError): ...@@ -150,8 +145,8 @@ class DanglingReferenceError(TransactionError):
self.missing = Boid self.missing = Boid
def __str__(self): def __str__(self):
return "from %s to %s" % (_fmt_oid(self.referer), return "from %s to %s" % (oid_repr(self.referer),
_fmt_oid(self.missing)) oid_repr(self.missing))
class VersionError(POSError): class VersionError(POSError):
"""An error in handling versions occurred.""" """An error in handling versions occurred."""
......
...@@ -13,14 +13,14 @@ ...@@ -13,14 +13,14 @@
############################################################################## ##############################################################################
"""Transaction management """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 import time, sys, struct, POSException
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 utils import oid_repr
# Flag indicating whether certain errors have occurred. # Flag indicating whether certain errors have occurred.
hosed=0 hosed=0
...@@ -138,7 +138,7 @@ class Transaction: ...@@ -138,7 +138,7 @@ class Transaction:
t, v, tb = sys.exc_info() t, v, tb = sys.exc_info()
else: else:
self.log("Failed to abort object %s" % 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 # tpc_begin() was never called, so tpc_abort() should not be
# called. # called.
...@@ -390,7 +390,7 @@ class Transaction: ...@@ -390,7 +390,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 %s" % repr(o._p_oid), self.log("Failed to abort object %s" % oid_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
......
...@@ -16,6 +16,7 @@ import sys ...@@ -16,6 +16,7 @@ import sys
import TimeStamp, time import TimeStamp, time
from struct import pack, unpack from struct import pack, unpack
from types import StringType
z64 = '\0'*8 z64 = '\0'*8
t32 = 1L << 32 t32 = 1L << 32
...@@ -86,3 +87,13 @@ def newTimeStamp(old=None, ...@@ -86,3 +87,13 @@ def newTimeStamp(old=None,
if old is not None: if old is not None:
return ts.laterThan(old) return ts.laterThan(old)
return ts 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