@quereus/sync 4.4.0 → 4.4.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/README.md +19 -1
- package/dist/src/create-sync-module.d.ts +11 -1
- package/dist/src/create-sync-module.d.ts.map +1 -1
- package/dist/src/create-sync-module.js +2 -2
- package/dist/src/create-sync-module.js.map +1 -1
- package/dist/src/index.d.ts +4 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +9 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/metadata/change-log.d.ts +39 -3
- package/dist/src/metadata/change-log.d.ts.map +1 -1
- package/dist/src/metadata/change-log.js +43 -8
- package/dist/src/metadata/change-log.js.map +1 -1
- package/dist/src/metadata/column-version.d.ts +62 -9
- package/dist/src/metadata/column-version.d.ts.map +1 -1
- package/dist/src/metadata/column-version.js +79 -25
- package/dist/src/metadata/column-version.js.map +1 -1
- package/dist/src/metadata/index.d.ts +1 -0
- package/dist/src/metadata/index.d.ts.map +1 -1
- package/dist/src/metadata/index.js +1 -0
- package/dist/src/metadata/index.js.map +1 -1
- package/dist/src/metadata/keys.d.ts +88 -22
- package/dist/src/metadata/keys.d.ts.map +1 -1
- package/dist/src/metadata/keys.js +134 -77
- package/dist/src/metadata/keys.js.map +1 -1
- package/dist/src/metadata/pk-identity.d.ts +60 -0
- package/dist/src/metadata/pk-identity.d.ts.map +1 -0
- package/dist/src/metadata/pk-identity.js +94 -0
- package/dist/src/metadata/pk-identity.js.map +1 -0
- package/dist/src/metadata/tombstones.d.ts +41 -11
- package/dist/src/metadata/tombstones.d.ts.map +1 -1
- package/dist/src/metadata/tombstones.js +58 -33
- package/dist/src/metadata/tombstones.js.map +1 -1
- package/dist/src/sync/change-applicator.d.ts +30 -1
- package/dist/src/sync/change-applicator.d.ts.map +1 -1
- package/dist/src/sync/change-applicator.js +161 -40
- package/dist/src/sync/change-applicator.js.map +1 -1
- package/dist/src/sync/maintenance.d.ts +70 -0
- package/dist/src/sync/maintenance.d.ts.map +1 -0
- package/dist/src/sync/maintenance.js +84 -0
- package/dist/src/sync/maintenance.js.map +1 -0
- package/dist/src/sync/protocol.d.ts +61 -10
- package/dist/src/sync/protocol.d.ts.map +1 -1
- package/dist/src/sync/protocol.js +15 -0
- package/dist/src/sync/protocol.js.map +1 -1
- package/dist/src/sync/snapshot-identity.d.ts +62 -0
- package/dist/src/sync/snapshot-identity.d.ts.map +1 -0
- package/dist/src/sync/snapshot-identity.js +88 -0
- package/dist/src/sync/snapshot-identity.js.map +1 -0
- package/dist/src/sync/snapshot-stream.d.ts +8 -1
- package/dist/src/sync/snapshot-stream.d.ts.map +1 -1
- package/dist/src/sync/snapshot-stream.js +166 -67
- package/dist/src/sync/snapshot-stream.js.map +1 -1
- package/dist/src/sync/snapshot.d.ts +1 -1
- package/dist/src/sync/snapshot.d.ts.map +1 -1
- package/dist/src/sync/snapshot.js +75 -44
- package/dist/src/sync/snapshot.js.map +1 -1
- package/dist/src/sync/staged-transaction-metadata.d.ts +75 -0
- package/dist/src/sync/staged-transaction-metadata.d.ts.map +1 -0
- package/dist/src/sync/staged-transaction-metadata.js +100 -0
- package/dist/src/sync/staged-transaction-metadata.js.map +1 -0
- package/dist/src/sync/store-adapter.d.ts +10 -4
- package/dist/src/sync/store-adapter.d.ts.map +1 -1
- package/dist/src/sync/store-adapter.js +244 -21
- package/dist/src/sync/store-adapter.js.map +1 -1
- package/dist/src/sync/sync-context.d.ts +54 -2
- package/dist/src/sync/sync-context.d.ts.map +1 -1
- package/dist/src/sync/sync-context.js +66 -0
- package/dist/src/sync/sync-context.js.map +1 -1
- package/dist/src/sync/sync-manager-impl.d.ts +70 -4
- package/dist/src/sync/sync-manager-impl.d.ts.map +1 -1
- package/dist/src/sync/sync-manager-impl.js +206 -36
- package/dist/src/sync/sync-manager-impl.js.map +1 -1
- package/dist/src/sync/wire.d.ts +47 -6
- package/dist/src/sync/wire.d.ts.map +1 -1
- package/dist/src/sync/wire.js +62 -11
- package/dist/src/sync/wire.js.map +1 -1
- package/package.json +6 -6
|
@@ -129,11 +129,35 @@ export interface ApplyResult {
|
|
|
129
129
|
unknownTable?: number;
|
|
130
130
|
}
|
|
131
131
|
/**
|
|
132
|
-
*
|
|
132
|
+
* Snapshot wire-format version, stamped into both snapshot forms (the streaming
|
|
133
|
+
* header chunk and the non-streaming `Snapshot`). Both apply paths REFUSE a
|
|
134
|
+
* snapshot whose stamp is missing or different, before touching any local state
|
|
135
|
+
* — same posture as the `fv:` sync-metadata format gate in `SyncManagerImpl.create`.
|
|
136
|
+
* Recovery is to regenerate the snapshot from a live peer (the coordinator's S3
|
|
137
|
+
* store persists serialized chunks at rest, so an old stored snapshot read by
|
|
138
|
+
* new code would otherwise silently mis-parse). Bump on ANY breaking change to
|
|
139
|
+
* snapshot entry shapes.
|
|
140
|
+
*
|
|
141
|
+
* Version 1: column-version entries are explicit `{ column, hlc, value, pk }`
|
|
142
|
+
* records and no snapshot shape carries a pk identity — the receiver always
|
|
143
|
+
* derives its own (see docs/sync.md § Row identity vs. address).
|
|
144
|
+
*/
|
|
145
|
+
export declare const SNAPSHOT_WIRE_FORMAT_VERSION = 1;
|
|
146
|
+
/**
|
|
147
|
+
* One column-version entry in a snapshot (streaming chunk or non-streaming
|
|
148
|
+
* table snapshot).
|
|
133
149
|
*/
|
|
134
150
|
export interface ColumnVersionEntry {
|
|
151
|
+
readonly column: string;
|
|
135
152
|
readonly hlc: HLC;
|
|
136
153
|
readonly value: SqlValue;
|
|
154
|
+
/**
|
|
155
|
+
* The row's raw pk (its ADDRESS). The pk IDENTITY deliberately does NOT
|
|
156
|
+
* travel: the receiver derives its own from this pk and its local table
|
|
157
|
+
* keying, so a sender with different keying (e.g. a raw-keyed relay) cannot
|
|
158
|
+
* file the receiver's bookkeeping under unreachable identities.
|
|
159
|
+
*/
|
|
160
|
+
readonly pk: SqlValue[];
|
|
137
161
|
}
|
|
138
162
|
/**
|
|
139
163
|
* Full snapshot of a table for initial sync or recovery.
|
|
@@ -141,15 +165,19 @@ export interface ColumnVersionEntry {
|
|
|
141
165
|
export interface TableSnapshot {
|
|
142
166
|
readonly schema: string;
|
|
143
167
|
readonly table: string;
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
168
|
+
/**
|
|
169
|
+
* Every live cell of the table, one record per `(row, column)` — the table's
|
|
170
|
+
* ONLY payload. Grouping cells into rows is the receiver's job (it groups by
|
|
171
|
+
* its own derived pk identity), so no pre-grouped row images travel.
|
|
172
|
+
*/
|
|
173
|
+
readonly columnVersions: ReadonlyArray<ColumnVersionEntry>;
|
|
147
174
|
}
|
|
148
175
|
/**
|
|
149
176
|
* A tombstone (deletion record) carried in a non-streaming snapshot. A GLOBAL
|
|
150
177
|
* collection on `Snapshot` (not nested under `TableSnapshot`) so a fully-deleted
|
|
151
178
|
* row — a tombstone with no live column-versions, hence no `TableSnapshot` — still
|
|
152
|
-
* travels. Mirrors the streaming `SnapshotTombstoneChunk` entry shape.
|
|
179
|
+
* travels. Mirrors the streaming `SnapshotTombstoneChunk` entry shape. Carries
|
|
180
|
+
* only the raw pk (the row's address); the receiver derives its own identity.
|
|
153
181
|
*/
|
|
154
182
|
export interface SnapshotTombstone {
|
|
155
183
|
readonly schema: string;
|
|
@@ -166,6 +194,8 @@ export interface SnapshotTombstone {
|
|
|
166
194
|
export interface Snapshot {
|
|
167
195
|
readonly siteId: SiteId;
|
|
168
196
|
readonly hlc: HLC;
|
|
197
|
+
/** Wire-format stamp; see {@link SNAPSHOT_WIRE_FORMAT_VERSION}. */
|
|
198
|
+
readonly snapshotFormat: number;
|
|
169
199
|
readonly tables: TableSnapshot[];
|
|
170
200
|
readonly schemaMigrations: SchemaMigration[];
|
|
171
201
|
/**
|
|
@@ -177,8 +207,18 @@ export interface Snapshot {
|
|
|
177
207
|
}
|
|
178
208
|
/**
|
|
179
209
|
* Snapshot chunk types for streaming.
|
|
210
|
+
*
|
|
211
|
+
* Listed in EMISSION ORDER, which is load-bearing — all DDL precedes all table data:
|
|
212
|
+
*
|
|
213
|
+
* header → schema-migration* → [table-start, column-versions*, table-end]*
|
|
214
|
+
* → tombstone* → footer
|
|
215
|
+
*
|
|
216
|
+
* The receiver flushes rows to the store in bounded batches rather than buffering
|
|
217
|
+
* the whole snapshot, and DDL only beats DML *within* one flush — so a `create
|
|
218
|
+
* table` emitted after its rows arrives too late for the flushes those rows already
|
|
219
|
+
* triggered. See docs/sync.md § Streaming Snapshot API.
|
|
180
220
|
*/
|
|
181
|
-
export type SnapshotChunkType = 'header' | '
|
|
221
|
+
export type SnapshotChunkType = 'header' | 'schema-migration' | 'table-start' | 'column-versions' | 'table-end' | 'tombstone' | 'footer';
|
|
182
222
|
/**
|
|
183
223
|
* Header chunk - sent first with metadata.
|
|
184
224
|
*/
|
|
@@ -186,6 +226,8 @@ export interface SnapshotHeaderChunk {
|
|
|
186
226
|
readonly type: 'header';
|
|
187
227
|
readonly siteId: SiteId;
|
|
188
228
|
readonly hlc: HLC;
|
|
229
|
+
/** Wire-format stamp; see {@link SNAPSHOT_WIRE_FORMAT_VERSION}. */
|
|
230
|
+
readonly snapshotFormat: number;
|
|
189
231
|
readonly tableCount: number;
|
|
190
232
|
readonly migrationCount: number;
|
|
191
233
|
/** Unique identifier for this snapshot transfer. */
|
|
@@ -208,8 +250,12 @@ export interface SnapshotColumnVersionsChunk {
|
|
|
208
250
|
readonly type: 'column-versions';
|
|
209
251
|
readonly schema: string;
|
|
210
252
|
readonly table: string;
|
|
211
|
-
/**
|
|
212
|
-
|
|
253
|
+
/**
|
|
254
|
+
* One record per live cell. No pk identity travels — the receiver groups
|
|
255
|
+
* cells into rows by DERIVING its own identity from each entry's raw pk
|
|
256
|
+
* (see {@link ColumnVersionEntry.pk}).
|
|
257
|
+
*/
|
|
258
|
+
readonly entries: ReadonlyArray<ColumnVersionEntry>;
|
|
213
259
|
}
|
|
214
260
|
/**
|
|
215
261
|
* Tombstone chunk - a batch of deletion records for one `(schema, table)`.
|
|
@@ -467,8 +513,13 @@ export interface SyncConfig {
|
|
|
467
513
|
retentionHorizonMs: number;
|
|
468
514
|
/**
|
|
469
515
|
* Whether deleted rows can be resurrected by later writes.
|
|
470
|
-
* If false (default), a
|
|
471
|
-
*
|
|
516
|
+
* If false (default), a tombstoned row blocks EVERY subsequent column write —
|
|
517
|
+
* regardless of the write's HLC — until the tombstone is pruned
|
|
518
|
+
* (see TombstoneStore.isDeletedAndBlocking).
|
|
519
|
+
* If true, an insert/update with HLC later than the tombstone's can resurrect
|
|
520
|
+
* a deleted row; writes at or before it stay blocked.
|
|
521
|
+
* A delete arriving in the same apply batch as column writes for its row blocks
|
|
522
|
+
* them by this same rule (change-applicator's in-batch reconciliation).
|
|
472
523
|
*/
|
|
473
524
|
allowResurrection: boolean;
|
|
474
525
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../../src/sync/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAM/C;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB;;;;;;OAMG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC;IAC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C,EAAE,MAAM,CAAC;IAEhB;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IAEpC;;;;;;;;;OASG;IACH,uBAAuB,EAAE,uBAAuB,CAAC;IAEjD;;;;;;;;OAQG;IACH,aAAa,CAAC,EAAE,mBAAmB,CAAC;IAEpC;;;;;;;OAOG;IACH,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,UAOjC,CAAC"}
|
|
@@ -5,6 +5,21 @@
|
|
|
5
5
|
* Applications can serialize these to JSON, MessagePack, protobuf, etc.
|
|
6
6
|
* and send via WebSocket, HTTP, WebRTC, or any other transport.
|
|
7
7
|
*/
|
|
8
|
+
/**
|
|
9
|
+
* Snapshot wire-format version, stamped into both snapshot forms (the streaming
|
|
10
|
+
* header chunk and the non-streaming `Snapshot`). Both apply paths REFUSE a
|
|
11
|
+
* snapshot whose stamp is missing or different, before touching any local state
|
|
12
|
+
* — same posture as the `fv:` sync-metadata format gate in `SyncManagerImpl.create`.
|
|
13
|
+
* Recovery is to regenerate the snapshot from a live peer (the coordinator's S3
|
|
14
|
+
* store persists serialized chunks at rest, so an old stored snapshot read by
|
|
15
|
+
* new code would otherwise silently mis-parse). Bump on ANY breaking change to
|
|
16
|
+
* snapshot entry shapes.
|
|
17
|
+
*
|
|
18
|
+
* Version 1: column-version entries are explicit `{ column, hlc, value, pk }`
|
|
19
|
+
* records and no snapshot shape carries a pk identity — the receiver always
|
|
20
|
+
* derives its own (see docs/sync.md § Row identity vs. address).
|
|
21
|
+
*/
|
|
22
|
+
export const SNAPSHOT_WIRE_FORMAT_VERSION = 1;
|
|
8
23
|
/**
|
|
9
24
|
* Default sync configuration.
|
|
10
25
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/sync/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/sync/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA6JH;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAC;AA0f9C;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAe;IAC7C,kBAAkB,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,EAAG,UAAU;IACzD,iBAAiB,EAAE,KAAK;IACxB,SAAS,EAAE,IAAI;IACf,uBAAuB,EAAE,YAAY;IACrC,aAAa,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;IAClC,eAAe,EAAE,IAAI;CACtB,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Receiver-side row identity for snapshot bootstrap.
|
|
3
|
+
*
|
|
4
|
+
* A snapshot carries only each entry's raw pk (the row's ADDRESS); no pk
|
|
5
|
+
* IDENTITY travels on the wire. Both apply paths — streaming
|
|
6
|
+
* (`snapshot-stream.ts`) and non-streaming (`snapshot.ts`) — therefore derive
|
|
7
|
+
* identity locally and reconcile the result, and they must do it identically:
|
|
8
|
+
* this module is the single definition of both halves.
|
|
9
|
+
*
|
|
10
|
+
* See docs/sync.md § Row identity vs. address.
|
|
11
|
+
*/
|
|
12
|
+
import type { SqlValue } from '@quereus/quereus';
|
|
13
|
+
import { type HLC } from '../clock/hlc.js';
|
|
14
|
+
import { type PkKeying } from '../metadata/keys.js';
|
|
15
|
+
import type { ColumnVersionEntry } from './protocol.js';
|
|
16
|
+
import type { SyncContext } from './sync-context.js';
|
|
17
|
+
/** Resolve a table's pk keying; see {@link createSnapshotKeyingResolver}. */
|
|
18
|
+
export type SnapshotKeyingResolver = (schema: string, table: string) => PkKeying;
|
|
19
|
+
/**
|
|
20
|
+
* One row's reconciled cells, keyed by column.
|
|
21
|
+
*
|
|
22
|
+
* `pk` is the row's address to apply: the spelling of the newest write in the
|
|
23
|
+
* row's equivalence class. Any spelling from the class is valid (they collapse
|
|
24
|
+
* to one identity); newest keeps the choice deterministic.
|
|
25
|
+
*/
|
|
26
|
+
export interface ReconciledRow {
|
|
27
|
+
pk: SqlValue[];
|
|
28
|
+
pkHlc: HLC;
|
|
29
|
+
cells: Map<string, {
|
|
30
|
+
hlc: HLC;
|
|
31
|
+
value: SqlValue;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Memoized per-`(schema, table)` keying lookup for one snapshot apply.
|
|
36
|
+
*
|
|
37
|
+
* A resolution failure (no local table definition, and none installed by the
|
|
38
|
+
* snapshot's own DDL) emits `status:'error'` before propagating, for parity with
|
|
39
|
+
* the data-apply failure path.
|
|
40
|
+
*/
|
|
41
|
+
export declare function createSnapshotKeyingResolver(ctx: SyncContext): SnapshotKeyingResolver;
|
|
42
|
+
/** Grouping key for one row across tables — see {@link joinKeyParts}. */
|
|
43
|
+
export declare function tableScopedRowKey(schema: string, table: string, identity: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Merge one snapshot cell into `rows` under the RECEIVER's derived identity.
|
|
46
|
+
*
|
|
47
|
+
* A sender with different keying (e.g. a raw-keyed relay with no schema oracle)
|
|
48
|
+
* can hold several records for what this receiver considers ONE row
|
|
49
|
+
* ('apple'/'APPLE' under `nocase`, 'PT1H'/'PT60M' for TIMESPAN). Keeping the
|
|
50
|
+
* greatest-HLC entry per `(identity, column)` resolves such a collapse by
|
|
51
|
+
* last-writer-wins rather than by chunk order, and leaves exactly one cell
|
|
52
|
+
* record + one change-log entry per surviving cell.
|
|
53
|
+
*/
|
|
54
|
+
export declare function reconcileCell(rows: Map<string, ReconciledRow>, entry: ColumnVersionEntry, keying: PkKeying): void;
|
|
55
|
+
/**
|
|
56
|
+
* Keep the greatest-HLC candidate per key — the tombstone counterpart of
|
|
57
|
+
* {@link reconcileCell} (a tombstone has no columns, so one winner per identity).
|
|
58
|
+
*/
|
|
59
|
+
export declare function keepMaxHLC<T extends {
|
|
60
|
+
readonly hlc: HLC;
|
|
61
|
+
}>(winners: Map<string, T>, key: string, candidate: T): void;
|
|
62
|
+
//# sourceMappingURL=snapshot-identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot-identity.d.ts","sourceRoot":"","sources":["../../../src/sync/snapshot-identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAc,KAAK,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAoB,KAAK,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,6EAA6E;AAC7E,MAAM,MAAM,sBAAsB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,QAAQ,CAAC;AAEjF;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC7B,EAAE,EAAE,QAAQ,EAAE,CAAC;IACf,KAAK,EAAE,GAAG,CAAC;IACX,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE;QAAE,GAAG,EAAE,GAAG,CAAC;QAAC,KAAK,EAAE,QAAQ,CAAA;KAAE,CAAC,CAAC;CAClD;AAWD;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAAC,GAAG,EAAE,WAAW,GAAG,sBAAsB,CAgBrF;AAED,yEAAyE;AACzE,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEzF;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC5B,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,EAChC,KAAK,EAAE,kBAAkB,EACzB,MAAM,EAAE,QAAQ,GACd,IAAI,CAeN;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAA;CAAE,EACzD,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,EACvB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,CAAC,GACV,IAAI,CAKN"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Receiver-side row identity for snapshot bootstrap.
|
|
3
|
+
*
|
|
4
|
+
* A snapshot carries only each entry's raw pk (the row's ADDRESS); no pk
|
|
5
|
+
* IDENTITY travels on the wire. Both apply paths — streaming
|
|
6
|
+
* (`snapshot-stream.ts`) and non-streaming (`snapshot.ts`) — therefore derive
|
|
7
|
+
* identity locally and reconcile the result, and they must do it identically:
|
|
8
|
+
* this module is the single definition of both halves.
|
|
9
|
+
*
|
|
10
|
+
* See docs/sync.md § Row identity vs. address.
|
|
11
|
+
*/
|
|
12
|
+
import { compareHLC } from '../clock/hlc.js';
|
|
13
|
+
import { encodePkIdentity } from '../metadata/keys.js';
|
|
14
|
+
import { toError } from './sync-context.js';
|
|
15
|
+
/**
|
|
16
|
+
* Length-prefixed join of components that may each contain any character (a
|
|
17
|
+
* quoted SQL identifier, an arbitrary pk identity), so no separator choice can
|
|
18
|
+
* let two distinct triples collide.
|
|
19
|
+
*/
|
|
20
|
+
function joinKeyParts(...parts) {
|
|
21
|
+
return parts.map(part => `${part.length}:${part}`).join('');
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Memoized per-`(schema, table)` keying lookup for one snapshot apply.
|
|
25
|
+
*
|
|
26
|
+
* A resolution failure (no local table definition, and none installed by the
|
|
27
|
+
* snapshot's own DDL) emits `status:'error'` before propagating, for parity with
|
|
28
|
+
* the data-apply failure path.
|
|
29
|
+
*/
|
|
30
|
+
export function createSnapshotKeyingResolver(ctx) {
|
|
31
|
+
const cache = new Map();
|
|
32
|
+
return (schema, table) => {
|
|
33
|
+
const cacheKey = joinKeyParts(schema, table);
|
|
34
|
+
let keying = cache.get(cacheKey);
|
|
35
|
+
if (!keying) {
|
|
36
|
+
try {
|
|
37
|
+
keying = ctx.getPkKeying(schema, table);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
ctx.syncEvents.emitSyncStateChange({ status: 'error', error: toError(error) });
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
cache.set(cacheKey, keying);
|
|
44
|
+
}
|
|
45
|
+
return keying;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** Grouping key for one row across tables — see {@link joinKeyParts}. */
|
|
49
|
+
export function tableScopedRowKey(schema, table, identity) {
|
|
50
|
+
return joinKeyParts(schema, table, identity);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Merge one snapshot cell into `rows` under the RECEIVER's derived identity.
|
|
54
|
+
*
|
|
55
|
+
* A sender with different keying (e.g. a raw-keyed relay with no schema oracle)
|
|
56
|
+
* can hold several records for what this receiver considers ONE row
|
|
57
|
+
* ('apple'/'APPLE' under `nocase`, 'PT1H'/'PT60M' for TIMESPAN). Keeping the
|
|
58
|
+
* greatest-HLC entry per `(identity, column)` resolves such a collapse by
|
|
59
|
+
* last-writer-wins rather than by chunk order, and leaves exactly one cell
|
|
60
|
+
* record + one change-log entry per surviving cell.
|
|
61
|
+
*/
|
|
62
|
+
export function reconcileCell(rows, entry, keying) {
|
|
63
|
+
const identity = encodePkIdentity(entry.pk, keying);
|
|
64
|
+
let row = rows.get(identity);
|
|
65
|
+
if (!row) {
|
|
66
|
+
row = { pk: entry.pk, pkHlc: entry.hlc, cells: new Map() };
|
|
67
|
+
rows.set(identity, row);
|
|
68
|
+
}
|
|
69
|
+
else if (compareHLC(entry.hlc, row.pkHlc) > 0) {
|
|
70
|
+
row.pk = entry.pk;
|
|
71
|
+
row.pkHlc = entry.hlc;
|
|
72
|
+
}
|
|
73
|
+
const cell = row.cells.get(entry.column);
|
|
74
|
+
if (!cell || compareHLC(entry.hlc, cell.hlc) > 0) {
|
|
75
|
+
row.cells.set(entry.column, { hlc: entry.hlc, value: entry.value });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Keep the greatest-HLC candidate per key — the tombstone counterpart of
|
|
80
|
+
* {@link reconcileCell} (a tombstone has no columns, so one winner per identity).
|
|
81
|
+
*/
|
|
82
|
+
export function keepMaxHLC(winners, key, candidate) {
|
|
83
|
+
const prev = winners.get(key);
|
|
84
|
+
if (!prev || compareHLC(candidate.hlc, prev.hlc) > 0) {
|
|
85
|
+
winners.set(key, candidate);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=snapshot-identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot-identity.js","sourceRoot":"","sources":["../../../src/sync/snapshot-identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,UAAU,EAAY,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAiB,MAAM,qBAAqB,CAAC;AAGtE,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAkB5C;;;;GAIG;AACH,SAAS,YAAY,CAAC,GAAG,KAAe;IACvC,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,4BAA4B,CAAC,GAAgB;IAC5D,MAAM,KAAK,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC1C,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QACxB,MAAM,QAAQ,GAAG,YAAY,CAAC,MAAM,EAAE,KA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GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QACjD,GAAG,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC;QAClB,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC;IACvB,CAAC;IAED,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACzC,IAAI,CAAC,IAAI,IAAI,UAAU,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QAClD,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;IACrE,CAAC;AACF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU,CACzB,OAAuB,EACvB,GAAW,EACX,SAAY;IAEZ,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAI,CAAC,IAAI,IAAI,UAAU,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QACtD,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IAC7B,CAAC;AACF,CAAC"}
|
|
@@ -5,8 +5,15 @@
|
|
|
5
5
|
* management for memory-efficient sync of large databases.
|
|
6
6
|
*/
|
|
7
7
|
import type { SnapshotCheckpoint } from './manager.js';
|
|
8
|
-
import type
|
|
8
|
+
import { type SnapshotChunk, type SnapshotProgress } from './protocol.js';
|
|
9
9
|
import type { SyncContext } from './sync-context.js';
|
|
10
|
+
/**
|
|
11
|
+
* Row changes `applySnapshotStream` accumulates before pushing them to the store.
|
|
12
|
+
*
|
|
13
|
+
* Exported so specs that must exceed this bound (to exercise a mid-table flush)
|
|
14
|
+
* derive their row counts from it rather than restating the literal.
|
|
15
|
+
*/
|
|
16
|
+
export declare const DATA_FLUSH_SIZE = 100;
|
|
10
17
|
/**
|
|
11
18
|
* Stream a snapshot as chunks for memory-efficient transfer.
|
|
12
19
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot-stream.d.ts","sourceRoot":"","sources":["../../../src/sync/snapshot-stream.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAqBH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"snapshot-stream.d.ts","sourceRoot":"","sources":["../../../src/sync/snapshot-stream.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAqBH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAEN,KAAK,aAAa,EAClB,KAAK,gBAAgB,EAWrB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAgBrD;;;;;GAKG;AACH,eAAO,MAAM,eAAe,MAAM,CAAC;AAwNnC;;GAEG;AACH,wBAAuB,iBAAiB,CACvC,GAAG,EAAE,WAAW,EAChB,SAAS,GAAE,MAAoC,GAC7C,aAAa,CAAC,aAAa,CAAC,CAO9B;AAED;;GAEG;AACH,wBAAuB,oBAAoB,CAC1C,GAAG,EAAE,WAAW,EAChB,UAAU,EAAE,kBAAkB,GAC5B,aAAa,CAAC,aAAa,CAAC,CAS9B;AAiED;;GAEG;AACH,wBAAsB,mBAAmB,CACxC,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,aAAa,CAAC,aAAa,CAAC,EACpC,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,gBAAgB,KAAK,IAAI,GAC/C,OAAO,CAAC,IAAI,CAAC,CA0Vf;AAcD;;GAEG;AACH,wBAAsB,qBAAqB,CAC1C,GAAG,EAAE,WAAW,EAChB,UAAU,EAAE,MAAM,GAChB,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC,CAkBzC"}
|