Commit e6bea85f authored by Kirill Smelkov's avatar Kirill Smelkov

bigarray: Test for ZBigArray invalidation via usual attribute, e.g. .shape

All is currently handled correctly, but an observation is made that upon
such invalidation we through away ._v_fileh i.e. we through away whole
data cache just because an array was resized.
parent 48b2bb74
......@@ -51,6 +51,18 @@ class ZBigArray(BigArray,
def __setstate__(self, state):
super(ZBigArray, self).__setstate__(state)
# NOTE __setstate__() is done after either
# - 1st time loading from DB, or
# - loading from DB after invalidation.
#
# as invalidation can happen e.g. by just changing .shape in another DB
# connection (e.g. resizing array and appending some data), via always
# resetting ._v_fileh we discard all data from it.
#
# IOW we discard whole cache just because some data were appended.
#
# -> TODO (optimize) do not through ._v_fileh if we can (.zfile not changed, etc)
self._v_fileh = None
......
......@@ -406,3 +406,52 @@ def test_zbigarray_vs_cache_invalidation():
conn2.close()
del conn2, root2
dbclose(root1)
# verify how ZBigArray behaves when plain properties are changed / invalidated
def test_zbigarray_invalidate_shape():
root = testdb.dbopen()
conn = root._p_jar
db = conn.db()
conn.close()
del root, conn
print
tm1 = TransactionManager()
tm2 = TransactionManager()
conn1 = db.open(transaction_manager=tm1)
root1 = conn1.root()
# setup zarray
root1['zarray4'] = a1 = ZBigArray((10,), uint8)
tm1.commit()
# set zarray initial data
a1[0:1] = [1] # XXX -> [0] = 1 after BigArray can
tm1.commit()
# read zarray in conn2
conn2 = db.open(transaction_manager=tm2)
root2 = conn2.root()
a2 = root2['zarray4']
assert a2[0:1] == [1] # read data in conn2 + make sure read correctly
# XXX -> [0] == 1 after BigArray can
# append to a1 which changes both RAM pages and a1.shape
assert a1.shape == (10,)
a1.append([123])
assert a1.shape == (11,)
assert a1[10:11] == [123] # XXX -> [10] = 123 after BigArray can
tm1.commit()
tm2.commit() # just transaction boundary for t2
# data from tm1 should propagate to tm
assert a2.shape == (11,)
assert a2[10:11] == [123] # XXX -> [10] = 123 after BigArray can
conn2.close()
del conn2, root2, a2
dbclose(root1)
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