Skip to content

Commit a06ccdf

Browse files
committed
Introducing PCC locking for DBTransaction
1 parent 58a62f2 commit a06ccdf

File tree

7 files changed

+375
-71
lines changed

7 files changed

+375
-71
lines changed

package-lock.json

Lines changed: 34 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
},
2929
"dependencies": {
3030
"@matrixai/async-init": "^1.8.1",
31-
"@matrixai/async-locks": "^2.3.1",
31+
"@matrixai/async-locks": "^3.0.0",
3232
"@matrixai/errors": "^1.1.2",
33-
"@matrixai/logger": "^2.2.2",
33+
"@matrixai/logger": "^2.3.0",
3434
"@matrixai/resources": "^1.1.3",
3535
"@matrixai/workers": "^1.3.3",
3636
"node-gyp-build": "4.4.0",

src/DB.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { ResourceAcquire } from '@matrixai/resources';
2+
import type { RWLockWriter } from '@matrixai/async-locks';
23
import type {
34
KeyPath,
45
LevelPath,
@@ -20,6 +21,7 @@ import {
2021
CreateDestroyStartStop,
2122
ready,
2223
} from '@matrixai/async-init/dist/CreateDestroyStartStop';
24+
import { LockBox } from '@matrixai/async-locks';
2325
import DBIterator from './DBIterator';
2426
import DBTransaction from './DBTransaction';
2527
import { rocksdbP } from './rocksdb';
@@ -69,6 +71,7 @@ class DB {
6971
protected fs: FileSystem;
7072
protected logger: Logger;
7173
protected workerManager?: DBWorkerManagerInterface;
74+
protected _lockBox: LockBox<RWLockWriter> = new LockBox();
7275
protected _db: RocksDBDatabase;
7376
/**
7477
* References to iterators
@@ -97,6 +100,10 @@ class DB {
97100
return this._transactionRefs;
98101
}
99102

103+
get lockBox(): Readonly<LockBox<RWLockWriter>> {
104+
return this._lockBox;
105+
}
106+
100107
constructor({
101108
dbPath,
102109
crypto,
@@ -193,6 +200,7 @@ class DB {
193200
return async () => {
194201
const tran = new DBTransaction({
195202
db: this,
203+
lockBox: this._lockBox,
196204
logger: this.logger,
197205
});
198206
return [

0 commit comments

Comments
 (0)