[PR #199] [CLOSED] Feature: db file locking #163

Closed
opened 2026-05-23 08:32:19 -06:00 by gitea-mirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/appy-one/acebase/pull/199
Author: @appy-one
Created: 1/1/2023
Status: Closed

Base: masterHead: feature/db-file-locking


📝 Commits (8)

  • 2bfedb0 implemented file locking to battle #48
  • f0082a7 use new retry utility function
  • a63ab71 Use assert function instead of console.assert
  • 211b092 using new Api event emitter instead of callback
  • b09cad1 fix compile error
  • 0867f6f use new api event emitter instead of callback
  • c8f5fa5 Implemented db file locking for #48
  • 6c32671 added file locking unit test

📊 Changes

10 files changed (+661 additions, -166 deletions)

View changed files

📝 src/acebase-local.ts (+3 -3)
📝 src/api-local.ts (+4 -3)
📝 src/data-index/data-index.ts (+8 -17)
📝 src/promise-fs/index.ts (+15 -0)
src/retry.ts (+57 -0)
src/storage/binary/error.ts (+5 -0)
📝 src/storage/binary/index.ts (+147 -142)
src/storage/binary/lockfile.LICENSE (+23 -0)
src/storage/binary/lockfile.ts (+371 -0)
📝 src/test/constructor.spec.ts (+28 -1)

📄 Description

(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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/appy-one/acebase/pull/199 **Author:** [@appy-one](https://github.com/appy-one) **Created:** 1/1/2023 **Status:** ❌ Closed **Base:** `master` ← **Head:** `feature/db-file-locking` --- ### 📝 Commits (8) - [`2bfedb0`](https://github.com/appy-one/acebase/commit/2bfedb04ea55d0f27415569249d18e26c2ebe211) implemented file locking to battle #48 - [`f0082a7`](https://github.com/appy-one/acebase/commit/f0082a77db60d1d80d691dd4d57ca268364cd4fe) use new `retry` utility function - [`a63ab71`](https://github.com/appy-one/acebase/commit/a63ab718494d2ecdc4ce2fbe0918dab86effef3f) Use `assert` function instead of `console.assert` - [`211b092`](https://github.com/appy-one/acebase/commit/211b092ce7275233c94934bb69e52e79e9dbdacb) using new Api event emitter instead of callback - [`b09cad1`](https://github.com/appy-one/acebase/commit/b09cad11c637dac61b6782e16e8f0606542c158b) fix compile error - [`0867f6f`](https://github.com/appy-one/acebase/commit/0867f6f50b50a669ff2555850a6763920990c38e) use new api event emitter instead of callback - [`c8f5fa5`](https://github.com/appy-one/acebase/commit/c8f5fa53aced7c1c321fd0720f419504d74bd67b) Implemented db file locking for #48 - [`6c32671`](https://github.com/appy-one/acebase/commit/6c32671bf7b23828feda533e5b060924efa9a53e) added file locking unit test ### 📊 Changes **10 files changed** (+661 additions, -166 deletions) <details> <summary>View changed files</summary> 📝 `src/acebase-local.ts` (+3 -3) 📝 `src/api-local.ts` (+4 -3) 📝 `src/data-index/data-index.ts` (+8 -17) 📝 `src/promise-fs/index.ts` (+15 -0) ➕ `src/retry.ts` (+57 -0) ➕ `src/storage/binary/error.ts` (+5 -0) 📝 `src/storage/binary/index.ts` (+147 -142) ➕ `src/storage/binary/lockfile.LICENSE` (+23 -0) ➕ `src/storage/binary/lockfile.ts` (+371 -0) 📝 `src/test/constructor.spec.ts` (+28 -1) </details> ### 📄 Description # (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](https://github.com/appy-one/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](https://github.com/moxystudio/node-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` ](https://github.com/appy-one/acebase-core/pull/29) to be merged, dependency updated --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
gitea-mirror 2026-05-23 08:32:19 -06:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/acebase#163
No description provided.