@powersync/service-module-mongodb-storage 0.0.0-dev-20260225160713 → 0.0.0-dev-20260511080634
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 +119 -6
- package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.js +1 -1
- package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.js.map +1 -1
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js +3 -3
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js.map +1 -1
- package/dist/migrations/db/migrations/1770213298299-storage-version.js.map +1 -1
- package/dist/storage/MongoBucketStorage.d.ts +5 -3
- package/dist/storage/MongoBucketStorage.js +53 -26
- package/dist/storage/MongoBucketStorage.js.map +1 -1
- package/dist/storage/MongoReportStorage.js.map +1 -1
- package/dist/storage/implementation/BucketDefinitionMapping.d.ts +17 -0
- package/dist/storage/implementation/BucketDefinitionMapping.js +58 -0
- package/dist/storage/implementation/BucketDefinitionMapping.js.map +1 -0
- package/dist/storage/implementation/MongoBucketBatch.d.ts +25 -21
- package/dist/storage/implementation/MongoBucketBatch.js +256 -210
- package/dist/storage/implementation/MongoBucketBatch.js.map +1 -1
- package/dist/storage/implementation/MongoBucketBatchShared.d.ts +5 -0
- package/dist/storage/implementation/MongoBucketBatchShared.js +8 -0
- package/dist/storage/implementation/MongoBucketBatchShared.js.map +1 -0
- package/dist/storage/implementation/MongoChecksums.d.ts +30 -19
- package/dist/storage/implementation/MongoChecksums.js +13 -71
- package/dist/storage/implementation/MongoChecksums.js.map +1 -1
- package/dist/storage/implementation/MongoCompactor.d.ts +99 -53
- package/dist/storage/implementation/MongoCompactor.js +265 -303
- package/dist/storage/implementation/MongoCompactor.js.map +1 -1
- package/dist/storage/implementation/MongoParameterCompactor.d.ts +12 -7
- package/dist/storage/implementation/MongoParameterCompactor.js +24 -9
- package/dist/storage/implementation/MongoParameterCompactor.js.map +1 -1
- package/dist/storage/implementation/MongoPersistedSyncRules.d.ts +14 -0
- package/dist/storage/implementation/MongoPersistedSyncRules.js +64 -0
- package/dist/storage/implementation/MongoPersistedSyncRules.js.map +1 -0
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.d.ts +3 -0
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.js +11 -7
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.js.map +1 -1
- package/dist/storage/implementation/MongoStorageProvider.js +1 -1
- package/dist/storage/implementation/MongoStorageProvider.js.map +1 -1
- package/dist/storage/implementation/MongoSyncBucketStorage.d.ts +54 -30
- package/dist/storage/implementation/MongoSyncBucketStorage.js +118 -472
- package/dist/storage/implementation/MongoSyncBucketStorage.js.map +1 -1
- package/dist/storage/implementation/MongoSyncRulesLock.d.ts +7 -5
- package/dist/storage/implementation/MongoSyncRulesLock.js +12 -10
- package/dist/storage/implementation/MongoSyncRulesLock.js.map +1 -1
- package/dist/storage/implementation/MongoWriteCheckpointAPI.d.ts +4 -4
- package/dist/storage/implementation/MongoWriteCheckpointAPI.js +1 -1
- package/dist/storage/implementation/MongoWriteCheckpointAPI.js.map +1 -1
- package/dist/storage/implementation/OperationBatch.js +3 -2
- package/dist/storage/implementation/OperationBatch.js.map +1 -1
- package/dist/storage/implementation/common/BucketDataDoc.d.ts +35 -0
- package/dist/storage/implementation/common/BucketDataDoc.js +2 -0
- package/dist/storage/implementation/common/BucketDataDoc.js.map +1 -0
- package/dist/storage/implementation/common/MongoSyncBucketStorageContext.d.ts +13 -0
- package/dist/storage/implementation/common/MongoSyncBucketStorageContext.js +2 -0
- package/dist/storage/implementation/common/MongoSyncBucketStorageContext.js.map +1 -0
- package/dist/storage/implementation/common/PersistedBatch.d.ts +108 -0
- package/dist/storage/implementation/common/PersistedBatch.js +237 -0
- package/dist/storage/implementation/common/PersistedBatch.js.map +1 -0
- package/dist/storage/implementation/common/SingleBucketStore.d.ts +54 -0
- package/dist/storage/implementation/common/SingleBucketStore.js +3 -0
- package/dist/storage/implementation/common/SingleBucketStore.js.map +1 -0
- package/dist/storage/implementation/common/SourceRecordStore.d.ts +36 -0
- package/dist/storage/implementation/common/SourceRecordStore.js +2 -0
- package/dist/storage/implementation/common/SourceRecordStore.js.map +1 -0
- package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.d.ts +27 -0
- package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.js +57 -0
- package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.js.map +1 -0
- package/dist/storage/implementation/createMongoSyncBucketStorage.d.ts +7 -0
- package/dist/storage/implementation/createMongoSyncBucketStorage.js +9 -0
- package/dist/storage/implementation/createMongoSyncBucketStorage.js.map +1 -0
- package/dist/storage/implementation/db.d.ts +38 -4
- package/dist/storage/implementation/db.js +80 -1
- package/dist/storage/implementation/db.js.map +1 -1
- package/dist/storage/implementation/models.d.ts +66 -25
- package/dist/storage/implementation/models.js +22 -2
- package/dist/storage/implementation/models.js.map +1 -1
- package/dist/storage/implementation/v1/MongoBucketBatchV1.d.ts +13 -0
- package/dist/storage/implementation/v1/MongoBucketBatchV1.js +22 -0
- package/dist/storage/implementation/v1/MongoBucketBatchV1.js.map +1 -0
- package/dist/storage/implementation/v1/MongoChecksumsV1.d.ts +12 -0
- package/dist/storage/implementation/v1/MongoChecksumsV1.js +56 -0
- package/dist/storage/implementation/v1/MongoChecksumsV1.js.map +1 -0
- package/dist/storage/implementation/v1/MongoCompactorV1.d.ts +23 -0
- package/dist/storage/implementation/v1/MongoCompactorV1.js +52 -0
- package/dist/storage/implementation/v1/MongoCompactorV1.js.map +1 -0
- package/dist/storage/implementation/v1/MongoParameterCompactorV1.d.ts +9 -0
- package/dist/storage/implementation/v1/MongoParameterCompactorV1.js +20 -0
- package/dist/storage/implementation/v1/MongoParameterCompactorV1.js.map +1 -0
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.d.ts +41 -0
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js +269 -0
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js.map +1 -0
- package/dist/storage/implementation/v1/PersistedBatchV1.d.ts +26 -0
- package/dist/storage/implementation/v1/PersistedBatchV1.js +183 -0
- package/dist/storage/implementation/v1/PersistedBatchV1.js.map +1 -0
- package/dist/storage/implementation/v1/SingleBucketStoreV1.d.ts +18 -0
- package/dist/storage/implementation/v1/SingleBucketStoreV1.js +57 -0
- package/dist/storage/implementation/v1/SingleBucketStoreV1.js.map +1 -0
- package/dist/storage/implementation/v1/SourceRecordStoreV1.d.ts +19 -0
- package/dist/storage/implementation/v1/SourceRecordStoreV1.js +105 -0
- package/dist/storage/implementation/v1/SourceRecordStoreV1.js.map +1 -0
- package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.d.ts +12 -0
- package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.js +20 -0
- package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.js.map +1 -0
- package/dist/storage/implementation/v1/models.d.ts +34 -0
- package/dist/storage/implementation/v1/models.js +37 -0
- package/dist/storage/implementation/v1/models.js.map +1 -0
- package/dist/storage/implementation/v3/MongoBucketBatchV3.d.ts +13 -0
- package/dist/storage/implementation/v3/MongoBucketBatchV3.js +34 -0
- package/dist/storage/implementation/v3/MongoBucketBatchV3.js.map +1 -0
- package/dist/storage/implementation/v3/MongoChecksumsV3.d.ts +15 -0
- package/dist/storage/implementation/v3/MongoChecksumsV3.js +84 -0
- package/dist/storage/implementation/v3/MongoChecksumsV3.js.map +1 -0
- package/dist/storage/implementation/v3/MongoCompactorV3.d.ts +23 -0
- package/dist/storage/implementation/v3/MongoCompactorV3.js +68 -0
- package/dist/storage/implementation/v3/MongoCompactorV3.js.map +1 -0
- package/dist/storage/implementation/v3/MongoParameterCompactorV3.d.ts +9 -0
- package/dist/storage/implementation/v3/MongoParameterCompactorV3.js +18 -0
- package/dist/storage/implementation/v3/MongoParameterCompactorV3.js.map +1 -0
- package/dist/storage/implementation/v3/MongoParameterLookupV3.d.ts +5 -0
- package/dist/storage/implementation/v3/MongoParameterLookupV3.js +9 -0
- package/dist/storage/implementation/v3/MongoParameterLookupV3.js.map +1 -0
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.d.ts +41 -0
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js +404 -0
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js.map +1 -0
- package/dist/storage/implementation/v3/PersistedBatchV3.d.ts +29 -0
- package/dist/storage/implementation/v3/PersistedBatchV3.js +259 -0
- package/dist/storage/implementation/v3/PersistedBatchV3.js.map +1 -0
- package/dist/storage/implementation/v3/SingleBucketStoreV3.d.ts +18 -0
- package/dist/storage/implementation/v3/SingleBucketStoreV3.js +48 -0
- package/dist/storage/implementation/v3/SingleBucketStoreV3.js.map +1 -0
- package/dist/storage/implementation/v3/SourceRecordStoreV3.d.ts +22 -0
- package/dist/storage/implementation/v3/SourceRecordStoreV3.js +164 -0
- package/dist/storage/implementation/v3/SourceRecordStoreV3.js.map +1 -0
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.d.ts +21 -0
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js +71 -0
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js.map +1 -0
- package/dist/storage/implementation/v3/models.d.ts +43 -0
- package/dist/storage/implementation/v3/models.js +34 -0
- package/dist/storage/implementation/v3/models.js.map +1 -0
- package/dist/storage/storage-index.d.ts +8 -5
- package/dist/storage/storage-index.js +8 -5
- package/dist/storage/storage-index.js.map +1 -1
- package/dist/utils/test-utils.d.ts +4 -1
- package/dist/utils/test-utils.js +15 -12
- package/dist/utils/test-utils.js.map +1 -1
- package/dist/utils/util.d.ts +13 -5
- package/dist/utils/util.js +40 -5
- package/dist/utils/util.js.map +1 -1
- package/package.json +9 -9
- package/src/migrations/db/migrations/1688556755264-initial-sync-rules.ts +1 -1
- package/src/migrations/db/migrations/1702295701188-sync-rule-state.ts +7 -7
- package/src/migrations/db/migrations/1770213298299-storage-version.ts +1 -1
- package/src/storage/MongoBucketStorage.ts +111 -55
- package/src/storage/MongoReportStorage.ts +2 -2
- package/src/storage/implementation/BucketDefinitionMapping.ts +72 -0
- package/src/storage/implementation/MongoBucketBatch.ts +322 -270
- package/src/storage/implementation/MongoBucketBatchShared.ts +11 -0
- package/src/storage/implementation/MongoChecksums.ts +54 -75
- package/src/storage/implementation/MongoCompactor.ts +411 -412
- package/src/storage/implementation/MongoParameterCompactor.ts +52 -26
- package/src/storage/implementation/MongoPersistedSyncRules.ts +76 -0
- package/src/storage/implementation/MongoPersistedSyncRulesContent.ts +19 -10
- package/src/storage/implementation/MongoStorageProvider.ts +1 -1
- package/src/storage/implementation/MongoSyncBucketStorage.ts +206 -466
- package/src/storage/implementation/MongoSyncRulesLock.ts +14 -16
- package/src/storage/implementation/MongoWriteCheckpointAPI.ts +7 -5
- package/src/storage/implementation/OperationBatch.ts +3 -2
- package/src/storage/implementation/common/BucketDataDoc.ts +37 -0
- package/src/storage/implementation/common/MongoSyncBucketStorageContext.ts +15 -0
- package/src/storage/implementation/common/PersistedBatch.ts +364 -0
- package/src/storage/implementation/common/SingleBucketStore.ts +63 -0
- package/src/storage/implementation/common/SourceRecordStore.ts +49 -0
- package/src/storage/implementation/common/VersionedPowerSyncMongoBase.ts +80 -0
- package/src/storage/implementation/createMongoSyncBucketStorage.ts +25 -0
- package/src/storage/implementation/db.ts +115 -8
- package/src/storage/implementation/models.ts +88 -28
- package/src/storage/implementation/v1/MongoBucketBatchV1.ts +32 -0
- package/src/storage/implementation/v1/MongoChecksumsV1.ts +75 -0
- package/src/storage/implementation/v1/MongoCompactorV1.ts +93 -0
- package/src/storage/implementation/v1/MongoParameterCompactorV1.ts +26 -0
- package/src/storage/implementation/v1/MongoSyncBucketStorageV1.ts +432 -0
- package/src/storage/implementation/v1/PersistedBatchV1.ts +230 -0
- package/src/storage/implementation/v1/SingleBucketStoreV1.ts +74 -0
- package/src/storage/implementation/v1/SourceRecordStoreV1.ts +156 -0
- package/src/storage/implementation/v1/VersionedPowerSyncMongoV1.ts +28 -0
- package/src/storage/implementation/v1/models.ts +84 -0
- package/src/storage/implementation/v3/MongoBucketBatchV3.ts +44 -0
- package/src/storage/implementation/v3/MongoChecksumsV3.ts +120 -0
- package/src/storage/implementation/v3/MongoCompactorV3.ts +107 -0
- package/src/storage/implementation/v3/MongoParameterCompactorV3.ts +24 -0
- package/src/storage/implementation/v3/MongoParameterLookupV3.ts +12 -0
- package/src/storage/implementation/v3/MongoSyncBucketStorageV3.ts +545 -0
- package/src/storage/implementation/v3/PersistedBatchV3.ts +318 -0
- package/src/storage/implementation/v3/SingleBucketStoreV3.ts +68 -0
- package/src/storage/implementation/v3/SourceRecordStoreV3.ts +226 -0
- package/src/storage/implementation/v3/VersionedPowerSyncMongoV3.ts +112 -0
- package/src/storage/implementation/v3/models.ts +96 -0
- package/src/storage/storage-index.ts +8 -5
- package/src/utils/test-utils.ts +15 -12
- package/src/utils/util.ts +53 -9
- package/test/src/__snapshots__/storage.test.ts.snap +201 -0
- package/test/src/__snapshots__/storage_compacting.test.ts.snap +17 -0
- package/test/src/__snapshots__/storage_sync.test.ts.snap +1393 -16
- package/test/src/connection-report-storage.test.ts +3 -3
- package/test/src/setup.ts +1 -1
- package/test/src/storage.test.ts +10 -8
- package/test/src/storage_compacting.test.ts +146 -46
- package/test/src/storage_sync.test.ts +404 -56
- package/test/src/util.ts +3 -3
- package/test/tsconfig.json +0 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/storage/implementation/PersistedBatch.d.ts +0 -64
- package/dist/storage/implementation/PersistedBatch.js +0 -323
- package/dist/storage/implementation/PersistedBatch.js.map +0 -1
- package/src/storage/implementation/PersistedBatch.ts +0 -401
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { mongo } from '@powersync/lib-service-mongodb';
|
|
2
|
+
import { DO_NOT_LOG } from '@powersync/lib-services-framework';
|
|
3
|
+
import { PowerSyncMongo } from '../db.js';
|
|
4
|
+
import { CommonSourceTableDocument, StorageConfig } from '../models.js';
|
|
5
|
+
|
|
6
|
+
export abstract class BaseVersionedPowerSyncMongo {
|
|
7
|
+
readonly client: mongo.MongoClient;
|
|
8
|
+
readonly db: mongo.Db;
|
|
9
|
+
readonly storageConfig: StorageConfig;
|
|
10
|
+
[DO_NOT_LOG] = true;
|
|
11
|
+
|
|
12
|
+
constructor(
|
|
13
|
+
protected readonly upstream: PowerSyncMongo,
|
|
14
|
+
storageConfig: StorageConfig
|
|
15
|
+
) {
|
|
16
|
+
this.client = upstream.client;
|
|
17
|
+
this.db = upstream.db;
|
|
18
|
+
this.storageConfig = storageConfig;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get bucket_data() {
|
|
22
|
+
return this.upstream.bucket_data;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
get op_id_sequence() {
|
|
26
|
+
return this.upstream.op_id_sequence;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get sync_rules() {
|
|
30
|
+
return this.upstream.sync_rules;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
get custom_write_checkpoints() {
|
|
34
|
+
return this.upstream.custom_write_checkpoints;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
get write_checkpoints() {
|
|
38
|
+
return this.upstream.write_checkpoints;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get instance() {
|
|
42
|
+
return this.upstream.instance;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get locks() {
|
|
46
|
+
return this.upstream.locks;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get checkpoint_events() {
|
|
50
|
+
return this.upstream.checkpoint_events;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
get connection_report_events() {
|
|
54
|
+
return this.upstream.connection_report_events;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
notifyCheckpoint() {
|
|
58
|
+
return this.upstream.notifyCheckpoint();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
protected sourceRecordsCollectionName(replicationStreamId: number, sourceTableId: mongo.ObjectId) {
|
|
62
|
+
return this.upstream.sourceRecordsCollectionName(replicationStreamId, sourceTableId);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
protected sourceTableCollectionName(replicationStreamId: number) {
|
|
66
|
+
return this.upstream.sourceTableCollectionName(replicationStreamId);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
protected async listCollectionsByPrefix<T extends mongo.Document>(prefix: string): Promise<mongo.Collection<T>[]> {
|
|
70
|
+
const collections = await this.db.listCollections({ name: new RegExp(`^${prefix}`) }, { nameOnly: true }).toArray();
|
|
71
|
+
|
|
72
|
+
return collections
|
|
73
|
+
.filter((collection) => collection.name.startsWith(prefix))
|
|
74
|
+
.map((collection) => this.db.collection<T>(collection.name));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
abstract commonSourceTables(replicationStreamId: number): mongo.Collection<CommonSourceTableDocument>;
|
|
78
|
+
|
|
79
|
+
abstract initializeStreamStorage(replicationStreamId: number): Promise<void>;
|
|
80
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { storage } from '@powersync/service-core';
|
|
2
|
+
import { MongoBucketStorage } from '../MongoBucketStorage.js';
|
|
3
|
+
import { MongoPersistedSyncRulesContent } from './MongoPersistedSyncRulesContent.js';
|
|
4
|
+
import { MongoSyncBucketStorage, MongoSyncBucketStorageOptions } from './MongoSyncBucketStorage.js';
|
|
5
|
+
import { MongoSyncBucketStorageV1 } from './v1/MongoSyncBucketStorageV1.js';
|
|
6
|
+
import { MongoSyncBucketStorageV3 } from './v3/MongoSyncBucketStorageV3.js';
|
|
7
|
+
|
|
8
|
+
export { MongoSyncBucketStorageOptions } from './MongoSyncBucketStorage.js';
|
|
9
|
+
|
|
10
|
+
export type { MongoSyncBucketStorage };
|
|
11
|
+
|
|
12
|
+
export function createMongoSyncBucketStorage(
|
|
13
|
+
factory: MongoBucketStorage,
|
|
14
|
+
group_id: number,
|
|
15
|
+
sync_rules: MongoPersistedSyncRulesContent,
|
|
16
|
+
slot_name: string,
|
|
17
|
+
writeCheckpointMode: storage.WriteCheckpointMode | undefined,
|
|
18
|
+
options: MongoSyncBucketStorageOptions
|
|
19
|
+
): MongoSyncBucketStorage {
|
|
20
|
+
if (sync_rules.getStorageConfig().incrementalReprocessing) {
|
|
21
|
+
return new MongoSyncBucketStorageV3(factory, group_id, sync_rules, slot_name, writeCheckpointMode, options);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return new MongoSyncBucketStorageV1(factory, group_id, sync_rules, slot_name, writeCheckpointMode, options);
|
|
25
|
+
}
|
|
@@ -2,21 +2,30 @@ import * as lib_mongo from '@powersync/lib-service-mongodb';
|
|
|
2
2
|
import { mongo } from '@powersync/lib-service-mongodb';
|
|
3
3
|
import { POWERSYNC_VERSION, storage } from '@powersync/service-core';
|
|
4
4
|
|
|
5
|
+
import { DO_NOT_LOG } from '@powersync/lib-services-framework';
|
|
5
6
|
import { MongoStorageConfig } from '../../types/types.js';
|
|
7
|
+
import { BaseVersionedPowerSyncMongo } from './common/VersionedPowerSyncMongoBase.js';
|
|
6
8
|
import {
|
|
7
|
-
BucketDataDocument,
|
|
8
|
-
BucketParameterDocument,
|
|
9
|
-
BucketStateDocument,
|
|
10
9
|
CheckpointEventDocument,
|
|
11
10
|
ClientConnectionDocument,
|
|
12
|
-
|
|
11
|
+
CommonSourceTableDocument,
|
|
13
12
|
CustomWriteCheckpointDocument,
|
|
14
13
|
IdSequenceDocument,
|
|
15
14
|
InstanceDocument,
|
|
16
15
|
SourceTableDocument,
|
|
16
|
+
StorageConfig,
|
|
17
17
|
SyncRuleDocument,
|
|
18
18
|
WriteCheckpointDocument
|
|
19
19
|
} from './models.js';
|
|
20
|
+
import {
|
|
21
|
+
BucketDataDocumentV1,
|
|
22
|
+
BucketParameterDocument,
|
|
23
|
+
BucketStateDocumentV1,
|
|
24
|
+
CurrentDataDocument
|
|
25
|
+
} from './v1/models.js';
|
|
26
|
+
import { VersionedPowerSyncMongoV1 } from './v1/VersionedPowerSyncMongoV1.js';
|
|
27
|
+
import { BucketDataDocumentV3 } from './v3/models.js';
|
|
28
|
+
import { VersionedPowerSyncMongoV3 } from './v3/VersionedPowerSyncMongoV3.js';
|
|
20
29
|
|
|
21
30
|
export interface PowerSyncMongoOptions {
|
|
22
31
|
/**
|
|
@@ -26,8 +35,10 @@ export interface PowerSyncMongoOptions {
|
|
|
26
35
|
}
|
|
27
36
|
|
|
28
37
|
export class PowerSyncMongo {
|
|
38
|
+
[DO_NOT_LOG] = true;
|
|
39
|
+
|
|
29
40
|
readonly current_data: mongo.Collection<CurrentDataDocument>;
|
|
30
|
-
readonly bucket_data: mongo.Collection<
|
|
41
|
+
readonly bucket_data: mongo.Collection<BucketDataDocumentV1>;
|
|
31
42
|
readonly bucket_parameters: mongo.Collection<BucketParameterDocument>;
|
|
32
43
|
readonly op_id_sequence: mongo.Collection<IdSequenceDocument>;
|
|
33
44
|
readonly sync_rules: mongo.Collection<SyncRuleDocument>;
|
|
@@ -36,7 +47,7 @@ export class PowerSyncMongo {
|
|
|
36
47
|
readonly write_checkpoints: mongo.Collection<WriteCheckpointDocument>;
|
|
37
48
|
readonly instance: mongo.Collection<InstanceDocument>;
|
|
38
49
|
readonly locks: mongo.Collection<lib_mongo.locks.Lock>;
|
|
39
|
-
readonly bucket_state: mongo.Collection<
|
|
50
|
+
readonly bucket_state: mongo.Collection<BucketStateDocumentV1>;
|
|
40
51
|
readonly checkpoint_events: mongo.Collection<CheckpointEventDocument>;
|
|
41
52
|
readonly connection_report_events: mongo.Collection<ClientConnectionDocument>;
|
|
42
53
|
|
|
@@ -51,7 +62,7 @@ export class PowerSyncMongo {
|
|
|
51
62
|
});
|
|
52
63
|
this.db = db;
|
|
53
64
|
|
|
54
|
-
this.current_data = db.collection
|
|
65
|
+
this.current_data = db.collection('current_data');
|
|
55
66
|
this.bucket_data = db.collection('bucket_data');
|
|
56
67
|
this.bucket_parameters = db.collection('bucket_parameters');
|
|
57
68
|
this.op_id_sequence = db.collection('op_id_sequence');
|
|
@@ -66,15 +77,106 @@ export class PowerSyncMongo {
|
|
|
66
77
|
this.connection_report_events = this.db.collection('connection_report_events');
|
|
67
78
|
}
|
|
68
79
|
|
|
80
|
+
versioned(storageConfig: StorageConfig): VersionedPowerSyncMongo {
|
|
81
|
+
if (storageConfig.incrementalReprocessing) {
|
|
82
|
+
return new VersionedPowerSyncMongoV3(this, storageConfig);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return new VersionedPowerSyncMongoV1(this, storageConfig);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Not safe for user-provided prefix - only for hardcoded values.
|
|
90
|
+
*/
|
|
91
|
+
async listBucketDataCollectionsV3(groupId?: number): Promise<mongo.Collection<BucketDataDocumentV3>[]> {
|
|
92
|
+
const prefix = groupId == null ? 'bucket_data_' : `bucket_data_${groupId}_`;
|
|
93
|
+
const collections = await this.db.listCollections({ name: new RegExp(`^${prefix}`) }, { nameOnly: true }).toArray();
|
|
94
|
+
|
|
95
|
+
return collections
|
|
96
|
+
.filter((collection) => collection.name.startsWith(prefix))
|
|
97
|
+
.map((collection) => this.db.collection<BucketDataDocumentV3>(collection.name));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Not safe for user-provided prefix - only for hardcoded values.
|
|
102
|
+
*/
|
|
103
|
+
private async collectionsByPrefix(prefix: string): Promise<mongo.Collection<never>[]> {
|
|
104
|
+
const collections = await this.db.listCollections({ name: new RegExp(`^${prefix}`) }, { nameOnly: true }).toArray();
|
|
105
|
+
|
|
106
|
+
return collections
|
|
107
|
+
.filter((collection) => collection.name.startsWith(prefix))
|
|
108
|
+
.map((collection) => this.db.collection<never>(collection.name));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* List all parameter index collections across all replication streams.
|
|
113
|
+
*
|
|
114
|
+
* Primarily used to clear the db.
|
|
115
|
+
*/
|
|
116
|
+
async listAllParameterIndexCollectionsV3(): Promise<mongo.Collection<never>[]> {
|
|
117
|
+
return this.collectionsByPrefix(`parameter_index_`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* List all parameter index collections across all replication streams.
|
|
122
|
+
*
|
|
123
|
+
* Primarily used to clear the db.
|
|
124
|
+
*/
|
|
125
|
+
async listAllSourceRecordCollectionsV3(): Promise<mongo.Collection<never>[]> {
|
|
126
|
+
return this.collectionsByPrefix(`source_records_`);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async listAllBucketStateCollectionsV3(): Promise<mongo.Collection<never>[]> {
|
|
130
|
+
return this.collectionsByPrefix(`bucket_state_`);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
sourceRecordsCollectionName(replicationStreamId: number, sourceTableId: mongo.ObjectId) {
|
|
134
|
+
return `source_records_${replicationStreamId}_${sourceTableId.toHexString()}`;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
sourceTableCollectionName(replicationStreamId: number) {
|
|
138
|
+
return `source_table_${replicationStreamId}`;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async listSourceTableCollections(
|
|
142
|
+
replicationStreamId?: number
|
|
143
|
+
): Promise<mongo.Collection<CommonSourceTableDocument>[]> {
|
|
144
|
+
const filter =
|
|
145
|
+
replicationStreamId == null
|
|
146
|
+
? { name: new RegExp('^source_table_') }
|
|
147
|
+
: { name: this.sourceTableCollectionName(replicationStreamId) };
|
|
148
|
+
const prefix = replicationStreamId == null ? 'source_table_' : this.sourceTableCollectionName(replicationStreamId);
|
|
149
|
+
const collections = await this.db.listCollections(filter, { nameOnly: true }).toArray();
|
|
150
|
+
|
|
151
|
+
return collections
|
|
152
|
+
.filter((collection) => collection.name.startsWith(prefix))
|
|
153
|
+
.map((collection) => this.db.collection<CommonSourceTableDocument>(collection.name));
|
|
154
|
+
}
|
|
155
|
+
|
|
69
156
|
/**
|
|
70
157
|
* Clear all collections.
|
|
71
158
|
*/
|
|
72
159
|
async clear() {
|
|
73
160
|
await this.current_data.deleteMany({});
|
|
161
|
+
for (const collection of await this.listAllSourceRecordCollectionsV3()) {
|
|
162
|
+
await collection.drop();
|
|
163
|
+
}
|
|
74
164
|
await this.bucket_data.deleteMany({});
|
|
165
|
+
for (const collection of await this.listBucketDataCollectionsV3()) {
|
|
166
|
+
await collection.drop();
|
|
167
|
+
}
|
|
75
168
|
await this.bucket_parameters.deleteMany({});
|
|
169
|
+
for (const collection of await this.listAllParameterIndexCollectionsV3()) {
|
|
170
|
+
await collection.drop();
|
|
171
|
+
}
|
|
172
|
+
for (const collection of await this.listAllBucketStateCollectionsV3()) {
|
|
173
|
+
await collection.drop();
|
|
174
|
+
}
|
|
76
175
|
await this.op_id_sequence.deleteMany({});
|
|
77
176
|
await this.sync_rules.deleteMany({});
|
|
177
|
+
for (const collection of await this.listSourceTableCollections()) {
|
|
178
|
+
await collection.drop();
|
|
179
|
+
}
|
|
78
180
|
await this.source_tables.deleteMany({});
|
|
79
181
|
await this.write_checkpoints.deleteMany({});
|
|
80
182
|
await this.instance.deleteOne({});
|
|
@@ -93,7 +195,7 @@ export class PowerSyncMongo {
|
|
|
93
195
|
}
|
|
94
196
|
|
|
95
197
|
/**
|
|
96
|
-
* Call this after every checkpoint or
|
|
198
|
+
* Call this after every checkpoint or replication stream status update. Rather call too often than too rarely.
|
|
97
199
|
*
|
|
98
200
|
* This is used in a similar way to the Postgres NOTIFY functionality.
|
|
99
201
|
*/
|
|
@@ -173,6 +275,11 @@ export class PowerSyncMongo {
|
|
|
173
275
|
}
|
|
174
276
|
}
|
|
175
277
|
|
|
278
|
+
/**
|
|
279
|
+
* This is similar to PowerSyncMongo, but blocks access to certain collections based on the storage version.
|
|
280
|
+
*/
|
|
281
|
+
export type VersionedPowerSyncMongo = BaseVersionedPowerSyncMongo;
|
|
282
|
+
|
|
176
283
|
export function createPowerSyncMongo(config: MongoStorageConfig, options?: lib_mongo.MongoConnectionOptions) {
|
|
177
284
|
return new PowerSyncMongo(
|
|
178
285
|
lib_mongo.createMongoClient(config, {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { ErrorCode, ServiceError } from '@powersync/lib-services-framework';
|
|
1
2
|
import { InternalOpId, SerializedSyncPlan, storage } from '@powersync/service-core';
|
|
2
3
|
import { SqliteJsonValue } from '@powersync/service-sync-rules';
|
|
3
|
-
import * as bson from 'bson';
|
|
4
4
|
import { event_types } from '@powersync/service-types';
|
|
5
|
+
import * as bson from 'bson';
|
|
6
|
+
import { ParameterIndexId } from './BucketDefinitionMapping.js';
|
|
7
|
+
import type { CurrentDataDocument, SourceTableDocumentV1 } from './v1/models.js';
|
|
8
|
+
import type { CurrentBucketV3, CurrentDataDocumentV3, RecordedLookupV3, SourceTableDocumentV3 } from './v3/models.js';
|
|
5
9
|
|
|
6
10
|
/**
|
|
7
11
|
* Replica id uniquely identifying a row on the source database.
|
|
@@ -21,37 +25,53 @@ export interface SourceKey {
|
|
|
21
25
|
k: ReplicaId;
|
|
22
26
|
}
|
|
23
27
|
|
|
28
|
+
export interface SourceTableKey {
|
|
29
|
+
/** source table id */
|
|
30
|
+
t: bson.ObjectId;
|
|
31
|
+
/** source key */
|
|
32
|
+
k: ReplicaId;
|
|
33
|
+
}
|
|
34
|
+
|
|
24
35
|
export interface BucketDataKey {
|
|
25
|
-
/** group_id */
|
|
26
|
-
g: number;
|
|
27
36
|
/** bucket name */
|
|
28
37
|
b: string;
|
|
29
38
|
/** op_id */
|
|
30
39
|
o: bigint;
|
|
31
40
|
}
|
|
32
41
|
|
|
33
|
-
export interface CurrentDataDocument {
|
|
34
|
-
_id: SourceKey;
|
|
35
|
-
data: bson.Binary;
|
|
36
|
-
buckets: CurrentBucket[];
|
|
37
|
-
lookups: bson.Binary[];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
42
|
export interface CurrentBucket {
|
|
41
43
|
bucket: string;
|
|
42
44
|
table: string;
|
|
43
45
|
id: string;
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
export interface
|
|
48
|
+
export interface BucketParameterDocumentBase<TKey> {
|
|
47
49
|
_id: bigint;
|
|
48
|
-
key:
|
|
50
|
+
key: TKey;
|
|
49
51
|
lookup: bson.Binary;
|
|
50
52
|
bucket_parameters: Record<string, SqliteJsonValue>[];
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
export interface
|
|
54
|
-
|
|
55
|
+
export interface TaggedBucketParameterDocument extends BucketParameterDocumentBase<SourceKey | SourceTableKey> {
|
|
56
|
+
index: ParameterIndexId;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function bucketParameterDocumentToTagged<TKey extends SourceKey | SourceTableKey>(
|
|
60
|
+
document: BucketParameterDocumentBase<TKey>,
|
|
61
|
+
index: ParameterIndexId
|
|
62
|
+
): TaggedBucketParameterDocument {
|
|
63
|
+
return {
|
|
64
|
+
...document,
|
|
65
|
+
index
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export type OpType = 'PUT' | 'REMOVE' | 'MOVE' | 'CLEAR';
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Common properties for storage V1, storage V3 and in-memory BucketDataDoc.
|
|
73
|
+
*/
|
|
74
|
+
export interface BucketDataProperties {
|
|
55
75
|
op: OpType;
|
|
56
76
|
source_table?: bson.ObjectId;
|
|
57
77
|
source_key?: ReplicaId;
|
|
@@ -62,11 +82,22 @@ export interface BucketDataDocument {
|
|
|
62
82
|
target_op?: bigint | null;
|
|
63
83
|
}
|
|
64
84
|
|
|
65
|
-
export
|
|
85
|
+
export interface BucketDataDocumentBase extends BucketDataProperties {
|
|
86
|
+
_id: { b: string };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Internal-only tag used for v1 bucket_data rows before they are converted to the v1 on-disk shape.
|
|
91
|
+
*/
|
|
92
|
+
export const LEGACY_BUCKET_DATA_DEFINITION_ID = '0';
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Internal-only tag used for v1 bucket_parameters rows before they are converted to the v1 on-disk shape.
|
|
96
|
+
*/
|
|
97
|
+
export const LEGACY_BUCKET_PARAMETER_INDEX_ID = '0';
|
|
66
98
|
|
|
67
99
|
export interface SourceTableDocument {
|
|
68
100
|
_id: bson.ObjectId;
|
|
69
|
-
group_id: number;
|
|
70
101
|
connection_id: number;
|
|
71
102
|
relation_id: number | string | undefined;
|
|
72
103
|
schema_name: string;
|
|
@@ -86,20 +117,21 @@ export interface SourceTableDocumentSnapshotStatus {
|
|
|
86
117
|
/**
|
|
87
118
|
* Record the state of each bucket.
|
|
88
119
|
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
120
|
+
* The primary use case is to track when buckets are updated, for efficient incremental sync.
|
|
121
|
+
*
|
|
122
|
+
* The secondary use case is to track operation counts to determine whether or not a bucket should be compacted.
|
|
92
123
|
*
|
|
93
|
-
* Note:
|
|
124
|
+
* Note: For storage V1, there is no migration to populate this collection from existing data - it is only
|
|
94
125
|
* populated by new updates.
|
|
126
|
+
*
|
|
127
|
+
* For storage V3, these will always be present.
|
|
95
128
|
*/
|
|
96
|
-
export interface
|
|
129
|
+
export interface BucketStateDocumentBase {
|
|
97
130
|
_id: {
|
|
98
|
-
g: number;
|
|
99
131
|
b: string;
|
|
100
132
|
};
|
|
101
133
|
/**
|
|
102
|
-
* Important: There is an unique index on
|
|
134
|
+
* Important: There is an unique index on last_op per logical stream.
|
|
103
135
|
* That means the last_op must match an actual op in the bucket, and not the commit checkpoint.
|
|
104
136
|
*/
|
|
105
137
|
last_op: bigint;
|
|
@@ -111,12 +143,12 @@ export interface BucketStateDocument {
|
|
|
111
143
|
op_id: InternalOpId;
|
|
112
144
|
count: number;
|
|
113
145
|
checksum: bigint;
|
|
114
|
-
bytes: number | null;
|
|
146
|
+
bytes: number | bigint | null;
|
|
115
147
|
};
|
|
116
148
|
|
|
117
149
|
estimate_since_compact?: {
|
|
118
150
|
count: number;
|
|
119
|
-
bytes: number;
|
|
151
|
+
bytes: number | bigint;
|
|
120
152
|
};
|
|
121
153
|
}
|
|
122
154
|
|
|
@@ -201,6 +233,20 @@ export interface SyncRuleDocument {
|
|
|
201
233
|
content: string;
|
|
202
234
|
serialized_plan?: SerializedSyncPlan | null;
|
|
203
235
|
|
|
236
|
+
/**
|
|
237
|
+
* Required for V3+ storage.
|
|
238
|
+
*/
|
|
239
|
+
rule_mapping?: {
|
|
240
|
+
/**
|
|
241
|
+
* Map of uniqueName -> id, unique per replication stream.
|
|
242
|
+
*/
|
|
243
|
+
definitions: Record<string, string>;
|
|
244
|
+
/**
|
|
245
|
+
* Map of (lookupName, queryId) -> id, unique per replication stream.
|
|
246
|
+
*/
|
|
247
|
+
parameter_indexes: Record<string, string>;
|
|
248
|
+
};
|
|
249
|
+
|
|
204
250
|
lock?: {
|
|
205
251
|
id: string;
|
|
206
252
|
expires_at: Date;
|
|
@@ -217,17 +263,26 @@ export interface StorageConfig extends storage.StorageVersionConfig {
|
|
|
217
263
|
* a Long before summing.
|
|
218
264
|
*/
|
|
219
265
|
longChecksums: boolean;
|
|
266
|
+
/**
|
|
267
|
+
* Enables v3 MongoDB storage behavior used for incremental reprocessing.
|
|
268
|
+
*/
|
|
269
|
+
incrementalReprocessing: boolean;
|
|
220
270
|
}
|
|
221
271
|
|
|
222
272
|
const LONG_CHECKSUMS_STORAGE_VERSION = 2;
|
|
273
|
+
const INCREMENTAL_REPROCESSING_STORAGE_VERSION = storage.STORAGE_VERSION_3;
|
|
223
274
|
|
|
224
|
-
export function getMongoStorageConfig(storageVersion: number): StorageConfig
|
|
275
|
+
export function getMongoStorageConfig(storageVersion: number): StorageConfig {
|
|
225
276
|
const baseConfig = storage.STORAGE_VERSION_CONFIG[storageVersion];
|
|
226
277
|
if (baseConfig == null) {
|
|
227
|
-
|
|
278
|
+
throw new ServiceError(ErrorCode.PSYNC_S1005, `Unsupported storage version ${storageVersion}`);
|
|
228
279
|
}
|
|
229
280
|
|
|
230
|
-
return {
|
|
281
|
+
return {
|
|
282
|
+
...baseConfig,
|
|
283
|
+
longChecksums: storageVersion >= LONG_CHECKSUMS_STORAGE_VERSION,
|
|
284
|
+
incrementalReprocessing: storageVersion >= INCREMENTAL_REPROCESSING_STORAGE_VERSION
|
|
285
|
+
};
|
|
231
286
|
}
|
|
232
287
|
|
|
233
288
|
export interface CheckpointEventDocument {
|
|
@@ -272,3 +327,8 @@ export interface InstanceDocument {
|
|
|
272
327
|
}
|
|
273
328
|
|
|
274
329
|
export interface ClientConnectionDocument extends event_types.ClientConnection {}
|
|
330
|
+
|
|
331
|
+
export type CurrentDataDocumentId = CurrentDataDocument['_id'] | CurrentDataDocumentV3['_id'];
|
|
332
|
+
export type CommonCurrentBucket = CurrentBucket | CurrentBucketV3;
|
|
333
|
+
export type CommonCurrentLookup = bson.Binary | RecordedLookupV3;
|
|
334
|
+
export type CommonSourceTableDocument = SourceTableDocumentV1 | SourceTableDocumentV3;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SourceTable } from '@powersync/service-core';
|
|
2
|
+
import { MongoBucketBatch, MongoBucketBatchOptions } from '../MongoBucketBatch.js';
|
|
3
|
+
import { PersistedBatch } from '../common/PersistedBatch.js';
|
|
4
|
+
import { SourceRecordStore } from '../common/SourceRecordStore.js';
|
|
5
|
+
import { PersistedBatchV1 } from './PersistedBatchV1.js';
|
|
6
|
+
import { SourceRecordStoreV1 } from './SourceRecordStoreV1.js';
|
|
7
|
+
import { VersionedPowerSyncMongoV1 } from './VersionedPowerSyncMongoV1.js';
|
|
8
|
+
|
|
9
|
+
export class MongoBucketBatchV1 extends MongoBucketBatch {
|
|
10
|
+
declare public readonly db: VersionedPowerSyncMongoV1;
|
|
11
|
+
|
|
12
|
+
private readonly store: SourceRecordStore;
|
|
13
|
+
|
|
14
|
+
constructor(options: MongoBucketBatchOptions) {
|
|
15
|
+
super(options);
|
|
16
|
+
this.store = new SourceRecordStoreV1(this.db, this.group_id);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
protected createPersistedBatch(writtenSize: number): PersistedBatch {
|
|
20
|
+
return new PersistedBatchV1(this.db, this.group_id, this.mapping, writtenSize, {
|
|
21
|
+
logger: this.logger
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
protected get sourceRecordStore(): SourceRecordStore {
|
|
26
|
+
return this.store;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
protected async cleanupDroppedSourceTables(_tables: SourceTable[]) {
|
|
30
|
+
// No-op for V1: source records live in a shared collection.
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
bson,
|
|
3
|
+
BucketChecksum,
|
|
4
|
+
FetchPartialBucketChecksum,
|
|
5
|
+
InternalOpId,
|
|
6
|
+
PartialChecksumMap
|
|
7
|
+
} from '@powersync/service-core';
|
|
8
|
+
import { FetchPartialBucketChecksumByBucket, MongoChecksums } from '../MongoChecksums.js';
|
|
9
|
+
import { VersionedPowerSyncMongoV1 } from './VersionedPowerSyncMongoV1.js';
|
|
10
|
+
|
|
11
|
+
export class MongoChecksumsV1 extends MongoChecksums {
|
|
12
|
+
declare protected readonly db: VersionedPowerSyncMongoV1;
|
|
13
|
+
|
|
14
|
+
async computePartialChecksumsDirectByBucket(
|
|
15
|
+
batch: FetchPartialBucketChecksumByBucket[]
|
|
16
|
+
): Promise<PartialChecksumMap> {
|
|
17
|
+
return this.computePartialChecksumsForCollection(batch, this.db.bucketDataV1, (request) => ({
|
|
18
|
+
_id: {
|
|
19
|
+
$gt: {
|
|
20
|
+
g: this.group_id,
|
|
21
|
+
b: request.bucket,
|
|
22
|
+
o: request.start ?? new bson.MinKey()
|
|
23
|
+
},
|
|
24
|
+
$lte: {
|
|
25
|
+
g: this.group_id,
|
|
26
|
+
b: request.bucket,
|
|
27
|
+
o: request.end
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
protected async fetchPreStates(
|
|
34
|
+
batch: FetchPartialBucketChecksum[]
|
|
35
|
+
): Promise<Map<string, { opId: InternalOpId; checksum: BucketChecksum }>> {
|
|
36
|
+
const preFilters = batch
|
|
37
|
+
.filter((request) => request.start == null)
|
|
38
|
+
.map((request) => ({
|
|
39
|
+
_id: {
|
|
40
|
+
g: this.group_id,
|
|
41
|
+
b: request.bucket
|
|
42
|
+
},
|
|
43
|
+
'compacted_state.op_id': { $exists: true, $lte: request.end }
|
|
44
|
+
}));
|
|
45
|
+
|
|
46
|
+
const preStates = new Map<string, { opId: InternalOpId; checksum: BucketChecksum }>();
|
|
47
|
+
if (preFilters.length == 0) {
|
|
48
|
+
return preStates;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const states = await this.db.bucketStateV1
|
|
52
|
+
.find({
|
|
53
|
+
$or: preFilters
|
|
54
|
+
})
|
|
55
|
+
.toArray();
|
|
56
|
+
|
|
57
|
+
for (const state of states) {
|
|
58
|
+
const compactedState = state.compacted_state!;
|
|
59
|
+
preStates.set(state._id.b, {
|
|
60
|
+
opId: compactedState.op_id,
|
|
61
|
+
checksum: {
|
|
62
|
+
bucket: state._id.b,
|
|
63
|
+
checksum: Number(compactedState.checksum),
|
|
64
|
+
count: compactedState.count
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return preStates;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
protected async computePartialChecksumsInternal(batch: FetchPartialBucketChecksum[]): Promise<PartialChecksumMap> {
|
|
73
|
+
return this.computePartialChecksumsDirectByBucket(batch);
|
|
74
|
+
}
|
|
75
|
+
}
|