Commit e856de9d authored by Levin Zimmermann's avatar Levin Zimmermann

erp5_wendelin: Add Base_deleteZBigArray to manually GC ZBigArray

With the new extension method 'Base_deleteZBigArray' we can garbage
collect individual ZBigArray.
parent 6b52e4f3
...@@ -4,6 +4,13 @@ ...@@ -4,6 +4,13 @@
""" """
from wendelin.bigarray.array_zodb import ZBigArray from wendelin.bigarray.array_zodb import ZBigArray
import numpy as np import numpy as np
try: # duplication wrt neo/client/patch
from ZODB.Connection import TransactionMetaData
except ImportError: # BBB: ZODB < 5
from ZODB.BaseStorage import TransactionRecord
TransactionMetaData = lambda user='', description='', extension=None: \
TransactionRecord(None, None, user, description, extension)
def DataStream_copyCSVToDataArray(data_stream, chunk_list, start, end, \ def DataStream_copyCSVToDataArray(data_stream, chunk_list, start, end, \
data_array_reference=None): data_array_reference=None):
...@@ -58,3 +65,30 @@ def DataStream_copyCSVToDataArray(data_stream, chunk_list, start, end, \ ...@@ -58,3 +65,30 @@ def DataStream_copyCSVToDataArray(data_stream, chunk_list, start, end, \
zarray[-ndarray_shape[0]:] = ndarray zarray[-ndarray_shape[0]:] = ndarray
return start, end return start, end
def Base_deleteZBigArray(zbigarray):
conn = zbigarray._p_jar
storage = conn.db().storage
txn = TransactionMetaData()
def rm(obj):
obj._p_activate()
oid, tid = obj._p_oid, obj._p_serial
obj._p_deactivate()
storage.deleteObject(oid, tid, txn)
storage.tpc_begin(txn)
zfile = zbigarray.zfile
blktab = zfile.blktab
for _, b in blktab.items():
rm(b)
for obj in (blktab, zfile, zbigarray):
rm(obj)
storage.tpc_vote(txn)
storage.tpc_finish(txn)
...@@ -6,12 +6,6 @@ ...@@ -6,12 +6,6 @@
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item> <item>
<key> <string>default_reference</string> </key> <key> <string>default_reference</string> </key>
<value> <string>Wendelin</string> </value> <value> <string>Wendelin</string> </value>
...@@ -55,28 +49,13 @@ ...@@ -55,28 +49,13 @@
<item> <item>
<key> <string>workflow_history</string> </key> <key> <string>workflow_history</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="2" aka="AAAAAAAAAAI="> <record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<global name="PersistentMapping" module="Persistence.mapping"/> <global name="PersistentMapping" module="Persistence.mapping"/>
</pickle> </pickle>
...@@ -89,7 +68,7 @@ ...@@ -89,7 +68,7 @@
<item> <item>
<key> <string>component_validation_workflow</string> </key> <key> <string>component_validation_workflow</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value> </value>
</item> </item>
</dictionary> </dictionary>
...@@ -98,7 +77,7 @@ ...@@ -98,7 +77,7 @@
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_function</string> </key>
<value> <string>Base_deleteZBigArray</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>Wendelin</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_deleteZBigArray</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Base_deleteZBigArray</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
############################################################################## ##############################################################################
# #
# Copyright (c) 2002-2015 Nexedi SA and Contributors. All Rights Reserved. # Copyright (c) 2002-2024 Nexedi SA and Contributors. All Rights Reserved.
# #
# This program is free software: you can Use, Study, Modify and Redistribute # This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your # it under the terms of the GNU General Public License version 3, or (at your
...@@ -882,3 +882,22 @@ result = [x for x in data_bucket_stream.getBucketIndexKeySequenceByIndex()] ...@@ -882,3 +882,22 @@ result = [x for x in data_bucket_stream.getBucketIndexKeySequenceByIndex()]
self.assertRaises(ValueError, self.assertRaises(ValueError,
portal.Base_wendelinTextToNumpy, portal.Base_wendelinTextToNumpy,
wendelin_text) wendelin_text)
def test_19_Base_deleteZBigArray(self):
"""
Simple test to ensure 'Base_deleteZBigArray' runs without errors.
"""
portal = self.portal
data_array = portal.newContent(portal_type = "Data Array")
data_array.initArray((1, 2), int)
self.tic()
A = data_array.getArray()
A.append([[1, 2] for _ in range(5000)])
self.tic()
data_array.setArray(None)
portal.Base_deleteZBigArray(A)
self.tic()
self.assertTrue(True)
...@@ -39,7 +39,9 @@ ...@@ -39,7 +39,9 @@
<item> <item>
<key> <string>text_content_warning_message</string> </key> <key> <string>text_content_warning_message</string> </key>
<value> <value>
<tuple/> <tuple>
<string>W:907, 4: Redundant use of assertTrue with constant value True (redundant-unittest-assert)</string>
</tuple>
</value> </value>
</item> </item>
<item> <item>
......
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