@powersync/service-core 0.0.0-dev-20260601140105 → 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.
Files changed (183) hide show
  1. package/CHANGELOG.md +83 -4
  2. package/dist/api/RouteAPI.d.ts +42 -14
  3. package/dist/api/diagnostics.d.ts +12 -1
  4. package/dist/api/diagnostics.js +34 -22
  5. package/dist/api/diagnostics.js.map +1 -1
  6. package/dist/entry/commands/compact-action.js +5 -1
  7. package/dist/entry/commands/compact-action.js.map +1 -1
  8. package/dist/modules/AbstractModule.d.ts +6 -2
  9. package/dist/modules/AbstractModule.js.map +1 -1
  10. package/dist/replication/AbstractReplicator.d.ts +26 -7
  11. package/dist/replication/AbstractReplicator.js +148 -68
  12. package/dist/replication/AbstractReplicator.js.map +1 -1
  13. package/dist/replication/ReplicationModule.d.ts +3 -3
  14. package/dist/replication/ReplicationModule.js.map +1 -1
  15. package/dist/routes/RouterEngine.d.ts +1 -0
  16. package/dist/routes/RouterEngine.js +6 -1
  17. package/dist/routes/RouterEngine.js.map +1 -1
  18. package/dist/routes/configure-fastify.d.ts +95 -56
  19. package/dist/routes/configure-fastify.js +15 -2
  20. package/dist/routes/configure-fastify.js.map +1 -1
  21. package/dist/routes/endpoints/admin.d.ts +24 -24
  22. package/dist/routes/endpoints/admin.js +46 -35
  23. package/dist/routes/endpoints/admin.js.map +1 -1
  24. package/dist/routes/endpoints/checkpointing.d.ts +62 -0
  25. package/dist/routes/endpoints/checkpointing.js +65 -7
  26. package/dist/routes/endpoints/checkpointing.js.map +1 -1
  27. package/dist/routes/endpoints/socket-route.js +3 -2
  28. package/dist/routes/endpoints/socket-route.js.map +1 -1
  29. package/dist/routes/endpoints/sync-rules.js +22 -13
  30. package/dist/routes/endpoints/sync-rules.js.map +1 -1
  31. package/dist/routes/endpoints/sync-stream.js +1 -1
  32. package/dist/routes/endpoints/sync-stream.js.map +1 -1
  33. package/dist/runner/teardown.js +8 -8
  34. package/dist/runner/teardown.js.map +1 -1
  35. package/dist/storage/BucketStorageBatch.d.ts +63 -17
  36. package/dist/storage/BucketStorageBatch.js.map +1 -1
  37. package/dist/storage/BucketStorageFactory.d.ts +22 -27
  38. package/dist/storage/BucketStorageFactory.js +4 -18
  39. package/dist/storage/BucketStorageFactory.js.map +1 -1
  40. package/dist/storage/CheckpointChecksumInvalidatedError.d.ts +12 -0
  41. package/dist/storage/CheckpointChecksumInvalidatedError.js +17 -0
  42. package/dist/storage/CheckpointChecksumInvalidatedError.js.map +1 -0
  43. package/dist/storage/ChecksumCache.d.ts +11 -6
  44. package/dist/storage/ChecksumCache.js +5 -4
  45. package/dist/storage/ChecksumCache.js.map +1 -1
  46. package/dist/storage/ParsedSyncConfigSet.d.ts +23 -0
  47. package/dist/storage/ParsedSyncConfigSet.js +2 -0
  48. package/dist/storage/ParsedSyncConfigSet.js.map +1 -0
  49. package/dist/storage/PersistedReplicationStream.d.ts +32 -0
  50. package/dist/storage/PersistedReplicationStream.js +26 -0
  51. package/dist/storage/PersistedReplicationStream.js.map +1 -0
  52. package/dist/storage/PersistedSyncConfigContent.d.ts +63 -0
  53. package/dist/storage/PersistedSyncConfigContent.js +125 -0
  54. package/dist/storage/PersistedSyncConfigContent.js.map +1 -0
  55. package/dist/storage/PersistedSyncConfigStatus.d.ts +13 -0
  56. package/dist/storage/PersistedSyncConfigStatus.js +2 -0
  57. package/dist/storage/PersistedSyncConfigStatus.js.map +1 -0
  58. package/dist/storage/SourceEntity.d.ts +6 -0
  59. package/dist/storage/SourceTable.d.ts +21 -3
  60. package/dist/storage/SourceTable.js +26 -3
  61. package/dist/storage/SourceTable.js.map +1 -1
  62. package/dist/storage/SyncRulesBucketStorage.d.ts +119 -21
  63. package/dist/storage/SyncRulesBucketStorage.js +3 -0
  64. package/dist/storage/SyncRulesBucketStorage.js.map +1 -1
  65. package/dist/storage/WriteCheckpointAPI.d.ts +60 -3
  66. package/dist/storage/WriteCheckpointAPI.js +33 -0
  67. package/dist/storage/WriteCheckpointAPI.js.map +1 -1
  68. package/dist/storage/implementation/BucketDefinitionMapping.d.ts +117 -0
  69. package/dist/storage/implementation/BucketDefinitionMapping.js +277 -0
  70. package/dist/storage/implementation/BucketDefinitionMapping.js.map +1 -0
  71. package/dist/storage/implementation/IncrementalReprocessingCompatibility.d.ts +6 -0
  72. package/dist/storage/implementation/IncrementalReprocessingCompatibility.js +31 -0
  73. package/dist/storage/implementation/IncrementalReprocessingCompatibility.js.map +1 -0
  74. package/dist/storage/implementation/IncrementalReprocessingSyncConfigLog.d.ts +17 -0
  75. package/dist/storage/implementation/IncrementalReprocessingSyncConfigLog.js +62 -0
  76. package/dist/storage/implementation/IncrementalReprocessingSyncConfigLog.js.map +1 -0
  77. package/dist/storage/implementation/ReplicationStreamStorageIds.d.ts +15 -0
  78. package/dist/storage/implementation/ReplicationStreamStorageIds.js +20 -0
  79. package/dist/storage/implementation/ReplicationStreamStorageIds.js.map +1 -0
  80. package/dist/storage/storage-index.d.ts +9 -1
  81. package/dist/storage/storage-index.js +9 -1
  82. package/dist/storage/storage-index.js.map +1 -1
  83. package/dist/sync/BucketChecksumState.d.ts +12 -2
  84. package/dist/sync/BucketChecksumState.js +69 -21
  85. package/dist/sync/BucketChecksumState.js.map +1 -1
  86. package/dist/sync/RequestTracker.d.ts +7 -0
  87. package/dist/sync/RequestTracker.js +12 -0
  88. package/dist/sync/RequestTracker.js.map +1 -1
  89. package/dist/sync/sync.js +154 -41
  90. package/dist/sync/sync.js.map +1 -1
  91. package/dist/sync/util.d.ts +5 -0
  92. package/dist/sync/util.js +9 -0
  93. package/dist/sync/util.js.map +1 -1
  94. package/dist/system/ServiceContext.d.ts +2 -0
  95. package/dist/system/ServiceContext.js +2 -0
  96. package/dist/system/ServiceContext.js.map +1 -1
  97. package/dist/tracing/PerformanceTracer.d.ts +23 -1
  98. package/dist/tracing/PerformanceTracer.js +11 -0
  99. package/dist/tracing/PerformanceTracer.js.map +1 -1
  100. package/dist/util/checkpointing.d.ts +4 -8
  101. package/dist/util/checkpointing.js +1 -16
  102. package/dist/util/checkpointing.js.map +1 -1
  103. package/dist/util/config/compound-config-collector.js +18 -2
  104. package/dist/util/config/compound-config-collector.js.map +1 -1
  105. package/dist/util/config/defaults.d.ts +2 -0
  106. package/dist/util/config/defaults.js +2 -0
  107. package/dist/util/config/defaults.js.map +1 -1
  108. package/dist/util/config/types.d.ts +3 -1
  109. package/dist/util/lsn.d.ts +4 -0
  110. package/dist/util/lsn.js +10 -0
  111. package/dist/util/lsn.js.map +1 -1
  112. package/dist/util/util-index.d.ts +1 -0
  113. package/dist/util/util-index.js +1 -0
  114. package/dist/util/util-index.js.map +1 -1
  115. package/dist/util/utils.d.ts +1 -1
  116. package/dist/util/utils.js +1 -1
  117. package/dist/util/write-checkpoint-batcher.d.ts +19 -0
  118. package/dist/util/write-checkpoint-batcher.js +100 -0
  119. package/dist/util/write-checkpoint-batcher.js.map +1 -0
  120. package/package.json +6 -7
  121. package/src/api/RouteAPI.ts +43 -14
  122. package/src/api/diagnostics.ts +43 -26
  123. package/src/entry/commands/compact-action.ts +7 -1
  124. package/src/modules/AbstractModule.ts +6 -2
  125. package/src/replication/AbstractReplicator.ts +181 -72
  126. package/src/replication/ReplicationModule.ts +2 -3
  127. package/src/routes/RouterEngine.ts +7 -1
  128. package/src/routes/configure-fastify.ts +25 -2
  129. package/src/routes/endpoints/admin.ts +72 -50
  130. package/src/routes/endpoints/checkpointing.ts +79 -8
  131. package/src/routes/endpoints/socket-route.ts +3 -2
  132. package/src/routes/endpoints/sync-rules.ts +23 -13
  133. package/src/routes/endpoints/sync-stream.ts +1 -1
  134. package/src/runner/teardown.ts +8 -8
  135. package/src/storage/BucketStorageBatch.ts +64 -18
  136. package/src/storage/BucketStorageFactory.ts +30 -39
  137. package/src/storage/CheckpointChecksumInvalidatedError.ts +17 -0
  138. package/src/storage/ChecksumCache.ts +27 -14
  139. package/src/storage/ParsedSyncConfigSet.ts +25 -0
  140. package/src/storage/PersistedReplicationStream.ts +55 -0
  141. package/src/storage/PersistedSyncConfigContent.ts +192 -0
  142. package/src/storage/PersistedSyncConfigStatus.ts +14 -0
  143. package/src/storage/SourceEntity.ts +6 -0
  144. package/src/storage/SourceTable.ts +34 -3
  145. package/src/storage/SyncRulesBucketStorage.ts +138 -22
  146. package/src/storage/WriteCheckpointAPI.ts +108 -3
  147. package/src/storage/implementation/BucketDefinitionMapping.ts +436 -0
  148. package/src/storage/implementation/IncrementalReprocessingCompatibility.ts +41 -0
  149. package/src/storage/implementation/IncrementalReprocessingSyncConfigLog.ts +109 -0
  150. package/src/storage/implementation/ReplicationStreamStorageIds.ts +21 -0
  151. package/src/storage/storage-index.ts +10 -1
  152. package/src/sync/BucketChecksumState.ts +103 -21
  153. package/src/sync/RequestTracker.ts +20 -0
  154. package/src/sync/sync.ts +183 -48
  155. package/src/sync/util.ts +12 -0
  156. package/src/system/ServiceContext.ts +7 -0
  157. package/src/tracing/PerformanceTracer.ts +41 -1
  158. package/src/util/checkpointing.ts +4 -22
  159. package/src/util/config/compound-config-collector.ts +25 -1
  160. package/src/util/config/defaults.ts +2 -0
  161. package/src/util/config/types.ts +3 -1
  162. package/src/util/lsn.ts +9 -0
  163. package/src/util/util-index.ts +1 -0
  164. package/src/util/utils.ts +1 -1
  165. package/src/util/write-checkpoint-batcher.ts +142 -0
  166. package/test/src/AbstractReplicator.test.ts +115 -0
  167. package/test/src/checksum_cache.test.ts +22 -0
  168. package/test/src/config.test.ts +102 -0
  169. package/test/src/diagnostics.test.ts +62 -34
  170. package/test/src/module-loader.test.ts +33 -1
  171. package/test/src/routes/admin.test.ts +182 -18
  172. package/test/src/routes/checkpointing.test.ts +54 -0
  173. package/test/src/routes/mocks.ts +6 -2
  174. package/test/src/storage/SourceTable.test.ts +89 -0
  175. package/test/src/sync/BucketChecksumState.test.ts +98 -12
  176. package/test/src/sync/util.test.ts +13 -1
  177. package/test/src/util/checkpointing.test.ts +249 -0
  178. package/tsconfig.json +1 -4
  179. package/tsconfig.tsbuildinfo +1 -1
  180. package/dist/storage/PersistedSyncRulesContent.d.ts +0 -59
  181. package/dist/storage/PersistedSyncRulesContent.js +0 -100
  182. package/dist/storage/PersistedSyncRulesContent.js.map +0 -1
  183. 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(next: storage.StorageCheckpointUpdate): Promise<CheckpointLine | null> {
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 breakdown = formatBucketDefinitionBreakdown(bucketsByDefinition);
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
- let updatedChecksums = await storage.getChecksums(base.checkpoint, checksumLookups);
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 bucketList = [...bucketDescriptionMap.values()].map((b) => ({ bucket: b.bucket, source: b.source }));
190
- checksumMap = await storage.getChecksums(base.checkpoint, bucketList);
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(checkpoint: storage.StorageCheckpointUpdate): Promise<CheckpointUpdate> {
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(checkpoint: storage.StorageCheckpointUpdate): Promise<CheckpointUpdate> {
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 bucket by sync stream definition.
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 10, and returns both the
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(bucketsByDefinition: Map<string, number>): {
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
- // Sort definitions by count (descending) and take top 10
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, 10);
833
+ const sortedDefinitions = allSorted.slice(0, maxLoggedDefinitions);
753
834
 
754
- let message = '\Buckets by definition:';
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 > 10) {
762
- const remainingResults = allSorted.slice(10).reduce((sum, [, count]) => sum + count, 0);
763
- const remainingDefinitions = allSorted.length - 10;
764
- message += `\n ... and ${remainingResults} more results from ${remainingDefinitions} definitions`;
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;