seald / nedb

The JavaScript Database, for Node.js, nw.js, electron and the browser
MIT License
351 stars 32 forks source link

Is there a way to know if a compaction failed #28

Open kavillo opened 1 year ago

kavillo commented 1 year ago

Describe the bug A compaction might fail for different reasons, the most common is that the filesystem is full. In that case the database is not written to the file system. The application keeps running and at the next restart data is partially or fully missing.

To Reproduce Not sure I could upload a package since we need to make the compacting fails. I just removed the write attribute to a data file to reproduce it. Expected behavior I would expect a "compact.fail" event to be called or a status variable that indicates the db is in error.

Actual behavior "compact.done" event is called with no indication that compacting failed

Logs

Environment info

Additional context Add any other context about the problem here.

tex0l commented 1 year ago

Hi! The auto compaction feature is set through the setAutocompactionInterval which simply calls a Datastore#compactDatafile, which is the version that is orchestrated through the executor of Persistence#persistCachedDatabaseAsync which only emits a compaction.done when it succeeds, therefore I don't think it emits a compaction.done when it fails, it just silently fails.

We could try/catch it and emit a comapction.failed with the error message in the event I guess.

kavillo commented 1 year ago

Thanks for the answer. Yes that would be ideal, in that way we would know if the failure happened even if the compaction is issued by a call to compactDatafileAsync directly.