@zukhruf/mutex 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +155 -2
- package/dist/fencing/counter-token-source.d.ts +11 -0
- package/dist/fencing/counter-token-source.d.ts.map +1 -0
- package/dist/fencing/counter-token-source.js +13 -0
- package/dist/fencing/counter-token-source.js.map +1 -0
- package/dist/fencing/epoch-token-source.d.ts +13 -0
- package/dist/fencing/epoch-token-source.d.ts.map +1 -0
- package/dist/fencing/epoch-token-source.js +27 -0
- package/dist/fencing/epoch-token-source.js.map +1 -0
- package/dist/fencing/fencing-token.d.ts +12 -0
- package/dist/fencing/fencing-token.d.ts.map +1 -0
- package/dist/fencing/fencing-token.js +18 -0
- package/dist/fencing/fencing-token.js.map +1 -0
- package/dist/fencing/file-token-source.d.ts +13 -0
- package/dist/fencing/file-token-source.d.ts.map +1 -0
- package/dist/fencing/file-token-source.js +35 -0
- package/dist/fencing/file-token-source.js.map +1 -0
- package/dist/fencing/monotonic-clock-token-source.d.ts +12 -0
- package/dist/fencing/monotonic-clock-token-source.d.ts.map +1 -0
- package/dist/fencing/monotonic-clock-token-source.js +15 -0
- package/dist/fencing/monotonic-clock-token-source.js.map +1 -0
- package/dist/fencing/token-source.d.ts +9 -0
- package/dist/fencing/token-source.d.ts.map +1 -0
- package/dist/fencing/token-source.js +2 -0
- package/dist/fencing/token-source.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/leader-election/index.d.ts +3 -0
- package/dist/leader-election/index.d.ts.map +1 -0
- package/dist/leader-election/index.js +3 -0
- package/dist/leader-election/index.js.map +1 -0
- package/dist/leader-election/leader-election.d.ts +23 -0
- package/dist/leader-election/leader-election.d.ts.map +1 -0
- package/dist/leader-election/leader-election.js +77 -0
- package/dist/leader-election/leader-election.js.map +1 -0
- package/dist/leader-election/leadership.d.ts +14 -0
- package/dist/leader-election/leadership.d.ts.map +1 -0
- package/dist/leader-election/leadership.js +23 -0
- package/dist/leader-election/leadership.js.map +1 -0
- package/dist/lock-stores/file-system/file-lock-store.d.ts +35 -0
- package/dist/lock-stores/file-system/file-lock-store.d.ts.map +1 -0
- package/dist/lock-stores/file-system/file-lock-store.js +64 -0
- package/dist/lock-stores/file-system/file-lock-store.js.map +1 -0
- package/dist/lock-stores/file-system/lock-file-store.d.ts +11 -0
- package/dist/lock-stores/file-system/lock-file-store.d.ts.map +1 -0
- package/dist/lock-stores/file-system/lock-file-store.js +44 -0
- package/dist/lock-stores/file-system/lock-file-store.js.map +1 -0
- package/dist/lock-stores/file-system/owner.d.ts +16 -0
- package/dist/lock-stores/file-system/owner.d.ts.map +1 -0
- package/dist/lock-stores/file-system/owner.js +47 -0
- package/dist/lock-stores/file-system/owner.js.map +1 -0
- package/dist/lock-stores/file-system/ticket-queue-file-store.d.ts +16 -0
- package/dist/lock-stores/file-system/ticket-queue-file-store.d.ts.map +1 -0
- package/dist/lock-stores/file-system/ticket-queue-file-store.js +111 -0
- package/dist/lock-stores/file-system/ticket-queue-file-store.js.map +1 -0
- package/dist/lock-stores/ipc/child-process-connection.d.ts +18 -0
- package/dist/lock-stores/ipc/child-process-connection.d.ts.map +1 -0
- package/dist/lock-stores/ipc/child-process-connection.js +46 -0
- package/dist/lock-stores/ipc/child-process-connection.js.map +1 -0
- package/dist/lock-stores/ipc/ipc-lock-coordinator.d.ts +24 -0
- package/dist/lock-stores/ipc/ipc-lock-coordinator.d.ts.map +1 -0
- package/dist/lock-stores/ipc/ipc-lock-coordinator.js +27 -0
- package/dist/lock-stores/ipc/ipc-lock-coordinator.js.map +1 -0
- package/dist/lock-stores/ipc/ipc-store.d.ts +15 -0
- package/dist/lock-stores/ipc/ipc-store.d.ts.map +1 -0
- package/dist/lock-stores/ipc/ipc-store.js +34 -0
- package/dist/lock-stores/ipc/ipc-store.js.map +1 -0
- package/dist/lock-stores/ipc/process-channel-connection.d.ts +18 -0
- package/dist/lock-stores/ipc/process-channel-connection.d.ts.map +1 -0
- package/dist/lock-stores/ipc/process-channel-connection.js +52 -0
- package/dist/lock-stores/ipc/process-channel-connection.js.map +1 -0
- package/dist/lock-stores/memory/memory-store.d.ts +14 -0
- package/dist/lock-stores/memory/memory-store.d.ts.map +1 -0
- package/dist/lock-stores/memory/memory-store.js +41 -0
- package/dist/lock-stores/memory/memory-store.js.map +1 -0
- package/dist/lock-stores/remote/connection.d.ts +17 -0
- package/dist/lock-stores/remote/connection.d.ts.map +1 -0
- package/dist/lock-stores/remote/connection.js +2 -0
- package/dist/lock-stores/remote/connection.js.map +1 -0
- package/dist/lock-stores/remote/connector.d.ts +12 -0
- package/dist/lock-stores/remote/connector.d.ts.map +1 -0
- package/dist/lock-stores/remote/connector.js +2 -0
- package/dist/lock-stores/remote/connector.js.map +1 -0
- package/dist/lock-stores/remote/coordinator-unavailable-error.d.ts +6 -0
- package/dist/lock-stores/remote/coordinator-unavailable-error.d.ts.map +1 -0
- package/dist/lock-stores/remote/coordinator-unavailable-error.js +10 -0
- package/dist/lock-stores/remote/coordinator-unavailable-error.js.map +1 -0
- package/dist/lock-stores/remote/envelope.d.ts +7 -0
- package/dist/lock-stores/remote/envelope.d.ts.map +1 -0
- package/dist/lock-stores/remote/envelope.js +11 -0
- package/dist/lock-stores/remote/envelope.js.map +1 -0
- package/dist/lock-stores/remote/lock-coordinator.d.ts +34 -0
- package/dist/lock-stores/remote/lock-coordinator.d.ts.map +1 -0
- package/dist/lock-stores/remote/lock-coordinator.js +150 -0
- package/dist/lock-stores/remote/lock-coordinator.js.map +1 -0
- package/dist/lock-stores/remote/protocol.d.ts +36 -0
- package/dist/lock-stores/remote/protocol.d.ts.map +1 -0
- package/dist/lock-stores/remote/protocol.js +33 -0
- package/dist/lock-stores/remote/protocol.js.map +1 -0
- package/dist/lock-stores/remote/remote-lock-client.d.ts +17 -0
- package/dist/lock-stores/remote/remote-lock-client.d.ts.map +1 -0
- package/dist/lock-stores/remote/remote-lock-client.js +172 -0
- package/dist/lock-stores/remote/remote-lock-client.js.map +1 -0
- package/dist/lock-stores/socket/electing-connector.d.ts +21 -0
- package/dist/lock-stores/socket/electing-connector.d.ts.map +1 -0
- package/dist/lock-stores/socket/electing-connector.js +45 -0
- package/dist/lock-stores/socket/electing-connector.js.map +1 -0
- package/dist/lock-stores/socket/lock-server.d.ts +23 -0
- package/dist/lock-stores/socket/lock-server.d.ts.map +1 -0
- package/dist/lock-stores/socket/lock-server.js +67 -0
- package/dist/lock-stores/socket/lock-server.js.map +1 -0
- package/dist/lock-stores/socket/socket-connection.d.ts +18 -0
- package/dist/lock-stores/socket/socket-connection.d.ts.map +1 -0
- package/dist/lock-stores/socket/socket-connection.js +54 -0
- package/dist/lock-stores/socket/socket-connection.js.map +1 -0
- package/dist/lock-stores/socket/socket-store.d.ts +35 -0
- package/dist/lock-stores/socket/socket-store.d.ts.map +1 -0
- package/dist/lock-stores/socket/socket-store.js +84 -0
- package/dist/lock-stores/socket/socket-store.js.map +1 -0
- package/dist/lock-stores/sqlite/sqlite-store.d.ts +21 -0
- package/dist/lock-stores/sqlite/sqlite-store.d.ts.map +1 -0
- package/dist/lock-stores/sqlite/sqlite-store.js +105 -0
- package/dist/lock-stores/sqlite/sqlite-store.js.map +1 -0
- package/dist/lock-stores/thread/parent-port-connection.d.ts +20 -0
- package/dist/lock-stores/thread/parent-port-connection.d.ts.map +1 -0
- package/dist/lock-stores/thread/parent-port-connection.js +44 -0
- package/dist/lock-stores/thread/parent-port-connection.js.map +1 -0
- package/dist/lock-stores/thread/thread-lock-coordinator.d.ts +22 -0
- package/dist/lock-stores/thread/thread-lock-coordinator.d.ts.map +1 -0
- package/dist/lock-stores/thread/thread-lock-coordinator.js +25 -0
- package/dist/lock-stores/thread/thread-lock-coordinator.js.map +1 -0
- package/dist/lock-stores/thread/thread-store.d.ts +13 -0
- package/dist/lock-stores/thread/thread-store.d.ts.map +1 -0
- package/dist/lock-stores/thread/thread-store.js +37 -0
- package/dist/lock-stores/thread/thread-store.js.map +1 -0
- package/dist/lock-stores/thread/worker-connection.d.ts +19 -0
- package/dist/lock-stores/thread/worker-connection.d.ts.map +1 -0
- package/dist/lock-stores/thread/worker-connection.js +45 -0
- package/dist/lock-stores/thread/worker-connection.js.map +1 -0
- package/dist/mutex/acquire-mode.d.ts +30 -0
- package/dist/mutex/acquire-mode.d.ts.map +1 -0
- package/dist/mutex/acquire-mode.js +2 -0
- package/dist/mutex/acquire-mode.js.map +1 -0
- package/dist/mutex/acquire-modes/modes.d.ts +9 -0
- package/dist/mutex/acquire-modes/modes.d.ts.map +1 -0
- package/dist/mutex/acquire-modes/modes.js +9 -0
- package/dist/mutex/acquire-modes/modes.js.map +1 -0
- package/dist/mutex/acquire-modes/skip-if-busy-mode.d.ts +15 -0
- package/dist/mutex/acquire-modes/skip-if-busy-mode.d.ts.map +1 -0
- package/dist/mutex/acquire-modes/skip-if-busy-mode.js +27 -0
- package/dist/mutex/acquire-modes/skip-if-busy-mode.js.map +1 -0
- package/dist/mutex/acquire-modes/wait-mode.d.ts +9 -0
- package/dist/mutex/acquire-modes/wait-mode.d.ts.map +1 -0
- package/dist/mutex/acquire-modes/wait-mode.js +8 -0
- package/dist/mutex/acquire-modes/wait-mode.js.map +1 -0
- package/dist/mutex/key.d.ts +22 -0
- package/dist/mutex/key.d.ts.map +1 -0
- package/dist/mutex/key.js +21 -0
- package/dist/mutex/key.js.map +1 -0
- package/dist/mutex/lease.d.ts +9 -0
- package/dist/mutex/lease.d.ts.map +1 -0
- package/dist/mutex/lease.js +12 -0
- package/dist/mutex/lease.js.map +1 -0
- package/dist/mutex/lock-lost-error.d.ts +6 -0
- package/dist/mutex/lock-lost-error.d.ts.map +1 -0
- package/dist/mutex/lock-lost-error.js +10 -0
- package/dist/mutex/lock-lost-error.js.map +1 -0
- package/dist/mutex/lock-store.d.ts +13 -0
- package/dist/mutex/lock-store.d.ts.map +1 -0
- package/dist/mutex/lock-store.js +2 -0
- package/dist/mutex/lock-store.js.map +1 -0
- package/dist/mutex/mutex.d.ts +25 -0
- package/dist/mutex/mutex.d.ts.map +1 -0
- package/dist/mutex/mutex.js +41 -0
- package/dist/mutex/mutex.js.map +1 -0
- package/dist/shared/fs/atomic-write.d.ts +3 -0
- package/dist/shared/fs/atomic-write.d.ts.map +1 -0
- package/dist/shared/fs/atomic-write.js +34 -0
- package/dist/shared/fs/atomic-write.js.map +1 -0
- package/dist/shared/fs/create-exclusive.d.ts +6 -0
- package/dist/shared/fs/create-exclusive.d.ts.map +1 -0
- package/dist/shared/fs/create-exclusive.js +24 -0
- package/dist/shared/fs/create-exclusive.js.map +1 -0
- package/dist/shared/fs/errno.d.ts +2 -0
- package/dist/shared/fs/errno.d.ts.map +1 -0
- package/dist/shared/fs/errno.js +4 -0
- package/dist/shared/fs/errno.js.map +1 -0
- package/dist/shared/fs/safe-file-name.d.ts +8 -0
- package/dist/shared/fs/safe-file-name.d.ts.map +1 -0
- package/dist/shared/fs/safe-file-name.js +10 -0
- package/dist/shared/fs/safe-file-name.js.map +1 -0
- package/dist/shared/is-record.d.ts +3 -0
- package/dist/shared/is-record.d.ts.map +1 -0
- package/dist/shared/is-record.js +3 -0
- package/dist/shared/is-record.js.map +1 -0
- package/dist/shared/sqlite/is-busy.d.ts +3 -0
- package/dist/shared/sqlite/is-busy.d.ts.map +1 -0
- package/dist/shared/sqlite/is-busy.js +10 -0
- package/dist/shared/sqlite/is-busy.js.map +1 -0
- package/dist/shared/until-aborted.d.ts +3 -0
- package/dist/shared/until-aborted.d.ts.map +1 -0
- package/dist/shared/until-aborted.js +19 -0
- package/dist/shared/until-aborted.js.map +1 -0
- package/package.json +50 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ipc-store.js","sourceRoot":"","sources":["../../../src/lock-stores/ipc/ipc-store.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAE3E,oFAAoF;AACpF,MAAM,uBAAuB;IAC3B,UAAU,GAAG,KAAK,CAAC;IAEnB,KAAK,CAAC,OAAO;QACX,IAAI,IAAI,CAAC,UAAU,IAAI,CAAC,OAAO,CAAC,SAAS;YAAE,OAAO,SAAS,CAAC;QAC5D,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,OAAO,IAAI,wBAAwB,EAAE,CAAC;IACxC,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,QAAQ;IACV,OAAO,CAAmB;IAEnC;QACE,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CACb,sGAAsG,CACvG,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,IAAI,gBAAgB,CAAC,IAAI,uBAAuB,EAAE,CAAC,CAAC;IACrE,CAAC;IAED,OAAO,CAAC,GAAW,EAAE,OAAwB;QAC3C,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED,UAAU,CAAC,GAAW;QACpB,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACtC,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Connection, ConnectionHandlers } from '../remote/connection.ts';
|
|
2
|
+
import { type LockRequest, type LockResponse } from '../remote/protocol.ts';
|
|
3
|
+
/**
|
|
4
|
+
* The child's end of the IPC channel to its parent. Node counts `message` and
|
|
5
|
+
* `disconnect` listeners to decide whether the channel keeps the process alive,
|
|
6
|
+
* so this adapter listens only while referenced. That leaves the application's
|
|
7
|
+
* own listeners in charge of the process lifetime. Messages that arrive while
|
|
8
|
+
* not listening are buffered by Node and delivered on the next `ref`.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ProcessChannelConnection implements Connection<LockRequest, LockResponse> {
|
|
11
|
+
#private;
|
|
12
|
+
send(request: LockRequest): Promise<void>;
|
|
13
|
+
listen(handlers: ConnectionHandlers<LockResponse>): void;
|
|
14
|
+
ref(): void;
|
|
15
|
+
unref(): void;
|
|
16
|
+
close(): void;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=process-channel-connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-channel-connection.d.ts","sourceRoot":"","sources":["../../../src/lock-stores/ipc/process-channel-connection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE9E,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,YAAY,EAElB,MAAM,uBAAuB,CAAC;AAE/B;;;;;;GAMG;AACH,qBAAa,wBAAyB,YAAW,UAAU,CACzD,WAAW,EACX,YAAY,CACb;;IAcC,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAYzC,MAAM,CAAC,QAAQ,EAAE,kBAAkB,CAAC,YAAY,CAAC;IAIjD,GAAG;IAOH,KAAK;IAOL,KAAK;CAGN"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { unwrap, wrap } from "../remote/envelope.js";
|
|
2
|
+
import { isLockResponse, } from "../remote/protocol.js";
|
|
3
|
+
/**
|
|
4
|
+
* The child's end of the IPC channel to its parent. Node counts `message` and
|
|
5
|
+
* `disconnect` listeners to decide whether the channel keeps the process alive,
|
|
6
|
+
* so this adapter listens only while referenced. That leaves the application's
|
|
7
|
+
* own listeners in charge of the process lifetime. Messages that arrive while
|
|
8
|
+
* not listening are buffered by Node and delivered on the next `ref`.
|
|
9
|
+
*/
|
|
10
|
+
export class ProcessChannelConnection {
|
|
11
|
+
#handlers;
|
|
12
|
+
#listening = false;
|
|
13
|
+
#onMessage = (envelope) => {
|
|
14
|
+
const response = unwrap(envelope);
|
|
15
|
+
if (isLockResponse(response))
|
|
16
|
+
this.#handlers?.message(response);
|
|
17
|
+
};
|
|
18
|
+
#onDisconnect = () => {
|
|
19
|
+
this.unref();
|
|
20
|
+
this.#handlers?.close();
|
|
21
|
+
};
|
|
22
|
+
send(request) {
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
if (!process.send || !process.connected) {
|
|
25
|
+
reject(new Error('The IPC channel to the parent is closed.'));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
process.send(wrap(request), undefined, {}, (error) => error ? reject(error) : resolve());
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
listen(handlers) {
|
|
32
|
+
this.#handlers = handlers;
|
|
33
|
+
}
|
|
34
|
+
ref() {
|
|
35
|
+
if (this.#listening)
|
|
36
|
+
return;
|
|
37
|
+
this.#listening = true;
|
|
38
|
+
process.on('message', this.#onMessage);
|
|
39
|
+
process.on('disconnect', this.#onDisconnect);
|
|
40
|
+
}
|
|
41
|
+
unref() {
|
|
42
|
+
if (!this.#listening)
|
|
43
|
+
return;
|
|
44
|
+
this.#listening = false;
|
|
45
|
+
process.off('message', this.#onMessage);
|
|
46
|
+
process.off('disconnect', this.#onDisconnect);
|
|
47
|
+
}
|
|
48
|
+
close() {
|
|
49
|
+
this.unref();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=process-channel-connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-channel-connection.js","sourceRoot":"","sources":["../../../src/lock-stores/ipc/process-channel-connection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAGL,cAAc,GACf,MAAM,uBAAuB,CAAC;AAE/B;;;;;;GAMG;AACH,MAAM,OAAO,wBAAwB;IAInC,SAAS,CAA+C;IACxD,UAAU,GAAG,KAAK,CAAC;IAEV,UAAU,GAAG,CAAC,QAA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UAAU,GAAG,KAAK,CAAC;QACxB,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IAChD,CAAC;IAED,KAAK;QACH,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TokenSource } from '../../fencing/token-source.ts';
|
|
2
|
+
import { type Lease } from '../../mutex/lease.ts';
|
|
3
|
+
import type { AcquireOptions, LockStore } from '../../mutex/lock-store.ts';
|
|
4
|
+
export interface MemoryStoreOptions {
|
|
5
|
+
tokens?: TokenSource;
|
|
6
|
+
}
|
|
7
|
+
/** Per-key FIFO promise chain; locks are shared only through this instance. */
|
|
8
|
+
export declare class MemoryStore implements LockStore {
|
|
9
|
+
#private;
|
|
10
|
+
constructor({ tokens }?: MemoryStoreOptions);
|
|
11
|
+
acquire(key: string, { signal }?: AcquireOptions): Promise<Lease>;
|
|
12
|
+
tryAcquire(key: string): Promise<Lease | undefined>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=memory-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-store.d.ts","sourceRoot":"","sources":["../../../src/lock-stores/memory/memory-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,KAAK,KAAK,EAAY,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAG3E,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,+EAA+E;AAC/E,qBAAa,WAAY,YAAW,SAAS;;gBAI/B,EAAE,MAAiC,EAAE,GAAE,kBAAuB;IAIpE,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,GAAE,cAAmB,GAAG,OAAO,CAAC,KAAK,CAAC;IAwBrE,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC;CAI1D"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { CounterTokenSource } from "../../fencing/counter-token-source.js";
|
|
2
|
+
import { leaseFor } from "../../mutex/lease.js";
|
|
3
|
+
import { untilAborted } from "../../shared/until-aborted.js";
|
|
4
|
+
/** Per-key FIFO promise chain; locks are shared only through this instance. */
|
|
5
|
+
export class MemoryStore {
|
|
6
|
+
#tails = new Map();
|
|
7
|
+
#tokens;
|
|
8
|
+
constructor({ tokens = new CounterTokenSource() } = {}) {
|
|
9
|
+
this.#tokens = tokens;
|
|
10
|
+
}
|
|
11
|
+
async acquire(key, { signal } = {}) {
|
|
12
|
+
signal?.throwIfAborted();
|
|
13
|
+
const previous = this.#tails.get(key);
|
|
14
|
+
const released = Promise.withResolvers();
|
|
15
|
+
const tail = previous
|
|
16
|
+
? previous.then(() => released.promise)
|
|
17
|
+
: released.promise;
|
|
18
|
+
this.#tails.set(key, tail);
|
|
19
|
+
const release = async () => {
|
|
20
|
+
released.resolve();
|
|
21
|
+
if (this.#tails.get(key) === tail)
|
|
22
|
+
this.#tails.delete(key);
|
|
23
|
+
};
|
|
24
|
+
const turn = Promise.resolve(previous);
|
|
25
|
+
try {
|
|
26
|
+
await untilAborted(turn, signal);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
// A waiter cannot leave the middle of the chain, so its place passes the key on when its turn comes.
|
|
30
|
+
void turn.then(release);
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
return leaseFor(key, { [Symbol.asyncDispose]: release }, this.#tokens);
|
|
34
|
+
}
|
|
35
|
+
async tryAcquire(key) {
|
|
36
|
+
if (this.#tails.has(key))
|
|
37
|
+
return undefined;
|
|
38
|
+
return this.acquire(key);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=memory-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-store.js","sourceRoot":"","sources":["../../../src/lock-stores/memory/memory-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAE3E,OAAO,EAAc,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAM7D,+EAA+E;AAC/E,MAAM,OAAO,WAAW;IACb,MAAM,GAAG,IAAI,GAAG,EAAyB,CAAC;IAC1C,OAAO,CAAc;IAE9B,YAAY,EAAE,MAAM,GAAG,IAAI,kBAAkB,EAAE,KAAyB,EAAE;QACxE,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,GAAW,EAAE,EAAE,MAAM,KAAqB,EAAE;QACxD,MAAM,EAAE,cAAc,EAAE,CAAC;QACzB,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACtC,MAAM,QAAQ,GAAG,OAAO,CAAC,aAAa,EAAQ,CAAC;QAC/C,MAAM,IAAI,GAAG,QAAQ;YACnB,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC;YACvC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC;QACrB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAC3B,MAAM,OAAO,GAAG,KAAK,IAAI,EAAE;YACzB,QAAQ,CAAC,OAAO,EAAE,CAAC;YACnB,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,IAAI;gBAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC7D,CAAC,CAAC;QAEF,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACvC,IAAI,CAAC;YACH,MAAM,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACnC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,qGAAqG;YACrG,KAAK,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACxB,MAAM,KAAK,CAAC;QACd,CAAC;QACD,OAAO,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACzE,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,GAAW;QAC1B,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,OAAO,SAAS,CAAC;QAC3C,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface ConnectionHandlers<Incoming> {
|
|
2
|
+
message(message: Incoming): void;
|
|
3
|
+
/** Called once, when the peer is gone. */
|
|
4
|
+
close(): void;
|
|
5
|
+
}
|
|
6
|
+
/** A message channel to one peer. Adapters wrap IPC channels and sockets. */
|
|
7
|
+
export interface Connection<Outgoing, Incoming> {
|
|
8
|
+
/** Rejects when the message cannot be delivered because the peer is gone. */
|
|
9
|
+
send(message: Outgoing): Promise<void>;
|
|
10
|
+
listen(handlers: ConnectionHandlers<Incoming>): void;
|
|
11
|
+
/** Keeps the process alive while its owner waits for a message. */
|
|
12
|
+
ref(): void;
|
|
13
|
+
/** Lets the process exit; messages and closure are still reported while it runs. */
|
|
14
|
+
unref(): void;
|
|
15
|
+
close(): void;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../../src/lock-stores/remote/connection.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB,CAAC,QAAQ;IAC1C,OAAO,CAAC,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IACjC,0CAA0C;IAC1C,KAAK,IAAI,IAAI,CAAC;CACf;AAED,6EAA6E;AAC7E,MAAM,WAAW,UAAU,CAAC,QAAQ,EAAE,QAAQ;IAC5C,6EAA6E;IAC7E,IAAI,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,MAAM,CAAC,QAAQ,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC;IACrD,mEAAmE;IACnE,GAAG,IAAI,IAAI,CAAC;IACZ,oFAAoF;IACpF,KAAK,IAAI,IAAI,CAAC;IACd,KAAK,IAAI,IAAI,CAAC;CACf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../../src/lock-stores/remote/connection.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Connection } from './connection.ts';
|
|
2
|
+
import type { LockRequest, LockResponse } from './protocol.ts';
|
|
3
|
+
export type ClientConnection = Connection<LockRequest, LockResponse>;
|
|
4
|
+
/** Decides how a client reaches its coordinator, and whether it can again after losing it. */
|
|
5
|
+
export interface Connector {
|
|
6
|
+
/**
|
|
7
|
+
* Resolves to `undefined` when the coordinator is gone for good and nothing
|
|
8
|
+
* can replace it, so no other holder can ever be granted a key either.
|
|
9
|
+
*/
|
|
10
|
+
connect(): Promise<ClientConnection | undefined>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=connector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../../../src/lock-stores/remote/connector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE/D,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;AAErE,8FAA8F;AAC9F,MAAM,WAAW,SAAS;IACxB;;;OAGG;IACH,OAAO,IAAI,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAAC;CAClD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connector.js","sourceRoot":"","sources":["../../../src/lock-stores/remote/connector.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coordinator-unavailable-error.d.ts","sourceRoot":"","sources":["../../../src/lock-stores/remote/coordinator-unavailable-error.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,qBAAa,2BAA4B,SAAQ,KAAK;IACpD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;gBAET,GAAG,EAAE,MAAM;CAKxB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** No coordinator is left that could ever grant this key. */
|
|
2
|
+
export class CoordinatorUnavailableError extends Error {
|
|
3
|
+
key;
|
|
4
|
+
constructor(key) {
|
|
5
|
+
super(`No lock coordinator is reachable to grant ${JSON.stringify(key)}.`);
|
|
6
|
+
this.name = 'CoordinatorUnavailableError';
|
|
7
|
+
this.key = key;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=coordinator-unavailable-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coordinator-unavailable-error.js","sourceRoot":"","sources":["../../../src/lock-stores/remote/coordinator-unavailable-error.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IAC3C,GAAG,CAAS;IAErB,YAAY,GAAW;QACrB,KAAK,CAAC,6CAA6C,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC3E,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;QAC1C,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;CACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
declare const TAG = "@lock";
|
|
2
|
+
/** Lock messages travel inside a tagged envelope so they share the IPC channel with the application's own messages. */
|
|
3
|
+
export declare function wrap<T>(message: T): Record<typeof TAG, T>;
|
|
4
|
+
/** The message inside a lock envelope, unchecked; `undefined` for the application's own messages. */
|
|
5
|
+
export declare function unwrap(envelope: unknown): unknown;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=envelope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../../src/lock-stores/remote/envelope.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,GAAG,UAAU,CAAC;AAEpB,uHAAuH;AACvH,wBAAgB,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,MAAM,CAAC,OAAO,GAAG,EAAE,CAAC,CAAC,CAEzD;AAED,qGAAqG;AACrG,wBAAgB,MAAM,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAEjD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isRecord } from "../../shared/is-record.js";
|
|
2
|
+
const TAG = '@lock';
|
|
3
|
+
/** Lock messages travel inside a tagged envelope so they share the IPC channel with the application's own messages. */
|
|
4
|
+
export function wrap(message) {
|
|
5
|
+
return { [TAG]: message };
|
|
6
|
+
}
|
|
7
|
+
/** The message inside a lock envelope, unchecked; `undefined` for the application's own messages. */
|
|
8
|
+
export function unwrap(envelope) {
|
|
9
|
+
return isRecord(envelope) && TAG in envelope ? envelope[TAG] : undefined;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=envelope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.js","sourceRoot":"","sources":["../../../src/lock-stores/remote/envelope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAErD,MAAM,GAAG,GAAG,OAAO,CAAC;AAEpB,uHAAuH;AACvH,MAAM,UAAU,IAAI,CAAI,OAAU;IAChC,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,CAAC;AAC5B,CAAC;AAED,qGAAqG;AACrG,MAAM,UAAU,MAAM,CAAC,QAAiB;IACtC,OAAO,QAAQ,CAAC,QAAQ,CAAC,IAAI,GAAG,IAAI,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3E,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { FencingToken } from '../../fencing/fencing-token.ts';
|
|
2
|
+
import type { TokenSource } from '../../fencing/token-source.ts';
|
|
3
|
+
import type { Lease } from '../../mutex/lease.ts';
|
|
4
|
+
import type { AcquireOptions, LockStore } from '../../mutex/lock-store.ts';
|
|
5
|
+
import type { Connection } from './connection.ts';
|
|
6
|
+
import type { LockRequest, LockResponse } from './protocol.ts';
|
|
7
|
+
export interface LockCoordinatorOptions {
|
|
8
|
+
tokens: TokenSource;
|
|
9
|
+
/**
|
|
10
|
+
* Milliseconds after start during which nothing is granted, so holders from a
|
|
11
|
+
* previous coordinator can reassert their keys first. Zero for a coordinator
|
|
12
|
+
* that never replaces another.
|
|
13
|
+
*/
|
|
14
|
+
graceWindow?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Grants keys in FIFO order to its own callers and to peers it serves over
|
|
18
|
+
* connections. A peer that disconnects releases everything it held or waited for.
|
|
19
|
+
*/
|
|
20
|
+
export declare class LockCoordinator implements LockStore {
|
|
21
|
+
#private;
|
|
22
|
+
constructor({ tokens, graceWindow }: LockCoordinatorOptions);
|
|
23
|
+
acquire(key: string, { signal }?: AcquireOptions): Promise<Lease>;
|
|
24
|
+
/** Nothing is granted during the grace window, so a key counts as busy then. */
|
|
25
|
+
tryAcquire(key: string): Promise<Lease | undefined>;
|
|
26
|
+
serve(connection: Connection<LockResponse, LockRequest>): void;
|
|
27
|
+
/**
|
|
28
|
+
* Re-registers a holder from before a failover. Accepted only during the
|
|
29
|
+
* grace window; for two claims on one key the newer token wins and the older
|
|
30
|
+
* claim's `lose` is called. Resolves `undefined` when the claim is refused.
|
|
31
|
+
*/
|
|
32
|
+
reassert(key: string, token: FencingToken, lose: () => void): Promise<Lease> | undefined;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=lock-coordinator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock-coordinator.d.ts","sourceRoot":"","sources":["../../../src/lock-stores/remote/lock-coordinator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAG3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE/D,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,WAAW,CAAC;IACpB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAQD;;;GAGG;AACH,qBAAa,eAAgB,YAAW,SAAS;;gBAMnC,EAAE,MAAM,EAAE,WAAe,EAAE,EAAE,sBAAsB;IAWzD,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,GAAE,cAAmB,GAAG,OAAO,CAAC,KAAK,CAAC;IAK3E,gFAAgF;IAC1E,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC;IAKzD,KAAK,CAAC,UAAU,EAAE,UAAU,CAAC,YAAY,EAAE,WAAW,CAAC,GAAG,IAAI;IAI9D;;;;OAIG;IACH,QAAQ,CACN,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,YAAY,EACnB,IAAI,EAAE,MAAM,IAAI,GACf,OAAO,CAAC,KAAK,CAAC,GAAG,SAAS;CAY9B"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
2
|
+
import { FencingToken } from "../../fencing/fencing-token.js";
|
|
3
|
+
import { untilAborted } from "../../shared/until-aborted.js";
|
|
4
|
+
import { MemoryStore } from "../memory/memory-store.js";
|
|
5
|
+
/**
|
|
6
|
+
* Grants keys in FIFO order to its own callers and to peers it serves over
|
|
7
|
+
* connections. A peer that disconnects releases everything it held or waited for.
|
|
8
|
+
*/
|
|
9
|
+
export class LockCoordinator {
|
|
10
|
+
#store;
|
|
11
|
+
#graceOver;
|
|
12
|
+
#reassertions = new Map();
|
|
13
|
+
#inGrace;
|
|
14
|
+
constructor({ tokens, graceWindow = 0 }) {
|
|
15
|
+
this.#store = new MemoryStore({ tokens });
|
|
16
|
+
this.#inGrace = graceWindow > 0;
|
|
17
|
+
this.#graceOver = this.#inGrace
|
|
18
|
+
? delay(graceWindow, undefined, { ref: false }).then(() => {
|
|
19
|
+
this.#inGrace = false;
|
|
20
|
+
this.#reassertions.clear();
|
|
21
|
+
})
|
|
22
|
+
: Promise.resolve();
|
|
23
|
+
}
|
|
24
|
+
async acquire(key, { signal } = {}) {
|
|
25
|
+
await untilAborted(this.#graceOver, signal);
|
|
26
|
+
return this.#store.acquire(key, { signal });
|
|
27
|
+
}
|
|
28
|
+
/** Nothing is granted during the grace window, so a key counts as busy then. */
|
|
29
|
+
async tryAcquire(key) {
|
|
30
|
+
if (this.#inGrace)
|
|
31
|
+
return undefined;
|
|
32
|
+
return this.#store.tryAcquire(key);
|
|
33
|
+
}
|
|
34
|
+
serve(connection) {
|
|
35
|
+
new Session(this, connection);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Re-registers a holder from before a failover. Accepted only during the
|
|
39
|
+
* grace window; for two claims on one key the newer token wins and the older
|
|
40
|
+
* claim's `lose` is called. Resolves `undefined` when the claim is refused.
|
|
41
|
+
*/
|
|
42
|
+
reassert(key, token, lose) {
|
|
43
|
+
if (!this.#inGrace)
|
|
44
|
+
return undefined;
|
|
45
|
+
const existing = this.#reassertions.get(key);
|
|
46
|
+
if (existing && !token.isNewerThan(existing.token))
|
|
47
|
+
return undefined;
|
|
48
|
+
existing?.lose();
|
|
49
|
+
// Nothing is granted during grace, so the first claim gets the key at once
|
|
50
|
+
// and a newer claim takes over that same lease.
|
|
51
|
+
const lease = existing?.lease ?? this.#store.acquire(key);
|
|
52
|
+
this.#reassertions.set(key, { token, lease, lose });
|
|
53
|
+
return lease;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
class Session {
|
|
57
|
+
#coordinator;
|
|
58
|
+
#connection;
|
|
59
|
+
#leases = new Map();
|
|
60
|
+
#requested = new Set();
|
|
61
|
+
#lost = new Set();
|
|
62
|
+
#closed = false;
|
|
63
|
+
constructor(coordinator, connection) {
|
|
64
|
+
this.#coordinator = coordinator;
|
|
65
|
+
this.#connection = connection;
|
|
66
|
+
connection.listen({
|
|
67
|
+
message: (request) => {
|
|
68
|
+
this.#handle(request).catch(() => connection.close());
|
|
69
|
+
},
|
|
70
|
+
close: () => {
|
|
71
|
+
void this.#close();
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
async #handle(request) {
|
|
76
|
+
switch (request.op) {
|
|
77
|
+
case 'acquire': {
|
|
78
|
+
// A reconnecting client may resend a request; granting it twice would orphan one lease.
|
|
79
|
+
if (this.#requested.has(request.id))
|
|
80
|
+
return;
|
|
81
|
+
this.#requested.add(request.id);
|
|
82
|
+
const lease = await this.#coordinator.acquire(request.key);
|
|
83
|
+
return this.#grant(request.id, lease);
|
|
84
|
+
}
|
|
85
|
+
case 'try': {
|
|
86
|
+
if (this.#requested.has(request.id))
|
|
87
|
+
return;
|
|
88
|
+
this.#requested.add(request.id);
|
|
89
|
+
const lease = await this.#coordinator.tryAcquire(request.key);
|
|
90
|
+
if (!lease) {
|
|
91
|
+
this.#requested.delete(request.id);
|
|
92
|
+
return this.#reply({ op: 'busy', id: request.id });
|
|
93
|
+
}
|
|
94
|
+
return this.#grant(request.id, lease);
|
|
95
|
+
}
|
|
96
|
+
case 'cancel': {
|
|
97
|
+
// A request still in line is released by #grant when its turn comes.
|
|
98
|
+
this.#requested.delete(request.id);
|
|
99
|
+
return this.#releaseLease(request.id);
|
|
100
|
+
}
|
|
101
|
+
case 'release': {
|
|
102
|
+
this.#requested.delete(request.id);
|
|
103
|
+
return this.#releaseLease(request.id);
|
|
104
|
+
}
|
|
105
|
+
case 'reassert': {
|
|
106
|
+
const claim = this.#coordinator.reassert(request.key, new FencingToken(BigInt(request.token)), () => this.#lose(request.id));
|
|
107
|
+
if (!claim)
|
|
108
|
+
return this.#reply({ op: 'rejected', id: request.id });
|
|
109
|
+
const lease = await claim;
|
|
110
|
+
if (this.#lost.has(request.id))
|
|
111
|
+
return;
|
|
112
|
+
if (this.#closed)
|
|
113
|
+
return lease[Symbol.asyncDispose]();
|
|
114
|
+
this.#leases.set(request.id, lease);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/** A request cancelled or a peer gone while the grant was on its way releases the key at once. */
|
|
120
|
+
#grant(id, lease) {
|
|
121
|
+
if (this.#closed || !this.#requested.has(id)) {
|
|
122
|
+
return lease[Symbol.asyncDispose]();
|
|
123
|
+
}
|
|
124
|
+
this.#leases.set(id, lease);
|
|
125
|
+
return this.#reply({ op: 'granted', id, token: lease.token.toString() });
|
|
126
|
+
}
|
|
127
|
+
#releaseLease(id) {
|
|
128
|
+
const lease = this.#leases.get(id);
|
|
129
|
+
this.#leases.delete(id);
|
|
130
|
+
return lease?.[Symbol.asyncDispose]();
|
|
131
|
+
}
|
|
132
|
+
/** A newer claim took this session's reasserted lease over, so it must not release it. */
|
|
133
|
+
#lose(id) {
|
|
134
|
+
this.#lost.add(id);
|
|
135
|
+
this.#leases.delete(id);
|
|
136
|
+
void this.#reply({ op: 'rejected', id });
|
|
137
|
+
}
|
|
138
|
+
async #reply(response) {
|
|
139
|
+
// A failed send means the peer is gone; `close` then releases its leases.
|
|
140
|
+
await this.#connection.send(response).catch(() => { });
|
|
141
|
+
}
|
|
142
|
+
async #close() {
|
|
143
|
+
this.#closed = true;
|
|
144
|
+
const leases = [...this.#leases.values()];
|
|
145
|
+
this.#leases.clear();
|
|
146
|
+
for (const lease of leases)
|
|
147
|
+
await lease[Symbol.asyncDispose]();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=lock-coordinator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock-coordinator.js","sourceRoot":"","sources":["../../../src/lock-stores/remote/lock-coordinator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAI9D,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAoBxD;;;GAGG;AACH,MAAM,OAAO,eAAe;IACjB,MAAM,CAAc;IACpB,UAAU,CAAgB;IAC1B,aAAa,GAAG,IAAI,GAAG,EAAuB,CAAC;IACxD,QAAQ,CAAU;IAElB,YAAY,EAAE,MAAM,EAAE,WAAW,GAAG,CAA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
op: 'try';
|
|
8
|
+
id: string;
|
|
9
|
+
key: string;
|
|
10
|
+
} | {
|
|
11
|
+
op: 'cancel';
|
|
12
|
+
id: string;
|
|
13
|
+
} | {
|
|
14
|
+
op: 'release';
|
|
15
|
+
id: string;
|
|
16
|
+
} | {
|
|
17
|
+
op: 'reassert';
|
|
18
|
+
id: string;
|
|
19
|
+
key: string;
|
|
20
|
+
token: string;
|
|
21
|
+
};
|
|
22
|
+
export type LockResponse = {
|
|
23
|
+
op: 'granted';
|
|
24
|
+
id: string;
|
|
25
|
+
token: string;
|
|
26
|
+
} | {
|
|
27
|
+
op: 'busy';
|
|
28
|
+
id: string;
|
|
29
|
+
} | {
|
|
30
|
+
op: 'rejected';
|
|
31
|
+
id: string;
|
|
32
|
+
};
|
|
33
|
+
/** Messages arrive from another thread or process, so their shape is checked before use. */
|
|
34
|
+
export declare function isLockRequest(message: unknown): message is LockRequest;
|
|
35
|
+
export declare function isLockResponse(message: unknown): message is LockResponse;
|
|
36
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../../src/lock-stores/remote/protocol.ts"],"names":[],"mappings":"AAEA,mEAAmE;AACnE,MAAM,MAAM,WAAW,GACnB;IAAE,EAAE,EAAE,SAAS,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAC1C;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GACtC;IAAE,EAAE,EAAE,QAAQ,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAC5B;IAAE,EAAE,EAAE,SAAS,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAC7B;IAAE,EAAE,EAAE,UAAU,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/D,MAAM,MAAM,YAAY,GACpB;IAAE,EAAE,EAAE,SAAS,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC5C;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAC1B;IAAE,EAAE,EAAE,UAAU,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAKnC,4FAA4F;AAC5F,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,WAAW,CActE;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,YAAY,CAWxE"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isRecord } from "../../shared/is-record.js";
|
|
2
|
+
const isToken = (value) => typeof value === 'string' && /^-?\d+$/.test(value);
|
|
3
|
+
/** Messages arrive from another thread or process, so their shape is checked before use. */
|
|
4
|
+
export function isLockRequest(message) {
|
|
5
|
+
if (!isRecord(message) || typeof message.id !== 'string')
|
|
6
|
+
return false;
|
|
7
|
+
switch (message.op) {
|
|
8
|
+
case 'acquire':
|
|
9
|
+
case 'try':
|
|
10
|
+
return typeof message.key === 'string';
|
|
11
|
+
case 'cancel':
|
|
12
|
+
case 'release':
|
|
13
|
+
return true;
|
|
14
|
+
case 'reassert':
|
|
15
|
+
return typeof message.key === 'string' && isToken(message.token);
|
|
16
|
+
default:
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function isLockResponse(message) {
|
|
21
|
+
if (!isRecord(message) || typeof message.id !== 'string')
|
|
22
|
+
return false;
|
|
23
|
+
switch (message.op) {
|
|
24
|
+
case 'granted':
|
|
25
|
+
return isToken(message.token);
|
|
26
|
+
case 'busy':
|
|
27
|
+
case 'rejected':
|
|
28
|
+
return true;
|
|
29
|
+
default:
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/lock-stores/remote/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAerD,MAAM,OAAO,GAAG,CAAC,KAAc,EAAW,EAAE,CAC1C,OAAO,KAAK,KAAK,QAAQ,IAAI,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAErD,4FAA4F;AAC5F,MAAM,UAAU,aAAa,CAAC,OAAgB;IAC5C,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,OAAO,CAAC,EAAE,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACvE,QAAQ,OAAO,CAAC,EAAE,EAAE,CAAC;QACnB,KAAK,SAAS,CAAC;QACf,KAAK,KAAK;YACR,OAAO,OAAO,OAAO,CAAC,GAAG,KAAK,QAAQ,CAAC;QACzC,KAAK,QAAQ,CAAC;QACd,KAAK,SAAS;YACZ,OAAO,IAAI,CAAC;QACd,KAAK,UAAU;YACb,OAAO,OAAO,OAAO,CAAC,GAAG,KAAK,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACnE;YACE,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAgB;IAC7C,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,OAAO,CAAC,EAAE,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACvE,QAAQ,OAAO,CAAC,EAAE,EAAE,CAAC;QACnB,KAAK,SAAS;YACZ,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAChC,KAAK,MAAM,CAAC;QACZ,KAAK,UAAU;YACb,OAAO,IAAI,CAAC;QACd;YACE,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Lease } from '../../mutex/lease.ts';
|
|
2
|
+
import type { AcquireOptions, LockStore } from '../../mutex/lock-store.ts';
|
|
3
|
+
import type { Connector } from './connector.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Asks a coordinator for keys over a connection. When the connection drops, it
|
|
6
|
+
* asks its connector for another, reasserts the keys it holds and re-requests
|
|
7
|
+
* the ones it waits for. A held key whose reassertion is refused is lost.
|
|
8
|
+
*/
|
|
9
|
+
export declare class RemoteLockClient implements LockStore {
|
|
10
|
+
#private;
|
|
11
|
+
constructor(connector: Connector);
|
|
12
|
+
acquire(key: string, { signal }?: AcquireOptions): Promise<Lease>;
|
|
13
|
+
tryAcquire(key: string): Promise<Lease | undefined>;
|
|
14
|
+
/** Disconnects for good; the coordinator releases whatever this client still holds. */
|
|
15
|
+
close(): void;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=remote-lock-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote-lock-client.d.ts","sourceRoot":"","sources":["../../../src/lock-stores/remote/remote-lock-client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAElD,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAE3E,OAAO,KAAK,EAAoB,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAgBlE;;;;GAIG;AACH,qBAAa,gBAAiB,YAAW,SAAS;;gBASpC,SAAS,EAAE,SAAS;IAI1B,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,GAAE,cAAmB,GAAG,OAAO,CAAC,KAAK,CAAC;IA0BrE,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC;IAqFzD,uFAAuF;IACvF,KAAK;CA0CN"}
|