Commit 743937a4 authored by Levin Zimmermann's avatar Levin Zimmermann

ZBigArray: Allow explicitly overridding global ZBlk fmt

Before this patch the ZBlk format of a ZBigArray could only be set
globally for all arrays. Now it's possible to explicitly set the ZBblk
format for single arrays, differing from the global setting.
parent a94ded9b
......@@ -51,14 +51,14 @@ class ZBigArray(BigArray,
# XXX default blksize hardcoded
def __init__(self, shape, dtype, order='C', blksize=2*1024*1024):
def __init__(self, shape, dtype, order='C', blksize=2*1024*1024, zblk_fmt=""):
LivePersistent.__init__(self)
# NOTE BigArray is cooperative to us - it names all helping (= not needing
# to be saved) data members starting with _v_. Were it otherwise, we
# could not inherit from BigArray and would need to keep its instance
# in e.g. ._v_array helper and redirect all BigArray method from us to it.
BigArray._init0(self, shape, dtype, order)
self.zfile = ZBigFile(blksize)
self.zfile = ZBigFile(blksize, zblk_fmt=zblk_fmt)
self._v_fileh = None
......
......@@ -18,6 +18,7 @@
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
from wendelin.bigarray.array_zodb import ZBigArray
from wendelin.bigfile import file_zodb
from wendelin.bigfile.tests.test_filezodb import ram_reclaim_all
from wendelin.bigfile.tests.test_thread import NotifyChannel
from wendelin.lib.zodb import dbclose
......@@ -654,3 +655,28 @@ def test_zbigarray_invalidate_shape():
del conn2, root2, a2
# test that explicitly setting the ZBlk format works
@func
def test_bigarray_set_zblk_fmt():
# ensure ZBlk_fmt_write is ZBlk0 during this test,
# so that we can be sure the global default is overridden
# by an explicitly set value during ZBigArray initialization
fmt_write_save = file_zodb.ZBlk_fmt_write
file_zodb.ZBlk_fmt_write = 'ZBlk0'
def _():
file_zodb.ZBlk_fmt_write = fmt_write_save
defer(_)
root = testdb.dbopen()
defer(lambda: dbclose(root))
root['zarray-set-zblk'] = A = ZBigArray((16*1024*1024,), uint8, zblk_fmt="ZBlk1")
transaction.commit()
a = A[:]
a[0] = 100
transaction.commit()
assert type(A.zfile.blktab[0]) is file_zodb.ZBlk1
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