Commit c84c48ee authored by Julien Muchembled's avatar Julien Muchembled

client: make clearer that max_size attribute is used from outside ClientCache

parent 1ef5c1ba
...@@ -447,7 +447,7 @@ class Application(ThreadedApplication): ...@@ -447,7 +447,7 @@ class Application(ThreadedApplication):
txn_context.data_dict[oid] = data, serial, txn_context.write( txn_context.data_dict[oid] = data, serial, txn_context.write(
self, packet, oid, oid=oid) self, packet, oid, oid=oid)
while txn_context.data_size >= self._cache._max_size: while txn_context.data_size >= self._cache.max_size:
self._waitAnyTransactionMessage(txn_context) self._waitAnyTransactionMessage(txn_context)
self._waitAnyTransactionMessage(txn_context, False) self._waitAnyTransactionMessage(txn_context, False)
......
...@@ -64,7 +64,7 @@ class ClientCache(object): ...@@ -64,7 +64,7 @@ class ClientCache(object):
- The history queue only contains items with counter > 0 - The history queue only contains items with counter > 0
""" """
__slots__ = ('_life_time', '_max_history_size', '_max_size', __slots__ = ('max_size', '_life_time', '_max_history_size',
'_queue_list', '_oid_dict', '_time', '_size', '_history_size', '_queue_list', '_oid_dict', '_time', '_size', '_history_size',
'_nhit', '_nmiss') '_nhit', '_nmiss')
...@@ -72,7 +72,7 @@ class ClientCache(object): ...@@ -72,7 +72,7 @@ class ClientCache(object):
max_size=20*1024*1024): max_size=20*1024*1024):
self._life_time = life_time self._life_time = life_time
self._max_history_size = max_history_size self._max_history_size = max_history_size
self._max_size = max_size self.max_size = max_size
self.clear() self.clear()
def clear(self): def clear(self):
...@@ -94,7 +94,7 @@ class ClientCache(object): ...@@ -94,7 +94,7 @@ class ClientCache(object):
[self._history_size] + [ [self._history_size] + [
sum(1 for _ in self._iterQueue(level)) sum(1 for _ in self._iterQueue(level))
for level in xrange(1, len(self._queue_list))], for level in xrange(1, len(self._queue_list))],
self._life_time, self._max_history_size, self._max_size) self._life_time, self._max_history_size, self.max_size)
def _iterQueue(self, level): def _iterQueue(self, level):
"""for debugging purpose""" """for debugging purpose"""
...@@ -168,7 +168,7 @@ class ClientCache(object): ...@@ -168,7 +168,7 @@ class ClientCache(object):
# XXX It might be better to adjust the level according to the object # XXX It might be better to adjust the level according to the object
# size. See commented factor for example. # size. See commented factor for example.
item.level = 1 + int(_log(counter, 2) item.level = 1 + int(_log(counter, 2)
# * (1.01 - len(item.data) / self._max_size) # * (1.01 - len(item.data) / self.max_size)
) )
self._add(item) self._add(item)
...@@ -212,7 +212,7 @@ class ClientCache(object): ...@@ -212,7 +212,7 @@ class ClientCache(object):
def store(self, oid, data, tid, next_tid): def store(self, oid, data, tid, next_tid):
"""Store a new data record in the cache""" """Store a new data record in the cache"""
size = len(data) size = len(data)
max_size = self._max_size max_size = self.max_size
if size < max_size: if size < max_size:
item = self._load(oid, next_tid) item = self._load(oid, next_tid)
if item: if item:
...@@ -331,7 +331,7 @@ def test(self): ...@@ -331,7 +331,7 @@ def test(self):
# Test late invalidations. # Test late invalidations.
cache.clear() cache.clear()
cache.store(1, '10*', 10, None) cache.store(1, '10*', 10, None)
cache._max_size = cache._size cache.max_size = cache._size
cache.store(2, '10', 10, 15) cache.store(2, '10', 10, 15)
self.assertEqual(cache._queue_list[0].oid, 1) self.assertEqual(cache._queue_list[0].oid, 1)
cache.store(2, '15', 15, None) cache.store(2, '15', 15, None)
......
...@@ -121,7 +121,7 @@ class Transaction(object): ...@@ -121,7 +121,7 @@ class Transaction(object):
size = len(data) size = len(data)
self.data_size -= size self.data_size -= size
size += self.cache_size size += self.cache_size
if size < app._cache._max_size: if size < app._cache.max_size:
self.cache_size = size self.cache_size = size
else: else:
# Do not cache data past cache max size, as it # Do not cache data past cache max size, as it
......
...@@ -425,7 +425,7 @@ class ClientApplication(Node, neo.client.app.Application): ...@@ -425,7 +425,7 @@ class ClientApplication(Node, neo.client.app.Application):
self.poll_thread.node_name = name self.poll_thread.node_name = name
# Smaller cache to speed up tests that checks behaviour when it's too # Smaller cache to speed up tests that checks behaviour when it's too
# small. See also NEOCluster.cache_size # small. See also NEOCluster.cache_size
self._cache._max_size //= 1024 self._cache.max_size //= 1024
def _run(self): def _run(self):
try: try:
...@@ -733,7 +733,7 @@ class NEOCluster(object): ...@@ -733,7 +733,7 @@ class NEOCluster(object):
@property @property
def cache_size(self): def cache_size(self):
return self.client._cache._max_size return self.client._cache.max_size
### ###
def __enter__(self): def __enter__(self):
......
...@@ -1939,7 +1939,7 @@ class Test(NEOThreadedTest): ...@@ -1939,7 +1939,7 @@ class Test(NEOThreadedTest):
def changes(r1, r2, r3): def changes(r1, r2, r3):
r1['b'].value = 1 r1['b'].value = 1
r1['d'].value = 2 r1['d'].value = 2
r2['a'].value = '*' * r2._p_jar.db().storage._cache._max_size r2['a'].value = '*' * r2._p_jar.db().storage._cache.max_size
r2['b'].value = 3 r2['b'].value = 3
r2['c'].value = 4 r2['c'].value = 4
r3['a'].value = 5 r3['a'].value = 5
......
...@@ -1046,7 +1046,7 @@ class ReplicationTests(NEOThreadedTest): ...@@ -1046,7 +1046,7 @@ class ReplicationTests(NEOThreadedTest):
# try to commit something to backup storage and make sure it is # try to commit something to backup storage and make sure it is
# really read-only # really read-only
Zb._cache._max_size = 0 # make store() do work in sync way Zb._cache.max_size = 0 # make store() do work in sync way
txn = transaction.Transaction() txn = transaction.Transaction()
self.assertRaises(ReadOnlyError, Zb.tpc_begin, txn) self.assertRaises(ReadOnlyError, Zb.tpc_begin, txn)
self.assertRaises(ReadOnlyError, Zb.new_oid) self.assertRaises(ReadOnlyError, Zb.new_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