Commit 69c5609d authored by Kirill Smelkov's avatar Kirill Smelkov

fixup! pack: Clear all non-current entries after pack

Take review feedback by @jamadden into account

- ret -> result
- use () for tuples uniformly
- no vertical alignment
parent 32c9a7af
...@@ -559,7 +559,7 @@ class ClientStorage(ZODB.ConflictResolution.ConflictResolvingStorage): ...@@ -559,7 +559,7 @@ class ClientStorage(ZODB.ConflictResolution.ConflictResolvingStorage):
if t is None: if t is None:
t = time.time() t = time.time()
t = t - (days * 86400) t = t - (days * 86400)
ret = self._call('pack', t, wait) result = self._call('pack', t, wait)
# remove all non-current entries from the cache. # remove all non-current entries from the cache.
# This way we make sure that loadBefore with before < packtime, won't # This way we make sure that loadBefore with before < packtime, won't
# return data from the cache, instead of returning "no data" if requested object # return data from the cache, instead of returning "no data" if requested object
...@@ -568,7 +568,7 @@ class ClientStorage(ZODB.ConflictResolution.ConflictResolvingStorage): ...@@ -568,7 +568,7 @@ class ClientStorage(ZODB.ConflictResolution.ConflictResolvingStorage):
# cache than is strictly necessary, but since access to noncurrent data # cache than is strictly necessary, but since access to noncurrent data
# is seldom, that should not cause problems in practice. # is seldom, that should not cause problems in practice.
self._cache.clearAllNonCurrent() self._cache.clearAllNonCurrent()
return ret return result
def store(self, oid, serial, data, version, txn): def store(self, oid, serial, data, version, txn):
"""Storage API: store data for an object.""" """Storage API: store data for an object."""
......
...@@ -250,7 +250,7 @@ class ClientCache(object): ...@@ -250,7 +250,7 @@ class ClientCache(object):
def clearAllNonCurrent(self): def clearAllNonCurrent(self):
with self._lock: with self._lock:
f = self.f f = self.f
for oid, tidofs in self.noncurrent.items(): for (oid, tidofs) in self.noncurrent.items():
for (tid, ofs) in tidofs.items(): for (tid, ofs) in tidofs.items():
f.seek(ofs) f.seek(ofs)
status = f.read(1) status = f.read(1)
......
...@@ -255,31 +255,31 @@ class CacheTests(ZODB.tests.util.TestCase): ...@@ -255,31 +255,31 @@ class CacheTests(ZODB.tests.util.TestCase):
def testClearAllNonCurrent(self): def testClearAllNonCurrent(self):
cache = self.cache cache = self.cache
cache.store(p64(1), n1, n2, b'1@1') cache.store(p64(1), n1, n2, b'1@1')
cache.store(p64(1), n2, n3, b'1@2') cache.store(p64(1), n2, n3, b'1@2')
cache.store(p64(1), n3, None, b'1') cache.store(p64(1), n3, None, b'1')
cache.store(p64(2), n2, n3, b'2@2') cache.store(p64(2), n2, n3, b'2@2')
cache.store(p64(2), n3, None, b'2') cache.store(p64(2), n3, None, b'2')
eq = self.assertEqual eq = self.assertEqual
eq(len(cache), 5) eq(len(cache), 5)
eq(cache.load(p64(1)), (b'1', n3)) eq(cache.load(p64(1)), (b'1', n3))
eq(cache.loadBefore(p64(1), n3), (b'1@2', n2, n3)) eq(cache.loadBefore(p64(1), n3), (b'1@2', n2, n3))
eq(cache.loadBefore(p64(1), n2), (b'1@1', n1, n2)) eq(cache.loadBefore(p64(1), n2), (b'1@1', n1, n2))
eq(cache.loadBefore(p64(1), n1), None) eq(cache.loadBefore(p64(1), n1), None)
eq(cache.load(p64(2)), (b'2', n3)) eq(cache.load(p64(2)), (b'2', n3))
eq(cache.loadBefore(p64(2), n3), (b'2@2', n2, n3)) eq(cache.loadBefore(p64(2), n3), (b'2@2', n2, n3))
eq(cache.loadBefore(p64(2), n2), None) eq(cache.loadBefore(p64(2), n2), None)
cache.clearAllNonCurrent() cache.clearAllNonCurrent()
eq(len(cache), 2) eq(len(cache), 2)
eq(cache.load(p64(1)), (b'1', n3)) eq(cache.load(p64(1)), (b'1', n3))
eq(cache.loadBefore(p64(1), n3), None) eq(cache.loadBefore(p64(1), n3), None)
eq(cache.loadBefore(p64(1), n2), None) eq(cache.loadBefore(p64(1), n2), None)
eq(cache.loadBefore(p64(1), n1), None) eq(cache.loadBefore(p64(1), n1), None)
eq(cache.load(p64(2)), (b'2', n3)) eq(cache.load(p64(2)), (b'2', n3))
eq(cache.loadBefore(p64(2), n3), None) eq(cache.loadBefore(p64(2), n3), None)
eq(cache.loadBefore(p64(2), n2), None) eq(cache.loadBefore(p64(2), n2), None)
def testChangingCacheSize(self): def testChangingCacheSize(self):
# start with a small cache # start with a small cache
......
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