seald / nedb

The JavaScript Database, for Node.js, nw.js, electron and the browser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there a way to know if a compaction failed

kavillo opened this issue · comments

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

  • Runtime: Node
  • Version: 12.13.0 and latest stable
  • OS: MacOS, Linux

Additional context
Add any other context about the problem here.

commented

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.

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.