Skip to content

Feature: db file locking#199

Closed
appy-one wants to merge 8 commits into
masterfrom
feature/db-file-locking
Closed

Feature: db file locking#199
appy-one wants to merge 8 commits into
masterfrom
feature/db-file-locking

Conversation

@appy-one
Copy link
Copy Markdown
Owner

@appy-one appy-one commented Jan 1, 2023

(H)appy new year! 🍾🥂

This PR helps preventing database corruption #48 by disallowing multiple processes to access the same database file simultaneously, unless they are using IPC for inter-process communication. This means that forked processes with pm2 or NodeJS clustering, or servers using acebase-ipc-server can still all access the database simultaneously, but all other processes that try to open an already open db will be denied access.

For its implementation I have modified proper-lockfile instead of adding it as a dependency for the following reasons:

  • The proper-lockfile project appears not to be maintained (last commit Jan 2021), has old open issues
  • package has no types
  • code uses callbacks instead of promises
  • has dependencies AceBase does not need

I changed the following:

  • ported to TypeScript
  • refactored callbacks to async promises
  • removed signal-exit dependency (not needed)
  • removed retry dependency (using own simple implementation)
  • removed graceful-fs dependency (using own pfs)
  • removed unused code (probably more to be removed later)

requires acebase-core #29 to be merged, dependency updated

@appy-one appy-one added the enhancement New feature or request label Jan 1, 2023
@appy-one appy-one self-assigned this Jan 1, 2023
@appy-one
Copy link
Copy Markdown
Owner Author

I'm parking this PR because I implemented an automatically starting up IPC service/"daemon" in #213, which acts as an automatic (local) IPC master for each process requesting access to the same database. Locking the file will therefore not be necessary.

@appy-one appy-one closed this Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant