@powersync/service-module-mongodb-storage 0.0.0-dev-20260602073133 → 0.0.0-dev-20260909133214
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 +177 -5
- package/dist/migrations/db/migrations/1782950400000-checkpoint-requested-at-index.d.ts +3 -0
- package/dist/migrations/db/migrations/1782950400000-checkpoint-requested-at-index.js +41 -0
- package/dist/migrations/db/migrations/1782950400000-checkpoint-requested-at-index.js.map +1 -0
- package/dist/storage/MongoBucketStorage.d.ts +71 -18
- package/dist/storage/MongoBucketStorage.js +516 -202
- package/dist/storage/MongoBucketStorage.js.map +1 -1
- package/dist/storage/implementation/MongoBucketBatch.d.ts +71 -29
- package/dist/storage/implementation/MongoBucketBatch.js +140 -66
- package/dist/storage/implementation/MongoBucketBatch.js.map +1 -1
- package/dist/storage/implementation/MongoChecksums.d.ts +41 -13
- package/dist/storage/implementation/MongoChecksums.js +36 -121
- package/dist/storage/implementation/MongoChecksums.js.map +1 -1
- package/dist/storage/implementation/MongoCompactor.d.ts +28 -90
- package/dist/storage/implementation/MongoCompactor.js +87 -481
- package/dist/storage/implementation/MongoCompactor.js.map +1 -1
- package/dist/storage/implementation/MongoHydrationState.d.ts +11 -0
- package/dist/storage/implementation/MongoHydrationState.js +49 -0
- package/dist/storage/implementation/MongoHydrationState.js.map +1 -0
- package/dist/storage/implementation/MongoParameterCompactor.d.ts +82 -8
- package/dist/storage/implementation/MongoParameterCompactor.js +312 -76
- package/dist/storage/implementation/MongoParameterCompactor.js.map +1 -1
- package/dist/storage/implementation/MongoParsedSyncConfigSet.d.ts +21 -0
- package/dist/storage/implementation/MongoParsedSyncConfigSet.js +93 -0
- package/dist/storage/implementation/MongoParsedSyncConfigSet.js.map +1 -0
- package/dist/storage/implementation/MongoPersistedReplicationStream.d.ts +36 -0
- package/dist/storage/implementation/MongoPersistedReplicationStream.js +90 -0
- package/dist/storage/implementation/MongoPersistedReplicationStream.js.map +1 -0
- package/dist/storage/implementation/MongoPersistedSyncConfigContent.d.ts +25 -0
- package/dist/storage/implementation/MongoPersistedSyncConfigContent.js +125 -0
- package/dist/storage/implementation/MongoPersistedSyncConfigContent.js.map +1 -0
- package/dist/storage/implementation/MongoStorageProvider.js +41 -4
- package/dist/storage/implementation/MongoStorageProvider.js.map +1 -1
- package/dist/storage/implementation/MongoSyncBucketStorage.d.ts +81 -37
- package/dist/storage/implementation/MongoSyncBucketStorage.js +159 -86
- package/dist/storage/implementation/MongoSyncBucketStorage.js.map +1 -1
- package/dist/storage/implementation/MongoSyncRulesLock.d.ts +1 -1
- package/dist/storage/implementation/MongoSyncRulesLock.js +23 -11
- package/dist/storage/implementation/MongoSyncRulesLock.js.map +1 -1
- package/dist/storage/implementation/MongoWriteCheckpointAPI.d.ts +11 -8
- package/dist/storage/implementation/MongoWriteCheckpointAPI.js +159 -33
- 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 +28 -0
- package/dist/storage/implementation/common/MongoSyncBucketStorageCheckpoint.js +2 -0
- package/dist/storage/implementation/common/MongoSyncBucketStorageCheckpoint.js.map +1 -0
- package/dist/storage/implementation/common/PersistedBatch.d.ts +34 -2
- package/dist/storage/implementation/common/PersistedBatch.js +63 -10
- package/dist/storage/implementation/common/PersistedBatch.js.map +1 -1
- package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.js +1 -1
- package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.js.map +1 -1
- package/dist/storage/implementation/createMongoSyncBucketStorage.d.ts +2 -2
- package/dist/storage/implementation/createMongoSyncBucketStorage.js +4 -4
- package/dist/storage/implementation/createMongoSyncBucketStorage.js.map +1 -1
- package/dist/storage/implementation/db.d.ts +4 -1
- package/dist/storage/implementation/db.js +31 -16
- package/dist/storage/implementation/db.js.map +1 -1
- package/dist/storage/implementation/models.d.ts +55 -13
- package/dist/storage/implementation/models.js.map +1 -1
- package/dist/storage/implementation/v1/MongoBucketBatchV1.d.ts +15 -1
- package/dist/storage/implementation/v1/MongoBucketBatchV1.js +135 -107
- package/dist/storage/implementation/v1/MongoBucketBatchV1.js.map +1 -1
- package/dist/storage/implementation/v1/MongoChecksumsV1.d.ts +4 -4
- package/dist/storage/implementation/v1/MongoChecksumsV1.js +119 -7
- package/dist/storage/implementation/v1/MongoChecksumsV1.js.map +1 -1
- package/dist/storage/implementation/v1/MongoCompactorV1.d.ts +47 -7
- package/dist/storage/implementation/v1/MongoCompactorV1.js +478 -8
- 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 +33 -27
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js +146 -73
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js.map +1 -1
- package/dist/storage/implementation/v1/SingleBucketStoreV1.d.ts +9 -10
- package/dist/storage/implementation/v1/SingleBucketStoreV1.js +2 -8
- package/dist/storage/implementation/v1/SingleBucketStoreV1.js.map +1 -1
- package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.d.ts +2 -1
- package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.js +3 -0
- package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.js.map +1 -1
- package/dist/storage/implementation/v1/models.d.ts +10 -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/BucketDataContextV3.d.ts +13 -0
- package/dist/storage/implementation/v3/BucketDataContextV3.js +23 -0
- package/dist/storage/implementation/v3/BucketDataContextV3.js.map +1 -0
- 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 +16 -5
- package/dist/storage/implementation/v3/MongoBucketBatchV3.js +393 -262
- package/dist/storage/implementation/v3/MongoBucketBatchV3.js.map +1 -1
- package/dist/storage/implementation/v3/MongoChecksumsV3.d.ts +30 -9
- package/dist/storage/implementation/v3/MongoChecksumsV3.js +161 -20
- package/dist/storage/implementation/v3/MongoChecksumsV3.js.map +1 -1
- package/dist/storage/implementation/v3/MongoCompactorV3.d.ts +108 -18
- package/dist/storage/implementation/v3/MongoCompactorV3.js +1115 -47
- package/dist/storage/implementation/v3/MongoCompactorV3.js.map +1 -1
- package/dist/storage/implementation/v3/MongoParameterCompactorV3.d.ts +12 -3
- package/dist/storage/implementation/v3/MongoParameterCompactorV3.js +13 -8
- package/dist/storage/implementation/v3/MongoParameterCompactorV3.js.map +1 -1
- package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.d.ts +54 -0
- package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.js +319 -0
- package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.js.map +1 -0
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.d.ts +61 -36
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js +353 -161
- 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 +8 -3
- package/dist/storage/implementation/v3/PersistedBatchV3.js +131 -29
- package/dist/storage/implementation/v3/PersistedBatchV3.js.map +1 -1
- package/dist/storage/implementation/v3/SourceRecordStoreV3.d.ts +3 -3
- package/dist/storage/implementation/v3/SourceRecordStoreV3.js +13 -11
- package/dist/storage/implementation/v3/SourceRecordStoreV3.js.map +1 -1
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.d.ts +26 -14
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js +73 -29
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js.map +1 -1
- package/dist/storage/implementation/v3/bucket-format.d.ts +13 -0
- package/dist/storage/implementation/v3/bucket-format.js +79 -0
- package/dist/storage/implementation/v3/bucket-format.js.map +1 -0
- package/dist/storage/implementation/v3/chunking.d.ts +10 -0
- package/dist/storage/implementation/v3/chunking.js +30 -0
- package/dist/storage/implementation/v3/chunking.js.map +1 -0
- 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 +187 -23
- package/dist/storage/implementation/v3/models.js +11 -28
- package/dist/storage/implementation/v3/models.js.map +1 -1
- package/dist/storage/implementation/v3/object-storage/BucketDataObjectStorage.d.ts +20 -0
- package/dist/storage/implementation/v3/object-storage/BucketDataObjectStorage.js +48 -0
- package/dist/storage/implementation/v3/object-storage/BucketDataObjectStorage.js.map +1 -0
- package/dist/storage/implementation/v3/object-storage/ObjectStorage.d.ts +33 -0
- package/dist/storage/implementation/v3/object-storage/ObjectStorage.js +12 -0
- package/dist/storage/implementation/v3/object-storage/ObjectStorage.js.map +1 -0
- package/dist/storage/implementation/v3/object-storage/ObjectStorageLifecycle.d.ts +68 -0
- package/dist/storage/implementation/v3/object-storage/ObjectStorageLifecycle.js +154 -0
- package/dist/storage/implementation/v3/object-storage/ObjectStorageLifecycle.js.map +1 -0
- package/dist/storage/implementation/v3/object-storage/ObjectStorageUsage.d.ts +37 -0
- package/dist/storage/implementation/v3/object-storage/ObjectStorageUsage.js +167 -0
- package/dist/storage/implementation/v3/object-storage/ObjectStorageUsage.js.map +1 -0
- package/dist/storage/implementation/v3/object-storage/S3ObjectStorage.d.ts +67 -0
- package/dist/storage/implementation/v3/object-storage/S3ObjectStorage.js +439 -0
- package/dist/storage/implementation/v3/object-storage/S3ObjectStorage.js.map +1 -0
- package/dist/storage/implementation/v3/source-table-utils.d.ts +63 -0
- package/dist/storage/implementation/v3/source-table-utils.js +206 -0
- package/dist/storage/implementation/v3/source-table-utils.js.map +1 -0
- package/dist/storage/storage-index.d.ts +5 -4
- package/dist/storage/storage-index.js +5 -4
- package/dist/storage/storage-index.js.map +1 -1
- package/dist/types/types.d.ts +71 -3
- package/dist/types/types.js +58 -2
- package/dist/types/types.js.map +1 -1
- package/dist/utils/test-utils.d.ts +1 -2
- package/dist/utils/test-utils.js +7 -1
- package/dist/utils/test-utils.js.map +1 -1
- package/dist/utils/util.d.ts +9 -2
- package/dist/utils/util.js +131 -5
- package/dist/utils/util.js.map +1 -1
- package/package.json +13 -19
- package/src/migrations/db/migrations/1782950400000-checkpoint-requested-at-index.ts +55 -0
- package/src/storage/MongoBucketStorage.ts +728 -242
- package/src/storage/implementation/MongoBucketBatch.ts +196 -91
- package/src/storage/implementation/MongoChecksums.ts +93 -153
- package/src/storage/implementation/MongoCompactor.ts +106 -631
- package/src/storage/implementation/MongoHydrationState.ts +61 -0
- package/src/storage/implementation/MongoParameterCompactor.ts +392 -87
- package/src/storage/implementation/MongoParsedSyncConfigSet.ts +122 -0
- package/src/storage/implementation/MongoPersistedReplicationStream.ts +118 -0
- package/src/storage/implementation/MongoPersistedSyncConfigContent.ts +156 -0
- package/src/storage/implementation/MongoStorageProvider.ts +48 -4
- package/src/storage/implementation/MongoSyncBucketStorage.ts +226 -118
- package/src/storage/implementation/MongoSyncRulesLock.ts +28 -12
- package/src/storage/implementation/MongoWriteCheckpointAPI.ts +194 -52
- package/src/storage/implementation/SyncRuleStateUpdate.ts +13 -6
- package/src/storage/implementation/common/MongoSyncBucketStorageCheckpoint.ts +31 -0
- package/src/storage/implementation/common/PersistedBatch.ts +83 -15
- package/src/storage/implementation/common/VersionedPowerSyncMongoBase.ts +1 -1
- package/src/storage/implementation/createMongoSyncBucketStorage.ts +21 -7
- package/src/storage/implementation/db.ts +40 -22
- package/src/storage/implementation/models.ts +58 -14
- package/src/storage/implementation/v1/MongoBucketBatchV1.ts +174 -125
- package/src/storage/implementation/v1/MongoChecksumsV1.ts +154 -12
- package/src/storage/implementation/v1/MongoCompactorV1.ts +594 -25
- package/src/storage/implementation/v1/MongoParameterCompactorV1.ts +25 -9
- package/src/storage/implementation/v1/MongoSyncBucketStorageV1.ts +226 -129
- package/src/storage/implementation/v1/SingleBucketStoreV1.ts +18 -27
- package/src/storage/implementation/v1/VersionedPowerSyncMongoV1.ts +11 -1
- package/src/storage/implementation/v1/models.ts +12 -1
- package/src/storage/implementation/v3/BucketDataContextV3.ts +32 -0
- package/src/storage/implementation/v3/CompactionLease.ts +152 -0
- package/src/storage/implementation/v3/MongoBucketBatchV3.ts +502 -324
- package/src/storage/implementation/v3/MongoChecksumsV3.ts +250 -32
- package/src/storage/implementation/v3/MongoCompactorV3.ts +1439 -70
- package/src/storage/implementation/v3/MongoParameterCompactorV3.ts +19 -9
- package/src/storage/implementation/v3/MongoStoppedSyncConfigCleanup.ts +473 -0
- package/src/storage/implementation/v3/MongoSyncBucketStorageV3.ts +453 -211
- package/src/storage/implementation/v3/MongoWriteCheckpointAPIV3.ts +111 -0
- package/src/storage/implementation/v3/PersistedBatchV3.ts +169 -45
- package/src/storage/implementation/v3/SourceRecordStoreV3.ts +12 -12
- package/src/storage/implementation/v3/VersionedPowerSyncMongoV3.ts +99 -38
- package/src/storage/implementation/v3/bucket-format.ts +99 -0
- package/src/storage/implementation/v3/chunking.ts +40 -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 +228 -58
- package/src/storage/implementation/v3/object-storage/BucketDataObjectStorage.ts +62 -0
- package/src/storage/implementation/v3/object-storage/ObjectStorage.ts +44 -0
- package/src/storage/implementation/v3/object-storage/ObjectStorageLifecycle.ts +182 -0
- package/src/storage/implementation/v3/object-storage/ObjectStorageUsage.ts +230 -0
- package/src/storage/implementation/v3/object-storage/S3ObjectStorage.ts +573 -0
- package/src/storage/implementation/v3/source-table-utils.ts +398 -0
- package/src/storage/storage-index.ts +14 -4
- package/src/types/types.ts +76 -2
- package/src/utils/test-utils.ts +8 -3
- package/src/utils/util.ts +188 -7
- package/test/src/__snapshots__/storage.test.ts.snap +4 -54
- package/test/src/__snapshots__/storage_sync.test.ts.snap +652 -645
- package/test/src/cleanup-stopped-sync-configs.test.ts +698 -0
- package/test/src/compact-utils.test.ts +226 -0
- package/test/src/helpers/MemoryObjectStorage.ts +61 -0
- package/test/src/helpers/s3TestFactory.ts +69 -0
- package/test/src/object_storage_lifecycle.test.ts +59 -0
- package/test/src/object_storage_usage.test.ts +255 -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/setup.ts +6 -1
- package/test/src/storage.test.ts +478 -13
- package/test/src/storage_compacting.test.ts +2516 -107
- package/test/src/storage_object_storage_inline_threshold.test.ts +116 -0
- package/test/src/storage_s3_checksums.test.ts +190 -0
- package/test/src/storage_s3_compaction_lifecycle.test.ts +543 -0
- package/test/src/storage_s3_reading.test.ts +768 -0
- package/test/src/storage_s3_writing.test.ts +136 -0
- package/test/src/storage_sync.test.ts +1507 -76
- package/test/src/storeCurrentData.test.ts +227 -0
- package/test/src/util.ts +3 -2
- package/tsconfig.json +1 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/storage/implementation/BucketDefinitionMapping.d.ts +0 -15
- package/dist/storage/implementation/BucketDefinitionMapping.js +0 -58
- package/dist/storage/implementation/BucketDefinitionMapping.js.map +0 -1
- package/dist/storage/implementation/MongoPersistedSyncRules.d.ts +0 -14
- package/dist/storage/implementation/MongoPersistedSyncRules.js +0 -67
- package/dist/storage/implementation/MongoPersistedSyncRules.js.map +0 -1
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.d.ts +0 -29
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.js +0 -76
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.js.map +0 -1
- package/dist/storage/implementation/common/MongoSyncBucketStorageContext.d.ts +0 -13
- package/dist/storage/implementation/common/MongoSyncBucketStorageContext.js +0 -2
- package/dist/storage/implementation/common/MongoSyncBucketStorageContext.js.map +0 -1
- package/dist/storage/implementation/common/SingleBucketStore.d.ts +0 -54
- package/dist/storage/implementation/common/SingleBucketStore.js +0 -3
- package/dist/storage/implementation/common/SingleBucketStore.js.map +0 -1
- package/dist/storage/implementation/v3/MongoParameterLookupV3.d.ts +0 -4
- package/dist/storage/implementation/v3/MongoParameterLookupV3.js +0 -9
- package/dist/storage/implementation/v3/MongoParameterLookupV3.js.map +0 -1
- package/dist/storage/implementation/v3/SingleBucketStoreV3.d.ts +0 -18
- package/dist/storage/implementation/v3/SingleBucketStoreV3.js +0 -48
- package/dist/storage/implementation/v3/SingleBucketStoreV3.js.map +0 -1
- package/src/storage/implementation/BucketDefinitionMapping.ts +0 -75
- package/src/storage/implementation/MongoPersistedSyncRules.ts +0 -82
- package/src/storage/implementation/MongoPersistedSyncRulesContent.ts +0 -101
- package/src/storage/implementation/common/MongoSyncBucketStorageContext.ts +0 -15
- package/src/storage/implementation/common/SingleBucketStore.ts +0 -63
- package/src/storage/implementation/v3/MongoParameterLookupV3.ts +0 -11
- package/src/storage/implementation/v3/SingleBucketStoreV3.ts +0 -68
package/dist/utils/util.js
CHANGED
|
@@ -5,6 +5,40 @@ import * as bson from 'bson';
|
|
|
5
5
|
import * as crypto from 'crypto';
|
|
6
6
|
import * as timers from 'node:timers/promises';
|
|
7
7
|
import * as uuid from 'uuid';
|
|
8
|
+
import { DEFAULT_CLEAR_BATCH_THROTTLE_RATE } from '../types/types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Default and max batch size for clearing.
|
|
11
|
+
*/
|
|
12
|
+
const CLEAR_BATCH_SIZE = 10_000;
|
|
13
|
+
/**
|
|
14
|
+
* Minimum batch size for clearing when a batch takes too long.
|
|
15
|
+
*/
|
|
16
|
+
const CLEAR_MIN_BATCH_SIZE = 100;
|
|
17
|
+
/**
|
|
18
|
+
* We target batch duration to stay between the min and max. If the druation is outside this range,
|
|
19
|
+
* we increase or decrease the batch size.
|
|
20
|
+
*
|
|
21
|
+
* MONGO_CLEAR_OPERATION_TIMEOUT_MS controls the absolute max of individual find and delete operations,
|
|
22
|
+
* but we try to avoid hitting that.
|
|
23
|
+
*/
|
|
24
|
+
const CLEAR_BATCH_MIN_DURATION_MS = 500;
|
|
25
|
+
const CLEAR_BATCH_MAX_DURATION_MS = 2000;
|
|
26
|
+
function throwIfClearAborted(signal) {
|
|
27
|
+
if (signal?.aborted) {
|
|
28
|
+
throw new ReplicationAbortedError('Aborted clearing data', signal.reason);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async function waitWithSignal(delayMs, signal, abortMessage) {
|
|
32
|
+
try {
|
|
33
|
+
await timers.setTimeout(delayMs, undefined, { signal });
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (signal?.aborted) {
|
|
37
|
+
throw new ReplicationAbortedError(abortMessage, signal.reason);
|
|
38
|
+
}
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
8
42
|
export function idPrefixFilter(prefix, rest) {
|
|
9
43
|
let filter = {
|
|
10
44
|
$gte: {
|
|
@@ -20,9 +54,9 @@ export function idPrefixFilter(prefix, rest) {
|
|
|
20
54
|
}
|
|
21
55
|
return filter;
|
|
22
56
|
}
|
|
23
|
-
export function
|
|
57
|
+
export function generateReplicationStreamName(prefix, replicationStreamId) {
|
|
24
58
|
const slot_suffix = crypto.randomBytes(2).toString('hex');
|
|
25
|
-
return `${prefix}${
|
|
59
|
+
return `${prefix}${replicationStreamId}_${slot_suffix}`;
|
|
26
60
|
}
|
|
27
61
|
/**
|
|
28
62
|
* Read a single batch of data from a cursor, then close it.
|
|
@@ -72,7 +106,9 @@ export function mapOpEntry(row) {
|
|
|
72
106
|
object_type: row.table,
|
|
73
107
|
object_id: row.row_id,
|
|
74
108
|
checksum: Number(row.checksum),
|
|
75
|
-
|
|
109
|
+
// Storage V3 always persists this during replication. The fallback serves V1 data
|
|
110
|
+
// written before subkey persistence was introduced.
|
|
111
|
+
subkey: row.subkey ?? replicaIdToSubkey(row.source_table, row.source_key),
|
|
76
112
|
data: row.data
|
|
77
113
|
};
|
|
78
114
|
}
|
|
@@ -124,6 +160,7 @@ export function setSessionSnapshotTime(session, time) {
|
|
|
124
160
|
}
|
|
125
161
|
export async function retryOnMongoMaxTimeMSExpired(operation, options) {
|
|
126
162
|
let retryCount = 0;
|
|
163
|
+
// Retry indefinitely on MaxTimeMSExpired errors with exponential backoff.
|
|
127
164
|
while (true) {
|
|
128
165
|
if (options.signal?.aborted) {
|
|
129
166
|
throw new ReplicationAbortedError(options.abortMessage ?? 'Aborted MongoDB operation', options.signal.reason);
|
|
@@ -132,15 +169,104 @@ export async function retryOnMongoMaxTimeMSExpired(operation, options) {
|
|
|
132
169
|
return await operation();
|
|
133
170
|
}
|
|
134
171
|
catch (e) {
|
|
135
|
-
if (!lib_mongo.
|
|
172
|
+
if (!lib_mongo.isMaxTimeMSExpiredError(e)) {
|
|
136
173
|
throw e;
|
|
137
174
|
}
|
|
138
175
|
retryCount += 1;
|
|
139
176
|
options.onRetry?.(retryCount);
|
|
140
|
-
await
|
|
177
|
+
await waitWithSignal(options.retryDelayMs, options.signal, options.abortMessage ?? 'Aborted MongoDB operation');
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
async function clearCollectionInBatches(logger, label, findAndDeleteBatch, signal, throttleRate = DEFAULT_CLEAR_BATCH_THROTTLE_RATE) {
|
|
182
|
+
let batchSize = CLEAR_BATCH_SIZE;
|
|
183
|
+
let deletedCount = 0;
|
|
184
|
+
while (true) {
|
|
185
|
+
throwIfClearAborted(signal);
|
|
186
|
+
try {
|
|
187
|
+
const batchStartedAt = performance.now();
|
|
188
|
+
const foundBatchSize = await findAndDeleteBatch(batchSize);
|
|
189
|
+
const batchDurationMs = performance.now() - batchStartedAt;
|
|
190
|
+
deletedCount += foundBatchSize;
|
|
191
|
+
if (foundBatchSize > 0) {
|
|
192
|
+
logger.info(`Cleared batch of ${label} (${foundBatchSize} documents) in ${Math.round(batchDurationMs)}ms, continuing...`);
|
|
193
|
+
}
|
|
194
|
+
if (foundBatchSize < batchSize) {
|
|
195
|
+
return deletedCount;
|
|
196
|
+
}
|
|
197
|
+
if (batchDurationMs > CLEAR_BATCH_MAX_DURATION_MS) {
|
|
198
|
+
batchSize = Math.max(CLEAR_MIN_BATCH_SIZE, Math.floor(batchSize / 2));
|
|
199
|
+
}
|
|
200
|
+
else if (batchDurationMs < CLEAR_BATCH_MIN_DURATION_MS) {
|
|
201
|
+
batchSize = Math.min(CLEAR_BATCH_SIZE, batchSize * 2);
|
|
202
|
+
}
|
|
203
|
+
await waitWithSignal(batchDurationMs * throttleRate, signal, 'Aborted clearing data');
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
if (!lib_mongo.isTimeoutError(error) || batchSize == CLEAR_MIN_BATCH_SIZE) {
|
|
207
|
+
throw error;
|
|
208
|
+
}
|
|
209
|
+
const nextBatchSize = Math.max(CLEAR_MIN_BATCH_SIZE, Math.floor(batchSize / 2));
|
|
210
|
+
logger.info(`Clearing batch of ${label} timed out with batch size ${batchSize}, retrying find and delete with ${nextBatchSize}...`);
|
|
211
|
+
batchSize = nextBatchSize;
|
|
212
|
+
// Pause for at least the equivalent of one query timeout before retrying, since the cause may be high database load.
|
|
213
|
+
const pauseDuration = Math.max(throttleRate, 1.0) * lib_mongo.MONGO_CLEAR_OPERATION_TIMEOUT_MS;
|
|
214
|
+
await waitWithSignal(pauseDuration, signal, 'Aborted clearing data');
|
|
141
215
|
}
|
|
142
216
|
}
|
|
143
217
|
}
|
|
218
|
+
export async function clearCollectionInIdRanges(logger, label, collection, filter, signal, throttleRate = DEFAULT_CLEAR_BATCH_THROTTLE_RATE) {
|
|
219
|
+
return clearCollectionInBatches(logger, label, async (batchSize) => {
|
|
220
|
+
const queryOptions = {
|
|
221
|
+
maxTimeMS: lib_mongo.db.MONGO_CLEAR_OPERATION_TIMEOUT_MS,
|
|
222
|
+
projection: { _id: 1 }
|
|
223
|
+
};
|
|
224
|
+
const [batchEnd] = await collection
|
|
225
|
+
.find(filter, queryOptions)
|
|
226
|
+
.sort({ _id: 1 })
|
|
227
|
+
.skip(batchSize)
|
|
228
|
+
.limit(1)
|
|
229
|
+
.toArray();
|
|
230
|
+
throwIfClearAborted(signal);
|
|
231
|
+
if (batchEnd == null) {
|
|
232
|
+
// We're on the last batch
|
|
233
|
+
const result = await collection.deleteMany(filter, {
|
|
234
|
+
maxTimeMS: lib_mongo.db.MONGO_CLEAR_OPERATION_TIMEOUT_MS
|
|
235
|
+
});
|
|
236
|
+
return result.deletedCount;
|
|
237
|
+
}
|
|
238
|
+
const idRange = {
|
|
239
|
+
...filter._id,
|
|
240
|
+
$lt: batchEnd._id
|
|
241
|
+
};
|
|
242
|
+
await collection.deleteMany({
|
|
243
|
+
...filter,
|
|
244
|
+
_id: idRange
|
|
245
|
+
}, { maxTimeMS: lib_mongo.db.MONGO_CLEAR_OPERATION_TIMEOUT_MS });
|
|
246
|
+
return batchSize;
|
|
247
|
+
}, signal, throttleRate);
|
|
248
|
+
}
|
|
249
|
+
export async function clearCollectionInIdBatches(logger, label, collection, filter, signal, throttleRate = DEFAULT_CLEAR_BATCH_THROTTLE_RATE) {
|
|
250
|
+
return clearCollectionInBatches(logger, label, async (batchSize) => {
|
|
251
|
+
const documents = await collection
|
|
252
|
+
.find(filter, {
|
|
253
|
+
maxTimeMS: lib_mongo.db.MONGO_CLEAR_OPERATION_TIMEOUT_MS,
|
|
254
|
+
projection: { _id: 1 }
|
|
255
|
+
})
|
|
256
|
+
.limit(batchSize)
|
|
257
|
+
.toArray();
|
|
258
|
+
throwIfClearAborted(signal);
|
|
259
|
+
if (documents.length === 0) {
|
|
260
|
+
return 0;
|
|
261
|
+
}
|
|
262
|
+
await collection.deleteMany({
|
|
263
|
+
_id: {
|
|
264
|
+
$in: documents.map((document) => document._id)
|
|
265
|
+
}
|
|
266
|
+
}, { maxTimeMS: lib_mongo.db.MONGO_CLEAR_OPERATION_TIMEOUT_MS });
|
|
267
|
+
return documents.length;
|
|
268
|
+
}, signal, throttleRate);
|
|
269
|
+
}
|
|
144
270
|
export const createPaginatedConnectionQuery = async (query, collection, limit, cursor) => {
|
|
145
271
|
const createQuery = (cursor) => {
|
|
146
272
|
if (!cursor) {
|
package/dist/utils/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/utils/util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,gCAAgC,CAAC;AAE5D,OAAO,
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/utils/util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,gCAAgC,CAAC;AAE5D,OAAO,EAAU,uBAAuB,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC3G,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KA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AAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS;QACxF,IAAI,EAAE,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC;KACzB,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,41 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powersync/service-module-mongodb-storage",
|
|
3
3
|
"repository": "https://github.com/powersync-ja/powersync-service",
|
|
4
|
-
"
|
|
5
|
-
"version": "0.0.0-dev-20260602073133",
|
|
6
|
-
"main": "dist/index.js",
|
|
4
|
+
"version": "0.0.0-dev-20260909133214",
|
|
7
5
|
"license": "FSL-1.1-ALv2",
|
|
8
6
|
"type": "module",
|
|
9
7
|
"publishConfig": {
|
|
10
8
|
"access": "public"
|
|
11
9
|
},
|
|
12
10
|
"exports": {
|
|
13
|
-
".":
|
|
14
|
-
|
|
15
|
-
"require": "./dist/index.js",
|
|
16
|
-
"default": "./dist/index.js"
|
|
17
|
-
},
|
|
18
|
-
"./types": {
|
|
19
|
-
"import": "./dist/types/types.js",
|
|
20
|
-
"require": "./dist/types/types.js",
|
|
21
|
-
"default": "./dist/types/types.js"
|
|
22
|
-
}
|
|
11
|
+
".": "./dist/index.js",
|
|
12
|
+
"./types": "./dist/types/types.js"
|
|
23
13
|
},
|
|
24
14
|
"dependencies": {
|
|
15
|
+
"@aws-sdk/client-s3": "^3.1116.0",
|
|
16
|
+
"@smithy/core": "^3.33.3",
|
|
17
|
+
"@smithy/node-http-handler": "^4.11.3",
|
|
18
|
+
"async-mutex": "^0.5.0",
|
|
25
19
|
"bson": "^6.10.4",
|
|
26
20
|
"ix": "^5.0.0",
|
|
27
21
|
"lru-cache": "^10.2.2",
|
|
28
22
|
"ts-codec": "^1.3.0",
|
|
29
23
|
"uuid": "^14.0.0",
|
|
30
|
-
"@powersync/lib-service-mongodb": "0.0.0-dev-
|
|
31
|
-
"@powersync/lib-services-framework": "0.0.0-dev-
|
|
32
|
-
"@powersync/service-core": "0.0.0-dev-
|
|
24
|
+
"@powersync/lib-service-mongodb": "0.0.0-dev-20260909133214",
|
|
25
|
+
"@powersync/lib-services-framework": "0.0.0-dev-20260909133214",
|
|
26
|
+
"@powersync/service-core": "0.0.0-dev-20260909133214",
|
|
33
27
|
"@powersync/service-jsonbig": "0.17.13",
|
|
34
|
-
"@powersync/service-sync-rules": "0.0.0-dev-
|
|
35
|
-
"@powersync/service-types": "0.
|
|
28
|
+
"@powersync/service-sync-rules": "0.0.0-dev-20260909133214",
|
|
29
|
+
"@powersync/service-types": "0.18.0"
|
|
36
30
|
},
|
|
37
31
|
"devDependencies": {
|
|
38
|
-
"@powersync/service-core-tests": "0.0.0-dev-
|
|
32
|
+
"@powersync/service-core-tests": "0.0.0-dev-20260909133214"
|
|
39
33
|
},
|
|
40
34
|
"scripts": {
|
|
41
35
|
"build": "tsc -b",
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { migrations } from '@powersync/service-core';
|
|
2
|
+
import * as storage from '../../../storage/storage-index.js';
|
|
3
|
+
import { MongoStorageConfig } from '../../../types/types.js';
|
|
4
|
+
|
|
5
|
+
export const up: migrations.PowerSyncMigrationFunction = async (context) => {
|
|
6
|
+
const {
|
|
7
|
+
service_context: { configuration }
|
|
8
|
+
} = context;
|
|
9
|
+
const db = storage.createPowerSyncMongo(configuration.storage as MongoStorageConfig);
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
await db.write_checkpoints.createIndex(
|
|
13
|
+
{
|
|
14
|
+
checkpoint_requested_at: 1
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: 'checkpoint_requested_at',
|
|
18
|
+
// Only client-requested checkpoints have this field; generated
|
|
19
|
+
// checkpoints leave it unset. This keeps the index limited to the
|
|
20
|
+
// documents the compact job's retention delete scans.
|
|
21
|
+
partialFilterExpression: { checkpoint_requested_at: { $exists: true } }
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
await db.custom_write_checkpoints.createIndex(
|
|
25
|
+
{
|
|
26
|
+
checkpoint_requested_at: 1
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: 'checkpoint_requested_at',
|
|
30
|
+
partialFilterExpression: { checkpoint_requested_at: { $exists: true } }
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
} finally {
|
|
34
|
+
await db.client.close();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const down: migrations.PowerSyncMigrationFunction = async (context) => {
|
|
39
|
+
const {
|
|
40
|
+
service_context: { configuration }
|
|
41
|
+
} = context;
|
|
42
|
+
|
|
43
|
+
const db = storage.createPowerSyncMongo(configuration.storage as MongoStorageConfig);
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
if (await db.write_checkpoints.indexExists('checkpoint_requested_at')) {
|
|
47
|
+
await db.write_checkpoints.dropIndex('checkpoint_requested_at');
|
|
48
|
+
}
|
|
49
|
+
if (await db.custom_write_checkpoints.indexExists('checkpoint_requested_at')) {
|
|
50
|
+
await db.custom_write_checkpoints.dropIndex('checkpoint_requested_at');
|
|
51
|
+
}
|
|
52
|
+
} finally {
|
|
53
|
+
await db.client.close();
|
|
54
|
+
}
|
|
55
|
+
};
|