@zukhruf/election 0.8.91 → 0.8.92
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/README.md +15 -7
- package/dist/leader-election.d.ts +6 -1
- package/dist/leader-election.d.ts.map +1 -1
- package/dist/leader-election.js +8 -2
- package/dist/leader-election.js.map +1 -1
- package/dist/sqlite/sqlite-election.d.ts +2 -1
- package/dist/sqlite/sqlite-election.d.ts.map +1 -1
- package/dist/sqlite/sqlite-election.js +5 -3
- package/dist/sqlite/sqlite-election.js.map +1 -1
- package/dist/term.d.ts +3 -1
- package/dist/term.d.ts.map +1 -1
- package/dist/term.js +5 -2
- package/dist/term.js.map +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -51,6 +51,7 @@ next term: 2n
|
|
|
51
51
|
|
|
52
52
|
- `campaign({ timeout, signal })` resolves with a `Term`, or with `undefined` when another candidate still leads after `timeout` milliseconds. Without a `timeout`, it tries once. With `timeout: Infinity`, it waits until it wins or `signal` aborts. When `signal` aborts, it rejects with `signal.reason`, and a claim that it won meanwhile is given up.
|
|
53
53
|
- `claimFile` and `epochFile` are files in `directory`. Candidates with the same directory and the same file names are one group. Never delete `claimFile` while candidates run: a new file lets a second leader win.
|
|
54
|
+
- `election.name` is the path of `claimFile`: `join(directory, claimFile)`. Two elections with the same name are one election. A warning names the election by its name ([ADR 0010](./docs/adr/0010-an-election-has-a-name-and-the-name-of-a-sqlite-election-is-the-path-of-its-claim-file.md)).
|
|
54
55
|
- `epochFile` holds the epoch of the last term as decimal digits. When it holds other text, `campaign` rejects with a `SyntaxError` that names the file, gives the claim up, and does not change the file. An example is the empty file that `@zukhruf/mutex` 0.2.0 or earlier can leave after a power loss, because those versions did not sync the file to the disk. Thus the epochs never start again at 1, and each new term has a higher epoch than each earlier term.
|
|
55
56
|
- `lastEpoch()` resolves with the epoch of the last term in `epochFile`, or with `0n` when no term was won yet. It only reads the file. It does not campaign, it does not take the claim, and it does not create a file or the directory. Use it to find out if a value from an earlier term is stale, for example a fencing token that an old leader made with `EpochTokenSource`. A new term can start immediately after the read, so the answer can be old when you get it. When `epochFile` holds text that is not decimal digits, `lastEpoch()` rejects with the same `SyntaxError` as `campaign`. When it cannot read the file for another reason, it rejects with that error. It never answers `0n` for a file that it cannot read.
|
|
56
57
|
- A term that resigns clean writes a third file, `<claimFile>.clean`, beside `claimFile`. It holds the epoch of that term. The next term reads it and removes it.
|
|
@@ -114,7 +115,7 @@ const token = await tokens.next('orders');
|
|
|
114
115
|
|
|
115
116
|
## Write a backend
|
|
116
117
|
|
|
117
|
-
`LeaderElection` is an abstract class. It runs the campaign, and it owns the term. Its constructor takes
|
|
118
|
+
`LeaderElection` is an abstract class. It runs the campaign, and it owns the term. Its constructor takes the name of the election and the clock. The name is the identity of the election in its backend: two elections with the same name are one election. Derive it from the claim, so that it cannot disagree with the claim ([ADR 0010](./docs/adr/0010-an-election-has-a-name-and-the-name-of-a-sqlite-election-is-the-path-of-its-claim-file.md)). A backend is a subclass that implements seven steps for its claim ([ADR 0008](./docs/adr/0008-the-backend-owns-the-wait-between-two-tries-and-poll-leaves-the-campaign.md)):
|
|
118
119
|
|
|
119
120
|
| Step | What it does |
|
|
120
121
|
| ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -149,7 +150,7 @@ class MapElection extends LeaderElection<string> {
|
|
|
149
150
|
readonly #name: string;
|
|
150
151
|
|
|
151
152
|
constructor(name: string) {
|
|
152
|
-
super(globalThis);
|
|
153
|
+
super(name, globalThis);
|
|
153
154
|
this.#name = name;
|
|
154
155
|
}
|
|
155
156
|
|
|
@@ -219,9 +220,9 @@ The socket lock store of `@zukhruf/mutex` uses `SqliteElection`, with the claim
|
|
|
219
220
|
|
|
220
221
|
A failure that no caller waits for is a process warning, in the shape of [root ADR 0010](../../docs/adr/0010-a-package-warning-names-its-type-code-and-subject-and-keeps-the-failure-as-its-cause.md). A `'warning'` listener reads its type as `name`, its `code`, and its subject in `detail`, one `<term>: <value>` line each. Its `cause` is the failure, and its message ends with the failure's message. `--disable-warning=<code or type>` stops the print.
|
|
221
222
|
|
|
222
|
-
| Warning | Code | Detail
|
|
223
|
-
| ------------- | ----------------------------------- |
|
|
224
|
-
| `TermWarning` | `ZUKHRUF_ELECTION_TERM_FREE_FAILED` | `epoch: <epoch>` | A lost term fails to stop watching its claim or to free it. The term still ends. When both fail, the `cause` is a `SuppressedError`: its `suppressed` is the failure to stop watching, and its `error` is the failure to free. |
|
|
223
|
+
| Warning | Code | Detail | When |
|
|
224
|
+
| ------------- | ----------------------------------- | --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
225
|
+
| `TermWarning` | `ZUKHRUF_ELECTION_TERM_FREE_FAILED` | `election: <name>` and `epoch: <epoch>` | A lost term fails to stop watching its claim or to free it. The term still ends. When both fail, the `cause` is a `SuppressedError`: its `suppressed` is the failure to stop watching, and its `error` is the failure to free. |
|
|
225
226
|
|
|
226
227
|
## API
|
|
227
228
|
|
|
@@ -232,8 +233,9 @@ interface CampaignOptions {
|
|
|
232
233
|
}
|
|
233
234
|
|
|
234
235
|
abstract class LeaderElection<Claim> {
|
|
236
|
+
readonly name: string; // the identity of the election in its backend
|
|
235
237
|
protected readonly clock: Clock;
|
|
236
|
-
protected constructor(clock: Clock);
|
|
238
|
+
protected constructor(name: string, clock: Clock);
|
|
237
239
|
campaign(options?: CampaignOptions): Promise<Term | undefined>;
|
|
238
240
|
protected abstract open(signal: AbortSignal | undefined): Promise<Claim>;
|
|
239
241
|
protected abstract tryClaim(
|
|
@@ -270,7 +272,11 @@ interface TermSteps {
|
|
|
270
272
|
|
|
271
273
|
class Term implements Lease, AsyncDisposable {
|
|
272
274
|
constructor(
|
|
273
|
-
{
|
|
275
|
+
{
|
|
276
|
+
epoch,
|
|
277
|
+
afterCleanShutdown,
|
|
278
|
+
election, // the name of the election, for the detail of a warning
|
|
279
|
+
}: Pick<Term, 'epoch' | 'afterCleanShutdown'> & { election: string },
|
|
274
280
|
steps: TermSteps,
|
|
275
281
|
);
|
|
276
282
|
readonly epoch: bigint;
|
|
@@ -291,6 +297,7 @@ interface SqliteElectionOptions {
|
|
|
291
297
|
|
|
292
298
|
class SqliteElection extends LeaderElection<SqliteAttempt> {
|
|
293
299
|
constructor(options: SqliteElectionOptions); // RangeError: unless 0 < heartbeatInterval < leaseDuration
|
|
300
|
+
readonly name: string; // join(directory, claimFile)
|
|
294
301
|
lastEpoch(): Promise<bigint>;
|
|
295
302
|
observe(): LeaderObserver;
|
|
296
303
|
}
|
|
@@ -320,6 +327,7 @@ export { LeaseLostError } from '@zukhruf/lease';
|
|
|
320
327
|
- [ADR 0007: A candidate waits on pushes from the leader's pipe, not on a period](./docs/adr/0007-a-candidate-waits-on-pushes-from-the-leaders-pipe-not-on-a-period.md) (proposed)
|
|
321
328
|
- [ADR 0008: The backend owns the wait between two tries, and poll leaves the campaign](./docs/adr/0008-the-backend-owns-the-wait-between-two-tries-and-poll-leaves-the-campaign.md) (proposed)
|
|
322
329
|
- [ADR 0009: A process that does not campaign observes the leader](./docs/adr/0009-a-process-that-does-not-campaign-observes-the-leader.md) (proposed)
|
|
330
|
+
- [ADR 0010: An election has a name, and the name of a SQLite election is the path of its claim file](./docs/adr/0010-an-election-has-a-name-and-the-name-of-a-sqlite-election-is-the-path-of-its-claim-file.md)
|
|
323
331
|
- [Code copied into this package](./docs/copied-code.md)
|
|
324
332
|
|
|
325
333
|
## Development
|
|
@@ -33,9 +33,14 @@ export interface CampaignOptions {
|
|
|
33
33
|
*/
|
|
34
34
|
export declare abstract class LeaderElection<Claim> {
|
|
35
35
|
#private;
|
|
36
|
+
/**
|
|
37
|
+
* The identity of the election in its backend: two elections with the
|
|
38
|
+
* same name are the same election. Each backend derives it from its claim.
|
|
39
|
+
*/
|
|
40
|
+
readonly name: string;
|
|
36
41
|
/** The clock of the campaign: `globalThis` in production, a fake clock in a test. */
|
|
37
42
|
protected readonly clock: Clock;
|
|
38
|
-
protected constructor(clock: Clock);
|
|
43
|
+
protected constructor(name: string, clock: Clock);
|
|
39
44
|
/**
|
|
40
45
|
* Resolves with the new term, or `undefined` when another candidate still
|
|
41
46
|
* leads after `timeout`. When a step fails and giving the claim up or
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"leader-election.d.ts","sourceRoot":"","sources":["../src/leader-election.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAA4B,MAAM,gBAAgB,CAAC;AAEtE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,4GAA4G;IAC5G,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,8BAAsB,cAAc,CAAC,KAAK;;IACxC,qFAAqF;IACrF,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IAEhC,SAAS,aAAa,KAAK,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"leader-election.d.ts","sourceRoot":"","sources":["../src/leader-election.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAA4B,MAAM,gBAAgB,CAAC;AAEtE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,4GAA4G;IAC5G,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,8BAAsB,cAAc,CAAC,KAAK;;IACxC;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,qFAAqF;IACrF,SAAS,CAAC,QAAQ,CAAC,KAAK,EA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 -22,9 +22,15 @@ import { Term } from './term.js';
|
|
|
22
22
|
* attempt itself.
|
|
23
23
|
*/
|
|
24
24
|
export class LeaderElection {
|
|
25
|
+
/**
|
|
26
|
+
* The identity of the election in its backend: two elections with the
|
|
27
|
+
* same name are the same election. Each backend derives it from its claim.
|
|
28
|
+
*/
|
|
29
|
+
name;
|
|
25
30
|
/** The clock of the campaign: `globalThis` in production, a fake clock in a test. */
|
|
26
31
|
clock;
|
|
27
|
-
constructor(clock) {
|
|
32
|
+
constructor(name, clock) {
|
|
33
|
+
this.name = name;
|
|
28
34
|
this.clock = clock;
|
|
29
35
|
}
|
|
30
36
|
/**
|
|
@@ -94,7 +100,7 @@ export class LeaderElection {
|
|
|
94
100
|
let term;
|
|
95
101
|
try {
|
|
96
102
|
signal?.throwIfAborted();
|
|
97
|
-
term = new Term(won, {
|
|
103
|
+
term = new Term({ ...won, election: this.name }, {
|
|
98
104
|
watch: (lose) => this.watch(claim, lose),
|
|
99
105
|
recordCleanShutdown: () => this.recordCleanShutdown(claim, won.epoch),
|
|
100
106
|
release: () => this.release(claim),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"leader-election.js","sourceRoot":"","sources":["../src/leader-election.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,OAAO,IAAI,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEtE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAajC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAgB,cAAc;IAClC,qFAAqF;IAClE,KAAK,CAAQ;IAEhC,YAAsB,KAAY;
|
|
1
|
+
{"version":3,"file":"leader-election.js","sourceRoot":"","sources":["../src/leader-election.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,OAAO,IAAI,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEtE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAajC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAA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
|
* frees it at once. A leader serves a pipe and pushes a heartbeat on it; a
|
|
39
39
|
* candidate waits on that pipe, and ends a leader that stays silent past its
|
|
40
|
-
* lease duration (ADR 0004 to 0007).
|
|
40
|
+
* lease duration (ADR 0004 to 0007). Its name is the path of the claim
|
|
41
|
+
* file, so two elections on one claim file are one election (ADR 0010).
|
|
41
42
|
*/
|
|
42
43
|
export declare class SqliteElection extends LeaderElection<SqliteAttempt> {
|
|
43
44
|
#private;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-election.d.ts","sourceRoot":"","sources":["../../src/sqlite/sqlite-election.ts"],"names":[],"mappings":"AAGA,OAAO,EAAW,KAAK,KAAK,EAAS,MAAM,gBAAgB,CAAC;AAS5D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAItD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,WAAW,qBAAqB;IACpC,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB;;;;;;OAMG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB,wFAAwF;IACxF,SAAS,EAAE,MAAM,CAAC;IAClB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,kJAAkJ;IAClJ,KAAK,EAAE,KAAK,CAAC;CACd;AAaD
|
|
1
|
+
{"version":3,"file":"sqlite-election.d.ts","sourceRoot":"","sources":["../../src/sqlite/sqlite-election.ts"],"names":[],"mappings":"AAGA,OAAO,EAAW,KAAK,KAAK,EAAS,MAAM,gBAAgB,CAAC;AAS5D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,E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,CAAC,IAAI,CAAC,CAIf;IAED,UAAgB,OAAO,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7D;IAED,SAAS,CAAC,KAAK,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAErD;CACF"}
|
|
@@ -24,7 +24,8 @@ const backoff = new Backoff({
|
|
|
24
24
|
* kernel keeps that lock until the leader's process dies, so a dead leader
|
|
25
25
|
* frees it at once. A leader serves a pipe and pushes a heartbeat on it; a
|
|
26
26
|
* candidate waits on that pipe, and ends a leader that stays silent past its
|
|
27
|
-
* lease duration (ADR 0004 to 0007).
|
|
27
|
+
* lease duration (ADR 0004 to 0007). Its name is the path of the claim
|
|
28
|
+
* file, so two elections on one claim file are one election (ADR 0010).
|
|
28
29
|
*/
|
|
29
30
|
export class SqliteElection extends LeaderElection {
|
|
30
31
|
#directory;
|
|
@@ -35,12 +36,13 @@ export class SqliteElection extends LeaderElection {
|
|
|
35
36
|
#leaseDuration;
|
|
36
37
|
#heartbeatInterval;
|
|
37
38
|
constructor({ directory, claimFile, epochFile, leaseDuration = 15_000, heartbeatInterval = leaseDuration / 3, clock, }) {
|
|
38
|
-
|
|
39
|
+
const claimPath = join(directory, claimFile);
|
|
40
|
+
super(claimPath, clock);
|
|
39
41
|
if (!(heartbeatInterval > 0 && heartbeatInterval < leaseDuration)) {
|
|
40
42
|
throw new RangeError(`heartbeatInterval (${heartbeatInterval}) must be above 0 and below leaseDuration (${leaseDuration}).`);
|
|
41
43
|
}
|
|
42
44
|
this.#directory = directory;
|
|
43
|
-
this.#claimPath =
|
|
45
|
+
this.#claimPath = claimPath;
|
|
44
46
|
this.#epochPath = join(directory, epochFile);
|
|
45
47
|
this.#cleanShutdownPath = `${this.#claimPath}.clean`;
|
|
46
48
|
this.#recordPath = `${this.#claimPath}.leader`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-election.js","sourceRoot":"","sources":["../../src/sqlite/sqlite-election.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,OAAO,EAAc,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EACL,QAAQ,EACR,oBAAoB,EACpB,WAAW,EACX,YAAY,EACZ,OAAO,GACR,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AA+BpD;;;GAGG;AACH,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC;IAC1B,OAAO,EAAE,EAAE;IACX,UAAU,EAAE,GAAG;IACf,GAAG,EAAE,IAAI;IACT,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE;CACtC,CAAC,CAAC;AAEH
|
|
1
|
+
{"version":3,"file":"sqlite-election.js","sourceRoot":"","sources":["../../src/sqlite/sqlite-election.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,OAAO,EAAc,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EACL,QAAQ,EACR,oBAAoB,EACpB,WAAW,EACX,YAAY,EACZ,OAAO,GACR,MAAM,aAAa,CAA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AAC;IACtC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC;YAAE,OAAO,EAAE,CAAC;QACxC,MAAM,KAAK,CAAC;IACd,CAAC;IACD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;QACrB,MAAM,IAAI,WAAW,CACnB,kBAAkB,IAAI,UAAU,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,uBAAuB,CAC5E,CAAC;IACJ,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC"}
|
package/dist/term.d.ts
CHANGED
|
@@ -37,7 +37,9 @@ export declare class Term implements Lease, AsyncDisposable {
|
|
|
37
37
|
* did not say it was clean, and for the first term.
|
|
38
38
|
*/
|
|
39
39
|
readonly afterCleanShutdown: boolean;
|
|
40
|
-
constructor({ epoch, afterCleanShutdown }: Pick<Term, 'epoch' | 'afterCleanShutdown'
|
|
40
|
+
constructor({ epoch, afterCleanShutdown, election, }: Pick<Term, 'epoch' | 'afterCleanShutdown'> & {
|
|
41
|
+
election: string;
|
|
42
|
+
}, steps: TermSteps);
|
|
41
43
|
/** Aborts with `LeaseLostError` when the term ends while its leader still runs. */
|
|
42
44
|
get signal(): AbortSignal;
|
|
43
45
|
/**
|
package/dist/term.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"term.d.ts","sourceRoot":"","sources":["../src/term.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,KAAK,EAAmB,MAAM,gBAAgB,CAAC;AAE7D,4FAA4F;AAC5F,MAAM,WAAW,SAAS;IACxB,+EAA+E;IAC/E,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,KAAK,KAAK,IAAI,GAAG,UAAU,CAAC;IACjD;;;OAGG;IACH,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,oEAAoE;IACpE,OAAO,IAAI,OAAO,CAAC,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,EAOjB;IAED,mFAAmF;IACnF,IAAI,MAAM,IAAI,WAAW,CAExB;IAED;;;;;;;OAOG;IACG,MAAM,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAYnD;IAED,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAErC;CA2DF"}
|
package/dist/term.js
CHANGED
|
@@ -15,15 +15,18 @@ export class Term {
|
|
|
15
15
|
* did not say it was clean, and for the first term.
|
|
16
16
|
*/
|
|
17
17
|
afterCleanShutdown;
|
|
18
|
+
/** The name of the election that elected this term, for the detail of a warning. */
|
|
19
|
+
#election;
|
|
18
20
|
#steps;
|
|
19
21
|
#lease = new LeaseController('leadership');
|
|
20
22
|
/** Aborts once the term starts to end, by resign or by loss. */
|
|
21
23
|
#ending = new AbortController();
|
|
22
24
|
#ended = new Future();
|
|
23
25
|
#watching = new DisposableStack();
|
|
24
|
-
constructor({ epoch, afterCleanShutdown }, steps) {
|
|
26
|
+
constructor({ epoch, afterCleanShutdown, election, }, steps) {
|
|
25
27
|
this.epoch = epoch;
|
|
26
28
|
this.afterCleanShutdown = afterCleanShutdown;
|
|
29
|
+
this.#election = election;
|
|
27
30
|
this.#steps = steps;
|
|
28
31
|
this.#watching.use(steps.watch((reason) => this.#lose(reason)));
|
|
29
32
|
}
|
|
@@ -103,7 +106,7 @@ export class Term {
|
|
|
103
106
|
process.emitWarning(Object.assign(new Error(`The lost term failed to stop watching its claim or to free it, and it ends anyway: ${Error.isError(error) ? error.message : String(error)}`, { cause: error }), {
|
|
104
107
|
name: 'TermWarning',
|
|
105
108
|
code: 'ZUKHRUF_ELECTION_TERM_FREE_FAILED',
|
|
106
|
-
detail: `
|
|
109
|
+
detail: `election: ${this.#election}\nepoch: ${this.epoch}`,
|
|
107
110
|
}));
|
|
108
111
|
}
|
|
109
112
|
}
|
package/dist/term.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"term.js","sourceRoot":"","sources":["../src/term.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAc,eAAe,EAAE,MAAM,gBAAgB,CAAC;AA0B7D;;;;;GAKG;AACH,MAAM,OAAO,IAAI;IACf,qGAAqG;IAC5F,KAAK,CAAS;IACvB;;;;OAIG;IACM,kBAAkB,CAAU;
|
|
1
|
+
{"version":3,"file":"term.js","sourceRoot":"","sources":["../src/term.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAc,eAAe,EAAE,MAAM,gBAAgB,CAAC;AA0B7D;;;;;GAKG;AACH,MAAM,OAAO,IAAI;IACf,qGAAqG;IAC5F,KAAK,CAAS;IACvB;;;;OAIG;IACM,kBAAkB,CAAU;IACrC,oFAAoF;IAC3E,SAAS,CAAS;IAClB,MAAM,CAAY;IAClB,MAAM,GAAG,IAAI,eAAe,CAAC,YAAY,CAAC,CAAC;IACpD,gEAAgE;IACvD,OAAO,GAAG,IAAI,eAAe,EAAE,CAAC;IAChC,MAAM,GAAG,IAAI,MAAM,EAAQ,CAAC;IAC5B,SAAS,GAAG,IAAI,eAAe,EAAE,CAAC;IAE3C,YACE,EACE,KAAK,EACL,kBAAkB,EAClB,QAAQ,GAC0D,EACpE,KAAgB;QAEhB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;QAC7C,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAClE,CAAC;IAED,mFAAmF;IACnF,IAAI,MAAM;QAC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1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/election",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.92",
|
|
4
4
|
"description": "Elects a leader among candidates. Each term has a higher epoch and ends when the leader resigns or dies. Backends subclass one campaign. `SqliteElection` elects among processes of one host; candidates and observers end a leader whose pipe heartbeats stop.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -40,13 +40,13 @@
|
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@zukhruf/async": "^0.8.
|
|
44
|
-
"@zukhruf/fs": "^0.8.
|
|
45
|
-
"@zukhruf/lease": "^0.8.
|
|
46
|
-
"@zukhruf/pipes": "^0.8.
|
|
43
|
+
"@zukhruf/async": "^0.8.92",
|
|
44
|
+
"@zukhruf/fs": "^0.8.92",
|
|
45
|
+
"@zukhruf/lease": "^0.8.92",
|
|
46
|
+
"@zukhruf/pipes": "^0.8.92"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@sinonjs/fake-timers": "15.5.0",
|
|
50
|
-
"@zukhruf/testing": "^0.8.
|
|
50
|
+
"@zukhruf/testing": "^0.8.92"
|
|
51
51
|
}
|
|
52
52
|
}
|