@powersync/service-core 0.0.0-dev-20260602073133 → 0.0.0-dev-20260803144812
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/CHANGELOG.md +83 -4
- package/dist/api/RouteAPI.d.ts +42 -14
- package/dist/api/diagnostics.d.ts +12 -1
- package/dist/api/diagnostics.js +34 -22
- package/dist/api/diagnostics.js.map +1 -1
- package/dist/entry/commands/compact-action.js +5 -1
- package/dist/entry/commands/compact-action.js.map +1 -1
- package/dist/modules/AbstractModule.d.ts +6 -2
- package/dist/modules/AbstractModule.js.map +1 -1
- package/dist/replication/AbstractReplicator.d.ts +26 -7
- package/dist/replication/AbstractReplicator.js +148 -68
- package/dist/replication/AbstractReplicator.js.map +1 -1
- package/dist/replication/ReplicationModule.d.ts +3 -3
- package/dist/replication/ReplicationModule.js.map +1 -1
- package/dist/routes/RouterEngine.d.ts +1 -0
- package/dist/routes/RouterEngine.js +6 -1
- package/dist/routes/RouterEngine.js.map +1 -1
- package/dist/routes/configure-fastify.d.ts +95 -56
- package/dist/routes/configure-fastify.js +15 -2
- package/dist/routes/configure-fastify.js.map +1 -1
- package/dist/routes/endpoints/admin.d.ts +24 -24
- package/dist/routes/endpoints/admin.js +46 -35
- package/dist/routes/endpoints/admin.js.map +1 -1
- package/dist/routes/endpoints/checkpointing.d.ts +62 -0
- package/dist/routes/endpoints/checkpointing.js +65 -7
- package/dist/routes/endpoints/checkpointing.js.map +1 -1
- package/dist/routes/endpoints/socket-route.js +3 -2
- package/dist/routes/endpoints/socket-route.js.map +1 -1
- package/dist/routes/endpoints/sync-rules.js +22 -13
- package/dist/routes/endpoints/sync-rules.js.map +1 -1
- package/dist/routes/endpoints/sync-stream.js +1 -1
- package/dist/routes/endpoints/sync-stream.js.map +1 -1
- package/dist/runner/teardown.js +8 -8
- package/dist/runner/teardown.js.map +1 -1
- package/dist/storage/BucketStorageBatch.d.ts +63 -17
- package/dist/storage/BucketStorageBatch.js.map +1 -1
- package/dist/storage/BucketStorageFactory.d.ts +22 -27
- package/dist/storage/BucketStorageFactory.js +4 -18
- package/dist/storage/BucketStorageFactory.js.map +1 -1
- package/dist/storage/CheckpointChecksumInvalidatedError.d.ts +12 -0
- package/dist/storage/CheckpointChecksumInvalidatedError.js +17 -0
- package/dist/storage/CheckpointChecksumInvalidatedError.js.map +1 -0
- package/dist/storage/ChecksumCache.d.ts +11 -6
- package/dist/storage/ChecksumCache.js +5 -4
- package/dist/storage/ChecksumCache.js.map +1 -1
- package/dist/storage/ParsedSyncConfigSet.d.ts +23 -0
- package/dist/storage/ParsedSyncConfigSet.js +2 -0
- package/dist/storage/ParsedSyncConfigSet.js.map +1 -0
- package/dist/storage/PersistedReplicationStream.d.ts +32 -0
- package/dist/storage/PersistedReplicationStream.js +26 -0
- package/dist/storage/PersistedReplicationStream.js.map +1 -0
- package/dist/storage/PersistedSyncConfigContent.d.ts +63 -0
- package/dist/storage/PersistedSyncConfigContent.js +125 -0
- package/dist/storage/PersistedSyncConfigContent.js.map +1 -0
- package/dist/storage/PersistedSyncConfigStatus.d.ts +13 -0
- package/dist/storage/PersistedSyncConfigStatus.js +2 -0
- package/dist/storage/PersistedSyncConfigStatus.js.map +1 -0
- package/dist/storage/SourceEntity.d.ts +6 -0
- package/dist/storage/SourceTable.d.ts +21 -3
- package/dist/storage/SourceTable.js +26 -3
- package/dist/storage/SourceTable.js.map +1 -1
- package/dist/storage/SyncRulesBucketStorage.d.ts +119 -21
- package/dist/storage/SyncRulesBucketStorage.js +3 -0
- package/dist/storage/SyncRulesBucketStorage.js.map +1 -1
- package/dist/storage/WriteCheckpointAPI.d.ts +60 -3
- package/dist/storage/WriteCheckpointAPI.js +33 -0
- package/dist/storage/WriteCheckpointAPI.js.map +1 -1
- package/dist/storage/implementation/BucketDefinitionMapping.d.ts +117 -0
- package/dist/storage/implementation/BucketDefinitionMapping.js +277 -0
- package/dist/storage/implementation/BucketDefinitionMapping.js.map +1 -0
- package/dist/storage/implementation/IncrementalReprocessingCompatibility.d.ts +6 -0
- package/dist/storage/implementation/IncrementalReprocessingCompatibility.js +31 -0
- package/dist/storage/implementation/IncrementalReprocessingCompatibility.js.map +1 -0
- package/dist/storage/implementation/IncrementalReprocessingSyncConfigLog.d.ts +17 -0
- package/dist/storage/implementation/IncrementalReprocessingSyncConfigLog.js +62 -0
- package/dist/storage/implementation/IncrementalReprocessingSyncConfigLog.js.map +1 -0
- package/dist/storage/implementation/ReplicationStreamStorageIds.d.ts +15 -0
- package/dist/storage/implementation/ReplicationStreamStorageIds.js +20 -0
- package/dist/storage/implementation/ReplicationStreamStorageIds.js.map +1 -0
- package/dist/storage/storage-index.d.ts +9 -1
- package/dist/storage/storage-index.js +9 -1
- package/dist/storage/storage-index.js.map +1 -1
- package/dist/sync/BucketChecksumState.d.ts +12 -2
- package/dist/sync/BucketChecksumState.js +69 -21
- package/dist/sync/BucketChecksumState.js.map +1 -1
- package/dist/sync/RequestTracker.d.ts +7 -0
- package/dist/sync/RequestTracker.js +12 -0
- package/dist/sync/RequestTracker.js.map +1 -1
- package/dist/sync/sync.js +154 -41
- package/dist/sync/sync.js.map +1 -1
- package/dist/sync/util.d.ts +5 -0
- package/dist/sync/util.js +9 -0
- package/dist/sync/util.js.map +1 -1
- package/dist/system/ServiceContext.d.ts +2 -0
- package/dist/system/ServiceContext.js +2 -0
- package/dist/system/ServiceContext.js.map +1 -1
- package/dist/tracing/PerformanceTracer.d.ts +23 -1
- package/dist/tracing/PerformanceTracer.js +11 -0
- package/dist/tracing/PerformanceTracer.js.map +1 -1
- package/dist/util/checkpointing.d.ts +4 -8
- package/dist/util/checkpointing.js +1 -16
- package/dist/util/checkpointing.js.map +1 -1
- package/dist/util/config/compound-config-collector.js +18 -2
- package/dist/util/config/compound-config-collector.js.map +1 -1
- package/dist/util/config/defaults.d.ts +2 -0
- package/dist/util/config/defaults.js +2 -0
- package/dist/util/config/defaults.js.map +1 -1
- package/dist/util/config/types.d.ts +3 -1
- package/dist/util/lsn.d.ts +4 -0
- package/dist/util/lsn.js +10 -0
- package/dist/util/lsn.js.map +1 -1
- package/dist/util/util-index.d.ts +1 -0
- package/dist/util/util-index.js +1 -0
- package/dist/util/util-index.js.map +1 -1
- package/dist/util/utils.d.ts +1 -1
- package/dist/util/utils.js +1 -1
- package/dist/util/write-checkpoint-batcher.d.ts +19 -0
- package/dist/util/write-checkpoint-batcher.js +100 -0
- package/dist/util/write-checkpoint-batcher.js.map +1 -0
- package/package.json +6 -7
- package/src/api/RouteAPI.ts +43 -14
- package/src/api/diagnostics.ts +43 -26
- package/src/entry/commands/compact-action.ts +7 -1
- package/src/modules/AbstractModule.ts +6 -2
- package/src/replication/AbstractReplicator.ts +181 -72
- package/src/replication/ReplicationModule.ts +2 -3
- package/src/routes/RouterEngine.ts +7 -1
- package/src/routes/configure-fastify.ts +25 -2
- package/src/routes/endpoints/admin.ts +72 -50
- package/src/routes/endpoints/checkpointing.ts +79 -8
- package/src/routes/endpoints/socket-route.ts +3 -2
- package/src/routes/endpoints/sync-rules.ts +23 -13
- package/src/routes/endpoints/sync-stream.ts +1 -1
- package/src/runner/teardown.ts +8 -8
- package/src/storage/BucketStorageBatch.ts +64 -18
- package/src/storage/BucketStorageFactory.ts +30 -39
- package/src/storage/CheckpointChecksumInvalidatedError.ts +17 -0
- package/src/storage/ChecksumCache.ts +27 -14
- package/src/storage/ParsedSyncConfigSet.ts +25 -0
- package/src/storage/PersistedReplicationStream.ts +55 -0
- package/src/storage/PersistedSyncConfigContent.ts +192 -0
- package/src/storage/PersistedSyncConfigStatus.ts +14 -0
- package/src/storage/SourceEntity.ts +6 -0
- package/src/storage/SourceTable.ts +34 -3
- package/src/storage/SyncRulesBucketStorage.ts +138 -22
- package/src/storage/WriteCheckpointAPI.ts +108 -3
- package/src/storage/implementation/BucketDefinitionMapping.ts +436 -0
- package/src/storage/implementation/IncrementalReprocessingCompatibility.ts +41 -0
- package/src/storage/implementation/IncrementalReprocessingSyncConfigLog.ts +109 -0
- package/src/storage/implementation/ReplicationStreamStorageIds.ts +21 -0
- package/src/storage/storage-index.ts +10 -1
- package/src/sync/BucketChecksumState.ts +103 -21
- package/src/sync/RequestTracker.ts +20 -0
- package/src/sync/sync.ts +183 -48
- package/src/sync/util.ts +12 -0
- package/src/system/ServiceContext.ts +7 -0
- package/src/tracing/PerformanceTracer.ts +41 -1
- package/src/util/checkpointing.ts +4 -22
- package/src/util/config/compound-config-collector.ts +25 -1
- package/src/util/config/defaults.ts +2 -0
- package/src/util/config/types.ts +3 -1
- package/src/util/lsn.ts +9 -0
- package/src/util/util-index.ts +1 -0
- package/src/util/utils.ts +1 -1
- package/src/util/write-checkpoint-batcher.ts +142 -0
- package/test/src/AbstractReplicator.test.ts +115 -0
- package/test/src/checksum_cache.test.ts +22 -0
- package/test/src/config.test.ts +102 -0
- package/test/src/diagnostics.test.ts +62 -34
- package/test/src/module-loader.test.ts +33 -1
- package/test/src/routes/admin.test.ts +182 -18
- package/test/src/routes/checkpointing.test.ts +54 -0
- package/test/src/routes/mocks.ts +6 -2
- package/test/src/storage/SourceTable.test.ts +89 -0
- package/test/src/sync/BucketChecksumState.test.ts +98 -12
- package/test/src/sync/util.test.ts +13 -1
- package/test/src/util/checkpointing.test.ts +249 -0
- package/tsconfig.json +1 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/storage/PersistedSyncRulesContent.d.ts +0 -59
- package/dist/storage/PersistedSyncRulesContent.js +0 -100
- package/dist/storage/PersistedSyncRulesContent.js.map +0 -1
- package/src/storage/PersistedSyncRulesContent.ts +0 -174
|
@@ -10,7 +10,8 @@ import { PerformanceTracer } from '../tracing/PerformanceTracer.js';
|
|
|
10
10
|
import * as util from '../util/util-index.js';
|
|
11
11
|
import { BucketStorageBatch, FlushedResult, SaveUpdate } from './BucketStorageBatch.js';
|
|
12
12
|
import { BucketStorageFactory } from './BucketStorageFactory.js';
|
|
13
|
-
import {
|
|
13
|
+
import { ParsedSyncConfigSet } from './ParsedSyncConfigSet.js';
|
|
14
|
+
import { ParseSyncConfigOptions } from './PersistedSyncConfigContent.js';
|
|
14
15
|
import { SourceEntityDescriptor } from './SourceEntity.js';
|
|
15
16
|
import { SourceTable } from './SourceTable.js';
|
|
16
17
|
import { StorageVersionConfig } from './StorageVersionConfig.js';
|
|
@@ -18,25 +19,35 @@ import { SyncStorageWriteCheckpointAPI } from './WriteCheckpointAPI.js';
|
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* Storage for a specific replication stream.
|
|
22
|
+
*
|
|
23
|
+
* Replication writes source changes, source table metadata, snapshot progress,
|
|
24
|
+
* resume positions, and checkpoint boundaries through this interface. The sync
|
|
25
|
+
* API reads the same stream state as checkpoints, checksums, bucket data,
|
|
26
|
+
* parameter lookup rows, and write-checkpoint acknowledgements.
|
|
21
27
|
*/
|
|
22
28
|
export interface SyncRulesBucketStorage
|
|
23
29
|
extends ObserverClient<SyncRulesBucketStorageListener>,
|
|
24
30
|
SyncStorageWriteCheckpointAPI {
|
|
25
|
-
readonly
|
|
26
|
-
readonly
|
|
31
|
+
readonly replicationStreamId: number;
|
|
32
|
+
readonly replicationStreamName: string;
|
|
27
33
|
readonly storageConfig: StorageVersionConfig;
|
|
28
34
|
|
|
29
35
|
readonly factory: BucketStorageFactory;
|
|
30
36
|
readonly logger: Logger;
|
|
31
37
|
|
|
32
38
|
/**
|
|
33
|
-
* Create a
|
|
39
|
+
* Create a writer for a source-specific unit of replication work.
|
|
34
40
|
*
|
|
35
|
-
* The writer
|
|
41
|
+
* The writer may be used for a long-running streaming attempt, a table
|
|
42
|
+
* snapshot, a page of snapshot work, or a short setup step. Pending work
|
|
43
|
+
* that should be persisted must be flushed, committed, or kept alive at the
|
|
44
|
+
* appropriate source boundary before the writer is disposed.
|
|
36
45
|
*/
|
|
37
46
|
createWriter(options: CreateWriterOptions): Promise<BucketStorageBatch>;
|
|
38
47
|
|
|
39
48
|
/**
|
|
49
|
+
* Callback wrapper around `createWriter()`.
|
|
50
|
+
*
|
|
40
51
|
* @deprecated Use `createWriter()` with `await using` instead.
|
|
41
52
|
*/
|
|
42
53
|
startBatch(
|
|
@@ -44,7 +55,20 @@ export interface SyncRulesBucketStorage
|
|
|
44
55
|
callback: (batch: BucketStorageBatch) => Promise<void>
|
|
45
56
|
): Promise<FlushedResult | null>;
|
|
46
57
|
|
|
47
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Get the canonical parsed sync config set for the given parse options.
|
|
60
|
+
*
|
|
61
|
+
* Repeated calls with the same options return the same instance for the lifetime of
|
|
62
|
+
* this storage instance. This is the identity boundary for parsed sync config state:
|
|
63
|
+
* all operations against this storage instance must use parsed objects from sets
|
|
64
|
+
* returned here, never from an independent parse of the same content.
|
|
65
|
+
*/
|
|
66
|
+
getParsedSyncConfigSet(options: ParseSyncConfigOptions): ParsedSyncConfigSet;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Shortcut for `getParsedSyncConfigSet(options).hydratedSyncConfig`.
|
|
70
|
+
*/
|
|
71
|
+
getParsedSyncRules(options: ParseSyncConfigOptions): HydratedSyncConfig;
|
|
48
72
|
|
|
49
73
|
/**
|
|
50
74
|
* Terminate the replication stream.
|
|
@@ -55,7 +79,7 @@ export interface SyncRulesBucketStorage
|
|
|
55
79
|
*/
|
|
56
80
|
terminate(options?: TerminateOptions): Promise<void>;
|
|
57
81
|
|
|
58
|
-
getStatus(): Promise<
|
|
82
|
+
getStatus(): Promise<ReplicationStreamStatus>;
|
|
59
83
|
|
|
60
84
|
/**
|
|
61
85
|
* Clear the storage, without changing state.
|
|
@@ -89,7 +113,7 @@ export interface SyncRulesBucketStorage
|
|
|
89
113
|
*
|
|
90
114
|
* This is a best-effort optimization:
|
|
91
115
|
* 1. This may include more changes than what actually occurred.
|
|
92
|
-
* 2. This may return invalidateDataBuckets or invalidateParameterBuckets instead of
|
|
116
|
+
* 2. This may return invalidateDataBuckets or invalidateParameterBuckets instead of returning
|
|
93
117
|
* specific changes.
|
|
94
118
|
* @param options
|
|
95
119
|
*/
|
|
@@ -109,15 +133,22 @@ export interface SyncRulesBucketStorage
|
|
|
109
133
|
* 1. Separate buckets.
|
|
110
134
|
* 2. Limit the size of each individual chunk according to options.batchSizeLimitBytes.
|
|
111
135
|
*
|
|
136
|
+
* The batch may not contain all data for the checkpoint, if the checkpoint is large. The caller must
|
|
137
|
+
* continue querying if either:
|
|
138
|
+
* 1. The last chunk for any bucket has has_more = true.
|
|
139
|
+
* 2. A SyncBucketDataBatchEnd is returned with hasMore = true.
|
|
140
|
+
*
|
|
141
|
+
* The first check can be skipped if a SyncBucketDataBatchEnd is returned with hasMore = false.
|
|
142
|
+
*
|
|
112
143
|
* @param checkpoint the checkpoint
|
|
113
144
|
* @param dataBuckets current bucket states
|
|
114
145
|
* @param options batch size options
|
|
115
146
|
*/
|
|
116
147
|
getBucketDataBatch(
|
|
117
|
-
checkpoint:
|
|
148
|
+
checkpoint: ReplicationCheckpoint,
|
|
118
149
|
dataBuckets: BucketDataRequest[],
|
|
119
150
|
options?: BucketDataBatchOptions
|
|
120
|
-
): AsyncIterable<SyncBucketDataChunk>;
|
|
151
|
+
): AsyncIterable<SyncBucketDataChunk | SyncBucketDataBatchEnd>;
|
|
121
152
|
|
|
122
153
|
/**
|
|
123
154
|
* Compute checksums for a given list of buckets.
|
|
@@ -127,12 +158,22 @@ export interface SyncRulesBucketStorage
|
|
|
127
158
|
* This may be slow, depending on the size of the buckets.
|
|
128
159
|
* The checksums are cached internally to compensate for this, but does not cover all cases.
|
|
129
160
|
*/
|
|
130
|
-
getChecksums(
|
|
161
|
+
getChecksums(
|
|
162
|
+
checkpoint: ReplicationCheckpoint,
|
|
163
|
+
buckets: BucketChecksumRequest[],
|
|
164
|
+
options?: BucketChecksumOptions
|
|
165
|
+
): Promise<util.ChecksumMap>;
|
|
131
166
|
|
|
132
167
|
/**
|
|
133
168
|
* Clear checksum cache. Primarily intended for tests.
|
|
134
169
|
*/
|
|
135
170
|
clearChecksumCache(): void;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Optional storage-provider cleanup for sync configs that have been stopped
|
|
174
|
+
* inside this replication stream.
|
|
175
|
+
*/
|
|
176
|
+
cleanupStoppedSyncConfigs?(options: CleanupStoppedSyncConfigsOptions): Promise<CleanupStoppedSyncConfigsResult>;
|
|
136
177
|
}
|
|
137
178
|
|
|
138
179
|
export interface SyncRulesBucketStorageListener {
|
|
@@ -149,35 +190,56 @@ export interface BucketChecksumRequest {
|
|
|
149
190
|
source: BucketDataSource;
|
|
150
191
|
}
|
|
151
192
|
|
|
152
|
-
export interface
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
193
|
+
export interface BucketChecksumOptions {
|
|
194
|
+
requestHint?: BucketRequestHint;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export type BucketRequestHint = 'bulk' | 'incremental';
|
|
198
|
+
|
|
199
|
+
export interface ReplicationStreamStatus {
|
|
200
|
+
/**
|
|
201
|
+
* Source position to resume replication from.
|
|
202
|
+
*/
|
|
203
|
+
resumeLsn: string | null;
|
|
157
204
|
/**
|
|
158
|
-
*
|
|
205
|
+
* True if _every_ active/processing sync config has a client-visible checkpoint.
|
|
159
206
|
*/
|
|
160
|
-
|
|
207
|
+
snapshotDone: boolean;
|
|
161
208
|
}
|
|
162
209
|
export interface ResolveTablesOptions {
|
|
163
210
|
connection_id: number;
|
|
211
|
+
/**
|
|
212
|
+
* Source table or collection metadata discovered during snapshot or streaming.
|
|
213
|
+
*/
|
|
164
214
|
source: SourceEntityDescriptor;
|
|
165
215
|
/**
|
|
166
216
|
* For tests only - custom id generator for stable ids.
|
|
167
217
|
*/
|
|
168
218
|
idGenerator?: () => string | bson.ObjectId;
|
|
169
219
|
/**
|
|
170
|
-
* For tests only - override the sync
|
|
220
|
+
* For tests only - override the parsed sync config set used.
|
|
171
221
|
*/
|
|
172
|
-
|
|
222
|
+
parsedSyncConfig?: ParsedSyncConfigSet;
|
|
173
223
|
}
|
|
174
224
|
|
|
175
225
|
export interface ResolveTablesResult {
|
|
226
|
+
/**
|
|
227
|
+
* Current source table mappings that should receive replicated data.
|
|
228
|
+
*/
|
|
176
229
|
tables: SourceTable[];
|
|
230
|
+
/**
|
|
231
|
+
* Outdated source table mappings that should be removed by the connector.
|
|
232
|
+
*/
|
|
177
233
|
dropTables: SourceTable[];
|
|
178
234
|
}
|
|
179
235
|
|
|
180
|
-
|
|
236
|
+
/**
|
|
237
|
+
* Options for creating a storage writer.
|
|
238
|
+
*/
|
|
239
|
+
export interface CreateWriterOptions extends ParseSyncConfigOptions {
|
|
240
|
+
/**
|
|
241
|
+
* Source-specific zero or empty replication position.
|
|
242
|
+
*/
|
|
181
243
|
zeroLSN: string;
|
|
182
244
|
/**
|
|
183
245
|
* Whether or not to store a copy of the current data.
|
|
@@ -253,6 +315,13 @@ export interface CompactOptions {
|
|
|
253
315
|
|
|
254
316
|
compactParameterData?: boolean;
|
|
255
317
|
|
|
318
|
+
/**
|
|
319
|
+
* Delete client-requested write checkpoints created before this time.
|
|
320
|
+
*
|
|
321
|
+
* Generated write checkpoints are not affected.
|
|
322
|
+
*/
|
|
323
|
+
deleteCheckpointRequestsBefore?: Date;
|
|
324
|
+
|
|
256
325
|
/** Minimum of 2 */
|
|
257
326
|
clearBatchLimit?: number;
|
|
258
327
|
|
|
@@ -262,6 +331,9 @@ export interface CompactOptions {
|
|
|
262
331
|
/** Minimum of 1 */
|
|
263
332
|
moveBatchQueryLimit?: number;
|
|
264
333
|
|
|
334
|
+
/** Byte cap per read batch for streaming compaction. Default 16MB. */
|
|
335
|
+
moveBatchByteLimit?: number;
|
|
336
|
+
|
|
265
337
|
/**
|
|
266
338
|
* Minimum number new operations in a bucket to trigger compaction of that bucket.
|
|
267
339
|
*
|
|
@@ -287,7 +359,14 @@ export interface CompactOptions {
|
|
|
287
359
|
}
|
|
288
360
|
|
|
289
361
|
export interface PopulateChecksumCacheOptions {
|
|
290
|
-
|
|
362
|
+
/**
|
|
363
|
+
* Compute checksums up to this op id.
|
|
364
|
+
*
|
|
365
|
+
* Defaults to the highest persisted op id for the replication stream, which covers
|
|
366
|
+
* the common case of populating the cache right after initial replication, before
|
|
367
|
+
* the first checkpoint exists.
|
|
368
|
+
*/
|
|
369
|
+
maxOpId?: util.InternalOpId;
|
|
291
370
|
minBucketChanges?: number;
|
|
292
371
|
signal?: AbortSignal;
|
|
293
372
|
}
|
|
@@ -303,6 +382,24 @@ export interface ClearStorageOptions {
|
|
|
303
382
|
signal?: AbortSignal;
|
|
304
383
|
}
|
|
305
384
|
|
|
385
|
+
export interface CleanupStoppedSyncConfigsOptions {
|
|
386
|
+
signal?: AbortSignal;
|
|
387
|
+
logger?: Logger;
|
|
388
|
+
defaultSchema: string;
|
|
389
|
+
sourceConnectionTag: string;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
export interface CleanupStoppedSyncConfigsResult {
|
|
393
|
+
stoppedSyncConfigsRemoved: number;
|
|
394
|
+
bucketDataCollectionsDropped: number;
|
|
395
|
+
parameterIndexCollectionsDropped: number;
|
|
396
|
+
/** Best-effort number, not accurate if the operation takes longer than the timeout. */
|
|
397
|
+
bucketStateDocumentsDeleted: number;
|
|
398
|
+
sourceRecordCollectionsDropped: number;
|
|
399
|
+
sourceTablesUpdated: number;
|
|
400
|
+
sourceTablesDeleted: number;
|
|
401
|
+
}
|
|
402
|
+
|
|
306
403
|
export interface TerminateOptions extends ClearStorageOptions {
|
|
307
404
|
/**
|
|
308
405
|
* If true, also clear the storage before terminating.
|
|
@@ -311,6 +408,11 @@ export interface TerminateOptions extends ClearStorageOptions {
|
|
|
311
408
|
}
|
|
312
409
|
|
|
313
410
|
export interface BucketDataBatchOptions {
|
|
411
|
+
requestHint?: BucketRequestHint;
|
|
412
|
+
|
|
413
|
+
/** Abort any in-progress work for this batch, including object-storage downloads. */
|
|
414
|
+
signal?: AbortSignal;
|
|
415
|
+
|
|
314
416
|
/** Limit number of documents returned. Defaults to 1000. */
|
|
315
417
|
limit?: number;
|
|
316
418
|
|
|
@@ -331,6 +433,20 @@ export interface SyncBucketDataChunk {
|
|
|
331
433
|
targetOp: util.InternalOpId | null;
|
|
332
434
|
}
|
|
333
435
|
|
|
436
|
+
export interface SyncBucketDataBatchEnd {
|
|
437
|
+
/**
|
|
438
|
+
* True if there may be more data for this checkpoint, and the caller should continue querying.
|
|
439
|
+
*
|
|
440
|
+
* This is different from `SyncBucketDataChunk.has_more`, which is per-bucket. This is a global signal for the
|
|
441
|
+
* entire request, and may be true even if there is no returned chunk with has_more: true.
|
|
442
|
+
*/
|
|
443
|
+
hasMore: boolean;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
export function isBatchEnd(chunk: SyncBucketDataChunk | SyncBucketDataBatchEnd): chunk is SyncBucketDataBatchEnd {
|
|
447
|
+
return (chunk as SyncBucketDataBatchEnd).hasMore !== undefined;
|
|
448
|
+
}
|
|
449
|
+
|
|
334
450
|
export interface ReplicationCheckpoint {
|
|
335
451
|
readonly checkpoint: util.InternalOpId;
|
|
336
452
|
readonly lsn: string | null;
|
|
@@ -19,6 +19,18 @@ export interface BaseWriteCheckpointIdentifier {
|
|
|
19
19
|
user_id: string;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
export interface ClientRequestedCheckpointOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Supplied for client-generated checkpoint requests.
|
|
25
|
+
*
|
|
26
|
+
* If omitted, storage creates or stores a regular write checkpoint.
|
|
27
|
+
* If supplied for managed write checkpoints, storage only uses it when it is
|
|
28
|
+
* greater than the stored id for the user_id. Same or lower supplied ids are
|
|
29
|
+
* no-ops, and storage returns the current stored id.
|
|
30
|
+
*/
|
|
31
|
+
checkpoint_request_id?: bigint;
|
|
32
|
+
}
|
|
33
|
+
|
|
22
34
|
export interface CustomWriteCheckpointFilters extends BaseWriteCheckpointIdentifier {
|
|
23
35
|
/**
|
|
24
36
|
* Replication stream which was active when this checkpoint was created.
|
|
@@ -28,9 +40,17 @@ export interface CustomWriteCheckpointFilters extends BaseWriteCheckpointIdentif
|
|
|
28
40
|
|
|
29
41
|
export interface BatchedCustomWriteCheckpointOptions extends BaseWriteCheckpointIdentifier {
|
|
30
42
|
/**
|
|
31
|
-
* A supplied incrementing
|
|
43
|
+
* A supplied incrementing checkpoint request id. This is still named
|
|
44
|
+
* "write checkpoint" in storage APIs for backwards compatibility.
|
|
32
45
|
*/
|
|
33
46
|
checkpoint: bigint;
|
|
47
|
+
/**
|
|
48
|
+
* Required when this custom checkpoint was created from a client checkpoint
|
|
49
|
+
* request and should be eligible for checkpoint request retention cleanup.
|
|
50
|
+
* Omit or set to null for persistent custom checkpoints owned by the source
|
|
51
|
+
* or integration.
|
|
52
|
+
*/
|
|
53
|
+
checkpoint_requested_at?: Date | null;
|
|
34
54
|
}
|
|
35
55
|
|
|
36
56
|
export interface CustomWriteCheckpointOptions extends BatchedCustomWriteCheckpointOptions {
|
|
@@ -50,7 +70,90 @@ export interface ManagedWriteCheckpointFilters extends BaseWriteCheckpointIdenti
|
|
|
50
70
|
heads: Record<string, string>;
|
|
51
71
|
}
|
|
52
72
|
|
|
53
|
-
export type ManagedWriteCheckpointOptions = ManagedWriteCheckpointFilters;
|
|
73
|
+
export type ManagedWriteCheckpointOptions = ManagedWriteCheckpointFilters & ClientRequestedCheckpointOptions;
|
|
74
|
+
|
|
75
|
+
export interface CreateManagedWriteCheckpointsResult {
|
|
76
|
+
/**
|
|
77
|
+
* Current managed checkpoint id for each full user_id after applying the batch.
|
|
78
|
+
*/
|
|
79
|
+
writeCheckpoints: Map<string, bigint>;
|
|
80
|
+
/**
|
|
81
|
+
* True when the source marker must be forced so replication observes the
|
|
82
|
+
* stored head. Callers use this to advance the source marker once for the
|
|
83
|
+
* whole batch.
|
|
84
|
+
*
|
|
85
|
+
* This must be true whenever a checkpoint in the batch has not yet been
|
|
86
|
+
* processed by replication - both freshly created/advanced checkpoints and
|
|
87
|
+
* existing checkpoints matched by a stale or duplicate request that are still
|
|
88
|
+
* pending. Already-processed checkpoints do not need a new marker.
|
|
89
|
+
*
|
|
90
|
+
* The case this guards against is a lost source marker on a stale retry. The
|
|
91
|
+
* source marker is forced after the checkpoint is persisted, so the two are
|
|
92
|
+
* not atomic (storage and source are usually different databases). Without
|
|
93
|
+
* this flag, the following sequence strands the checkpoint:
|
|
94
|
+
*
|
|
95
|
+
* 1. A client-supplied checkpoint id is persisted (write checkpoint stored,
|
|
96
|
+
* processed_at_lsn null).
|
|
97
|
+
* 2. Forcing the source marker fails, so the request errors and the client
|
|
98
|
+
* retries with the same id.
|
|
99
|
+
* 3. The retry is a no-op for the stored id (monotonic, not greater), so if
|
|
100
|
+
* we only advanced on "a row changed" we would skip the marker.
|
|
101
|
+
* 4. On an idle source nothing else moves replication past the stored head,
|
|
102
|
+
* so the checkpoint never gets acknowledged and the client waits forever.
|
|
103
|
+
*
|
|
104
|
+
* Reporting true while the checkpoint is still pending makes the retry re-force
|
|
105
|
+
* the marker, which resolves the wait.
|
|
106
|
+
*
|
|
107
|
+
* Backends that do not track a per-row processed indicator may conservatively
|
|
108
|
+
* report true whenever any checkpoint was matched.
|
|
109
|
+
*/
|
|
110
|
+
shouldAdvance: boolean;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function uniqueManagedWriteCheckpoints(
|
|
114
|
+
checkpoints: ManagedWriteCheckpointOptions[]
|
|
115
|
+
): ManagedWriteCheckpointOptions[] {
|
|
116
|
+
const byUser = new Map<string, ManagedWriteCheckpointOptions>();
|
|
117
|
+
|
|
118
|
+
for (const checkpoint of checkpoints) {
|
|
119
|
+
const existing = byUser.get(checkpoint.user_id);
|
|
120
|
+
// A batch can contain entries for many users, and different users may use
|
|
121
|
+
// different request types (generated vs client-supplied). For a single full
|
|
122
|
+
// user_id, though, all entries should be the same type - a batch can still
|
|
123
|
+
// hold multiple entries for that user (e.g. coalesced requests), so we
|
|
124
|
+
// collapse them to one. For client-supplied ids we keep the greatest
|
|
125
|
+
// requested value, so lower stale ids cannot hide the request that should
|
|
126
|
+
// advance storage. For generated ids the entries are equivalent, so any one
|
|
127
|
+
// is kept.
|
|
128
|
+
//
|
|
129
|
+
// Mixing generated and supplied entries for the same user_id is not expected;
|
|
130
|
+
// shouldReplaceManagedWriteCheckpoint still resolves it deterministically
|
|
131
|
+
// (supplied wins) if that invariant is ever violated.
|
|
132
|
+
if (existing == null || shouldReplaceManagedWriteCheckpoint(existing, checkpoint)) {
|
|
133
|
+
byUser.set(checkpoint.user_id, checkpoint);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return [...byUser.values()];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function shouldReplaceManagedWriteCheckpoint(
|
|
141
|
+
existing: ManagedWriteCheckpointOptions,
|
|
142
|
+
candidate: ManagedWriteCheckpointOptions
|
|
143
|
+
) {
|
|
144
|
+
const existingRequestId = existing.checkpoint_request_id;
|
|
145
|
+
const candidateRequestId = candidate.checkpoint_request_id;
|
|
146
|
+
|
|
147
|
+
if (candidateRequestId == null) {
|
|
148
|
+
return existingRequestId == null;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (existingRequestId == null) {
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return candidateRequestId > existingRequestId;
|
|
156
|
+
}
|
|
54
157
|
|
|
55
158
|
export type SyncStorageLastWriteCheckpointFilters = BaseWriteCheckpointIdentifier | ManagedWriteCheckpointFilters;
|
|
56
159
|
export type LastWriteCheckpointFilters = CustomWriteCheckpointFilters | ManagedWriteCheckpointFilters;
|
|
@@ -58,7 +161,9 @@ export type LastWriteCheckpointFilters = CustomWriteCheckpointFilters | ManagedW
|
|
|
58
161
|
export interface BaseWriteCheckpointAPI {
|
|
59
162
|
readonly writeCheckpointMode: WriteCheckpointMode;
|
|
60
163
|
setWriteCheckpointMode(mode: WriteCheckpointMode): void;
|
|
61
|
-
|
|
164
|
+
createManagedWriteCheckpoints(
|
|
165
|
+
checkpoints: ManagedWriteCheckpointOptions[]
|
|
166
|
+
): Promise<CreateManagedWriteCheckpointsResult>;
|
|
62
167
|
}
|
|
63
168
|
|
|
64
169
|
/**
|