Commit c51a5e18 authored by Kirill Smelkov's avatar Kirill Smelkov

X ZBigArrray: Don't throw away data cache on e.g. .shape change

parent cdc05b26
# -*- coding: utf-8 -*-
# Wendelin.bigarray | ZODB-Persistent BigArray
# Copyright (C) 2014-2015 Nexedi SA and Contributors.
# Copyright (C) 2014-2019 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
......@@ -56,7 +56,8 @@ class ZBigArray(BigArray,
self.zfile = ZBigFile(blksize)
self._v_fileh = None
# __setstate__ (re-)loads ZBigArray data from DB, e.g. after live ZBigArray
# object was invalidated.
def __setstate__(self, state):
super(ZBigArray, self).__setstate__(state)
......@@ -68,18 +69,15 @@ class ZBigArray(BigArray,
if not hasattr(self, '_'+k):
setattr(self, '_'+k, v)
# 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.
# (re-)set ._v_fileh; make sure not to loose fileh and its cache if
# .zfile has not changed. By preserving fileh we don't throw away data
# cache on e.g. just .shape change.
#
# 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
# TODO test/bench that cache is preserved after .shape change (e.g. append)
_v_fileh = getattr(self, '_v_fileh', None)
if _v_fileh is not None and self.zfile is not _v_fileh.zfile:
_v_fileh = None
self._v_fileh = _v_fileh
# open fileh lazily, so that when we open it, zfile was already associated
......
  • /cc @klaus, @Tyagov (FYI: this is draft change; I will add corresponding test and benchmark before merging to master; this should likely improve speed even for WC1 when cluster of zopes work on array that is regularly appended to)

  • @kirr , thanks. You know this part better than us. I trust your judgement.

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