@powersync/service-module-mongodb-storage 0.16.0 → 0.18.0

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 (206) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/dist/storage/MongoBucketStorage.d.ts +35 -15
  3. package/dist/storage/MongoBucketStorage.js +309 -86
  4. package/dist/storage/MongoBucketStorage.js.map +1 -1
  5. package/dist/storage/implementation/CheckpointState.d.ts +20 -0
  6. package/dist/storage/implementation/CheckpointState.js +31 -0
  7. package/dist/storage/implementation/CheckpointState.js.map +1 -0
  8. package/dist/storage/implementation/MongoBucketBatch.d.ts +69 -39
  9. package/dist/storage/implementation/MongoBucketBatch.js +104 -313
  10. package/dist/storage/implementation/MongoBucketBatch.js.map +1 -1
  11. package/dist/storage/implementation/MongoChecksums.d.ts +11 -9
  12. package/dist/storage/implementation/MongoChecksums.js +3 -111
  13. package/dist/storage/implementation/MongoChecksums.js.map +1 -1
  14. package/dist/storage/implementation/MongoCompactor.d.ts +3 -1
  15. package/dist/storage/implementation/MongoCompactor.js +18 -9
  16. package/dist/storage/implementation/MongoCompactor.js.map +1 -1
  17. package/dist/storage/implementation/MongoHydrationState.d.ts +11 -0
  18. package/dist/storage/implementation/MongoHydrationState.js +49 -0
  19. package/dist/storage/implementation/MongoHydrationState.js.map +1 -0
  20. package/dist/storage/implementation/MongoParameterCompactor.d.ts +6 -5
  21. package/dist/storage/implementation/MongoParameterCompactor.js +24 -1
  22. package/dist/storage/implementation/MongoParameterCompactor.js.map +1 -1
  23. package/dist/storage/implementation/MongoParsedSyncConfigSet.d.ts +13 -0
  24. package/dist/storage/implementation/MongoParsedSyncConfigSet.js +64 -0
  25. package/dist/storage/implementation/MongoParsedSyncConfigSet.js.map +1 -0
  26. package/dist/storage/implementation/MongoPersistedReplicationStream.d.ts +36 -0
  27. package/dist/storage/implementation/MongoPersistedReplicationStream.js +90 -0
  28. package/dist/storage/implementation/MongoPersistedReplicationStream.js.map +1 -0
  29. package/dist/storage/implementation/MongoPersistedSyncConfigContent.d.ts +25 -0
  30. package/dist/storage/implementation/MongoPersistedSyncConfigContent.js +121 -0
  31. package/dist/storage/implementation/MongoPersistedSyncConfigContent.js.map +1 -0
  32. package/dist/storage/implementation/MongoStorageProvider.js +5 -2
  33. package/dist/storage/implementation/MongoStorageProvider.js.map +1 -1
  34. package/dist/storage/implementation/MongoSyncBucketStorage.d.ts +50 -21
  35. package/dist/storage/implementation/MongoSyncBucketStorage.js +62 -199
  36. package/dist/storage/implementation/MongoSyncBucketStorage.js.map +1 -1
  37. package/dist/storage/implementation/MongoSyncRulesLock.d.ts +5 -1
  38. package/dist/storage/implementation/MongoSyncRulesLock.js +9 -5
  39. package/dist/storage/implementation/MongoSyncRulesLock.js.map +1 -1
  40. package/dist/storage/implementation/SyncRuleStateUpdate.d.ts +14 -0
  41. package/dist/storage/implementation/SyncRuleStateUpdate.js +36 -0
  42. package/dist/storage/implementation/SyncRuleStateUpdate.js.map +1 -0
  43. package/dist/storage/implementation/common/BucketDataDoc.d.ts +1 -1
  44. package/dist/storage/implementation/common/MongoSyncBucketStorageCheckpoint.d.ts +6 -0
  45. package/dist/storage/implementation/common/MongoSyncBucketStorageCheckpoint.js +2 -0
  46. package/dist/storage/implementation/common/MongoSyncBucketStorageCheckpoint.js.map +1 -0
  47. package/dist/storage/implementation/common/PersistedBatch.d.ts +2 -3
  48. package/dist/storage/implementation/common/PersistedBatch.js +5 -0
  49. package/dist/storage/implementation/common/PersistedBatch.js.map +1 -1
  50. package/dist/storage/implementation/common/SourceRecordStore.d.ts +1 -2
  51. package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.d.ts +1 -1
  52. package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.js +1 -1
  53. package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.js.map +1 -1
  54. package/dist/storage/implementation/createMongoSyncBucketStorage.d.ts +2 -2
  55. package/dist/storage/implementation/createMongoSyncBucketStorage.js +4 -4
  56. package/dist/storage/implementation/createMongoSyncBucketStorage.js.map +1 -1
  57. package/dist/storage/implementation/db.d.ts +10 -2
  58. package/dist/storage/implementation/db.js +9 -14
  59. package/dist/storage/implementation/db.js.map +1 -1
  60. package/dist/storage/implementation/models.d.ts +25 -50
  61. package/dist/storage/implementation/models.js.map +1 -1
  62. package/dist/storage/implementation/v1/MongoBucketBatchV1.d.ts +23 -1
  63. package/dist/storage/implementation/v1/MongoBucketBatchV1.js +403 -2
  64. package/dist/storage/implementation/v1/MongoBucketBatchV1.js.map +1 -1
  65. package/dist/storage/implementation/v1/MongoChecksumsV1.js +114 -3
  66. package/dist/storage/implementation/v1/MongoChecksumsV1.js.map +1 -1
  67. package/dist/storage/implementation/v1/MongoCompactorV1.d.ts +1 -1
  68. package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.d.ts +22 -15
  69. package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js +100 -27
  70. package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js.map +1 -1
  71. package/dist/storage/implementation/v1/PersistedBatchV1.d.ts +1 -2
  72. package/dist/storage/implementation/v1/PersistedBatchV1.js.map +1 -1
  73. package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.d.ts +2 -1
  74. package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.js +3 -0
  75. package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.js.map +1 -1
  76. package/dist/storage/implementation/v1/models.d.ts +21 -1
  77. package/dist/storage/implementation/v1/models.js.map +1 -1
  78. package/dist/storage/implementation/v3/MongoBucketBatchV3.d.ts +21 -0
  79. package/dist/storage/implementation/v3/MongoBucketBatchV3.js +459 -3
  80. package/dist/storage/implementation/v3/MongoBucketBatchV3.js.map +1 -1
  81. package/dist/storage/implementation/v3/MongoChecksumsV3.d.ts +27 -7
  82. package/dist/storage/implementation/v3/MongoChecksumsV3.js +202 -18
  83. package/dist/storage/implementation/v3/MongoChecksumsV3.js.map +1 -1
  84. package/dist/storage/implementation/v3/MongoCompactorV3.d.ts +20 -3
  85. package/dist/storage/implementation/v3/MongoCompactorV3.js +511 -22
  86. package/dist/storage/implementation/v3/MongoCompactorV3.js.map +1 -1
  87. package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.d.ts +62 -0
  88. package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.js +350 -0
  89. package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.js.map +1 -0
  90. package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.d.ts +50 -16
  91. package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js +292 -75
  92. package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js.map +1 -1
  93. package/dist/storage/implementation/v3/PersistedBatchV3.d.ts +2 -3
  94. package/dist/storage/implementation/v3/PersistedBatchV3.js +43 -20
  95. package/dist/storage/implementation/v3/PersistedBatchV3.js.map +1 -1
  96. package/dist/storage/implementation/v3/SingleBucketStoreV3.js +52 -16
  97. package/dist/storage/implementation/v3/SingleBucketStoreV3.js.map +1 -1
  98. package/dist/storage/implementation/v3/SourceRecordStoreV3.d.ts +3 -3
  99. package/dist/storage/implementation/v3/SourceRecordStoreV3.js +13 -11
  100. package/dist/storage/implementation/v3/SourceRecordStoreV3.js.map +1 -1
  101. package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.d.ts +16 -14
  102. package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js +32 -27
  103. package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js.map +1 -1
  104. package/dist/storage/implementation/v3/bucket-format.d.ts +4 -0
  105. package/dist/storage/implementation/v3/bucket-format.js +58 -0
  106. package/dist/storage/implementation/v3/bucket-format.js.map +1 -0
  107. package/dist/storage/implementation/v3/chunking.d.ts +10 -0
  108. package/dist/storage/implementation/v3/chunking.js +28 -0
  109. package/dist/storage/implementation/v3/chunking.js.map +1 -0
  110. package/dist/storage/implementation/v3/models.d.ts +111 -10
  111. package/dist/storage/implementation/v3/models.js +11 -28
  112. package/dist/storage/implementation/v3/models.js.map +1 -1
  113. package/dist/storage/implementation/v3/source-table-utils.d.ts +55 -0
  114. package/dist/storage/implementation/v3/source-table-utils.js +214 -0
  115. package/dist/storage/implementation/v3/source-table-utils.js.map +1 -0
  116. package/dist/storage/storage-index.d.ts +4 -4
  117. package/dist/storage/storage-index.js +4 -4
  118. package/dist/storage/storage-index.js.map +1 -1
  119. package/dist/types/types.d.ts +2 -2
  120. package/dist/utils/test-utils.d.ts +1 -2
  121. package/dist/utils/test-utils.js +5 -1
  122. package/dist/utils/test-utils.js.map +1 -1
  123. package/dist/utils/util.d.ts +1 -1
  124. package/dist/utils/util.js +3 -2
  125. package/dist/utils/util.js.map +1 -1
  126. package/package.json +9 -19
  127. package/src/migrations/db/migrations/1702295701188-sync-rule-state.ts +1 -1
  128. package/src/storage/MongoBucketStorage.ts +464 -95
  129. package/src/storage/implementation/CheckpointState.ts +59 -0
  130. package/src/storage/implementation/MongoBucketBatch.ts +159 -405
  131. package/src/storage/implementation/MongoChecksums.ts +7 -138
  132. package/src/storage/implementation/MongoCompactor.ts +20 -10
  133. package/src/storage/implementation/MongoHydrationState.ts +61 -0
  134. package/src/storage/implementation/MongoParameterCompactor.ts +24 -5
  135. package/src/storage/implementation/MongoParsedSyncConfigSet.ts +88 -0
  136. package/src/storage/implementation/MongoPersistedReplicationStream.ts +118 -0
  137. package/src/storage/implementation/MongoPersistedSyncConfigContent.ts +152 -0
  138. package/src/storage/implementation/MongoStorageProvider.ts +5 -2
  139. package/src/storage/implementation/MongoSyncBucketStorage.ts +89 -250
  140. package/src/storage/implementation/MongoSyncRulesLock.ts +14 -5
  141. package/src/storage/implementation/SyncRuleStateUpdate.ts +38 -0
  142. package/src/storage/implementation/common/BucketDataDoc.ts +1 -1
  143. package/src/storage/implementation/common/MongoSyncBucketStorageCheckpoint.ts +7 -0
  144. package/src/storage/implementation/common/PersistedBatch.ts +8 -4
  145. package/src/storage/implementation/common/SourceRecordStore.ts +1 -2
  146. package/src/storage/implementation/common/VersionedPowerSyncMongoBase.ts +1 -1
  147. package/src/storage/implementation/createMongoSyncBucketStorage.ts +21 -7
  148. package/src/storage/implementation/db.ts +16 -21
  149. package/src/storage/implementation/models.ts +28 -61
  150. package/src/storage/implementation/v1/MongoBucketBatchV1.ts +503 -5
  151. package/src/storage/implementation/v1/MongoChecksumsV1.ts +137 -4
  152. package/src/storage/implementation/v1/MongoCompactorV1.ts +1 -1
  153. package/src/storage/implementation/v1/MongoSyncBucketStorageV1.ts +150 -49
  154. package/src/storage/implementation/v1/PersistedBatchV1.ts +1 -2
  155. package/src/storage/implementation/v1/VersionedPowerSyncMongoV1.ts +11 -1
  156. package/src/storage/implementation/v1/models.ts +25 -0
  157. package/src/storage/implementation/v3/MongoBucketBatchV3.ts +611 -4
  158. package/src/storage/implementation/v3/MongoChecksumsV3.ts +262 -26
  159. package/src/storage/implementation/v3/MongoCompactorV3.ts +647 -30
  160. package/src/storage/implementation/v3/MongoStoppedSyncConfigCleanup.ts +480 -0
  161. package/src/storage/implementation/v3/MongoSyncBucketStorageV3.ts +397 -111
  162. package/src/storage/implementation/v3/PersistedBatchV3.ts +63 -38
  163. package/src/storage/implementation/v3/SingleBucketStoreV3.ts +59 -19
  164. package/src/storage/implementation/v3/SourceRecordStoreV3.ts +12 -12
  165. package/src/storage/implementation/v3/VersionedPowerSyncMongoV3.ts +48 -38
  166. package/src/storage/implementation/v3/bucket-format.ts +70 -0
  167. package/src/storage/implementation/v3/chunking.ts +38 -0
  168. package/src/storage/implementation/v3/models.ts +150 -44
  169. package/src/storage/implementation/v3/source-table-utils.ts +392 -0
  170. package/src/storage/storage-index.ts +12 -4
  171. package/src/utils/test-utils.ts +6 -3
  172. package/src/utils/util.ts +3 -2
  173. package/test/src/__snapshots__/storage.test.ts.snap +0 -75
  174. package/test/src/__snapshots__/storage_sync.test.ts.snap +48 -48
  175. package/test/src/cleanup-stopped-sync-configs.test.ts +648 -0
  176. package/test/src/storage.test.ts +11 -11
  177. package/test/src/storage_compacting.test.ts +1956 -6
  178. package/test/src/storage_sync.test.ts +1429 -42
  179. package/test/src/storeCurrentData.test.ts +221 -0
  180. package/test/src/util.ts +2 -1
  181. package/tsconfig.json +1 -4
  182. package/tsconfig.tsbuildinfo +1 -1
  183. package/dist/storage/implementation/BucketDefinitionMapping.d.ts +0 -17
  184. package/dist/storage/implementation/BucketDefinitionMapping.js +0 -58
  185. package/dist/storage/implementation/BucketDefinitionMapping.js.map +0 -1
  186. package/dist/storage/implementation/MongoPersistedSyncRules.d.ts +0 -14
  187. package/dist/storage/implementation/MongoPersistedSyncRules.js +0 -64
  188. package/dist/storage/implementation/MongoPersistedSyncRules.js.map +0 -1
  189. package/dist/storage/implementation/MongoPersistedSyncRulesContent.d.ts +0 -15
  190. package/dist/storage/implementation/MongoPersistedSyncRulesContent.js +0 -42
  191. package/dist/storage/implementation/MongoPersistedSyncRulesContent.js.map +0 -1
  192. package/dist/storage/implementation/common/MongoSyncBucketStorageContext.d.ts +0 -13
  193. package/dist/storage/implementation/common/MongoSyncBucketStorageContext.js +0 -2
  194. package/dist/storage/implementation/common/MongoSyncBucketStorageContext.js.map +0 -1
  195. package/dist/storage/implementation/v3/MongoParameterCompactorV3.d.ts +0 -9
  196. package/dist/storage/implementation/v3/MongoParameterCompactorV3.js +0 -18
  197. package/dist/storage/implementation/v3/MongoParameterCompactorV3.js.map +0 -1
  198. package/dist/storage/implementation/v3/MongoParameterLookupV3.d.ts +0 -5
  199. package/dist/storage/implementation/v3/MongoParameterLookupV3.js +0 -9
  200. package/dist/storage/implementation/v3/MongoParameterLookupV3.js.map +0 -1
  201. package/src/storage/implementation/BucketDefinitionMapping.ts +0 -72
  202. package/src/storage/implementation/MongoPersistedSyncRules.ts +0 -76
  203. package/src/storage/implementation/MongoPersistedSyncRulesContent.ts +0 -56
  204. package/src/storage/implementation/common/MongoSyncBucketStorageContext.ts +0 -15
  205. package/src/storage/implementation/v3/MongoParameterCompactorV3.ts +0 -24
  206. package/src/storage/implementation/v3/MongoParameterLookupV3.ts +0 -12
