[Zope-CVS] CVS: Products/Ape/lib/apelib/zodb3 - storage.py:1.16
Shane Hathaway
shane at zope.com
Thu Mar 25 23:01:40 EST 2004
Update of /cvs-repository/Products/Ape/lib/apelib/zodb3
In directory cvs.zope.org:/tmp/cvs-serv461/lib/apelib/zodb3
Modified Files:
storage.py
Log Message:
Made conflict debugging a ZConfig option.
It is useful to turn on when writing gateways.
=== Products/Ape/lib/apelib/zodb3/storage.py 1.15 => 1.16 ===
--- Products/Ape/lib/apelib/zodb3/storage.py:1.15 Sat Mar 20 01:34:25 2004
+++ Products/Ape/lib/apelib/zodb3/storage.py Thu Mar 25 23:01:09 2004
@@ -23,13 +23,14 @@
from ZODB import POSException, BaseStorage
from apelib.core.io import GatewayIO
-from consts import HASH0, HASH1, DEBUG
+from consts import HASH0, HASH1
from interfaces import IResourceAccess
class ApeStorage(BaseStorage.BaseStorage):
- def __init__(self, conf_resource, connections, name='', clear_all=0):
+ def __init__(self, conf_resource, connections, name='', clear_all=0,
+ debug_conflicts=0):
"""Initializes an ApeStorage.
conf_resource is a resource for loading the IMapperConfiguration.
@@ -53,8 +54,7 @@
self._ltid = None
self.scanner = None
self.changed = {} # {tid: {oid: 1}}
- if DEBUG:
- self._loaded_hashes = {} # {oid: hash}
+ self.set_debug_conflicts(debug_conflicts)
BaseStorage.BaseStorage.__init__(self, name)
def __len__(self):
@@ -75,6 +75,11 @@
def init_databases(self, clear_all=0):
self._gwio.init_databases(clear_all=clear_all)
+ def set_debug_conflicts(self, debug_conflicts):
+ self.debug_conflicts = debug_conflicts
+ if debug_conflicts:
+ self._loaded_hashes = {} # {oid: hash}
+
def hash64(self, value):
"""Returns an 8-byte hash value.
"""
@@ -101,7 +106,7 @@
p.dump(state)
data = file.getvalue()
h = self.hash64(hash_value)
- if DEBUG:
+ if self.debug_conflicts:
self._loaded_hashes[oid] = hash_value
if self.scanner is not None:
sources = event.mapper.gateway.get_sources(event)
@@ -135,14 +140,14 @@
old_h64 = self.hash64(old_hash)
if h64 != old_h64:
h = None
- if DEBUG:
+ if self.debug_conflicts:
h = self._loaded_hashes.get(oid)
if h is None:
h = h64
old_hash = old_h64
error = ("Storing %s based on old data. %s != %s." % (
repr(oid), repr(h), repr(old_hash)))
- if DEBUG:
+ if self.debug_conflicts:
# Expose the error for debugging..
raise RuntimeError(error)
else:
@@ -157,7 +162,7 @@
event, new_hash = self._gwio.store(
oid, classification, state, is_new)
new_h64 = self.hash64(new_hash)
- if DEBUG:
+ if self.debug_conflicts:
self._loaded_hashes[oid] = new_hash
# Remember that this OID changed (for scanning)
More information about the Zope-CVS
mailing list