Commit 9c47277a authored by Tim Peters's avatar Tim Peters

Massive rewrite to make simul.py's circular cache aware of

MVCC.  It isn't blowing up, but it thinks the hit rate is
100% -- might have missed something there <wink>.
parent 15bb2e12
...@@ -205,17 +205,20 @@ class ClientCache(object): ...@@ -205,17 +205,20 @@ class ClientCache(object):
if L is None: if L is None:
self._trace(0x24, oid, tid) self._trace(0x24, oid, tid)
return None return None
# A pair with None as the second element will always be less # A pair with None as the second element is less than any pair with
# than any pair with the same first tid. # the same first tid. Dubious: this relies on that None is less
# than any comparable non-None object in recent Pythons.
i = bisect.bisect_left(L, (tid, None)) i = bisect.bisect_left(L, (tid, None))
# The least element left of tid was written before tid. If # Now L[i-1] < (tid, None) < L[i], and the start_tid for everything in
# there is no element, the cache doesn't have old enough data. # L[:i} is < tid, and the start_tid for everything in L[i:] is >= tid.
# Therefore the largest start_tid < tid must be at L[i-1]. If i is 0,
# there is no start_tid < tid: we don't have any data old enougn.
if i == 0: if i == 0:
self._trace(0x24, oid, tid) self._trace(0x24, oid, tid)
return return
lo, hi = L[i-1] lo, hi = L[i-1]
# lo should always be less than tid assert lo < tid
if not lo < tid <= hi: if tid > hi: # we don't have any data in the right range
self._trace(0x24, oid, tid) self._trace(0x24, oid, tid)
return None return None
o = self.fc.access((oid, lo)) o = self.fc.access((oid, lo))
...@@ -284,7 +287,7 @@ class ClientCache(object): ...@@ -284,7 +287,7 @@ class ClientCache(object):
p = start_tid, end_tid p = start_tid, end_tid
if p in L: if p in L:
return # duplicate store return # duplicate store
bisect.insort_left(L, (start_tid, end_tid)) bisect.insort_left(L, p)
self._trace(0x54, oid, version, start_tid, end_tid, self._trace(0x54, oid, version, start_tid, end_tid,
dlen=len(data)) dlen=len(data))
self.fc.add(o) self.fc.add(o)
...@@ -457,7 +460,7 @@ class ClientCache(object): ...@@ -457,7 +460,7 @@ class ClientCache(object):
self._trace = notrace self._trace = notrace
def _trace(self, def _trace(self,
code, oid="", version="", tid="", end_tid=z64, dlen=0, code, oid="", version="", tid=z64, end_tid=z64, dlen=0,
# The next two are just speed hacks. # The next two are just speed hacks.
time_time=time.time, struct_pack=struct.pack): time_time=time.time, struct_pack=struct.pack):
# The code argument is two hex digits; bits 0 and 7 must be zero. # The code argument is two hex digits; bits 0 and 7 must be zero.
......
This diff is collapsed.
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