@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
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
BucketParameterQuerier,
|
|
3
3
|
BucketPriority,
|
|
4
4
|
BucketSource,
|
|
5
|
+
BucketSourceType,
|
|
5
6
|
HydratedSyncConfig,
|
|
6
7
|
mergeBuckets,
|
|
7
8
|
QuerierError,
|
|
@@ -22,9 +23,24 @@ import {
|
|
|
22
23
|
} from '@powersync/lib-services-framework';
|
|
23
24
|
import { JwtPayload } from '../auth/JwtPayload.js';
|
|
24
25
|
import { ParameterSetLimitExceededError } from '../storage/storage-index.js';
|
|
26
|
+
import { PerformanceTracer } from '../tracing/PerformanceTracer.js';
|
|
25
27
|
import { SyncContext } from './SyncContext.js';
|
|
26
28
|
import { getIntersection, hasIntersection } from './util.js';
|
|
27
29
|
|
|
30
|
+
export type SyncCheckpointTraceCategory =
|
|
31
|
+
// buildNextCheckpointLine, excluding parameter computation and checksum lookups
|
|
32
|
+
| 'checkpoint'
|
|
33
|
+
// Parameter lookups
|
|
34
|
+
| 'parameters'
|
|
35
|
+
// Checksum calculations
|
|
36
|
+
| 'checksum'
|
|
37
|
+
// Waiting for a data lock to become available
|
|
38
|
+
| 'acquiring_lock'
|
|
39
|
+
// Data fetches. Holds one data lock for this period.
|
|
40
|
+
| 'bucket_data'
|
|
41
|
+
// Sending data to client, may include serialization overhead. Holds one data lock for this period in most cases.
|
|
42
|
+
| 'sending';
|
|
43
|
+
|
|
28
44
|
export interface BucketChecksumStateOptions {
|
|
29
45
|
syncContext: SyncContext;
|
|
30
46
|
bucketStorage: BucketChecksumStateStorage;
|
|
@@ -60,6 +76,12 @@ export class BucketChecksumState {
|
|
|
60
76
|
*/
|
|
61
77
|
private lastChecksums: util.ChecksumMap | null = null;
|
|
62
78
|
private lastWriteCheckpoint: bigint | null = null;
|
|
79
|
+
/**
|
|
80
|
+
* The next storage checkpoint diff may be relative to a checksum-invalidated
|
|
81
|
+
* checkpoint that was never sent to the client. Re-check every bucket once
|
|
82
|
+
* instead of applying that diff to the last client-visible checksums.
|
|
83
|
+
*/
|
|
84
|
+
private forceFullChecksumForNextCheckpoint = false;
|
|
63
85
|
/**
|
|
64
86
|
* Once we've sent the first full checkpoint line including all {@link util.Checkpoint.streams} that the user is
|
|
65
87
|
* subscribed to, we keep an index of the stream names to their index in that array.
|
|
@@ -101,6 +123,10 @@ export class BucketChecksumState {
|
|
|
101
123
|
}
|
|
102
124
|
}
|
|
103
125
|
|
|
126
|
+
invalidateChecksumBaseline() {
|
|
127
|
+
this.forceFullChecksumForNextCheckpoint = true;
|
|
128
|
+
}
|
|
129
|
+
|
|
104
130
|
/**
|
|
105
131
|
* Build a new checkpoint line for an underlying storage checkpoint update if any buckets have changed.
|
|
106
132
|
*
|
|
@@ -112,14 +138,20 @@ export class BucketChecksumState {
|
|
|
112
138
|
* @param next The updated checkpoint
|
|
113
139
|
* @returns A {@link CheckpointLine} if any of the buckets watched by this connected was updated, or otherwise `null`.
|
|
114
140
|
*/
|
|
115
|
-
async buildNextCheckpointLine(
|
|
141
|
+
async buildNextCheckpointLine(
|
|
142
|
+
next: storage.StorageCheckpointUpdate,
|
|
143
|
+
tracer?: PerformanceTracer<SyncCheckpointTraceCategory>
|
|
144
|
+
): Promise<CheckpointLine | null> {
|
|
145
|
+
tracer ??= new PerformanceTracer<SyncCheckpointTraceCategory>(`sync checkpoint ${next.base.checkpoint}`);
|
|
146
|
+
|
|
116
147
|
const { writeCheckpoint, base } = next;
|
|
117
148
|
const userIdForLogs = this.parameterState.syncParams.userId;
|
|
118
149
|
|
|
119
150
|
const storage = this.bucketStorage;
|
|
120
151
|
|
|
121
|
-
const update = await this.parameterState.getCheckpointUpdate(next);
|
|
152
|
+
const update = await this.parameterState.getCheckpointUpdate(next, tracer);
|
|
122
153
|
const { buckets: allBuckets, updatedBuckets, usedParameterResults } = update;
|
|
154
|
+
const forceFullChecksum = this.forceFullChecksumForNextCheckpoint;
|
|
123
155
|
|
|
124
156
|
/** Set of all buckets in this checkpoint. */
|
|
125
157
|
const bucketDescriptionMap = new Map(allBuckets.map((b) => [b.bucket, b]));
|
|
@@ -144,8 +176,9 @@ export class BucketChecksumState {
|
|
|
144
176
|
const count = bucketsByDefinition.get(definition) ?? 0;
|
|
145
177
|
bucketsByDefinition.set(definition, count + 1);
|
|
146
178
|
}
|
|
147
|
-
|
|
148
|
-
const
|
|
179
|
+
// Only 1 type is allowed per sync config
|
|
180
|
+
const bucketSourceType = this.parameterState.syncRules.bucketSourceDefinitions[0].type;
|
|
181
|
+
const breakdown = formatBucketDefinitionBreakdown(bucketsByDefinition, bucketSourceType);
|
|
149
182
|
errorMessage += breakdown.message;
|
|
150
183
|
logData.buckets_by_definition = breakdown.countsByDefinition;
|
|
151
184
|
|
|
@@ -154,13 +187,14 @@ export class BucketChecksumState {
|
|
|
154
187
|
}
|
|
155
188
|
|
|
156
189
|
let checksumMap: util.ChecksumMap;
|
|
157
|
-
if (updatedBuckets != INVALIDATE_ALL_BUCKETS) {
|
|
190
|
+
if (!forceFullChecksum && updatedBuckets != INVALIDATE_ALL_BUCKETS) {
|
|
158
191
|
if (this.lastChecksums == null) {
|
|
159
192
|
throw new ServiceAssertionError(`Bucket diff received without existing checksums`);
|
|
160
193
|
}
|
|
161
194
|
|
|
162
195
|
// Re-check updated buckets only
|
|
163
196
|
let checksumLookups: storage.BucketChecksumRequest[] = [];
|
|
197
|
+
let hasNewBucket = false;
|
|
164
198
|
|
|
165
199
|
let newChecksums = new Map<string, util.BucketChecksum>();
|
|
166
200
|
for (let desc of bucketDescriptionMap.values()) {
|
|
@@ -174,11 +208,17 @@ export class BucketChecksumState {
|
|
|
174
208
|
newChecksums.set(desc.bucket, existing);
|
|
175
209
|
} else {
|
|
176
210
|
checksumLookups.push({ bucket: desc.bucket, source: desc.source });
|
|
211
|
+
hasNewBucket ||= !this.lastChecksums.has(desc.bucket);
|
|
177
212
|
}
|
|
178
213
|
}
|
|
179
214
|
|
|
180
215
|
if (checksumLookups.length > 0) {
|
|
181
|
-
|
|
216
|
+
const requestHint: storage.BucketRequestHint = hasNewBucket ? 'bulk' : 'incremental';
|
|
217
|
+
let updatedChecksums: util.ChecksumMap;
|
|
218
|
+
|
|
219
|
+
using _ = tracer.span('checksum');
|
|
220
|
+
updatedChecksums = await storage.getChecksums(base, checksumLookups, { requestHint });
|
|
221
|
+
|
|
182
222
|
for (let [bucket, value] of updatedChecksums.entries()) {
|
|
183
223
|
newChecksums.set(bucket, value);
|
|
184
224
|
}
|
|
@@ -186,12 +226,23 @@ export class BucketChecksumState {
|
|
|
186
226
|
checksumMap = newChecksums;
|
|
187
227
|
} else {
|
|
188
228
|
// Re-check all buckets
|
|
189
|
-
const
|
|
190
|
-
|
|
229
|
+
const hasNewBucket =
|
|
230
|
+
this.lastChecksums == null ||
|
|
231
|
+
[...bucketDescriptionMap.values()].some((b) => !this.lastChecksums!.has(b.bucket));
|
|
232
|
+
const requestHint: storage.BucketRequestHint = hasNewBucket ? 'bulk' : 'incremental';
|
|
233
|
+
const bucketList = [...bucketDescriptionMap.values()].map((b) => ({
|
|
234
|
+
bucket: b.bucket,
|
|
235
|
+
source: b.source
|
|
236
|
+
}));
|
|
237
|
+
|
|
238
|
+
using _ = tracer.span('checksum');
|
|
239
|
+
checksumMap = await storage.getChecksums(base, bucketList, { requestHint });
|
|
191
240
|
}
|
|
192
241
|
|
|
193
242
|
// Subset of buckets for which there may be new data in this batch.
|
|
194
243
|
let bucketsToFetch: ResolvedBucket[];
|
|
244
|
+
let bucketDataRequestHint: storage.BucketRequestHint;
|
|
245
|
+
const newBucketDownloads = new Set<string>();
|
|
195
246
|
|
|
196
247
|
let checkpointLine: util.StreamingSyncCheckpointDiff | util.StreamingSyncCheckpoint;
|
|
197
248
|
|
|
@@ -210,6 +261,9 @@ export class BucketChecksumState {
|
|
|
210
261
|
diff.updatedBuckets.length == 0
|
|
211
262
|
) {
|
|
212
263
|
// No changes - don't send anything to the client
|
|
264
|
+
if (forceFullChecksum) {
|
|
265
|
+
this.forceFullChecksumForNextCheckpoint = false;
|
|
266
|
+
}
|
|
213
267
|
return null;
|
|
214
268
|
}
|
|
215
269
|
|
|
@@ -232,6 +286,12 @@ export class BucketChecksumState {
|
|
|
232
286
|
bucketsToFetch = [...generateBucketsToFetch].map((b) => {
|
|
233
287
|
return bucketDescriptionMap.get(b)!;
|
|
234
288
|
});
|
|
289
|
+
for (const bucket of diff.updatedBuckets) {
|
|
290
|
+
if (!this.lastChecksums!.has(bucket.bucket)) {
|
|
291
|
+
newBucketDownloads.add(bucket.bucket);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
bucketDataRequestHint = newBucketDownloads.size > 0 ? 'bulk' : 'incremental';
|
|
235
295
|
|
|
236
296
|
deferredLog = () => {
|
|
237
297
|
let message = `Updated checkpoint: ${base.checkpoint} | `;
|
|
@@ -280,6 +340,10 @@ export class BucketChecksumState {
|
|
|
280
340
|
);
|
|
281
341
|
};
|
|
282
342
|
bucketsToFetch = allBuckets;
|
|
343
|
+
for (const bucket of bucketsToFetch) {
|
|
344
|
+
newBucketDownloads.add(bucket.bucket);
|
|
345
|
+
}
|
|
346
|
+
bucketDataRequestHint = 'bulk';
|
|
283
347
|
|
|
284
348
|
const subscriptions: util.StreamDescription[] = [];
|
|
285
349
|
const streamNameToIndex = new Map<string, number>();
|
|
@@ -321,6 +385,7 @@ export class BucketChecksumState {
|
|
|
321
385
|
return {
|
|
322
386
|
checkpointLine,
|
|
323
387
|
bucketsToFetch,
|
|
388
|
+
bucketDataRequestHint,
|
|
324
389
|
advance: () => {
|
|
325
390
|
hasAdvanced = true;
|
|
326
391
|
// bucketDataPositions must be updated in-place - it represents the current state of
|
|
@@ -353,6 +418,9 @@ export class BucketChecksumState {
|
|
|
353
418
|
this.lastChecksums = checksumMap;
|
|
354
419
|
this.lastWriteCheckpoint = writeCheckpoint;
|
|
355
420
|
this.pendingBucketDownloads = pendingBucketDownloads;
|
|
421
|
+
if (forceFullChecksum) {
|
|
422
|
+
this.forceFullChecksumForNextCheckpoint = false;
|
|
423
|
+
}
|
|
356
424
|
deferredLog();
|
|
357
425
|
},
|
|
358
426
|
|
|
@@ -512,12 +580,15 @@ export class BucketParameterState {
|
|
|
512
580
|
return (desc.subscribedToByDefault && this.includeDefaultStreams) || this.subscribedStreamNames.has(desc.name);
|
|
513
581
|
}
|
|
514
582
|
|
|
515
|
-
async getCheckpointUpdate(
|
|
583
|
+
async getCheckpointUpdate(
|
|
584
|
+
checkpoint: storage.StorageCheckpointUpdate,
|
|
585
|
+
tracer: PerformanceTracer<SyncCheckpointTraceCategory>
|
|
586
|
+
): Promise<CheckpointUpdate> {
|
|
516
587
|
const querier = this.querier;
|
|
517
588
|
let update: CheckpointUpdate;
|
|
518
589
|
if (querier.hasDynamicBuckets) {
|
|
519
590
|
try {
|
|
520
|
-
update = await this.getCheckpointUpdateDynamic(checkpoint);
|
|
591
|
+
update = await this.getCheckpointUpdateDynamic(checkpoint, tracer);
|
|
521
592
|
} catch (e: unknown) {
|
|
522
593
|
if (e instanceof ParameterSetLimitExceededError) {
|
|
523
594
|
// Too many parameter results, create a breakdown of which streams are responsible for the most queries and
|
|
@@ -580,7 +651,10 @@ export class BucketParameterState {
|
|
|
580
651
|
/**
|
|
581
652
|
* For dynamic buckets, we need to re-query the list of buckets every time.
|
|
582
653
|
*/
|
|
583
|
-
private async getCheckpointUpdateDynamic(
|
|
654
|
+
private async getCheckpointUpdateDynamic(
|
|
655
|
+
checkpoint: storage.StorageCheckpointUpdate,
|
|
656
|
+
tracer: PerformanceTracer<SyncCheckpointTraceCategory>
|
|
657
|
+
): Promise<CheckpointUpdate> {
|
|
584
658
|
const querier = this.querier;
|
|
585
659
|
const staticBuckets = this.staticBuckets.values();
|
|
586
660
|
const update = checkpoint.update;
|
|
@@ -636,6 +710,7 @@ export class BucketParameterState {
|
|
|
636
710
|
}
|
|
637
711
|
|
|
638
712
|
try {
|
|
713
|
+
using _ = tracer.span('parameters', definition);
|
|
639
714
|
const results = await checkpoint.base.getParameterSets(lookups, remainingBudget);
|
|
640
715
|
const numRows = results.reduce((a, b) => a + b.rows.length, 0);
|
|
641
716
|
|
|
@@ -692,6 +767,7 @@ export class BucketParameterState {
|
|
|
692
767
|
export interface CheckpointLine {
|
|
693
768
|
checkpointLine: util.StreamingSyncCheckpointDiff | util.StreamingSyncCheckpoint;
|
|
694
769
|
bucketsToFetch: ResolvedBucket[];
|
|
770
|
+
bucketDataRequestHint: storage.BucketRequestHint;
|
|
695
771
|
|
|
696
772
|
/**
|
|
697
773
|
* Call when a checkpoint line is being sent to a client, to update the internal state.
|
|
@@ -738,30 +814,36 @@ function logCheckpoint(
|
|
|
738
814
|
}
|
|
739
815
|
|
|
740
816
|
/**
|
|
741
|
-
* Format a breakdown of dynamic
|
|
817
|
+
* Format a breakdown of dynamic buckets by sync stream or legacy bucket definition.
|
|
742
818
|
*
|
|
743
|
-
* Sorts definitions by count (descending), includes the top
|
|
819
|
+
* Sorts definitions by count (descending), includes the top 100, and returns both the
|
|
744
820
|
* formatted message string and the counts record suitable for structured log data.
|
|
745
821
|
*/
|
|
746
|
-
function formatBucketDefinitionBreakdown(
|
|
822
|
+
function formatBucketDefinitionBreakdown(
|
|
823
|
+
bucketsByDefinition: Map<string, number>,
|
|
824
|
+
bucketSourceType: BucketSourceType
|
|
825
|
+
): {
|
|
747
826
|
message: string;
|
|
748
827
|
countsByDefinition: Record<string, number>;
|
|
749
828
|
} {
|
|
750
|
-
|
|
829
|
+
const maxLoggedDefinitions = 100;
|
|
830
|
+
|
|
831
|
+
// Sort definitions by count (descending) and take the largest entries.
|
|
751
832
|
const allSorted = Array.from(bucketsByDefinition.entries()).sort((a, b) => b[1] - a[1]);
|
|
752
|
-
const sortedDefinitions = allSorted.slice(0,
|
|
833
|
+
const sortedDefinitions = allSorted.slice(0, maxLoggedDefinitions);
|
|
753
834
|
|
|
754
|
-
|
|
835
|
+
const sourceLabel = bucketSourceType == BucketSourceType.SYNC_STREAM ? 'sync stream' : 'bucket definition';
|
|
836
|
+
let message = `\nBuckets by ${sourceLabel}:`;
|
|
755
837
|
const countsByDefinition: Record<string, number> = {};
|
|
756
838
|
for (const [definition, count] of sortedDefinitions) {
|
|
757
839
|
message += `\n ${definition}: ${count}`;
|
|
758
840
|
countsByDefinition[definition] = count;
|
|
759
841
|
}
|
|
760
842
|
|
|
761
|
-
if (allSorted.length >
|
|
762
|
-
const remainingResults = allSorted.slice(
|
|
763
|
-
const remainingDefinitions = allSorted.length -
|
|
764
|
-
message += `\n ... and ${remainingResults} more
|
|
843
|
+
if (allSorted.length > maxLoggedDefinitions) {
|
|
844
|
+
const remainingResults = allSorted.slice(maxLoggedDefinitions).reduce((sum, [, count]) => sum + count, 0);
|
|
845
|
+
const remainingDefinitions = allSorted.length - maxLoggedDefinitions;
|
|
846
|
+
message += `\n ... and ${remainingResults} more buckets from ${remainingDefinitions} ${sourceLabel}s`;
|
|
765
847
|
}
|
|
766
848
|
|
|
767
849
|
return { message, countsByDefinition };
|
|
@@ -15,6 +15,8 @@ export class RequestTracker {
|
|
|
15
15
|
largeBuckets: Record<string, number> = {};
|
|
16
16
|
|
|
17
17
|
private encoding: string | undefined = undefined;
|
|
18
|
+
private lastCheckpointLogOperationsSynced = 0;
|
|
19
|
+
private lastCheckpointLogDataSyncedBytes = 0;
|
|
18
20
|
|
|
19
21
|
constructor(private metrics: MetricsEngine) {
|
|
20
22
|
this.metrics = metrics;
|
|
@@ -68,6 +70,19 @@ export class RequestTracker {
|
|
|
68
70
|
encoding: this.encoding
|
|
69
71
|
};
|
|
70
72
|
}
|
|
73
|
+
|
|
74
|
+
getIncrementalCheckpointStats(): CheckpointLogStats {
|
|
75
|
+
const operationsSynced = this.operationsSynced - this.lastCheckpointLogOperationsSynced;
|
|
76
|
+
const dataSyncedBytes = this.dataSyncedBytes - this.lastCheckpointLogDataSyncedBytes;
|
|
77
|
+
|
|
78
|
+
this.lastCheckpointLogOperationsSynced = this.operationsSynced;
|
|
79
|
+
this.lastCheckpointLogDataSyncedBytes = this.dataSyncedBytes;
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
operations_synced: operationsSynced,
|
|
83
|
+
data_synced_bytes: dataSyncedBytes
|
|
84
|
+
};
|
|
85
|
+
}
|
|
71
86
|
}
|
|
72
87
|
|
|
73
88
|
export interface OperationCounts {
|
|
@@ -83,6 +98,11 @@ export interface OperationsSentStats {
|
|
|
83
98
|
total: number;
|
|
84
99
|
}
|
|
85
100
|
|
|
101
|
+
export interface CheckpointLogStats {
|
|
102
|
+
operations_synced: number;
|
|
103
|
+
data_synced_bytes: number;
|
|
104
|
+
}
|
|
105
|
+
|
|
86
106
|
export function statsForBatch(batch: SyncBucketData): OperationsSentStats {
|
|
87
107
|
let put = 0;
|
|
88
108
|
let remove = 0;
|