Commit 60cff1c0 authored by Jim Fulton's avatar Jim Fulton

Fixed a serious bug that caused cache failures when run

with Python optimization turned on.

https://bugs.launchpad.net/zodb/+bug/544305
parent 5eda31ab
...@@ -20,6 +20,11 @@ New Features ...@@ -20,6 +20,11 @@ New Features
Bugs Fixed Bugs Fixed
---------- ----------
- Fixed a serious bug that caused cache failures when run
with Python optimization turned on.
https://bugs.launchpad.net/zodb/+bug/544305
- Fixed bug in cPickleCache's byte size estimation logic. - Fixed bug in cPickleCache's byte size estimation logic.
(https://bugs.launchpad.net/zodb/+bug/533015) (https://bugs.launchpad.net/zodb/+bug/533015)
......
...@@ -473,7 +473,8 @@ class ClientCache(object): ...@@ -473,7 +473,8 @@ class ClientCache(object):
return None return None
self.f.seek(ofs) self.f.seek(ofs)
read = self.f.read read = self.f.read
assert read(1) == 'a', (ofs, self.f.tell(), oid) status = read(1)
assert status == 'a', (ofs, self.f.tell(), oid)
size, saved_oid, tid, end_tid, lver, ldata = unpack( size, saved_oid, tid, end_tid, lver, ldata = unpack(
">I8s8s8sHI", read(34)) ">I8s8s8sHI", read(34))
assert saved_oid == oid, (ofs, self.f.tell(), oid, saved_oid) assert saved_oid == oid, (ofs, self.f.tell(), oid, saved_oid)
...@@ -481,6 +482,9 @@ class ClientCache(object): ...@@ -481,6 +482,9 @@ class ClientCache(object):
data = read(ldata) data = read(ldata)
assert len(data) == ldata, (ofs, self.f.tell(), oid, len(data), ldata) assert len(data) == ldata, (ofs, self.f.tell(), oid, len(data), ldata)
# WARNING: The following assert changes the file position.
# We must not depend on this below or we'll fail in optimized mode.
assert read(8) == oid, (ofs, self.f.tell(), oid) assert read(8) == oid, (ofs, self.f.tell(), oid)
self._n_accesses += 1 self._n_accesses += 1
...@@ -509,7 +513,8 @@ class ClientCache(object): ...@@ -509,7 +513,8 @@ class ClientCache(object):
self.f.seek(ofs) self.f.seek(ofs)
read = self.f.read read = self.f.read
assert read(1) == 'a', (ofs, self.f.tell(), oid, before_tid) status = read(1)
assert status == 'a', (ofs, self.f.tell(), oid, before_tid)
size, saved_oid, saved_tid, end_tid, lver, ldata = unpack( size, saved_oid, saved_tid, end_tid, lver, ldata = unpack(
">I8s8s8sHI", read(34)) ">I8s8s8sHI", read(34))
assert saved_oid == oid, (ofs, self.f.tell(), oid, saved_oid) assert saved_oid == oid, (ofs, self.f.tell(), oid, saved_oid)
...@@ -518,6 +523,9 @@ class ClientCache(object): ...@@ -518,6 +523,9 @@ class ClientCache(object):
assert lver == 0, "Versions aren't supported" assert lver == 0, "Versions aren't supported"
data = read(ldata) data = read(ldata)
assert len(data) == ldata, (ofs, self.f.tell()) assert len(data) == ldata, (ofs, self.f.tell())
# WARNING: The following assert changes the file position.
# We must not depend on this below or we'll fail in optimized mode.
assert read(8) == oid, (ofs, self.f.tell(), oid) assert read(8) == oid, (ofs, self.f.tell(), oid)
if end_tid < before_tid: if end_tid < before_tid:
...@@ -545,7 +553,8 @@ class ClientCache(object): ...@@ -545,7 +553,8 @@ class ClientCache(object):
if ofs: if ofs:
seek(ofs) seek(ofs)
read = self.f.read read = self.f.read
assert read(1) == 'a', (ofs, self.f.tell(), oid) status = read(1)
assert status == 'a', (ofs, self.f.tell(), oid)
size, saved_oid, saved_tid, end_tid = unpack( size, saved_oid, saved_tid, end_tid = unpack(
">I8s8s8s", read(28)) ">I8s8s8s", read(28))
assert saved_oid == oid, (ofs, self.f.tell(), oid, saved_oid) assert saved_oid == oid, (ofs, self.f.tell(), oid, saved_oid)
...@@ -657,7 +666,8 @@ class ClientCache(object): ...@@ -657,7 +666,8 @@ class ClientCache(object):
self.f.seek(ofs) self.f.seek(ofs)
read = self.f.read read = self.f.read
assert read(1) == 'a', (ofs, self.f.tell(), oid) status = read(1)
assert status == 'a', (ofs, self.f.tell(), oid)
size, saved_oid, saved_tid, end_tid = unpack(">I8s8s8s", read(28)) size, saved_oid, saved_tid, end_tid = unpack(">I8s8s8s", read(28))
assert saved_oid == oid, (ofs, self.f.tell(), oid, saved_oid) assert saved_oid == oid, (ofs, self.f.tell(), oid, saved_oid)
assert end_tid == z64, (ofs, self.f.tell(), oid) assert end_tid == z64, (ofs, self.f.tell(), oid)
...@@ -687,7 +697,8 @@ class ClientCache(object): ...@@ -687,7 +697,8 @@ class ClientCache(object):
self._lock.acquire() self._lock.acquire()
try: try:
seek(ofs) seek(ofs)
assert read(1) == 'a', (ofs, self.f.tell(), oid) status = read(1)
assert status == 'a', (ofs, self.f.tell(), oid)
size, saved_oid, tid, end_tid = unpack(">I8s8s8s", read(28)) size, saved_oid, tid, end_tid = unpack(">I8s8s8s", read(28))
assert saved_oid == oid, (ofs, self.f.tell(), oid, saved_oid) assert saved_oid == oid, (ofs, self.f.tell(), oid, saved_oid)
assert end_tid == z64, (ofs, self.f.tell(), oid) assert end_tid == z64, (ofs, self.f.tell(), oid)
......
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