@@ -1,26 +1,88 @@
1
1
  import * as lib_mongo from '@powersync/lib-service-mongodb';
2
+ import { ReplicationAssertionError } from '@powersync/lib-services-framework';
3
+ import { storage } from '@powersync/service-core';
4
+ import * as bson from 'bson';
2
5
  import { mongoTableId } from '../../../utils/util.js';
6
+ import { canCheckpointState } from '../CheckpointState.js';
3
7
  import { MongoBucketBatch } from '../MongoBucketBatch.js';
8
+ import { syncRuleStateUpdatePipeline } from '../SyncRuleStateUpdate.js';
4
9
  import { PersistedBatchV3 } from './PersistedBatchV3.js';
5
10
  import { SourceRecordStoreV3 } from './SourceRecordStoreV3.js';
11
+ import { createNewSourceTable, designateEventCarrier, overlappingSourceTableFilter, planSourceTableReconciliation, sourceTableDesiredResolution, sourceTableFromDocument } from './source-table-utils.js';
6
12
  export class MongoBucketBatchV3 extends MongoBucketBatch {
7
13
  store;
14
+ syncConfigIds;
15
+ needsActivationV3 = true;
16
+ lastWaitingLogThrottledV3 = 0;
8
17
  constructor(options) {
9
18
  super(options);
10
- this.store = new SourceRecordStoreV3(this.db, this.group_id, this.mapping);
19
+ const syncConfigIds = options.syncConfigIds ?? [];
20
+ if (syncConfigIds.length == 0) {
21
+ throw new ReplicationAssertionError('Missing sync config id for v3 batch');
22
+ }
23
+ this.syncConfigIds = syncConfigIds;
24
+ this.store = new SourceRecordStoreV3(this.db, this.replicationStreamId, this.mapping);
11
25
  }
12
26
  createPersistedBatch(writtenSize) {
13
- return new PersistedBatchV3(this.db, this.group_id, this.mapping, writtenSize, {
27
+ return new PersistedBatchV3(this.db, this.replicationStreamId, this.mapping, writtenSize, {
14
28
  logger: this.logger
15
29
  });
16
30
  }
17
31
  get sourceRecordStore() {
18
32
  return this.store;
19
33
  }
34
+ async onReplicationTransactionFlush(session, lastOp) {
35
+ // Durably advance the stream-level head of persisted ops within the flush transaction.
36
+ // This ensures a checkpoint created later (even by an empty commit, or by a freshly-appended
37
+ // config that replicates nothing) covers all ops persisted before a potential crash.
38
+ await this.db.sync_rules.updateOne({
39
+ _id: this.replicationStreamId
40
+ }, {
41
+ $max: {
42
+ last_persisted_op: lastOp
43
+ }
44
+ }, { session });
45
+ }
46
+ selectedSyncConfigObjectIds(syncConfigIds) {
47
+ const selectedIds = new Set(this.syncConfigIds.map((id) => id.toHexString()));
48
+ return syncConfigIds
49
+ .filter((id) => selectedIds.has(id) && bson.ObjectId.isValid(id))
50
+ .map((id) => new bson.ObjectId(id));
51
+ }
52
+ relevantSyncConfigIds(table) {
53
+ const bucketDataSourceIds = table.bucketDataSources.map((source) => this.mapping.bucketSourceId(source));
54
+ const parameterLookupSourceIds = table.parameterLookupSources.map((source) => this.mapping.parameterLookupId(source));
55
+ return this.selectedSyncConfigObjectIds(this.mapping.syncConfigIdsForSourceTable(this.syncConfigIds.map((id) => id.toHexString()), table.ref, bucketDataSourceIds, parameterLookupSourceIds));
56
+ }
57
+ relevantSyncConfigIdsForTables(tables) {
58
+ const ids = new Map();
59
+ for (const table of tables) {
60
+ for (const id of this.relevantSyncConfigIds(table)) {
61
+ ids.set(id.toHexString(), id);
62
+ }
63
+ }
64
+ return [...ids.values()];
65
+ }
66
+ snapshotBlockingSourceTablesFilter() {
67
+ const clauses = this.syncConfigIds.flatMap((syncConfigId) => {
68
+ const filter = this.mapping.snapshotBlockingSourceTablesFilter(syncConfigId.toHexString());
69
+ return filter.$or ?? [];
70
+ });
71
+ if (clauses.length == 0) {
72
+ return {
73
+ snapshot_done: false,
74
+ _id: { $exists: false }
75
+ };
76
+ }
77
+ return {
78
+ snapshot_done: false,
79
+ $or: clauses
80
+ };
81
+ }
20
82
  async cleanupDroppedSourceTables(sourceTables) {
21
83
  for (const table of sourceTables) {
22
84
  await this.db
23
- .sourceRecordsV3(this.group_id, mongoTableId(table.id))
85
+ .sourceRecords(this.replicationStreamId, mongoTableId(table.id))
24
86
  .drop()
25
87
  .catch((error) => {
26
88
  if (lib_mongo.isMongoServerError(error) && error.codeName === 'NamespaceNotFound') {
@@ -30,5 +92,399 @@ export class MongoBucketBatchV3 extends MongoBucketBatch {
30
92
  });
31
93
  }
32
94
  }
95
+ async resolveTables(options) {
96
+ // The test-only override is a whole parsed set, so the sync rules and the mapping
97
+ // used below always come from the same parse.
98
+ const parsedOverride = options.parsedSyncConfig;
99
+ const syncConfig = parsedOverride?.hydratedSyncConfig ?? this.sync_rules;
100
+ const mapping = parsedOverride?.mapping ?? this.mapping;
101
+ const { connection_id, source } = options;
102
+ const context = {
103
+ connectionId: connection_id,
104
+ connectionTag: source.connectionTag,
105
+ identity: {
106
+ schema: source.schema,
107
+ name: source.name,
108
+ objectId: source.objectId,
109
+ replicaIdColumns: source.replicaIdColumns.map((column) => ({
110
+ name: column.name,
111
+ type: column.type,
112
+ type_oid: column.typeId
113
+ }))
114
+ },
115
+ storeCurrentData: source.sendsCompleteRows !== true,
116
+ syncConfig,
117
+ mapping,
118
+ desired: sourceTableDesiredResolution(syncConfig, source, mapping)
119
+ };
120
+ let result = null;
121
+ const session = this.db.client.startSession();
122
+ await using _ = { [Symbol.asyncDispose]: () => session.endSession() };
123
+ await session.withTransaction(async () => {
124
+ const col = this.db.sourceTables(this.replicationStreamId);
125
+ // Fetch every persisted source-table doc that can overlap this physical table.
126
+ // Exact-identity docs are candidates for reuse; non-exact overlaps are possible drops.
127
+ const candidateDocs = await col
128
+ .find(overlappingSourceTableFilter(connection_id, context.identity), { session })
129
+ .toArray();
130
+ // Pure planning: which docs to retain (and narrow), whether a new doc is needed for
131
+ // uncovered memberships, and which docs conflict with the current identity.
132
+ const plan = planSourceTableReconciliation(candidateDocs, context);
133
+ // Persist narrowing for incomplete snapshots only. Snapshot-complete docs keep stale
134
+ // coverage ids so compatible future configs can reuse already-snapshotted data.
135
+ // Narrowing occurs after removing a sync config, meaning we don't process those
136
+ // definitions anymore.
137
+ for (const update of plan.narrowingUpdates) {
138
+ await col.updateOne({ _id: update.id }, {
139
+ $set: {
140
+ bucket_data_source_ids: update.memberships.bucketDataSourceIds,
141
+ parameter_lookup_source_ids: update.memberships.parameterLookupSourceIds
142
+ }
143
+ }, { session });
144
+ }
145
+ // Any desired membership not covered by an existing doc gets a new source table.
146
+ // That table snapshots only the uncovered memberships.
147
+ if (plan.newTableMemberships != null) {
148
+ const id = options.idGenerator ? options.idGenerator() : new bson.ObjectId();
149
+ const { doc, table } = createNewSourceTable(id, plan.newTableMemberships, context);
150
+ await col.insertOne(doc, { session });
151
+ await this.db.initializeSourceRecordsCollection(this.replicationStreamId, doc._id, session);
152
+ plan.tables.push(table);
153
+ }
154
+ // If memberships are split across multiple source tables, only one may fire events.
155
+ designateEventCarrier(plan.tables, context.desired.triggersEvent);
156
+ result = {
157
+ tables: plan.tables,
158
+ dropTables: plan.dropDocs.map((doc) => sourceTableFromDocument(doc, context.connectionTag, syncConfig, mapping))
159
+ };
160
+ });
161
+ return result;
162
+ }
163
+ async getSourceTableStatus(table) {
164
+ const doc = (await this.db
165
+ .sourceTables(this.replicationStreamId)
166
+ .findOne({ _id: mongoTableId(table.id) }, { session: this.session }));
167
+ if (doc == null) {
168
+ return null;
169
+ }
170
+ const refreshed = sourceTableFromDocument(doc, table.ref.connectionTag, this.sync_rules, this.mapping);
171
+ // The event-carrier designation is decided per resolveTables result and not persisted -
172
+ // preserve the caller's designation instead of recomputing it from the ref, so that
173
+ // refreshing a non-carrier table does not make it fire events.
174
+ refreshed.syncEvent = table.syncEvent;
175
+ return refreshed;
176
+ }
177
+ async commit(lsn, options) {
178
+ const { createEmptyCheckpoints } = { ...storage.DEFAULT_BUCKET_BATCH_COMMIT_OPTIONS, ...options };
179
+ await this.flush(options);
180
+ const now = new Date();
181
+ await this.db.write_checkpoints.updateMany({
182
+ processed_at_lsn: null,
183
+ 'lsns.1': { $lte: lsn }
184
+ }, {
185
+ $set: {
186
+ processed_at_lsn: lsn
187
+ }
188
+ }, {
189
+ session: this.session
190
+ });
191
+ const preUpdateDocument = (await this.db.sync_rules.findOne({
192
+ _id: this.replicationStreamId,
193
+ 'sync_configs._id': { $in: this.syncConfigIds }
194
+ }, {
195
+ session: this.session,
196
+ projection: {
197
+ sync_configs: 1,
198
+ last_persisted_op: 1
199
+ }
200
+ }));
201
+ const states = preUpdateDocument?.sync_configs?.filter((config) => this.syncConfigIds.some((id) => id.equals(config._id))) ?? [];
202
+ if (states.length == 0) {
203
+ throw new ReplicationAssertionError(`Failed to update checkpoint - no matching sync_config for _id: ${this.replicationStreamId}/${this.syncConfigIds
204
+ .map((id) => id.toHexString())
205
+ .join(',')}`);
206
+ }
207
+ // The replication job / MongoBucketBatch must be constructed with all replicating (PROCESSING / ACTIVE)
208
+ // sync configs in the stream, otherwise we'll get inconsistencies. Configs in other states (e.g. STOP)
209
+ // remain embedded in the document and are ignored here.
210
+ const missingSyncConfig = preUpdateDocument.sync_configs.find((config) => [storage.SyncRuleState.PROCESSING, storage.SyncRuleState.ACTIVE].includes(config.state) &&
211
+ !this.syncConfigIds.some((id) => id.equals(config._id)));
212
+ if (missingSyncConfig != null) {
213
+ throw new ReplicationAssertionError(`Replication job not configured for sync config ${missingSyncConfig._id}`);
214
+ }
215
+ // Effective head of the stream's op sequence.
216
+ // last_persisted_op is $max-advanced durably in the same transaction as every flush, and this
217
+ // read uses the same session, so it covers all ops persisted by this batch.
218
+ const newCheckpoint = preUpdateDocument?.last_persisted_op == null ? 0n : BigInt(preUpdateDocument.last_persisted_op);
219
+ let checkpointBlocked = false;
220
+ let checkpointCreated = false;
221
+ let checkpointLogState = null;
222
+ const unblockedConfigIds = [];
223
+ for (const state of states) {
224
+ if (state.last_checkpoint != null && state.last_checkpoint > newCheckpoint) {
225
+ // last_persisted_op is $max-advanced durably in the same transaction as every flush, and
226
+ // checkpoints are only ever created at that head, so a checkpoint past the head means the
227
+ // op sequence or the stored state is corrupt.
228
+ throw new ReplicationAssertionError(`Invariant violation: sync config ${state._id} has last_checkpoint ${state.last_checkpoint} > stream head ${newCheckpoint}`);
229
+ }
230
+ const canCheckpoint = canCheckpointState(lsn, {
231
+ snapshotDone: state.snapshot_done === true,
232
+ lastCheckpointLsn: state.last_checkpoint_lsn,
233
+ noCheckpointBefore: state.no_checkpoint_before
234
+ });
235
+ if (!canCheckpoint) {
236
+ checkpointBlocked = true;
237
+ // Log the first blocked config's state.
238
+ checkpointLogState ??= {
239
+ snapshot_done: state.snapshot_done,
240
+ last_checkpoint_lsn: state.last_checkpoint_lsn,
241
+ no_checkpoint_before: state.no_checkpoint_before
242
+ };
243
+ continue;
244
+ }
245
+ checkpointCreated ||= createEmptyCheckpoints || state.last_checkpoint !== newCheckpoint;
246
+ unblockedConfigIds.push(state._id);
247
+ }
248
+ // Every commit advances the stream's resume position: commit() flushes first, so all
249
+ // source changes up to this lsn have been persisted, even when checkpoints are blocked.
250
+ // In the future we could also advance this on flush, when the connector provides the
251
+ // current position (see setResumeLsn, which connectors may already call after flushing).
252
+ const resumeLsnUpdate = { resume_lsn: lsn };
253
+ if (unblockedConfigIds.length > 0) {
254
+ // All unblocked configs get the SAME new value, so we apply it with a single updateOne
255
+ // (single-document atomicity).
256
+ const updateSet = {
257
+ last_keepalive_ts: now,
258
+ last_fatal_error: null,
259
+ last_fatal_error_ts: null
260
+ };
261
+ // Only advance checkpoint fields when an actual (non-empty) checkpoint is created, matching
262
+ // the previous per-config / v1 behaviour.
263
+ if (checkpointCreated) {
264
+ updateSet['sync_configs.$[config].last_checkpoint'] = newCheckpoint;
265
+ updateSet['sync_configs.$[config].last_checkpoint_lsn'] = lsn;
266
+ updateSet['last_checkpoint_ts'] = now;
267
+ }
268
+ await this.db.sync_rules.updateOne({
269
+ _id: this.replicationStreamId,
270
+ 'sync_configs._id': { $in: unblockedConfigIds }
271
+ }, { $set: updateSet, $max: resumeLsnUpdate }, {
272
+ session: this.session,
273
+ arrayFilters: checkpointCreated ? [{ 'config._id': { $in: unblockedConfigIds } }] : undefined
274
+ });
275
+ }
276
+ else {
277
+ // All selected configs are blocked - only update keepalive/error tracking and the
278
+ // resume position.
279
+ await this.db.sync_rules.updateOne({
280
+ _id: this.replicationStreamId
281
+ }, {
282
+ $set: {
283
+ last_keepalive_ts: now,
284
+ last_fatal_error: null,
285
+ last_fatal_error_ts: null
286
+ },
287
+ $max: resumeLsnUpdate
288
+ }, { session: this.session });
289
+ }
290
+ if (checkpointBlocked) {
291
+ if (Date.now() - this.lastWaitingLogThrottledV3 > 5_000) {
292
+ this.logger.info(`Waiting before creating checkpoint, currently at ${lsn}. Current state: ${JSON.stringify(checkpointLogState)}`);
293
+ this.lastWaitingLogThrottledV3 = Date.now();
294
+ }
295
+ }
296
+ else {
297
+ if (checkpointCreated) {
298
+ this.logger.debug(`Created checkpoint at ${lsn}`);
299
+ }
300
+ await this.autoActivateV3(lsn);
301
+ // All configs are now checkpointed at newCheckpoint (the stream head).
302
+ await this.sourceRecordStore.postCommitCleanup(newCheckpoint, this.logger);
303
+ }
304
+ if (checkpointCreated) {
305
+ await this.db.notifyCheckpoint();
306
+ }
307
+ return {
308
+ checkpointBlocked,
309
+ checkpointCreated
310
+ };
311
+ }
312
+ async keepalive(lsn) {
313
+ return await this.commit(lsn, { createEmptyCheckpoints: true });
314
+ }
315
+ async setResumeLsn(lsn) {
316
+ await this.db.sync_rules.updateOne({
317
+ _id: this.replicationStreamId
318
+ }, {
319
+ $set: {
320
+ resume_lsn: lsn
321
+ }
322
+ }, { session: this.session });
323
+ }
324
+ async autoActivateV3(lsn) {
325
+ if (!this.needsActivationV3) {
326
+ return;
327
+ }
328
+ const session = this.session;
329
+ let activated = false;
330
+ await session.withTransaction(async () => {
331
+ const doc = await this.db.sync_rules.findOne({
332
+ _id: this.replicationStreamId,
333
+ 'sync_configs._id': { $in: this.syncConfigIds }
334
+ }, {
335
+ session,
336
+ projection: {
337
+ state: 1,
338
+ sync_configs: 1
339
+ }
340
+ });
341
+ const states = doc?.sync_configs?.filter((config) => this.syncConfigIds.some((id) => id.equals(config._id))) ?? [];
342
+ if (doc == null || states.length == 0) {
343
+ return;
344
+ }
345
+ const processingStates = states.filter((state) => state.state == storage.SyncRuleState.PROCESSING);
346
+ if (doc.state == storage.SyncRuleState.PROCESSING &&
347
+ processingStates.length == states.length &&
348
+ states.every((state) => state.snapshot_done && state.last_checkpoint != null)) {
349
+ await this.db.sync_rules.updateOne({
350
+ _id: this.replicationStreamId,
351
+ 'sync_configs._id': { $in: this.syncConfigIds }
352
+ }, {
353
+ $set: {
354
+ state: storage.SyncRuleState.ACTIVE,
355
+ 'sync_configs.$[config].state': storage.SyncRuleState.ACTIVE
356
+ }
357
+ }, {
358
+ session,
359
+ arrayFilters: [{ 'config._id': { $in: this.syncConfigIds } }]
360
+ });
361
+ await this.db.sync_rules.updateMany({
362
+ _id: { $ne: this.replicationStreamId },
363
+ state: { $in: [storage.SyncRuleState.ACTIVE, storage.SyncRuleState.ERRORED] }
364
+ }, syncRuleStateUpdatePipeline(storage.SyncRuleState.STOP), { session });
365
+ activated = true;
366
+ }
367
+ else if (doc.state == storage.SyncRuleState.ACTIVE &&
368
+ processingStates.length > 0 &&
369
+ processingStates.every((state) => state.snapshot_done && state.last_checkpoint != null)) {
370
+ await this.db.sync_rules.updateOne({
371
+ _id: this.replicationStreamId,
372
+ 'sync_configs._id': { $in: processingStates.map((state) => state._id) }
373
+ }, {
374
+ $set: {
375
+ 'sync_configs.$[activeConfig].state': storage.SyncRuleState.STOP,
376
+ 'sync_configs.$[processingConfig].state': storage.SyncRuleState.ACTIVE
377
+ }
378
+ }, {
379
+ session,
380
+ arrayFilters: [
381
+ { 'activeConfig.state': storage.SyncRuleState.ACTIVE },
382
+ { 'processingConfig._id': { $in: processingStates.map((state) => state._id) } }
383
+ ]
384
+ });
385
+ activated = true;
386
+ }
387
+ else if (doc.state != storage.SyncRuleState.PROCESSING && doc.state != storage.SyncRuleState.ACTIVE) {
388
+ this.needsActivationV3 = false;
389
+ }
390
+ });
391
+ if (activated) {
392
+ this.logger.info(`Activated new replication stream at ${lsn}`);
393
+ await this.db.notifyCheckpoint();
394
+ this.needsActivationV3 = false;
395
+ }
396
+ }
397
+ async markAllSnapshotDone(no_checkpoint_before_lsn) {
398
+ await this.db.sync_rules.updateOne({
399
+ _id: this.replicationStreamId,
400
+ 'sync_configs._id': { $in: this.syncConfigIds }
401
+ }, {
402
+ $set: {
403
+ 'sync_configs.$[config].snapshot_done': true,
404
+ last_keepalive_ts: new Date()
405
+ },
406
+ $max: {
407
+ 'sync_configs.$[config].no_checkpoint_before': no_checkpoint_before_lsn
408
+ }
409
+ }, {
410
+ session: this.session,
411
+ arrayFilters: [{ 'config._id': { $in: this.syncConfigIds } }]
412
+ });
413
+ }
414
+ async markSnapshotDone(no_checkpoint_before_lsn, options) {
415
+ await this.withTransaction(async () => {
416
+ // Protect against race conditions
417
+ const blockingTables = await this.db
418
+ .sourceTables(this.replicationStreamId)
419
+ .find(this.snapshotBlockingSourceTablesFilter(), {
420
+ session: this.session,
421
+ projection: { schema_name: 1, table_name: 1 }
422
+ })
423
+ .toArray();
424
+ if (blockingTables.length > 0) {
425
+ if (options?.throwOnConflict ?? true) {
426
+ throw new ReplicationAssertionError(`Cannot mark snapshot done while source tables still require snapshotting. Tables: ${blockingTables.map((t) => `${t.schema_name}.${t.table_name}`).join(', ')}`);
427
+ }
428
+ else {
429
+ return;
430
+ }
431
+ }
432
+ await this.markAllSnapshotDone(no_checkpoint_before_lsn);
433
+ });
434
+ }
435
+ async markTableSnapshotRequired(table) {
436
+ const syncConfigIds = this.relevantSyncConfigIds(table);
437
+ if (syncConfigIds.length == 0) {
438
+ return;
439
+ }
440
+ await this.db.sync_rules.updateOne({
441
+ _id: this.replicationStreamId,
442
+ 'sync_configs._id': { $in: syncConfigIds }
443
+ }, {
444
+ $set: {
445
+ 'sync_configs.$[config].snapshot_done': false
446
+ }
447
+ }, {
448
+ session: this.session,
449
+ arrayFilters: [{ 'config._id': { $in: syncConfigIds } }]
450
+ });
451
+ }
452
+ async markTableSnapshotDone(tables, no_checkpoint_before_lsn) {
453
+ const session = this.session;
454
+ const ids = tables.map((table) => mongoTableId(table.id));
455
+ const syncConfigIds = this.relevantSyncConfigIdsForTables(tables);
456
+ await this.withTransaction(async () => {
457
+ await this.db.sourceTables(this.replicationStreamId).updateMany({ _id: { $in: ids } }, {
458
+ $set: {
459
+ snapshot_done: true
460
+ },
461
+ $unset: {
462
+ snapshot_status: 1
463
+ }
464
+ }, { session });
465
+ if (no_checkpoint_before_lsn != null && syncConfigIds.length > 0) {
466
+ await this.db.sync_rules.updateOne({
467
+ _id: this.replicationStreamId,
468
+ 'sync_configs._id': { $in: syncConfigIds }
469
+ }, {
470
+ $set: {
471
+ last_keepalive_ts: new Date()
472
+ },
473
+ $max: {
474
+ 'sync_configs.$[config].no_checkpoint_before': no_checkpoint_before_lsn
475
+ }
476
+ }, {
477
+ session: this.session,
478
+ // Only set for sync configs that use this table
479
+ arrayFilters: [{ 'config._id': { $in: syncConfigIds } }]
480
+ });
481
+ }
482
+ });
483
+ return tables.map((table) => {
484
+ const copy = table.clone();
485
+ copy.snapshotComplete = true;
486
+ return copy;
487
+ });
488
+ }
33
489
  }
34
490
  //# sourceMappingURL=MongoBucketBatchV3.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"MongoBucketBatchV3.js","sourceRoot":"","sources":["../../../../src/storage/implementation/v3/MongoBucketBatchV3.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,gCAAgC,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAA2B,MAAM,wBAAwB,CAAC;AAGnF,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAG/D,MAAM,OAAO,kBAAmB,SAAQ,gBAAgB;IAGrC,KAAK,CAAoB;IAE1C,YAAY,OAAgC;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,IAAI,mBAAmB,CAAC,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AE,IAAI,IAAI,EAAE;qBAC9B;oBACD,IAAI,EAAE;wBACJ,6CAA6C,EAAE,wBAAwB;qBACxE;iBACF,EACD;oBACE,OAAO,EAAE,IAAI,CAAC,OAAO;oBACrB,gDAAgD;oBAChD,YAAY,EAAE,CAAC,EAAE,YAAY,EAAE,EAAE,GAAG,EAAE,aAAa,EAAE,EAAE,CAAC;iBACzD,CACF,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YAC1B,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;YAC3B,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;YAC7B,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -1,15 +1,35 @@
1
- import { BucketChecksum, FetchPartialBucketChecksum, InternalOpId, PartialChecksumMap } from '@powersync/service-core';
2
- import { FetchPartialBucketChecksumV3, MongoChecksumOptions, MongoChecksums } from '../MongoChecksums.js';
1
+ import { BucketChecksum, FetchPartialBucketChecksum, InternalOpId, PartialChecksumMap, SingleSyncConfigBucketDefinitionMapping } from '@powersync/service-core';
2
+ import { FetchPartialBucketChecksumByDefinition, MongoChecksumOptions, MongoChecksums } from '../MongoChecksums.js';
3
3
  import { VersionedPowerSyncMongoV3 } from './VersionedPowerSyncMongoV3.js';
4
- export declare class MongoChecksumsV3 extends MongoChecksums {
4
+ /**
5
+ * Checksum operations addressed by persisted definition id.
6
+ *
7
+ * Safe on any storage instance, including multi-config replication-side instances - no
8
+ * source resolution is involved. This is the only checksum surface the compactor may use.
9
+ */
10
+ export interface DefinitionChecksumOperations {
11
+ computePartialChecksumsDirectByDefinition(batch: FetchPartialBucketChecksumByDefinition[]): Promise<PartialChecksumMap>;
12
+ }
13
+ export interface MongoChecksumOptionsV3 extends MongoChecksumOptions {
14
+ /**
15
+ * The persisted mapping of the single sync config that reads are served from.
16
+ *
17
+ * A thunk rather than a plain value: checksums are constructed eagerly with the storage
18
+ * instance, but the single-config requirement may only be asserted when a read happens.
19
+ */
20
+ syncConfigMapping: () => SingleSyncConfigBucketDefinitionMapping;
21
+ }
22
+ export declare class MongoChecksumsV3 extends MongoChecksums implements DefinitionChecksumOperations {
5
23
  protected readonly db: VersionedPowerSyncMongoV3;
6
- private readonly mapping;
7
- constructor(db: VersionedPowerSyncMongoV3, group_id: number, options: MongoChecksumOptions);
8
- private normalizeBatch;
9
- computePartialChecksumsDirectByDefinition(batch: FetchPartialBucketChecksumV3[]): Promise<PartialChecksumMap>;
24
+ private readonly syncConfigMapping;
25
+ constructor(db: VersionedPowerSyncMongoV3, group_id: number, options: MongoChecksumOptionsV3);
26
+ computePartialChecksumsDirectByDefinition(batch: FetchPartialBucketChecksumByDefinition[]): Promise<PartialChecksumMap>;
10
27
  protected fetchPreStates(batch: FetchPartialBucketChecksum[]): Promise<Map<string, {
11
28
  opId: InternalOpId;
12
29
  checksum: BucketChecksum;
13
30
  }>>;
14
31
  protected computePartialChecksumsInternal(batch: FetchPartialBucketChecksum[]): Promise<PartialChecksumMap>;
32
+ private computeChecksumsByDefinition;
33
+ private buildPartialChecksumPipeline;
34
+ private normalizePartialChecksumResults;
15
35
  }