@powersync/service-module-mongodb-storage 0.20.0 → 0.22.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.
- package/CHANGELOG.md +62 -0
- package/dist/storage/MongoBucketStorage.d.ts +36 -3
- package/dist/storage/MongoBucketStorage.js +372 -207
- package/dist/storage/MongoBucketStorage.js.map +1 -1
- package/dist/storage/implementation/MongoBucketBatch.d.ts +17 -5
- package/dist/storage/implementation/MongoBucketBatch.js +44 -17
- package/dist/storage/implementation/MongoBucketBatch.js.map +1 -1
- package/dist/storage/implementation/MongoCompactor.d.ts +19 -79
- package/dist/storage/implementation/MongoCompactor.js +27 -238
- package/dist/storage/implementation/MongoCompactor.js.map +1 -1
- package/dist/storage/implementation/MongoParameterCompactor.d.ts +83 -10
- package/dist/storage/implementation/MongoParameterCompactor.js +309 -96
- package/dist/storage/implementation/MongoParameterCompactor.js.map +1 -1
- package/dist/storage/implementation/MongoParsedSyncConfigSet.d.ts +9 -1
- package/dist/storage/implementation/MongoParsedSyncConfigSet.js +29 -0
- package/dist/storage/implementation/MongoParsedSyncConfigSet.js.map +1 -1
- package/dist/storage/implementation/MongoPersistedSyncConfigContent.js +4 -2
- package/dist/storage/implementation/MongoPersistedSyncConfigContent.js.map +1 -1
- package/dist/storage/implementation/MongoStorageProvider.js +7 -3
- package/dist/storage/implementation/MongoStorageProvider.js.map +1 -1
- package/dist/storage/implementation/MongoSyncBucketStorage.d.ts +27 -11
- package/dist/storage/implementation/MongoSyncBucketStorage.js +78 -31
- package/dist/storage/implementation/MongoSyncBucketStorage.js.map +1 -1
- package/dist/storage/implementation/MongoSyncRulesLock.js +21 -9
- package/dist/storage/implementation/MongoSyncRulesLock.js.map +1 -1
- package/dist/storage/implementation/MongoWriteBatch.d.ts +49 -0
- package/dist/storage/implementation/MongoWriteBatch.js +149 -0
- package/dist/storage/implementation/MongoWriteBatch.js.map +1 -0
- package/dist/storage/implementation/MongoWriteCheckpointAPI.d.ts +9 -7
- package/dist/storage/implementation/MongoWriteCheckpointAPI.js +9 -30
- package/dist/storage/implementation/MongoWriteCheckpointAPI.js.map +1 -1
- package/dist/storage/implementation/SyncRuleStateUpdate.d.ts +11 -5
- package/dist/storage/implementation/SyncRuleStateUpdate.js +14 -6
- package/dist/storage/implementation/SyncRuleStateUpdate.js.map +1 -1
- package/dist/storage/implementation/common/MongoSyncBucketStorageCheckpoint.d.ts +22 -2
- package/dist/storage/implementation/common/PersistedBatch.d.ts +32 -4
- package/dist/storage/implementation/common/PersistedBatch.js +49 -6
- package/dist/storage/implementation/common/PersistedBatch.js.map +1 -1
- package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.d.ts +3 -0
- package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.js +3 -0
- package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.js.map +1 -1
- package/dist/storage/implementation/db.d.ts +9 -1
- package/dist/storage/implementation/db.js +27 -1
- package/dist/storage/implementation/db.js.map +1 -1
- package/dist/storage/implementation/models.d.ts +31 -0
- package/dist/storage/implementation/models.js.map +1 -1
- package/dist/storage/implementation/v1/MongoBucketBatchV1.d.ts +2 -0
- package/dist/storage/implementation/v1/MongoBucketBatchV1.js +33 -4
- package/dist/storage/implementation/v1/MongoBucketBatchV1.js.map +1 -1
- package/dist/storage/implementation/v1/MongoCompactorV1.d.ts +38 -6
- package/dist/storage/implementation/v1/MongoCompactorV1.js +247 -20
- package/dist/storage/implementation/v1/MongoCompactorV1.js.map +1 -1
- package/dist/storage/implementation/v1/MongoParameterCompactorV1.d.ts +16 -2
- package/dist/storage/implementation/v1/MongoParameterCompactorV1.js +20 -9
- package/dist/storage/implementation/v1/MongoParameterCompactorV1.js.map +1 -1
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.d.ts +18 -11
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js +65 -16
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js.map +1 -1
- package/dist/storage/implementation/v1/PersistedBatchV1.d.ts +7 -5
- package/dist/storage/implementation/v1/PersistedBatchV1.js +22 -28
- package/dist/storage/implementation/v1/PersistedBatchV1.js.map +1 -1
- package/dist/storage/implementation/v1/models.js +1 -0
- package/dist/storage/implementation/v1/models.js.map +1 -1
- package/dist/storage/implementation/v3/CompactionLease.d.ts +50 -0
- package/dist/storage/implementation/v3/CompactionLease.js +131 -0
- package/dist/storage/implementation/v3/CompactionLease.js.map +1 -0
- package/dist/storage/implementation/v3/MongoBucketBatchV3.d.ts +10 -2
- package/dist/storage/implementation/v3/MongoBucketBatchV3.js +100 -26
- package/dist/storage/implementation/v3/MongoBucketBatchV3.js.map +1 -1
- package/dist/storage/implementation/v3/MongoCompactorV3.d.ts +82 -25
- package/dist/storage/implementation/v3/MongoCompactorV3.js +698 -159
- package/dist/storage/implementation/v3/MongoCompactorV3.js.map +1 -1
- package/dist/storage/implementation/v3/MongoParameterCompactorV3.d.ts +18 -0
- package/dist/storage/implementation/v3/MongoParameterCompactorV3.js +23 -0
- package/dist/storage/implementation/v3/MongoParameterCompactorV3.js.map +1 -0
- package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.d.ts +2 -15
- package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.js +60 -92
- package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.js.map +1 -1
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.d.ts +19 -9
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js +91 -31
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js.map +1 -1
- package/dist/storage/implementation/v3/MongoWriteCheckpointAPIV3.d.ts +26 -0
- package/dist/storage/implementation/v3/MongoWriteCheckpointAPIV3.js +82 -0
- package/dist/storage/implementation/v3/MongoWriteCheckpointAPIV3.js.map +1 -0
- package/dist/storage/implementation/v3/PersistedBatchV3.d.ts +14 -8
- package/dist/storage/implementation/v3/PersistedBatchV3.js +76 -42
- package/dist/storage/implementation/v3/PersistedBatchV3.js.map +1 -1
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.d.ts +12 -2
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js +42 -3
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js.map +1 -1
- package/dist/storage/implementation/v3/bucket-format.js +2 -0
- package/dist/storage/implementation/v3/bucket-format.js.map +1 -1
- package/dist/storage/implementation/v3/compact-utils.d.ts +107 -0
- package/dist/storage/implementation/v3/compact-utils.js +216 -0
- package/dist/storage/implementation/v3/compact-utils.js.map +1 -0
- package/dist/storage/implementation/v3/compaction-constants.d.ts +5 -0
- package/dist/storage/implementation/v3/compaction-constants.js +6 -0
- package/dist/storage/implementation/v3/compaction-constants.js.map +1 -0
- package/dist/storage/implementation/v3/models.d.ts +84 -4
- package/dist/storage/implementation/v3/models.js.map +1 -1
- package/dist/storage/implementation/v3/object-storage/BucketDataObjectStorage.d.ts +7 -8
- package/dist/storage/implementation/v3/object-storage/BucketDataObjectStorage.js +16 -5
- package/dist/storage/implementation/v3/object-storage/BucketDataObjectStorage.js.map +1 -1
- package/dist/storage/implementation/v3/object-storage/ObjectStorage.d.ts +14 -11
- package/dist/storage/implementation/v3/object-storage/ObjectStorageLifecycle.d.ts +6 -8
- package/dist/storage/implementation/v3/object-storage/ObjectStorageLifecycle.js +17 -11
- package/dist/storage/implementation/v3/object-storage/ObjectStorageLifecycle.js.map +1 -1
- package/dist/storage/implementation/v3/object-storage/ObjectStorageUsage.d.ts +38 -0
- package/dist/storage/implementation/v3/object-storage/ObjectStorageUsage.js +164 -0
- package/dist/storage/implementation/v3/object-storage/ObjectStorageUsage.js.map +1 -0
- package/dist/storage/implementation/v3/object-storage/S3ObjectStorage.d.ts +37 -12
- package/dist/storage/implementation/v3/object-storage/S3ObjectStorage.js +197 -25
- package/dist/storage/implementation/v3/object-storage/S3ObjectStorage.js.map +1 -1
- package/dist/storage/implementation/v3/source-table-utils.d.ts +6 -6
- package/dist/storage/implementation/v3/source-table-utils.js +30 -37
- package/dist/storage/implementation/v3/source-table-utils.js.map +1 -1
- package/dist/storage/storage-index.d.ts +2 -1
- package/dist/storage/storage-index.js +1 -0
- package/dist/storage/storage-index.js.map +1 -1
- package/dist/types/types.d.ts +28 -1
- package/dist/types/types.js +28 -7
- package/dist/types/types.js.map +1 -1
- package/dist/utils/test-utils.js +1 -0
- package/dist/utils/test-utils.js.map +1 -1
- package/dist/utils/util.js +3 -1
- package/dist/utils/util.js.map +1 -1
- package/package.json +10 -9
- package/src/storage/MongoBucketStorage.ts +507 -269
- package/src/storage/implementation/MongoBucketBatch.ts +67 -24
- package/src/storage/implementation/MongoCompactor.ts +35 -346
- package/src/storage/implementation/MongoParameterCompactor.ts +388 -102
- package/src/storage/implementation/MongoParsedSyncConfigSet.ts +34 -0
- package/src/storage/implementation/MongoPersistedSyncConfigContent.ts +4 -2
- package/src/storage/implementation/MongoStorageProvider.ts +15 -3
- package/src/storage/implementation/MongoSyncBucketStorage.ts +114 -40
- package/src/storage/implementation/MongoSyncRulesLock.ts +22 -9
- package/src/storage/implementation/MongoWriteBatch.ts +172 -0
- package/src/storage/implementation/MongoWriteCheckpointAPI.ts +16 -46
- package/src/storage/implementation/SyncRuleStateUpdate.ts +13 -6
- package/src/storage/implementation/common/MongoSyncBucketStorageCheckpoint.ts +24 -2
- package/src/storage/implementation/common/PersistedBatch.ts +66 -10
- package/src/storage/implementation/common/VersionedPowerSyncMongoBase.ts +4 -0
- package/src/storage/implementation/db.ts +35 -2
- package/src/storage/implementation/models.ts +34 -0
- package/src/storage/implementation/v1/MongoBucketBatchV1.ts +46 -6
- package/src/storage/implementation/v1/MongoCompactorV1.ts +327 -40
- package/src/storage/implementation/v1/MongoParameterCompactorV1.ts +25 -9
- package/src/storage/implementation/v1/MongoSyncBucketStorageV1.ts +87 -27
- package/src/storage/implementation/v1/PersistedBatchV1.ts +25 -30
- package/src/storage/implementation/v1/models.ts +1 -0
- package/src/storage/implementation/v3/CompactionLease.ts +152 -0
- package/src/storage/implementation/v3/MongoBucketBatchV3.ts +138 -34
- package/src/storage/implementation/v3/MongoCompactorV3.ts +958 -225
- package/src/storage/implementation/v3/MongoParameterCompactorV3.ts +34 -0
- package/src/storage/implementation/v3/MongoStoppedSyncConfigCleanup.ts +100 -109
- package/src/storage/implementation/v3/MongoSyncBucketStorageV3.ts +111 -41
- package/src/storage/implementation/v3/MongoWriteCheckpointAPIV3.ts +111 -0
- package/src/storage/implementation/v3/PersistedBatchV3.ts +93 -48
- package/src/storage/implementation/v3/VersionedPowerSyncMongoV3.ts +55 -4
- package/src/storage/implementation/v3/bucket-format.ts +2 -0
- package/src/storage/implementation/v3/compact-utils.ts +320 -0
- package/src/storage/implementation/v3/compaction-constants.ts +5 -0
- package/src/storage/implementation/v3/models.ts +91 -3
- package/src/storage/implementation/v3/object-storage/BucketDataObjectStorage.ts +24 -9
- package/src/storage/implementation/v3/object-storage/ObjectStorage.ts +20 -5
- package/src/storage/implementation/v3/object-storage/ObjectStorageLifecycle.ts +26 -14
- package/src/storage/implementation/v3/object-storage/ObjectStorageUsage.ts +229 -0
- package/src/storage/implementation/v3/object-storage/S3ObjectStorage.ts +279 -29
- package/src/storage/implementation/v3/source-table-utils.ts +39 -41
- package/src/storage/storage-index.ts +2 -0
- package/src/types/types.ts +42 -7
- package/src/utils/test-utils.ts +1 -0
- package/src/utils/util.ts +3 -1
- package/test/src/__snapshots__/storage.test.ts.snap +25 -0
- package/test/src/__snapshots__/storage_sync.test.ts.snap +605 -16
- package/test/src/chunk_compaction_config.test.ts +38 -0
- package/test/src/cleanup-stopped-sync-configs.test.ts +40 -13
- package/test/src/compact-utils.test.ts +226 -0
- package/test/src/helpers/MemoryObjectStorage.ts +14 -6
- package/test/src/object_storage_usage.test.ts +267 -0
- package/test/src/parameter_compacting_v1.test.ts +120 -0
- package/test/src/parameter_compacting_v3.test.ts +192 -0
- package/test/src/parameter_compaction_fence.test.ts +276 -0
- package/test/src/storage.test.ts +273 -22
- package/test/src/storage_compacting.test.ts +968 -246
- package/test/src/storage_s3_checksums.test.ts +3 -4
- package/test/src/storage_s3_compaction_lifecycle.test.ts +138 -12
- package/test/src/storage_s3_reading.test.ts +290 -2
- package/test/src/storage_s3_writing.test.ts +1 -0
- package/test/src/storage_sync.test.ts +336 -41
- package/test/src/util.ts +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { mongo } from '@powersync/lib-service-mongodb';
|
|
2
|
+
/**
|
|
3
|
+
* Explicitly groups writes with no intervening reads or result dependencies.
|
|
4
|
+
* Callers retain responsibility for transaction and ordering boundaries.
|
|
5
|
+
*
|
|
6
|
+
* On MongoDB 8.0+, this uses the client-level bulkWrite API.
|
|
7
|
+
*
|
|
8
|
+
* On MongoDB earlier versions, this uses the the collection-level bulkWrite API, or individual operations.
|
|
9
|
+
* This is less efficient, but produces the same results.
|
|
10
|
+
*/
|
|
11
|
+
export class MongoWriteBatch {
|
|
12
|
+
client;
|
|
13
|
+
supportsClientBulkWrite;
|
|
14
|
+
session;
|
|
15
|
+
operations = [];
|
|
16
|
+
deleteChecks = [];
|
|
17
|
+
fallback = [];
|
|
18
|
+
ordered;
|
|
19
|
+
constructor(client, supportsClientBulkWrite, session, options) {
|
|
20
|
+
this.client = client;
|
|
21
|
+
this.supportsClientBulkWrite = supportsClientBulkWrite;
|
|
22
|
+
this.session = session;
|
|
23
|
+
this.ordered = options.ordered;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Perform a collection-level bulkWrite.
|
|
27
|
+
*
|
|
28
|
+
* On MongoDB 8.0+, these operations join the client-level bulkWrite with the batch's ordering.
|
|
29
|
+
* The driver may split commands to respect server batch limits.
|
|
30
|
+
*
|
|
31
|
+
* On earlier MongoDB versions, this always uses an unordered collection-level bulkWrite.
|
|
32
|
+
* Operations within this collection bulk must therefore be independent of their order.
|
|
33
|
+
*/
|
|
34
|
+
bulkWriteUnordered(collection, operations) {
|
|
35
|
+
if (operations.length === 0)
|
|
36
|
+
return;
|
|
37
|
+
if (!this.supportsClientBulkWrite) {
|
|
38
|
+
this.fallback.push(() => collection.bulkWrite(operations, { ordered: false, session: this.session }));
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
for (const operation of operations) {
|
|
42
|
+
// Collection and client models contain the same operation fields, with a
|
|
43
|
+
// different envelope. Keep the schema checked at the collection boundary.
|
|
44
|
+
const [name, model] = Object.entries(operation)[0];
|
|
45
|
+
this.operations.push({ ...model, name, namespace: collection.namespace });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
insertOne(collection, document) {
|
|
49
|
+
if (!this.supportsClientBulkWrite) {
|
|
50
|
+
this.fallback.push(() => collection.insertOne(document, { session: this.session }));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
this.addModel({ name: 'insertOne', namespace: collection.namespace, document: document });
|
|
54
|
+
}
|
|
55
|
+
insertMany(collection, documents) {
|
|
56
|
+
if (documents.length === 0)
|
|
57
|
+
return;
|
|
58
|
+
if (!this.supportsClientBulkWrite) {
|
|
59
|
+
this.fallback.push(() => collection.insertMany(documents, { session: this.session }));
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
for (const document of documents) {
|
|
63
|
+
this.addModel({
|
|
64
|
+
name: 'insertOne',
|
|
65
|
+
namespace: collection.namespace,
|
|
66
|
+
document: document
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
deleteMany(collection, filter, checkDeletedCount) {
|
|
71
|
+
if (checkDeletedCount) {
|
|
72
|
+
// Client-bulk results are checked after all writes execute. A failed
|
|
73
|
+
// invariant must roll back the entire batch, not leave later writes visible.
|
|
74
|
+
if (!this.session?.inTransaction())
|
|
75
|
+
throw new Error('Checked deletes require a transaction');
|
|
76
|
+
}
|
|
77
|
+
if (!this.supportsClientBulkWrite) {
|
|
78
|
+
this.fallback.push(async () => {
|
|
79
|
+
const result = await collection.deleteMany(filter, { session: this.session });
|
|
80
|
+
checkDeletedCount?.(result.deletedCount);
|
|
81
|
+
});
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (checkDeletedCount) {
|
|
85
|
+
this.deleteChecks.push({ index: this.operations.length, check: checkDeletedCount });
|
|
86
|
+
}
|
|
87
|
+
this.addModel({ name: 'deleteMany', namespace: collection.namespace, filter });
|
|
88
|
+
}
|
|
89
|
+
updateOne(collection, filter, update, options = {}) {
|
|
90
|
+
if (!this.supportsClientBulkWrite) {
|
|
91
|
+
this.fallback.push(() => collection.updateOne(filter, update, { ...options, session: this.session }));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
this.addModel({ name: 'updateOne', namespace: collection.namespace, filter, update, ...options });
|
|
95
|
+
}
|
|
96
|
+
updateMany(collection, filter, update, options = {}) {
|
|
97
|
+
if (!this.supportsClientBulkWrite) {
|
|
98
|
+
this.fallback.push(() => collection.updateMany(filter, update, { ...options, session: this.session }));
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
this.addModel({ name: 'updateMany', namespace: collection.namespace, filter, update, ...options });
|
|
102
|
+
}
|
|
103
|
+
addModel(operation) {
|
|
104
|
+
// The collection-specific methods validate the schema before erasing it here.
|
|
105
|
+
this.operations.push(operation);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Execute the queued writes.
|
|
109
|
+
*
|
|
110
|
+
* On MongoDB 8.0+, this uses the client-level bulkWrite API, typically resulting in a single command.
|
|
111
|
+
* The command may be split if there are a large number of operations.
|
|
112
|
+
*
|
|
113
|
+
* On earlier MongoDB versions, this executes each queued operation individually.
|
|
114
|
+
*
|
|
115
|
+
* If no operations were queued, this is a no-op.
|
|
116
|
+
*/
|
|
117
|
+
async execute() {
|
|
118
|
+
if (!this.supportsClientBulkWrite) {
|
|
119
|
+
// Sessions cannot execute concurrent operations within a transaction.
|
|
120
|
+
for (const write of this.fallback)
|
|
121
|
+
await write();
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (this.operations.length === 0)
|
|
125
|
+
return;
|
|
126
|
+
try {
|
|
127
|
+
const result = await this.client.bulkWrite(this.operations, {
|
|
128
|
+
session: this.session,
|
|
129
|
+
ordered: this.ordered,
|
|
130
|
+
verboseResults: this.deleteChecks.length > 0
|
|
131
|
+
});
|
|
132
|
+
for (const { index, check } of this.deleteChecks) {
|
|
133
|
+
const deleted = result.deleteResults?.get(index);
|
|
134
|
+
if (deleted == null)
|
|
135
|
+
throw new Error('Missing client bulk delete result');
|
|
136
|
+
check(deleted.deletedCount);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
// The driver wraps command failures without copying their error labels.
|
|
141
|
+
// Preserve withTransaction's retry handling for e.g. write conflicts.
|
|
142
|
+
if (error instanceof mongo.MongoClientBulkWriteError && error.cause instanceof mongo.MongoError) {
|
|
143
|
+
throw error.cause;
|
|
144
|
+
}
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=MongoWriteBatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MongoWriteBatch.js","sourceRoot":"","sources":["../../../src/storage/implementation/MongoWriteBatch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAEvD;;;;;;;;GAQG;AACH,MAAM,OAAO,eAAe;IAQP;IACA;IACA;IATF,UAAU,GAAoD,EAAE,CAAC;IACjE,YAAY,GAAwD,EAAE,CAAC;IACvE,QAAQ,GAA+B,EAAE,CAAC;IAE1C,OAAO,CAAU;IAElC,YACmB,MAAyB,EACzB,uBAAgC,EAChC,OAAwC,EACzD,OAA6B;QAHZ,WAAM,GAAN,MAAM,CAAmB;QACzB,4BAAuB,GAAvB,uBAAuB,CAAS;QAChC,YAAO,GAAP,OAAO,CAAiC;QAGzD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAC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AO;QACX,IAAI,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC;YAClC,sEAAsE;YACtE,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ;gBAAE,MAAM,KAAK,EAAE,CAAC;YACjD,OAAO;QACT,CAAC;QACD,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QAEzC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,EAAE;gBAC1D,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,cAAc,EAAE,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC;aAC7C,CAAC,CAAC;YACH,KAAK,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;gBACjD,MAAM,OAAO,GAAG,MAAM,CAAC,aAAa,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;gBACjD,IAAI,OAAO,IAAI,IAAI;oBAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;gBAC1E,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,wEAAwE;YACxE,sEAAsE;YACtE,IAAI,KAAK,YAAY,KAAK,CAAC,yBAAyB,IAAI,KAAK,CAAC,KAAK,YAAY,KAAK,CAAC,UAAU,EAAE,CAAC;gBAChG,MAAM,KAAK,CAAC,KAAK,CAAC;YACpB,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { GetCheckpointChangesOptions, InternalOpId, storage } from '@powersync/service-core';
|
|
1
|
+
import { GetCheckpointChangesOptions, storage } from '@powersync/service-core';
|
|
3
2
|
import { VersionedPowerSyncMongo } from './db.js';
|
|
4
3
|
export type MongoCheckpointAPIOptions = {
|
|
5
4
|
db: VersionedPowerSyncMongo;
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
writeCheckpointMode: storage.WriteCheckpointModeConfig;
|
|
6
|
+
replicationStreamId: number;
|
|
8
7
|
};
|
|
9
8
|
export declare class MongoWriteCheckpointAPI implements storage.WriteCheckpointAPI {
|
|
10
9
|
readonly db: VersionedPowerSyncMongo;
|
|
10
|
+
readonly replicationStreamId: number;
|
|
11
11
|
private _mode;
|
|
12
12
|
constructor(options: MongoCheckpointAPIOptions);
|
|
13
13
|
get writeCheckpointMode(): storage.WriteCheckpointMode;
|
|
14
|
-
setWriteCheckpointMode(
|
|
14
|
+
setWriteCheckpointMode(config: storage.WriteCheckpointModeConfig): void;
|
|
15
15
|
createManagedWriteCheckpoints(checkpoints: storage.ManagedWriteCheckpointOptions[]): Promise<storage.CreateManagedWriteCheckpointsResult>;
|
|
16
16
|
private createSuppliedManagedWriteCheckpoints;
|
|
17
17
|
lastWriteCheckpoint(filters: storage.LastWriteCheckpointFilters): Promise<bigint | null>;
|
|
@@ -22,6 +22,8 @@ export declare class MongoWriteCheckpointAPI implements storage.WriteCheckpointA
|
|
|
22
22
|
protected lastCustomWriteCheckpoint(filters: storage.CustomWriteCheckpointFilters): Promise<bigint | null>;
|
|
23
23
|
protected lastManagedWriteCheckpoint(filters: storage.ManagedWriteCheckpointFilters): Promise<bigint | null>;
|
|
24
24
|
private getManagedWriteCheckpointChanges;
|
|
25
|
-
|
|
25
|
+
protected getCustomWriteCheckpointChanges(options: GetCheckpointChangesOptions): Promise<{
|
|
26
|
+
invalidateWriteCheckpoints: boolean;
|
|
27
|
+
updatedWriteCheckpoints: Map<string, bigint>;
|
|
28
|
+
}>;
|
|
26
29
|
}
|
|
27
|
-
export declare function batchCreateCustomWriteCheckpoints(db: VersionedPowerSyncMongo, session: mongo.ClientSession, checkpoints: storage.CustomWriteCheckpointOptions[], opId: InternalOpId): Promise<void>;
|
|
@@ -2,16 +2,18 @@ import * as framework from '@powersync/lib-services-framework';
|
|
|
2
2
|
import { storage } from '@powersync/service-core';
|
|
3
3
|
export class MongoWriteCheckpointAPI {
|
|
4
4
|
db;
|
|
5
|
+
replicationStreamId;
|
|
5
6
|
_mode;
|
|
6
7
|
constructor(options) {
|
|
7
8
|
this.db = options.db;
|
|
8
|
-
this._mode = options.mode;
|
|
9
|
+
this._mode = options.writeCheckpointMode.mode;
|
|
10
|
+
this.replicationStreamId = options.replicationStreamId;
|
|
9
11
|
}
|
|
10
12
|
get writeCheckpointMode() {
|
|
11
13
|
return this._mode;
|
|
12
14
|
}
|
|
13
|
-
setWriteCheckpointMode(
|
|
14
|
-
this._mode = mode;
|
|
15
|
+
setWriteCheckpointMode(config) {
|
|
16
|
+
this._mode = config.mode;
|
|
15
17
|
}
|
|
16
18
|
async createManagedWriteCheckpoints(checkpoints) {
|
|
17
19
|
if (this.writeCheckpointMode !== storage.WriteCheckpointMode.MANAGED) {
|
|
@@ -68,7 +70,7 @@ export class MongoWriteCheckpointAPI {
|
|
|
68
70
|
},
|
|
69
71
|
upsert: true
|
|
70
72
|
}
|
|
71
|
-
})));
|
|
73
|
+
})), { ordered: false });
|
|
72
74
|
const userIds = generatedCheckpoints.map((checkpoint) => checkpoint.user_id);
|
|
73
75
|
const docs = await this.db.write_checkpoints
|
|
74
76
|
.find({
|
|
@@ -140,7 +142,7 @@ export class MongoWriteCheckpointAPI {
|
|
|
140
142
|
upsert: true
|
|
141
143
|
}
|
|
142
144
|
};
|
|
143
|
-
}));
|
|
145
|
+
}), { ordered: false });
|
|
144
146
|
// Fetch the final ids separately so stale requests can still return the
|
|
145
147
|
// checkpoint currently stored. If duplicate rows already exist for a
|
|
146
148
|
// user_id, use the highest stored id instead of whichever document MongoDB
|
|
@@ -194,6 +196,7 @@ export class MongoWriteCheckpointAPI {
|
|
|
194
196
|
}
|
|
195
197
|
}
|
|
196
198
|
async lastCustomWriteCheckpoint(filters) {
|
|
199
|
+
// Legacy V1/V2 implementation.
|
|
197
200
|
const { user_id, sync_rules_id } = filters;
|
|
198
201
|
const lastWriteCheckpoint = await this.db.custom_write_checkpoints.findOne({
|
|
199
202
|
user_id,
|
|
@@ -242,6 +245,7 @@ export class MongoWriteCheckpointAPI {
|
|
|
242
245
|
}
|
|
243
246
|
async getCustomWriteCheckpointChanges(options) {
|
|
244
247
|
const limit = 1000;
|
|
248
|
+
// Legacy V1/V2 implementation.
|
|
245
249
|
const changes = await this.db.custom_write_checkpoints
|
|
246
250
|
.find({
|
|
247
251
|
op_id: { $gt: options.lastCheckpoint.checkpoint, $lte: options.nextCheckpoint.checkpoint }
|
|
@@ -266,29 +270,4 @@ export class MongoWriteCheckpointAPI {
|
|
|
266
270
|
};
|
|
267
271
|
}
|
|
268
272
|
}
|
|
269
|
-
export async function batchCreateCustomWriteCheckpoints(db, session, checkpoints, opId) {
|
|
270
|
-
if (checkpoints.length == 0) {
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
await db.custom_write_checkpoints.bulkWrite(checkpoints.map((checkpointOptions) => {
|
|
274
|
-
const set = {
|
|
275
|
-
checkpoint: checkpointOptions.checkpoint,
|
|
276
|
-
sync_rules_id: checkpointOptions.sync_rules_id,
|
|
277
|
-
op_id: opId
|
|
278
|
-
};
|
|
279
|
-
if (checkpointOptions.checkpoint_requested_at != null) {
|
|
280
|
-
set.checkpoint_requested_at = checkpointOptions.checkpoint_requested_at;
|
|
281
|
-
}
|
|
282
|
-
return {
|
|
283
|
-
updateOne: {
|
|
284
|
-
filter: { user_id: checkpointOptions.user_id, sync_rules_id: checkpointOptions.sync_rules_id },
|
|
285
|
-
update: {
|
|
286
|
-
$set: set,
|
|
287
|
-
...(checkpointOptions.checkpoint_requested_at == null ? { $unset: { checkpoint_requested_at: 1 } } : {})
|
|
288
|
-
},
|
|
289
|
-
upsert: true
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
|
-
}), { session });
|
|
293
|
-
}
|
|
294
273
|
//# sourceMappingURL=MongoWriteCheckpointAPI.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongoWriteCheckpointAPI.js","sourceRoot":"","sources":["../../../src/storage/implementation/MongoWriteCheckpointAPI.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MongoWriteCheckpointAPI.js","sourceRoot":"","sources":["../../../src/storage/implementation/MongoWriteCheckpointAPI.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,mCAAmC,CAAC;AAC/D,OAAO,EAA+B,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAS/E,MAAM,OAAO,uBAAuB;IACzB,EAAE,CAA0B;IAC5B,mBAAmB,CAAS;IAE7B,KAAK,CAA8B;IAE3C,YAAY,OAAkC;QAC5C,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC;QAC9C,IAAI,CAAC,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IACzD,CAAC;IAED,IAAI,mBAAmB;QACrB,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,sBAAsB,CAAC,MAAyC;QAC9D,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,6BAA6B,CACjC,WAAoD;QAEpD,IAAI,IAAI,CAAC,mBAAmB,KAAK,OAAO,CAAC,mBAAmB,CAAC,OAAO,EAAE,CAAC;YACrE,MAAM,IAAI,SAAS,CAAC,qBAAqB,CACvC,qGAAqG,IAAI,CAAC,mBAAmB,GAAG,CACjI,CAAC;QACJ,CAAC;QAED,MAAM,iBAAiB,GAAG,OAAO,CAAC,6BAA6B,CAAC,WAAW,CAAC,CAAC;QAC7E,IAAI,iBAAiB,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC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AC,MAAM,GAAG,KAAK,CAAC;QAE1C,MAAM,uBAAuB,GAAG,IAAI,GAAG,EAAkB,CAAC;QAC1D,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,KAAK,IAAI,CAAC,IAAI,OAAO,EAAE,CAAC;gBACtB,uBAAuB,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC;YACvD,CAAC;QACH,CAAC;QAED,OAAO;YACL,0BAA0B,EAAE,UAAU;YACtC,uBAAuB;SACxB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { mongo } from '@powersync/lib-service-mongodb';
|
|
2
|
-
import { storage } from '@powersync/service-core';
|
|
3
2
|
/**
|
|
4
|
-
* Update pipeline to
|
|
3
|
+
* Update pipeline to stop a deploying replication stream, covering all storage versions.
|
|
5
4
|
*
|
|
6
5
|
* Roughly equivalent to:
|
|
7
6
|
* $set: {
|
|
8
|
-
* state:
|
|
9
|
-
* 'sync_configs.$[].state':
|
|
7
|
+
* state: STOP,
|
|
8
|
+
* 'sync_configs.$[].state': STOP
|
|
10
9
|
* }
|
|
11
10
|
*
|
|
12
11
|
* The difference is that this also handles v1 storage cases, where `sync_configs` is not present.
|
|
12
|
+
*
|
|
13
|
+
* This can be used for specific use cases:
|
|
14
|
+
* 1. Stop an existing PROCESSING stream, when it is being replaced by a new PROCESSING one.
|
|
15
|
+
* 2. Stop an existing ACTIVE or ERRORED stream, when it is being replaced by a new ACTIVE one.
|
|
16
|
+
*
|
|
17
|
+
* Do not use this when an ACTIVE stream transitions to ERRORED, and is being replaced by a new PROCESSING one.
|
|
18
|
+
* In that case, we need to maintain the ERRORED state, which this pipeline does not cover.
|
|
13
19
|
*/
|
|
14
|
-
export declare function
|
|
20
|
+
export declare function stopReplicationStreamPipeline(): mongo.Document[];
|
|
@@ -1,19 +1,27 @@
|
|
|
1
|
+
import { storage } from '@powersync/service-core';
|
|
1
2
|
/**
|
|
2
|
-
* Update pipeline to
|
|
3
|
+
* Update pipeline to stop a deploying replication stream, covering all storage versions.
|
|
3
4
|
*
|
|
4
5
|
* Roughly equivalent to:
|
|
5
6
|
* $set: {
|
|
6
|
-
* state:
|
|
7
|
-
* 'sync_configs.$[].state':
|
|
7
|
+
* state: STOP,
|
|
8
|
+
* 'sync_configs.$[].state': STOP
|
|
8
9
|
* }
|
|
9
10
|
*
|
|
10
11
|
* The difference is that this also handles v1 storage cases, where `sync_configs` is not present.
|
|
12
|
+
*
|
|
13
|
+
* This can be used for specific use cases:
|
|
14
|
+
* 1. Stop an existing PROCESSING stream, when it is being replaced by a new PROCESSING one.
|
|
15
|
+
* 2. Stop an existing ACTIVE or ERRORED stream, when it is being replaced by a new ACTIVE one.
|
|
16
|
+
*
|
|
17
|
+
* Do not use this when an ACTIVE stream transitions to ERRORED, and is being replaced by a new PROCESSING one.
|
|
18
|
+
* In that case, we need to maintain the ERRORED state, which this pipeline does not cover.
|
|
11
19
|
*/
|
|
12
|
-
export function
|
|
20
|
+
export function stopReplicationStreamPipeline() {
|
|
13
21
|
return [
|
|
14
22
|
{
|
|
15
23
|
$set: {
|
|
16
|
-
state,
|
|
24
|
+
state: storage.SyncRuleState.STOP,
|
|
17
25
|
sync_configs: {
|
|
18
26
|
$cond: [
|
|
19
27
|
{ $isArray: '$sync_configs' },
|
|
@@ -22,7 +30,7 @@ export function syncRuleStateUpdatePipeline(state) {
|
|
|
22
30
|
input: '$sync_configs',
|
|
23
31
|
as: 'config',
|
|
24
32
|
in: {
|
|
25
|
-
$mergeObjects: ['$$config', { state }]
|
|
33
|
+
$mergeObjects: ['$$config', { state: storage.SyncRuleState.STOP }]
|
|
26
34
|
}
|
|
27
35
|
}
|
|
28
36
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SyncRuleStateUpdate.js","sourceRoot":"","sources":["../../../src/storage/implementation/SyncRuleStateUpdate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SyncRuleStateUpdate.js","sourceRoot":"","sources":["../../../src/storage/implementation/SyncRuleStateUpdate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAElD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,6BAA6B;IAC3C,OAAO;QACL;YACE,IAAI,EAAE;gBACJ,KAAK,EAAE,OAAO,CAAC,aAAa,CAAC,IAAI;gBACjC,YAAY,EAAE;oBACZ,KAAK,EAAE;wBACL,EAAE,QAAQ,EAAE,eAAe,EAAE;wBAC7B;4BACE,IAAI,EAAE;gCACJ,KAAK,EAAE,eAAe;gCACtB,EAAE,EAAE,QAAQ;gCACZ,EAAE,EAAE;oCACF,aAAa,EAAE,CAAC,UAAU,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;iCACnE;6BACF;yBACF;wBACD,UAAU;qBACX;iBACF;aACF;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
import { mongo } from '@powersync/lib-service-mongodb';
|
|
2
|
-
import { InternalOpId } from '@powersync/service-core';
|
|
2
|
+
import { InternalOpId, ReplicationCheckpoint } from '@powersync/service-core';
|
|
3
3
|
import * as bson from 'bson';
|
|
4
|
-
export interface MongoSyncBucketStorageCheckpoint {
|
|
4
|
+
export interface MongoSyncBucketStorageCheckpoint extends ReplicationCheckpoint {
|
|
5
5
|
checkpoint: InternalOpId;
|
|
6
6
|
snapshotTime: bson.Timestamp;
|
|
7
7
|
clusterTime: mongo.ClusterTime;
|
|
8
|
+
/**
|
|
9
|
+
* The stream's `parameter_compaction.checkpoint_changes_invalid_before` boundary, read in the
|
|
10
|
+
* same snapshot as {@link checkpoint} and {@link snapshotTime}.
|
|
11
|
+
*
|
|
12
|
+
* Parameter compaction may have deleted parameter entries below this boundary, so checkpoint
|
|
13
|
+
* change detection cannot enumerate individual lookup changes from a checkpoint below it.
|
|
14
|
+
*
|
|
15
|
+
* 0n for streams that have never been compacted.
|
|
16
|
+
*/
|
|
17
|
+
parameterChangesInvalidBefore: InternalOpId;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* MongoDB-specific version of GetCheckpointChangesOptions.
|
|
21
|
+
*
|
|
22
|
+
* The next checkpoint carries the snapshot and invalidation boundary that change detection must
|
|
23
|
+
* be evaluated against. Only `checkpoint` is used from the previous one.
|
|
24
|
+
*/
|
|
25
|
+
export interface MongoGetCheckpointChangesOptions {
|
|
26
|
+
lastCheckpoint: ReplicationCheckpoint;
|
|
27
|
+
nextCheckpoint: MongoSyncBucketStorageCheckpoint;
|
|
8
28
|
}
|
|
@@ -4,6 +4,7 @@ import * as bson from 'bson';
|
|
|
4
4
|
import { Logger } from '@powersync/lib-services-framework';
|
|
5
5
|
import { BucketDefinitionMapping, InternalOpId, storage } from '@powersync/service-core';
|
|
6
6
|
import { MongoIdSequence } from '../MongoIdSequence.js';
|
|
7
|
+
import { MongoWriteBatch } from '../MongoWriteBatch.js';
|
|
7
8
|
import type { VersionedPowerSyncMongo } from '../db.js';
|
|
8
9
|
import { TaggedBucketParameterDocument } from '../models.js';
|
|
9
10
|
import { ObjectStorage } from '../v3/object-storage/ObjectStorage.js';
|
|
@@ -35,6 +36,11 @@ export interface PersistedBatchOptions {
|
|
|
35
36
|
logger?: Logger;
|
|
36
37
|
objectStorage?: ObjectStorage;
|
|
37
38
|
inlineThresholdBytes?: number;
|
|
39
|
+
/**
|
|
40
|
+
* Aborts in-flight object storage uploads when replication stops.
|
|
41
|
+
*/
|
|
42
|
+
signal?: AbortSignal;
|
|
43
|
+
objectStorageUsageWriterId?: string;
|
|
38
44
|
}
|
|
39
45
|
/**
|
|
40
46
|
* Keeps track of bulkwrite operations within a transaction.
|
|
@@ -52,6 +58,8 @@ export declare abstract class PersistedBatch {
|
|
|
52
58
|
bucketStates: Map<string, BucketStateUpdate>;
|
|
53
59
|
protected readonly objectStorage?: ObjectStorage;
|
|
54
60
|
protected readonly inlineThresholdBytes: number;
|
|
61
|
+
protected readonly signal?: AbortSignal;
|
|
62
|
+
protected readonly objectStorageUsageWriterId?: string;
|
|
55
63
|
/**
|
|
56
64
|
* For debug logging only.
|
|
57
65
|
*/
|
|
@@ -67,21 +75,39 @@ export declare abstract class PersistedBatch {
|
|
|
67
75
|
abstract softDeleteCurrentData(sourceTableId: bson.ObjectId, replicaId: storage.ReplicaId, checkpointGreaterThan: bigint): void;
|
|
68
76
|
abstract upsertCurrentData(values: UpsertCurrentDataOptions): void;
|
|
69
77
|
protected abstract get currentDataCount(): number;
|
|
70
|
-
protected abstract
|
|
71
|
-
protected abstract
|
|
72
|
-
protected abstract
|
|
73
|
-
protected abstract
|
|
78
|
+
protected abstract queueBucketData(writes: MongoWriteBatch): Promise<void>;
|
|
79
|
+
protected abstract queueBucketParameters(writes: MongoWriteBatch): void;
|
|
80
|
+
protected abstract queueCurrentData(writes: MongoWriteBatch): void;
|
|
81
|
+
protected abstract queueBucketStates(writes: MongoWriteBatch): void;
|
|
74
82
|
protected abstract resetCurrentData(): void;
|
|
75
83
|
protected abstract checkDefinitionId(definitionId: BucketDefinitionId | null): BucketDefinitionId;
|
|
76
84
|
protected abstract getBucketDefinitionId(bucketSource: BucketDataSource): BucketDefinitionId;
|
|
85
|
+
/**
|
|
86
|
+
* New bucket operations persist protocol subkeys during replication. Older
|
|
87
|
+
* V1 documents may not have one, so sync reads retain a fallback.
|
|
88
|
+
*/
|
|
89
|
+
protected persistedSubkey(table: storage.SourceTableId, key: storage.ReplicaId): string;
|
|
77
90
|
protected get bucketDataCount(): number;
|
|
78
91
|
protected incrementBucket(definitionId: BucketDefinitionId, bucket: string, op_id: InternalOpId, bytes: number): void;
|
|
92
|
+
/**
|
|
93
|
+
* V3 persists operations in chunks. Keep this separate from incrementBucket:
|
|
94
|
+
* operation counts are known while evaluating rows, while chunk counts and
|
|
95
|
+
* exact persisted bytes are only known after the writer has chunked a flush.
|
|
96
|
+
*/
|
|
97
|
+
protected incrementBucketPersistedChunk(definitionId: BucketDefinitionId, bucket: string, bytes: number): void;
|
|
98
|
+
/**
|
|
99
|
+
* V3's compactor calculates byte deltas from persisted chunk metadata.
|
|
100
|
+
* Replace the writer's per-operation estimate with those exact sizes before
|
|
101
|
+
* flushing the corresponding bucket state.
|
|
102
|
+
*/
|
|
103
|
+
protected resetBucketPersistedBytes(definitionId: BucketDefinitionId, bucket: string): void;
|
|
79
104
|
protected addBucketDataPut(options: {
|
|
80
105
|
op_id: InternalOpId;
|
|
81
106
|
bucketKey: BucketKey;
|
|
82
107
|
bucket: string;
|
|
83
108
|
sourceTableId: storage.SourceTable['id'];
|
|
84
109
|
sourceKey: storage.ReplicaId;
|
|
110
|
+
subkey: string;
|
|
85
111
|
table: string;
|
|
86
112
|
rowId: string;
|
|
87
113
|
checksum: bigint;
|
|
@@ -92,6 +118,7 @@ export declare abstract class PersistedBatch {
|
|
|
92
118
|
bucketKey: BucketKey;
|
|
93
119
|
sourceTableId: storage.SourceTable['id'];
|
|
94
120
|
sourceKey: storage.ReplicaId;
|
|
121
|
+
subkey: string;
|
|
95
122
|
table: string;
|
|
96
123
|
rowId: string;
|
|
97
124
|
checksum: bigint;
|
|
@@ -110,4 +137,5 @@ export interface BucketStateUpdate {
|
|
|
110
137
|
lastOp: InternalOpId;
|
|
111
138
|
incrementCount: number;
|
|
112
139
|
incrementBytes: number;
|
|
140
|
+
incrementChunks: number;
|
|
113
141
|
}
|
|
@@ -39,6 +39,8 @@ export class PersistedBatch {
|
|
|
39
39
|
bucketStates = new Map();
|
|
40
40
|
objectStorage;
|
|
41
41
|
inlineThresholdBytes = DEFAULT_INLINE_THRESHOLD_BYTES;
|
|
42
|
+
signal;
|
|
43
|
+
objectStorageUsageWriterId;
|
|
42
44
|
/**
|
|
43
45
|
* For debug logging only.
|
|
44
46
|
*/
|
|
@@ -54,6 +56,8 @@ export class PersistedBatch {
|
|
|
54
56
|
this.currentSize = writtenSize;
|
|
55
57
|
this.logger = options?.logger ?? defaultLogger;
|
|
56
58
|
this.objectStorage = options?.objectStorage;
|
|
59
|
+
this.signal = options?.signal;
|
|
60
|
+
this.objectStorageUsageWriterId = options?.objectStorageUsageWriterId;
|
|
57
61
|
if (options?.inlineThresholdBytes != null) {
|
|
58
62
|
this.inlineThresholdBytes = options.inlineThresholdBytes;
|
|
59
63
|
}
|
|
@@ -74,7 +78,8 @@ export class PersistedBatch {
|
|
|
74
78
|
}
|
|
75
79
|
remaining_buckets.set(currentBucketKey(mapped), mapped);
|
|
76
80
|
}
|
|
77
|
-
const
|
|
81
|
+
const subkey = this.persistedSubkey(options.table.id, options.sourceKey);
|
|
82
|
+
const dchecksum = BigInt(utils.hashDelete(subkey));
|
|
78
83
|
for (const evaluated of options.evaluated) {
|
|
79
84
|
const definitionId = this.getBucketDefinitionId(evaluated.source);
|
|
80
85
|
const key = currentBucketKey({
|
|
@@ -104,6 +109,7 @@ export class PersistedBatch {
|
|
|
104
109
|
bucket: evaluated.bucket,
|
|
105
110
|
sourceTableId: options.table.id,
|
|
106
111
|
sourceKey: options.sourceKey,
|
|
112
|
+
subkey,
|
|
107
113
|
table: evaluated.table,
|
|
108
114
|
rowId: evaluated.id,
|
|
109
115
|
checksum: BigInt(checksum),
|
|
@@ -124,6 +130,7 @@ export class PersistedBatch {
|
|
|
124
130
|
op_id,
|
|
125
131
|
sourceTableId: options.table.id,
|
|
126
132
|
sourceKey: options.sourceKey,
|
|
133
|
+
subkey,
|
|
127
134
|
table: bucket.table,
|
|
128
135
|
rowId: bucket.id,
|
|
129
136
|
checksum: dchecksum
|
|
@@ -132,6 +139,13 @@ export class PersistedBatch {
|
|
|
132
139
|
this.incrementBucket(definitionId, bucket.bucket, op_id, 200);
|
|
133
140
|
}
|
|
134
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* New bucket operations persist protocol subkeys during replication. Older
|
|
144
|
+
* V1 documents may not have one, so sync reads retain a fallback.
|
|
145
|
+
*/
|
|
146
|
+
persistedSubkey(table, key) {
|
|
147
|
+
return replicaIdToSubkey(table, key);
|
|
148
|
+
}
|
|
135
149
|
get bucketDataCount() {
|
|
136
150
|
return this.bucketData.length;
|
|
137
151
|
}
|
|
@@ -149,10 +163,35 @@ export class PersistedBatch {
|
|
|
149
163
|
bucket,
|
|
150
164
|
lastOp: op_id,
|
|
151
165
|
incrementCount: 1,
|
|
152
|
-
incrementBytes: bytes
|
|
166
|
+
incrementBytes: bytes,
|
|
167
|
+
incrementChunks: 0
|
|
153
168
|
});
|
|
154
169
|
}
|
|
155
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* V3 persists operations in chunks. Keep this separate from incrementBucket:
|
|
173
|
+
* operation counts are known while evaluating rows, while chunk counts and
|
|
174
|
+
* exact persisted bytes are only known after the writer has chunked a flush.
|
|
175
|
+
*/
|
|
176
|
+
incrementBucketPersistedChunk(definitionId, bucket, bytes) {
|
|
177
|
+
const key = `${definitionId ?? ''}:${bucket}`;
|
|
178
|
+
const existingState = this.bucketStates.get(key);
|
|
179
|
+
if (existingState != null) {
|
|
180
|
+
existingState.incrementChunks += 1;
|
|
181
|
+
existingState.incrementBytes += bytes;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* V3's compactor calculates byte deltas from persisted chunk metadata.
|
|
186
|
+
* Replace the writer's per-operation estimate with those exact sizes before
|
|
187
|
+
* flushing the corresponding bucket state.
|
|
188
|
+
*/
|
|
189
|
+
resetBucketPersistedBytes(definitionId, bucket) {
|
|
190
|
+
const state = this.bucketStates.get(`${definitionId ?? ''}:${bucket}`);
|
|
191
|
+
if (state != null) {
|
|
192
|
+
state.incrementBytes = 0;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
156
195
|
addBucketDataPut(options) {
|
|
157
196
|
this.bucketData.push({
|
|
158
197
|
bucketKey: options.bucketKey,
|
|
@@ -160,6 +199,7 @@ export class PersistedBatch {
|
|
|
160
199
|
op: 'PUT',
|
|
161
200
|
source_table: mongoTableId(options.sourceTableId),
|
|
162
201
|
source_key: options.sourceKey,
|
|
202
|
+
subkey: options.subkey,
|
|
163
203
|
table: options.table,
|
|
164
204
|
row_id: options.rowId,
|
|
165
205
|
checksum: options.checksum,
|
|
@@ -173,6 +213,7 @@ export class PersistedBatch {
|
|
|
173
213
|
op: 'REMOVE',
|
|
174
214
|
source_table: mongoTableId(options.sourceTableId),
|
|
175
215
|
source_key: options.sourceKey,
|
|
216
|
+
subkey: options.subkey,
|
|
176
217
|
table: options.table,
|
|
177
218
|
row_id: options.rowId,
|
|
178
219
|
checksum: options.checksum,
|
|
@@ -188,22 +229,24 @@ export class PersistedBatch {
|
|
|
188
229
|
async flush(session, options) {
|
|
189
230
|
const startAt = performance.now();
|
|
190
231
|
let flushedSomething = false;
|
|
232
|
+
const writes = this.db.createWriteBatch(session, { ordered: false });
|
|
191
233
|
if (this.bucketDataCount > 0) {
|
|
192
234
|
flushedSomething = true;
|
|
193
|
-
await this.
|
|
235
|
+
await this.queueBucketData(writes);
|
|
194
236
|
}
|
|
195
237
|
if (this.bucketParameters.length > 0) {
|
|
196
238
|
flushedSomething = true;
|
|
197
|
-
|
|
239
|
+
this.queueBucketParameters(writes);
|
|
198
240
|
}
|
|
199
241
|
if (this.currentDataCount > 0) {
|
|
200
242
|
flushedSomething = true;
|
|
201
|
-
|
|
243
|
+
this.queueCurrentData(writes);
|
|
202
244
|
}
|
|
203
245
|
if (this.bucketStates.size > 0) {
|
|
204
246
|
flushedSomething = true;
|
|
205
|
-
|
|
247
|
+
this.queueBucketStates(writes);
|
|
206
248
|
}
|
|
249
|
+
await writes.execute();
|
|
207
250
|
if (flushedSomething) {
|
|
208
251
|
const duration = Math.round(performance.now() - startAt);
|
|
209
252
|
if (options?.oldestUncommittedChange != null) {
|