appy-one / acebase

A fast, low memory, transactional, index & query enabled NoSQL database engine and server for node.js and browser with realtime data change notifications
MIT License
492 stars 27 forks source link

TypeError when trying to add new records after removing old ones #239

Closed darkjedi9922 closed 1 year ago

darkjedi9922 commented 1 year ago

Hello. I face a problem with following scenario:

  1. Add a "large" dataset to some collection, using update. I have noticed that it starts to reproduce from around 110 records. If set it to much less, the problem does not happen for some reason
  2. Remove all that records with a query
  3. Try to add a new "small" dataset (around 5-10 records), using update, and this fails with a TypeError somewhere in the binary tree:
S:\Projects\debug\acebase\dist\cjs\btree\binary-tree.js:1642
        const lastKey = lastEntry.key;
                                  ^
TypeError: Cannot read properties of undefined (reading 'key')
    at BinaryBPlusTree._findAll (S:\Projects\debug\acebase\dist\cjs\btree\binary-tree.js:1642:35)
    at async BinaryBPlusTree._threadSafe (S:\Projects\debug\acebase\dist\cjs\btree\binary-tree.js:942:26)
    at async createStreamFromBinaryTree (S:\Projects\debug\acebase\dist\cjs\storage\binary\index.js:2666:33)
    at async _mergeNode (S:\Projects\debug\acebase\dist\cjs\storage\binary\index.js:3160:5)
    at async Object.write [as _customWriteFunction] (S:\Projects\debug\acebase\dist\cjs\storage\binary\index.js:1945:28)
    at async AceBaseStorage._updateNode (S:\Projects\debug\acebase\dist\cjs\storage\binary\index.js:1957:26)
    at async AceBaseStorage.updateNode (S:\Projects\debug\acebase\dist\cjs\storage\binary\index.js:1891:27)
    at async LocalApi.update (S:\Projects\debug\acebase\dist\cjs\api-local.js:70:24)
    at async DataReference.update (S:\Projects\debug\acebase\node_modules\acebase-core\dist\cjs\data-reference.js:232:36)
    at async S:\Projects\debug\acebase\spec\custom-test.js:25:5

Node.js v18.15.0

In order to help to debug it, I prepared a test for this scenario, where the problem is reproduced stably: https://github.com/darkjedi9922/acebase-bug-reproduce/blob/bug-reproduce/spec/custom-test.js Run the test with node .\spec\custom-test.js

appy-one commented 1 year ago

Hi @darkjedi9922 I published a fix for this in v1.29.3, thanks for reporting and providing unit testing code!

Do you like AceBase? 👇🏼

Sponsor AceBase Spread the word contribute