@delali/sirannon-db 0.2.0 → 0.2.1
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/dist/backup-scheduler/index.d.ts +15 -1
- package/dist/backup-scheduler/index.mjs +2 -2
- package/dist/baseline-D93hcIEE.d.ts +17 -0
- package/dist/{change-tracker-DKRVUC3l.d.ts → change-tracker-DDmXB754.d.ts} +56 -8
- package/dist/{chunk-5NOIGN5Y.mjs → chunk-2QLXDHAP.mjs} +1 -1
- package/dist/{chunk-LNY2VVHE.mjs → chunk-7C36BCSN.mjs} +1 -1
- package/dist/{chunk-NVQS53NT.mjs → chunk-7FQRQH5Z.mjs} +53 -64
- package/dist/{chunk-D7LAYTKN.mjs → chunk-7R4ER4FB.mjs} +1 -1
- package/dist/{chunk-FHWTZFI4.mjs → chunk-BQFQ65OL.mjs} +1 -1
- package/dist/{chunk-O7SLN3GI.mjs → chunk-BTTFW4Z4.mjs} +1 -1
- package/dist/{chunk-H6PIVVDN.mjs → chunk-CCZK6LCB.mjs} +38 -25
- package/dist/{chunk-JZGINXTN.mjs → chunk-HCCGEIZ2.mjs} +2 -2
- package/dist/{chunk-67M7KAH6.mjs → chunk-IWGIYDMZ.mjs} +1 -1
- package/dist/{chunk-LFZ37BSX.mjs → chunk-OUSWVNWT.mjs} +1 -1
- package/dist/{chunk-HR5CWTLC.mjs → chunk-P2VJYRVY.mjs} +60 -7
- package/dist/{chunk-UC3SCMIN.mjs → chunk-PBRXXISQ.mjs} +3 -0
- package/dist/{chunk-JU64Y7HM.mjs → chunk-SBL6GN43.mjs} +1 -1
- package/dist/{chunk-EBJXPQQO.mjs → chunk-UPKKSUPA.mjs} +2 -2
- package/dist/{chunk-TJF5GZSV.mjs → chunk-VOSJBZ6Q.mjs} +1 -1
- package/dist/{chunk-PIKHN33N.mjs → chunk-VOYGMAU7.mjs} +9 -1
- package/dist/{chunk-H237TXZW.mjs → chunk-WJ67DTD6.mjs} +48 -6
- package/dist/{chunk-OQVZBEBY.mjs → chunk-XF2HH5E6.mjs} +4 -61
- package/dist/client/index.d.ts +211 -12
- package/dist/client/index.mjs +155 -67
- package/dist/client/topology.d.ts +55 -7
- package/dist/client/topology.mjs +20 -1
- package/dist/{client-base-CLWmH5Ln.d.ts → client-base-CmZO0v3m.d.ts} +133 -24
- package/dist/codegen/cli.mjs +3 -3
- package/dist/codegen/index.d.ts +92 -2
- package/dist/codegen/index.mjs +3 -3
- package/dist/core/index.d.ts +177 -15
- package/dist/core/index.mjs +2481 -2226
- package/dist/core/writer-worker.mjs +3 -3
- package/dist/database-B5Qv1-cU.d.ts +380 -0
- package/dist/driver/better-sqlite3.d.ts +18 -1
- package/dist/driver/better-sqlite3.mjs +5 -5
- package/dist/driver/bun.d.ts +28 -0
- package/dist/driver/expo.d.ts +17 -0
- package/dist/driver/node.d.ts +18 -1
- package/dist/driver/node.mjs +5 -5
- package/dist/driver/wa-sqlite.d.ts +18 -1
- package/dist/{errors-Bw5MdNCu.d.ts → errors-Dei4GdBb.d.ts} +80 -7
- package/dist/file-migrations/index.d.ts +54 -2
- package/dist/file-migrations/index.mjs +3 -3
- package/dist/{operation-registry-9DcvxcE5.d.ts → operation-registry-hlbhqu7q.d.ts} +50 -1
- package/dist/{primary-wins-DPAm2AKG.d.ts → primary-wins-B0np8JS3.d.ts} +25 -1
- package/dist/protocol-rqANt-9Q.d.ts +152 -0
- package/dist/query-types-DL3LtPvY.d.ts +95 -0
- package/dist/react/index.d.ts +58 -3
- package/dist/replication/coordinator/etcd.d.ts +63 -3
- package/dist/replication/coordinator/etcd.mjs +82 -46
- package/dist/replication/index.d.ts +329 -95
- package/dist/replication/index.mjs +256 -141
- package/dist/server/index.d.ts +230 -12
- package/dist/server/index.mjs +63 -50
- package/dist/{server-options-1JHu8pid.d.ts → server-options-Dab_Jvd_.d.ts} +96 -12
- package/dist/sirannon-CMhiJa5Y.d.ts +111 -0
- package/dist/transport/grpc.d.ts +93 -9
- package/dist/transport/grpc.mjs +63 -20
- package/dist/transport/memory.d.ts +50 -20
- package/dist/transport/memory.mjs +25 -0
- package/dist/{types-CL6piSnD.d.ts → types-BCejqzNA.d.ts} +20 -0
- package/dist/types-CMBcFPhb.d.ts +336 -0
- package/dist/types-CjhxcjhA.d.ts +123 -0
- package/dist/types-DyrCiWuc.d.ts +499 -0
- package/dist/types-rVZKnKN-.d.ts +591 -0
- package/package.json +7 -1
- package/dist/baseline-Br77Fnhb.d.ts +0 -6
- package/dist/database-BY0L5Q2n.d.ts +0 -172
- package/dist/protocol-6KrSq2Hy.d.ts +0 -66
- package/dist/sirannon-DaQSyhbJ.d.ts +0 -36
- package/dist/types-B7gmEsZW.d.ts +0 -221
- package/dist/types-BsVabqSI.d.ts +0 -139
- package/dist/types-C_D8IhpO.d.ts +0 -60
- package/dist/types-zhnRXrsb.d.ts +0 -384
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
export { F as FieldMergeResolver, L as LWWResolver, P as PrimaryWinsResolver } from '../primary-wins-
|
|
2
|
-
import { H as HLCTimestamp, R as ReplicationBatch, C as ConflictResolver, A as ApplyResult, S as SyncTableManifest } from '../types-
|
|
3
|
-
export { a as ConflictContext, b as ConflictResolution, c as ReplicationChange } from '../types-
|
|
4
|
-
import {
|
|
5
|
-
export { A as AcquireControllerLeaseInput,
|
|
1
|
+
export { F as FieldMergeResolver, L as LWWResolver, P as PrimaryWinsResolver } from '../primary-wins-B0np8JS3.js';
|
|
2
|
+
import { H as HLCTimestamp, R as ReplicationBatch, C as ConflictResolver, A as ApplyResult, S as SyncTableManifest } from '../types-CjhxcjhA.js';
|
|
3
|
+
export { a as ConflictContext, b as ConflictResolution, c as ReplicationChange } from '../types-CjhxcjhA.js';
|
|
4
|
+
import { c as ReplicationGroupState, e as CoordinatorWatchDisposer } from '../types-CMBcFPhb.js';
|
|
5
|
+
export { A as AcquireControllerLeaseInput, a as AcquireControllerLeaseResult, h as AdmitNodeToInSyncSetInput, C as ClusterCoordinator, f as CompareAndAdvancePrimaryTermInput, g as CompareAndAdvancePrimaryTermResult, j as CoordinatorCompatibilityMetadata, k as CoordinatorLease, b as CoordinatorNodeSession, l as CoordinatorPrimary, P as PromoteEligibleReplicaInput, R as RegisterNodeSessionInput, d as ReplicationGroupWatcher, S as SetReplicationGroupStateInput, U as UpdateInSyncSetInput, i as UpdateNodeMaintenanceInput } from '../types-CMBcFPhb.js';
|
|
6
6
|
import { EventEmitter } from 'node:events';
|
|
7
|
-
import { C as ChangeTracker } from '../change-tracker-
|
|
8
|
-
import { D as Database } from '../database-
|
|
9
|
-
import { e as SQLiteConnection,
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import '../
|
|
14
|
-
import '../
|
|
15
|
-
import '../
|
|
7
|
+
import { C as ChangeTracker } from '../change-tracker-DDmXB754.js';
|
|
8
|
+
import { D as Database } from '../database-B5Qv1-cU.js';
|
|
9
|
+
import { e as SQLiteConnection, T as Transaction } from '../types-rVZKnKN-.js';
|
|
10
|
+
import { P as Params, Q as QueryOptions, E as ExecuteResult } from '../query-types-DL3LtPvY.js';
|
|
11
|
+
import { g as SyncPhase, I as InFlightBatch, P as PeerState, a as ForwardedTransactionResult, b as SyncBatch, c as SyncComplete, d as SyncAck, S as SyncRequest, h as ReplicationConfig, i as SyncState, j as ReplicationStatus, k as ReplicationErrorEvent, R as ReplicationAck, l as Topology, f as TopologyRole } from '../types-DyrCiWuc.js';
|
|
12
|
+
export { F as ForwardedTransaction, N as NodeInfo, e as ReplicationTransport, T as TransportConfig } from '../types-DyrCiWuc.js';
|
|
13
|
+
import { S as SirannonError } from '../errors-Dei4GdBb.js';
|
|
14
|
+
import '../server-options-Dab_Jvd_.js';
|
|
15
|
+
import '../operation-registry-hlbhqu7q.js';
|
|
16
|
+
import '../types-BCejqzNA.js';
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Hybrid Logical Clock (HLC) for causal ordering of events across nodes.
|
|
@@ -28,20 +29,38 @@ import '../types-CL6piSnD.js';
|
|
|
28
29
|
* increasing timestamp. Call `receive(remote)` when processing a remote
|
|
29
30
|
* change to merge the remote clock into the local state, ensuring the local
|
|
30
31
|
* clock is never behind any observed timestamp.
|
|
32
|
+
*
|
|
33
|
+
* @public
|
|
31
34
|
*/
|
|
32
35
|
declare class HLC {
|
|
33
36
|
private wallMs;
|
|
34
37
|
private logical;
|
|
35
38
|
private readonly nodeId;
|
|
36
39
|
constructor(nodeId: string);
|
|
37
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* Generate a new HLC timestamp, advancing the clock.
|
|
42
|
+
*
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
38
45
|
now(): string;
|
|
39
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* Merge a remote HLC timestamp into the local clock and return the updated value.
|
|
48
|
+
*
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
40
51
|
receive(remote: string): string;
|
|
41
52
|
/** Lexicographic comparison of two encoded HLC strings. Returns -1, 0, or 1. */
|
|
42
53
|
static compare(a: string, b: string): number;
|
|
43
54
|
/** Parse an encoded HLC string into its wall-clock, logical, and nodeId components. */
|
|
44
55
|
static decode(hlc: string): HLCTimestamp;
|
|
56
|
+
/**
|
|
57
|
+
* Builds the string form of a clock reading, which sorts in the same order as the reading itself.
|
|
58
|
+
*
|
|
59
|
+
* @param wallMs - Wall-clock milliseconds since the Unix epoch.
|
|
60
|
+
* @param logical - Counter that orders events sharing one millisecond.
|
|
61
|
+
* @param nodeId - Identifier of the node taking the reading.
|
|
62
|
+
* @returns The encoded stamp.
|
|
63
|
+
*/
|
|
45
64
|
static encode(wallMs: number, logical: number, nodeId: string): string;
|
|
46
65
|
}
|
|
47
66
|
|
|
@@ -53,6 +72,8 @@ declare class HLC {
|
|
|
53
72
|
* manifests), SchemaOps (replication-table bootstrap, schema dump, wipe),
|
|
54
73
|
* StateOps (sequence and sync metadata), and PkResolver (cached primary-key
|
|
55
74
|
* lookups).
|
|
75
|
+
*
|
|
76
|
+
* @internal
|
|
56
77
|
*/
|
|
57
78
|
declare class ReplicationLog {
|
|
58
79
|
private readonly changesTable;
|
|
@@ -77,7 +98,6 @@ declare class ReplicationLog {
|
|
|
77
98
|
getMinAckedSeq(): Promise<bigint | null>;
|
|
78
99
|
registerActiveSyncSeq(seq: bigint): void;
|
|
79
100
|
unregisterActiveSyncSeq(seq: bigint): void;
|
|
80
|
-
dumpTable(table: string, batchSize: number): AsyncGenerator<ReplicationBatch>;
|
|
81
101
|
dumpTableOnConnection(conn: SQLiteConnection, table: string, batchSize: number): AsyncGenerator<{
|
|
82
102
|
rows: Record<string, unknown>[];
|
|
83
103
|
checksum: string;
|
|
@@ -113,6 +133,8 @@ declare class ReplicationLog {
|
|
|
113
133
|
* with a sequence number and timeout. These methods resolve once enough
|
|
114
134
|
* peers have acknowledged that sequence, or reject with a
|
|
115
135
|
* WriteConcernError on timeout.
|
|
136
|
+
*
|
|
137
|
+
* @internal
|
|
116
138
|
*/
|
|
117
139
|
declare class PeerTracker {
|
|
118
140
|
private readonly peers;
|
|
@@ -135,6 +157,11 @@ declare class PeerTracker {
|
|
|
135
157
|
private checkWaiters;
|
|
136
158
|
}
|
|
137
159
|
|
|
160
|
+
/**
|
|
161
|
+
* Runs a statement on the local node and records the resulting changes in the replication log.
|
|
162
|
+
*
|
|
163
|
+
* @internal
|
|
164
|
+
*/
|
|
138
165
|
declare class LocalExecutor {
|
|
139
166
|
private readonly engine;
|
|
140
167
|
/**
|
|
@@ -164,6 +191,11 @@ declare class LocalExecutor {
|
|
|
164
191
|
private runTransaction;
|
|
165
192
|
}
|
|
166
193
|
|
|
194
|
+
/**
|
|
195
|
+
* Batches locally recorded changes and pushes them to the peers the topology accepts.
|
|
196
|
+
*
|
|
197
|
+
* @internal
|
|
198
|
+
*/
|
|
167
199
|
declare class SenderLoop {
|
|
168
200
|
private readonly engine;
|
|
169
201
|
private senderTimer;
|
|
@@ -175,6 +207,11 @@ declare class SenderLoop {
|
|
|
175
207
|
private shouldReplicateTo;
|
|
176
208
|
}
|
|
177
209
|
|
|
210
|
+
/**
|
|
211
|
+
* Drives a joining node through first sync and the catch-up that follows it.
|
|
212
|
+
*
|
|
213
|
+
* @internal
|
|
214
|
+
*/
|
|
178
215
|
declare class SyncJoiner {
|
|
179
216
|
private readonly engine;
|
|
180
217
|
private catchUpCheckTimer;
|
|
@@ -184,7 +221,7 @@ declare class SyncJoiner {
|
|
|
184
221
|
handleSyncBatchReceived(batch: SyncBatch, fromPeerId: string): Promise<void>;
|
|
185
222
|
handleSyncCompleteReceived(complete: SyncComplete, fromPeerId: string): Promise<void>;
|
|
186
223
|
startCatchUpCheck(): void;
|
|
187
|
-
stopCatchUpCheck
|
|
224
|
+
private stopCatchUpCheck;
|
|
188
225
|
stopTimers(): void;
|
|
189
226
|
isSourceRejection(ack: SyncAck, fromPeerId: string): boolean;
|
|
190
227
|
handleSourceRejection(ack: SyncAck, fromPeerId: string): void;
|
|
@@ -193,39 +230,20 @@ declare class SyncJoiner {
|
|
|
193
230
|
private finishCatchUpAsReady;
|
|
194
231
|
}
|
|
195
232
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
interface ActiveSyncSession {
|
|
202
|
-
requestId: string;
|
|
203
|
-
joinerNodeId: string;
|
|
204
|
-
readConn: SQLiteConnection;
|
|
205
|
-
snapshotSeq: bigint;
|
|
206
|
-
tables: string[];
|
|
207
|
-
totalTables: number;
|
|
208
|
-
completedTables: Set<string>;
|
|
209
|
-
startedAt: number;
|
|
210
|
-
timeoutTimer: ReturnType<typeof setTimeout>;
|
|
211
|
-
aborted: boolean;
|
|
212
|
-
streamVerification: boolean;
|
|
213
|
-
tableDigests: Map<string, TableStreamDigest>;
|
|
214
|
-
}
|
|
215
|
-
interface SyncAckWaiter {
|
|
216
|
-
resolve: (ack: SyncAck) => void;
|
|
217
|
-
timer: ReturnType<typeof setTimeout>;
|
|
218
|
-
}
|
|
219
|
-
|
|
233
|
+
/**
|
|
234
|
+
* Serves first-sync requests from joining nodes by streaming schema, table pages, and a manifest.
|
|
235
|
+
*
|
|
236
|
+
* @internal
|
|
237
|
+
*/
|
|
220
238
|
declare class SyncServer {
|
|
221
239
|
private readonly engine;
|
|
222
|
-
readonly activeSyncs
|
|
223
|
-
readonly syncAckWaiters
|
|
240
|
+
private readonly activeSyncs;
|
|
241
|
+
private readonly syncAckWaiters;
|
|
224
242
|
constructor(engine: ReplicationEngine);
|
|
225
243
|
private rejectSyncRequest;
|
|
226
244
|
handleSyncRequest(request: SyncRequest, fromPeerId: string): Promise<void>;
|
|
227
245
|
handleSyncAckReceived(ack: SyncAck): void;
|
|
228
|
-
abortSyncSession
|
|
246
|
+
private abortSyncSession;
|
|
229
247
|
abortAll(): void;
|
|
230
248
|
abortSessionsForPeer(peerId: string): void;
|
|
231
249
|
private waitForSyncAck;
|
|
@@ -234,185 +252,372 @@ declare class SyncServer {
|
|
|
234
252
|
private serveSyncSession;
|
|
235
253
|
}
|
|
236
254
|
|
|
255
|
+
interface TableStreamDigest {
|
|
256
|
+
rowCount: number;
|
|
257
|
+
digest: string;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
type CoordinatorStampedMessage = ReplicationBatch | ReplicationAck | ForwardedTransactionResult | SyncRequest | SyncBatch | SyncComplete | SyncAck;
|
|
237
261
|
/**
|
|
238
262
|
* Coordinates replication for a single database node.
|
|
239
263
|
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
* constructor wiring.
|
|
264
|
+
* Its state and dependencies are readable properties so that the collaborating
|
|
265
|
+
* modules in `./engine/` share one mutable engine instance.
|
|
266
|
+
*
|
|
267
|
+
* @public
|
|
245
268
|
*/
|
|
246
269
|
declare class ReplicationEngine extends EventEmitter {
|
|
270
|
+
/** @internal */
|
|
247
271
|
readonly database: Database;
|
|
272
|
+
/** @internal */
|
|
248
273
|
readonly writerConn: SQLiteConnection;
|
|
274
|
+
/** @internal */
|
|
249
275
|
readonly config: ReplicationConfig;
|
|
276
|
+
/**
|
|
277
|
+
* Identifier of this node, which every change it authors carries.
|
|
278
|
+
*/
|
|
250
279
|
readonly nodeId: string;
|
|
280
|
+
/** @internal */
|
|
251
281
|
readonly hlc: HLC;
|
|
282
|
+
/** @internal */
|
|
252
283
|
readonly log: ReplicationLog;
|
|
284
|
+
/** @internal */
|
|
253
285
|
readonly peerTracker: PeerTracker;
|
|
286
|
+
/** @internal */
|
|
254
287
|
readonly defaultResolver: ConflictResolver;
|
|
288
|
+
/** @internal */
|
|
255
289
|
readonly tracker: ChangeTracker | undefined;
|
|
290
|
+
/** @internal */
|
|
256
291
|
readonly snapshotConnectionFactory: (() => Promise<SQLiteConnection>) | undefined;
|
|
292
|
+
/** @internal */
|
|
257
293
|
readonly batchSize: number;
|
|
294
|
+
/** @internal */
|
|
258
295
|
readonly batchIntervalMs: number;
|
|
296
|
+
/** @internal */
|
|
259
297
|
readonly maxClockDriftMs: number;
|
|
298
|
+
/** @internal */
|
|
260
299
|
readonly maxPendingBatches: number;
|
|
300
|
+
/** @internal */
|
|
261
301
|
readonly maxBatchChanges: number;
|
|
302
|
+
/** @internal */
|
|
262
303
|
readonly ackTimeoutMs: number;
|
|
304
|
+
/** @internal */
|
|
263
305
|
readonly initialSync: boolean;
|
|
306
|
+
/** @internal */
|
|
264
307
|
readonly syncBatchSize: number;
|
|
308
|
+
/** @internal */
|
|
265
309
|
readonly maxConcurrentSyncs: number;
|
|
310
|
+
/** @internal */
|
|
266
311
|
readonly maxSyncDurationMs: number;
|
|
312
|
+
/** @internal */
|
|
267
313
|
readonly maxSyncLagBeforeReady: number;
|
|
314
|
+
/** @internal */
|
|
268
315
|
readonly syncAckTimeoutMs: number;
|
|
316
|
+
/** @internal */
|
|
269
317
|
readonly catchUpDeadlineMs: number;
|
|
318
|
+
/** @internal */
|
|
270
319
|
readonly resumeFromSeq: bigint | undefined;
|
|
320
|
+
/** @internal */
|
|
271
321
|
running: boolean;
|
|
322
|
+
/** @internal */
|
|
272
323
|
coordinatorState: ReplicationGroupState | null;
|
|
324
|
+
/** @internal */
|
|
273
325
|
coordinatorAuthority: boolean;
|
|
326
|
+
/** @internal */
|
|
274
327
|
controllerState: 'disabled' | 'standby' | 'active' | 'lost';
|
|
328
|
+
/** @internal */
|
|
275
329
|
nodeSessionLeaseId: string | null;
|
|
330
|
+
/** @internal */
|
|
276
331
|
controllerLeaseId: string | null;
|
|
332
|
+
/** @internal */
|
|
277
333
|
coordinatorWatchDisposer: CoordinatorWatchDisposer | null;
|
|
334
|
+
/** @internal */
|
|
278
335
|
coordinatorLeaseTimer: ReturnType<typeof setInterval> | null;
|
|
336
|
+
/** @internal */
|
|
279
337
|
controllerTimer: ReturnType<typeof setInterval> | null;
|
|
338
|
+
/** @internal */
|
|
280
339
|
coordinatorRejoinSyncStarting: boolean;
|
|
340
|
+
/** @internal */
|
|
281
341
|
coordinatorSessionRestoring: boolean;
|
|
342
|
+
/** @internal */
|
|
282
343
|
coordinatorLastContactMs: number;
|
|
344
|
+
/** @internal */
|
|
283
345
|
inSyncReconcileTimer: ReturnType<typeof setInterval> | null;
|
|
346
|
+
/** @internal */
|
|
284
347
|
inSyncReconciling: boolean;
|
|
348
|
+
/** @internal */
|
|
285
349
|
lastSentSeq: bigint;
|
|
350
|
+
/** @internal */
|
|
286
351
|
lastLocalSeq: bigint;
|
|
352
|
+
/** @internal */
|
|
287
353
|
highestSourceSeqSeen: bigint;
|
|
354
|
+
/** @internal */
|
|
288
355
|
readonly appliedSeqByPeer: Map<string, bigint>;
|
|
356
|
+
/** @internal */
|
|
289
357
|
readonly expectedBatchIndex: Map<string, number>;
|
|
358
|
+
/** @internal */
|
|
290
359
|
readonly syncTableDigests: Map<string, TableStreamDigest>;
|
|
360
|
+
/** @internal */
|
|
291
361
|
syncState: SyncState;
|
|
362
|
+
/** @internal */
|
|
292
363
|
readonly localExecutor: LocalExecutor;
|
|
364
|
+
/** @internal */
|
|
293
365
|
readonly syncServer: SyncServer;
|
|
366
|
+
/** @internal */
|
|
294
367
|
readonly syncJoiner: SyncJoiner;
|
|
368
|
+
/** @internal */
|
|
295
369
|
readonly senderLoop: SenderLoop;
|
|
296
370
|
constructor(database: Database, writerConn: SQLiteConnection, config: ReplicationConfig);
|
|
371
|
+
/**
|
|
372
|
+
* Connects the transport, pulls a full copy when this node needs one, and starts replicating.
|
|
373
|
+
*/
|
|
297
374
|
start(): Promise<void>;
|
|
375
|
+
/**
|
|
376
|
+
* Stops replicating, abandons any sync in flight, and disconnects the transport.
|
|
377
|
+
*/
|
|
298
378
|
stop(): Promise<void>;
|
|
379
|
+
/**
|
|
380
|
+
* Reports where this node stands.
|
|
381
|
+
*
|
|
382
|
+
* @returns The node's role, its peers, its progress, its health, and its group state.
|
|
383
|
+
*/
|
|
299
384
|
status(): ReplicationStatus;
|
|
385
|
+
/**
|
|
386
|
+
* Returns the highest change-log position this node has recorded locally.
|
|
387
|
+
*
|
|
388
|
+
* @returns That position, which a caller waits for a replica to reach.
|
|
389
|
+
*/
|
|
300
390
|
getCurrentSeq(): bigint;
|
|
391
|
+
/**
|
|
392
|
+
* Returns how far this node has applied one peer's changes.
|
|
393
|
+
*
|
|
394
|
+
* @param peerId - Identifier of the peer.
|
|
395
|
+
* @returns The highest position from that peer this node has applied.
|
|
396
|
+
*/
|
|
301
397
|
getAppliedSeq(peerId: string): bigint;
|
|
398
|
+
/**
|
|
399
|
+
* Runs a read, refusing it when the node cannot meet the read concern.
|
|
400
|
+
*
|
|
401
|
+
* @param sql - The statement to run.
|
|
402
|
+
* @param params - Values bound to the statement, named or positional.
|
|
403
|
+
* @param options - Read concern for this statement.
|
|
404
|
+
* @returns The rows the statement produced.
|
|
405
|
+
*/
|
|
302
406
|
query<T>(sql: string, params?: Params, options?: QueryOptions): Promise<T[]>;
|
|
407
|
+
/**
|
|
408
|
+
* Runs one write, forwarding it to the primary when this node accepts no writes and forwarding is on.
|
|
409
|
+
*
|
|
410
|
+
* @param sql - The statement to run.
|
|
411
|
+
* @param params - Values bound to the statement, named or positional.
|
|
412
|
+
* @param options - Write concern for this statement.
|
|
413
|
+
* @returns How many rows changed, and the last inserted row id.
|
|
414
|
+
*/
|
|
303
415
|
execute(sql: string, params?: Params, options?: QueryOptions): Promise<ExecuteResult>;
|
|
416
|
+
/**
|
|
417
|
+
* Runs one statement over many parameter sets in a single transaction.
|
|
418
|
+
*
|
|
419
|
+
* @param sql - The statement to run for each parameter set.
|
|
420
|
+
* @param paramsBatch - One parameter set per run.
|
|
421
|
+
* @param options - Write concern for the transaction.
|
|
422
|
+
* @returns One result per parameter set, in order.
|
|
423
|
+
*/
|
|
304
424
|
executeBatch(sql: string, paramsBatch: Params[], options?: QueryOptions): Promise<ExecuteResult[]>;
|
|
425
|
+
/**
|
|
426
|
+
* Runs a function inside one transaction on this node.
|
|
427
|
+
*
|
|
428
|
+
* @param fn - Receives the transaction and runs statements on it.
|
|
429
|
+
* @param options - Write concern for the transaction.
|
|
430
|
+
* @returns Whatever the function returned.
|
|
431
|
+
*/
|
|
305
432
|
transaction<T>(fn: (tx: Transaction) => Promise<T>, options?: QueryOptions): Promise<T>;
|
|
433
|
+
/**
|
|
434
|
+
* Sends a write to the primary and waits for its result.
|
|
435
|
+
*
|
|
436
|
+
* @param statements - The statements to run, in order, each with its own parameters.
|
|
437
|
+
* @param options - Write concern the primary applies.
|
|
438
|
+
* @returns What the primary reported for each statement.
|
|
439
|
+
*/
|
|
306
440
|
forwardStatements(statements: Array<{
|
|
307
441
|
sql: string;
|
|
308
442
|
params?: Params;
|
|
309
443
|
}>, options?: QueryOptions): Promise<ForwardedTransactionResult>;
|
|
310
|
-
|
|
444
|
+
/** @internal */
|
|
311
445
|
emitError(event: ReplicationErrorEvent): void;
|
|
312
|
-
|
|
313
|
-
checkClockDrift(remoteHlc: string): number;
|
|
314
|
-
refreshTriggersAfterDdl(): Promise<void>;
|
|
315
|
-
waitForWriteConcern(seq: bigint, wc: {
|
|
316
|
-
level: string;
|
|
317
|
-
timeoutMs?: number;
|
|
318
|
-
}): Promise<void>;
|
|
319
|
-
loadAppliedSeqs(): Promise<void>;
|
|
446
|
+
/** @internal */
|
|
320
447
|
isCoordinatorMode(): boolean;
|
|
321
|
-
|
|
322
|
-
prepareCoordinatorRejoinIfNeeded(): Promise<void>;
|
|
323
|
-
hasCoordinatorWriteAuthority(): boolean;
|
|
324
|
-
requiresCoordinatorRejoinSync(state?: ReplicationGroupState | null): boolean;
|
|
325
|
-
markCoordinatorSyncReady(): Promise<void>;
|
|
326
|
-
handleCoordinatorAckProgress(nodeId: string, ackedSeq: bigint): Promise<void>;
|
|
448
|
+
/** @internal */
|
|
327
449
|
verifyPrimaryAuthority(): Promise<ReplicationGroupState>;
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
}, fromPeerId: string, direction: 'batch' | 'ack' | 'forward' | 'sync-request' | 'sync-data'): Promise<void>;
|
|
332
|
-
decorateBatch(batch: ReplicationBatch): ReplicationBatch;
|
|
333
|
-
decorateAck(ack: ReplicationAck): ReplicationAck;
|
|
334
|
-
decorateForwardResult(result: ForwardedTransactionResult): ForwardedTransactionResult;
|
|
335
|
-
decorateSyncRequest(request: SyncRequest): SyncRequest;
|
|
336
|
-
decorateSyncBatch(batch: SyncBatch): SyncBatch;
|
|
337
|
-
decorateSyncComplete(complete: SyncComplete): SyncComplete;
|
|
338
|
-
decorateSyncAck(ack: SyncAck): SyncAck;
|
|
339
|
-
resolveWriteConcern(wc: {
|
|
340
|
-
level: string;
|
|
341
|
-
timeoutMs?: number;
|
|
342
|
-
} | undefined): {
|
|
343
|
-
level: string;
|
|
344
|
-
timeoutMs?: number;
|
|
345
|
-
} | undefined;
|
|
450
|
+
/** @internal */
|
|
451
|
+
markCoordinatorSyncReady(): Promise<void>;
|
|
452
|
+
/** @internal */
|
|
346
453
|
getCurrentPrimaryPeerId(): string | null;
|
|
454
|
+
/**
|
|
455
|
+
* Stamps an outgoing replication message with this node's group and primary term.
|
|
456
|
+
*
|
|
457
|
+
* @internal
|
|
458
|
+
*/
|
|
459
|
+
decorate<T extends CoordinatorStampedMessage>(message: T): T;
|
|
347
460
|
}
|
|
348
461
|
|
|
349
|
-
/** Base error for all replication-related failures.
|
|
462
|
+
/** Base error for all replication-related failures.
|
|
463
|
+
* @public
|
|
464
|
+
*/
|
|
350
465
|
declare class ReplicationError extends SirannonError {
|
|
466
|
+
/** Anything the failing operation attached, such as the peer or the batch involved. */
|
|
351
467
|
readonly details?: Record<string, unknown> | undefined;
|
|
352
|
-
constructor(message: string, code?: string,
|
|
468
|
+
constructor(message: string, code?: string,
|
|
469
|
+
/** Anything the failing operation attached, such as the peer or the batch involved. */
|
|
470
|
+
details?: Record<string, unknown> | undefined);
|
|
353
471
|
}
|
|
354
|
-
/** Thrown when an incoming replication batch fails integrity checks (checksum, schema, clock drift).
|
|
472
|
+
/** Thrown when an incoming replication batch fails integrity checks (checksum, schema, clock drift).
|
|
473
|
+
* @public
|
|
474
|
+
*/
|
|
355
475
|
declare class BatchValidationError extends ReplicationError {
|
|
356
476
|
constructor(message: string);
|
|
357
477
|
}
|
|
358
478
|
|
|
359
|
-
/** Thrown when a write conflict cannot be resolved automatically.
|
|
479
|
+
/** Thrown when a write conflict cannot be resolved automatically.
|
|
480
|
+
* @public
|
|
481
|
+
*/
|
|
360
482
|
declare class ConflictError extends ReplicationError {
|
|
483
|
+
/**
|
|
484
|
+
* Table the conflicting row belongs to.
|
|
485
|
+
*/
|
|
361
486
|
readonly table: string;
|
|
487
|
+
/**
|
|
488
|
+
* Primary key of the conflicting row, encoded as a string.
|
|
489
|
+
*/
|
|
362
490
|
readonly rowId: string;
|
|
363
|
-
constructor(message: string,
|
|
491
|
+
constructor(message: string,
|
|
492
|
+
/**
|
|
493
|
+
* Table the conflicting row belongs to.
|
|
494
|
+
*/
|
|
495
|
+
table: string,
|
|
496
|
+
/**
|
|
497
|
+
* Primary key of the conflicting row, encoded as a string.
|
|
498
|
+
*/
|
|
499
|
+
rowId: string);
|
|
364
500
|
}
|
|
365
|
-
/** Thrown when inter-node communication fails.
|
|
501
|
+
/** Thrown when inter-node communication fails.
|
|
502
|
+
* @public
|
|
503
|
+
*/
|
|
366
504
|
declare class TransportError extends ReplicationError {
|
|
367
505
|
constructor(message: string);
|
|
368
506
|
}
|
|
369
|
-
/** Thrown when a write-concern quorum is not met within the configured timeout.
|
|
507
|
+
/** Thrown when a write-concern quorum is not met within the configured timeout.
|
|
508
|
+
* @public
|
|
509
|
+
*/
|
|
370
510
|
declare class WriteConcernError extends ReplicationError {
|
|
371
511
|
constructor(message: string);
|
|
372
512
|
}
|
|
513
|
+
/**
|
|
514
|
+
* @public
|
|
515
|
+
*
|
|
516
|
+
* Thrown when a node cannot prove a read is as current as the caller required.
|
|
517
|
+
*/
|
|
373
518
|
declare class ReadConcernError extends ReplicationError {
|
|
374
519
|
constructor(message: string, details?: Record<string, unknown>);
|
|
375
520
|
}
|
|
376
|
-
/** Thrown when a write or routing operation violates the configured topology rules.
|
|
521
|
+
/** Thrown when a write or routing operation violates the configured topology rules.
|
|
522
|
+
* @public
|
|
523
|
+
*/
|
|
377
524
|
declare class TopologyError extends ReplicationError {
|
|
378
525
|
constructor(message: string);
|
|
379
526
|
}
|
|
527
|
+
/**
|
|
528
|
+
* @public
|
|
529
|
+
*
|
|
530
|
+
* Thrown when a node cannot reach its cluster coordinator.
|
|
531
|
+
*/
|
|
380
532
|
declare class CoordinatorError extends ReplicationError {
|
|
381
533
|
constructor(message: string, details?: Record<string, unknown>);
|
|
382
534
|
}
|
|
535
|
+
/**
|
|
536
|
+
* @public
|
|
537
|
+
*
|
|
538
|
+
* Thrown when a node cannot prove it holds write authority for the current term.
|
|
539
|
+
*/
|
|
383
540
|
declare class AuthorityError extends ReplicationError {
|
|
384
541
|
constructor(message: string, code?: string, details?: Record<string, unknown>);
|
|
385
542
|
}
|
|
543
|
+
/**
|
|
544
|
+
* @public
|
|
545
|
+
*
|
|
546
|
+
* Thrown when a node believing itself primary finds the group has moved to a later term.
|
|
547
|
+
*/
|
|
386
548
|
declare class StalePrimaryError extends AuthorityError {
|
|
387
549
|
constructor(message: string, details?: Record<string, unknown>);
|
|
388
550
|
}
|
|
551
|
+
/**
|
|
552
|
+
* @public
|
|
553
|
+
*
|
|
554
|
+
* Thrown when failover cannot complete safely.
|
|
555
|
+
*/
|
|
389
556
|
declare class FailoverError extends ReplicationError {
|
|
390
557
|
constructor(message: string, code?: string, details?: Record<string, unknown>);
|
|
391
558
|
}
|
|
559
|
+
/**
|
|
560
|
+
* @public
|
|
561
|
+
*
|
|
562
|
+
* Thrown when no replica is in sync enough to take over as primary, so writes stay unavailable rather than risking loss.
|
|
563
|
+
*/
|
|
392
564
|
declare class NoSafePrimaryError extends FailoverError {
|
|
393
565
|
constructor(message: string, details?: Record<string, unknown>);
|
|
394
566
|
}
|
|
567
|
+
/**
|
|
568
|
+
* @public
|
|
569
|
+
*
|
|
570
|
+
* Thrown when a node cannot meet a read concern because the group does not count it as in sync.
|
|
571
|
+
*/
|
|
395
572
|
declare class NodeNotInSyncError extends ReplicationError {
|
|
396
573
|
constructor(message: string, details?: Record<string, unknown>);
|
|
397
574
|
}
|
|
575
|
+
/**
|
|
576
|
+
* @public
|
|
577
|
+
*
|
|
578
|
+
* Thrown when a node is being taken out of service and refuses new work.
|
|
579
|
+
*/
|
|
398
580
|
declare class NodeDrainingError extends ReplicationError {
|
|
399
581
|
constructor(message: string, details?: Record<string, unknown>);
|
|
400
582
|
}
|
|
583
|
+
/**
|
|
584
|
+
* @public
|
|
585
|
+
*
|
|
586
|
+
* Thrown when a peer speaks a replication protocol version this node cannot work with.
|
|
587
|
+
*/
|
|
401
588
|
declare class ProtocolVersionMismatchError extends ReplicationError {
|
|
402
589
|
constructor(message: string, details?: Record<string, unknown>);
|
|
403
590
|
}
|
|
591
|
+
/**
|
|
592
|
+
* @public
|
|
593
|
+
*
|
|
594
|
+
* Thrown when recovery would lose acknowledged writes, so an operator must rebuild or restore the node first.
|
|
595
|
+
*/
|
|
404
596
|
declare class UnsafeRecoveryRequiredError extends FailoverError {
|
|
405
597
|
constructor(message: string, details?: Record<string, unknown>);
|
|
406
598
|
}
|
|
407
|
-
/** Thrown for initial sync failures.
|
|
599
|
+
/** Thrown for initial sync failures.
|
|
600
|
+
* @public
|
|
601
|
+
*/
|
|
408
602
|
declare class SyncError extends ReplicationError {
|
|
603
|
+
/**
|
|
604
|
+
* Identifier of the sync that failed.
|
|
605
|
+
*/
|
|
409
606
|
readonly requestId?: string | undefined;
|
|
410
|
-
constructor(message: string,
|
|
607
|
+
constructor(message: string,
|
|
608
|
+
/**
|
|
609
|
+
* Identifier of the sync that failed.
|
|
610
|
+
*/
|
|
611
|
+
requestId?: string | undefined);
|
|
411
612
|
}
|
|
412
613
|
|
|
413
|
-
/** Generate a cryptographically random 32-hex-character node identifier.
|
|
614
|
+
/** Generate a cryptographically random 32-hex-character node identifier.
|
|
615
|
+
* @public
|
|
616
|
+
*/
|
|
414
617
|
declare function generateNodeId(): string;
|
|
415
|
-
/** Throw a ReplicationError if the given string is not a valid 32-hex-character node ID.
|
|
618
|
+
/** Throw a ReplicationError if the given string is not a valid 32-hex-character node ID.
|
|
619
|
+
* @public
|
|
620
|
+
*/
|
|
416
621
|
declare function validateNodeId(id: string): void;
|
|
417
622
|
|
|
418
623
|
/**
|
|
@@ -424,13 +629,42 @@ declare function validateNodeId(id: string): void;
|
|
|
424
629
|
* is 'replica', and replicas only accept inbound batches from a peer whose
|
|
425
630
|
* role is 'primary'. Conflict resolution is not required because a single
|
|
426
631
|
* writer eliminates concurrent write conflicts by design.
|
|
632
|
+
*
|
|
633
|
+
* @public
|
|
427
634
|
*/
|
|
428
635
|
declare class PrimaryReplicaTopology implements Topology {
|
|
636
|
+
/**
|
|
637
|
+
* Whether this node accepts writes or serves reads.
|
|
638
|
+
*/
|
|
429
639
|
readonly role: TopologyRole;
|
|
430
640
|
constructor(role: 'primary' | 'replica');
|
|
641
|
+
/**
|
|
642
|
+
* Reports whether this node accepts writes, which only the primary does.
|
|
643
|
+
*
|
|
644
|
+
* @returns True on the primary.
|
|
645
|
+
*/
|
|
431
646
|
canWrite(): boolean;
|
|
647
|
+
/**
|
|
648
|
+
* Reports whether this node sends its changes to a given peer.
|
|
649
|
+
*
|
|
650
|
+
* @param _peerId - Identifier of the peer, which this topology ignores.
|
|
651
|
+
* @param peerRole - Role of the peer.
|
|
652
|
+
* @returns True when this node is the primary and the peer is a replica.
|
|
653
|
+
*/
|
|
432
654
|
shouldReplicateTo(_peerId: string, peerRole: TopologyRole): boolean;
|
|
655
|
+
/**
|
|
656
|
+
* Reports whether this node applies changes arriving from a given peer.
|
|
657
|
+
*
|
|
658
|
+
* @param _peerId - Identifier of the peer, which this topology ignores.
|
|
659
|
+
* @param peerRole - Role of the peer.
|
|
660
|
+
* @returns True when this node is a replica and the peer is the primary.
|
|
661
|
+
*/
|
|
433
662
|
shouldAcceptFrom(_peerId: string, peerRole: TopologyRole): boolean;
|
|
663
|
+
/**
|
|
664
|
+
* Reports whether incoming changes need a resolver, which a single writer removes the need for.
|
|
665
|
+
*
|
|
666
|
+
* @returns False.
|
|
667
|
+
*/
|
|
434
668
|
requiresConflictResolution(): boolean;
|
|
435
669
|
}
|
|
436
670
|
|