appy-one / acebase-server

A fast, low memory, transactional, index & query enabled NoSQL database server for node.js that easily syncs with browser and node.js clients and servers
MIT License
32 stars 14 forks source link

Running Into Issue Creating Server. Am I Missing Something? #27

Closed flancast90 closed 2 years ago

flancast90 commented 2 years ago

Hi, I've begun migrating my project to AceBase, and while the regular AceBase library works fine, as soon as I attempt to integrate with AceBase-Server, I get an error (see bottom of issue). Mainly, I'm confused as to how the code should look (e.g. do I need both an AceBase and AceBase-server instance)?

The issue is probably just an issue with how I've imported everything, so I'd appreciate some guidance on how to fix :)

My Code:

import { AceBase } from 'acebase'
const db = new AceBase('db');

import { AceBaseServer } from 'acebase-server';
const server = new AceBaseServer('db', { host: 'localhost', port: 5757 });

Error Message:

[db] DEBUG THIS: getNodeInfo error Error: Not enough bytes read from file at index 131072, expected 128 but got 0
    at NodeReader.readHeader (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:3051:49)
    at async start (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:2649:17)
    at async NodeReader.getChildInfo (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:2956:9)
    at async AceBaseStorage.getNodeInfo (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:1725:33)
    at async AceBaseStorage.getNodeInfo (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:1701:34)
    at async AceBaseStorage.getNodeInfo (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:1701:34)
    at async AceBaseStorage.getNode (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:1587:30)
    at async AceBaseStorage.transactNode (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage.js:1274:26)
    at async LocalApi.transaction (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\api-local.js:133:24)
    at async DataReference.transaction (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase-core\dist\cjs\data-reference.js:293:28)
[db] DEBUG THIS: getNodeInfo error Error: Not enough bytes read from file at index 131072, expected 128 but got 0
    at NodeReader.readHeader (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:3051:49)
    at async start (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:2649:17)
    at async NodeReader.getChildInfo (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:2956:9)
    at async AceBaseStorage.getNodeInfo (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:1725:33)
    at async AceBaseStorage.getNodeInfo (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:1701:34)
    at async AceBaseStorage.getNodeInfo (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:1701:34)
    at async AceBaseStorage.getNode (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:1587:30)
    at async AceBaseStorage.transactNode (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage.js:1274:26)
    at async LocalApi.transaction (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\api-local.js:133:24)
    at async DataReference.transaction (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase-core\dist\cjs\data-reference.js:293:28)
[db] DEBUG THIS: getNodeInfo error Error: Not enough bytes read from file at index 131072, expected 128 but got 0      
    at NodeReader.readHeader (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:3051:49)
    at async start (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:2649:17)
    at async NodeReader.getChildInfo (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:2956:9)
    at async AceBaseStorage.getNodeInfo (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:1725:33)
    at async AceBaseStorage.getNodeInfo (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:1701:34)
    at async AceBaseStorage.getNodeInfo (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:1701:34)
    at async AceBaseStorage.getNode (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:1587:30)
    at async AceBaseStorage.transactNode (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage.js:1274:26)
    at async LocalApi.transaction (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\api-local.js:133:24)
    at async DataReference.transaction (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase-core\dist\cjs\data-reference.js:293:28)
[db] DEBUG THIS: getNode error: Error: Not enough bytes read from file at index 131072, expected 128 but got 0
    at NodeReader.readHeader (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:3051:49)
    at async start (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:2649:17)
    at async NodeReader.getChildInfo (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:2956:9)
    at async AceBaseStorage.getNodeInfo (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:1725:33)
    at async AceBaseStorage.getNodeInfo (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:1701:34)
    at async AceBaseStorage.getNodeInfo (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:1701:34)
    at async AceBaseStorage.getNode (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:1587:30)
    at async AceBaseStorage.transactNode (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage.js:1274:26)
    at async LocalApi.transaction (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\api-local.js:133:24)
    at async DataReference.transaction (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase-core\dist\cjs\data-reference.js:293:28)
node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

Error: Not enough bytes read from file at index 131072, expected 128 but got 0
    at NodeReader.readHeader (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:3051:49)
    at async start (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:2649:17)
    at async NodeReader.getChildInfo (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:2956:9)
    at async AceBaseStorage.getNodeInfo (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:1725:33)
    at async AceBaseStorage.getNodeInfo (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:1701:34)
    at async AceBaseStorage.getNodeInfo (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:1701:34)
    at async AceBaseStorage.getNode (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage-acebase.js:1587:30)
    at async AceBaseStorage.transactNode (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\storage.js:1274:26)
    at async LocalApi.transaction (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase\src\api-local.js:133:24)
    at async DataReference.transaction (C:\Users\Finn Lancaster\Desktop\Finned-Backend\node_modules\acebase-core\dist\cjs\data-reference.js:293:28)
donl commented 2 years ago

Try removing

const db = new AceBase('db');

Otherwise you are creating/accessing the same database named 'db' on disk multiple times simultaneously, which requires special coordination.

flancast90 commented 2 years ago

I tried both with and without that line, and got the same issue either way. Any other ideas?

On Mon, Jul 25, 2022 at 10:03 PM Don @.***> wrote:

Try removing

const db = new AceBase('db');

Otherwise you are creating/accessing the same database named 'db' on disk multiple times simultaneously, which requires special coordination.

— Reply to this email directly, view it on GitHub https://github.com/appy-one/acebase-server/issues/27#issuecomment-1194885548, or unsubscribe https://github.com/notifications/unsubscribe-auth/AR2EVEEBIWLEL3BLGP4IOQLVV5BNNANCNFSM54FYQGJQ . You are receiving this because you authored the thread.Message ID: @.***>

appy-one commented 2 years ago

It looks like you may have corrupted the database file by accessing (writing to) it from both an AceBaseServer and local AceBase db instance, I posted about this a while ago in the discussion "How to protect your database from corruption".

If the data you stored in the db is important, I might be able to help you recover the data. If it only has dev/test data, I recommend removing it and starting over with a fresh db. Make sure you only let a single AceBaseServer instance access the database files, or configure an acebase-ipc-server to setup a cluster.

flancast90 commented 2 years ago

I tried using only one of the instances and deleting the existing db to allow it to create a fresh one, with the same issue. In terms of recovery, I never actually got it to work, so there was no data in it.

On Tue, Jul 26, 2022 at 3:14 PM Ewout Stortenbeker @.***> wrote:

It looks like you may have corrupted the database file by accessing (writing to) it from both an AceBaseServer and local AceBase db instance, I posted about this a while ago in the discussion "How to protect your database from corruption" https://github.com/appy-one/acebase/discussions/48.

If the data you stored in the db is important, I might be able to help you recover the data. If it only has dev/test data, I recommend removing it and starting over with a fresh db. Make sure you only let a single AceBaseServer instance access the database files, or configure an acebase-ipc-server https://github.com/appy-one/acebase-ipc-server to setup a cluster.

— Reply to this email directly, view it on GitHub https://github.com/appy-one/acebase-server/issues/27#issuecomment-1195879825, or unsubscribe https://github.com/notifications/unsubscribe-auth/AR2EVEARWLLBNI46GDX3LHDVWA2IVANCNFSM54FYQGJQ . You are receiving this because you authored the thread.Message ID: @.***>

appy-one commented 2 years ago

Alright, you'll have to provide more code to reproduce this then. Only importing AceBaseServer and instantiating it with a new db does not cause any issues in my tests?

appy-one commented 2 years ago

I'm closing this issue for now. If you have more info about how to reproduce this, feel free to reopen!