@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,11 @@
|
|
|
1
|
+
import * as bson from 'bson';
|
|
2
|
+
import { SourceRecordBucketState } from './common/SourceRecordStore.js';
|
|
3
|
+
|
|
4
|
+
export const MAX_ROW_SIZE = 15 * 1024 * 1024;
|
|
5
|
+
|
|
6
|
+
export const EMPTY_DATA = new bson.Binary(bson.serialize({}));
|
|
7
|
+
|
|
8
|
+
export function currentBucketKey(bucket: SourceRecordBucketState) {
|
|
9
|
+
const prefix = bucket.definitionId == null ? '' : `${bucket.definitionId}:`;
|
|
10
|
+
return `${prefix}${bucket.bucket}/${bucket.table}/${bucket.id}`;
|
|
11
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as lib_mongo from '@powersync/lib-service-mongodb';
|
|
2
1
|
import {
|
|
3
2
|
addPartialChecksums,
|
|
4
3
|
bson,
|
|
5
4
|
BucketChecksum,
|
|
5
|
+
BucketChecksumRequest,
|
|
6
6
|
ChecksumCache,
|
|
7
7
|
ChecksumMap,
|
|
8
8
|
FetchPartialBucketChecksum,
|
|
@@ -12,8 +12,24 @@ import {
|
|
|
12
12
|
PartialChecksumMap,
|
|
13
13
|
PartialOrFullChecksum
|
|
14
14
|
} from '@powersync/service-core';
|
|
15
|
-
import {
|
|
16
|
-
|
|
15
|
+
import type { VersionedPowerSyncMongo } from './db.js';
|
|
16
|
+
|
|
17
|
+
import * as lib_mongo from '@powersync/lib-service-mongodb';
|
|
18
|
+
import { BucketDefinitionId, BucketDefinitionMapping } from './BucketDefinitionMapping.js';
|
|
19
|
+
import { BucketDataDocumentBase, StorageConfig } from './models.js';
|
|
20
|
+
|
|
21
|
+
export interface FetchPartialBucketChecksumV3 {
|
|
22
|
+
bucket: string;
|
|
23
|
+
definitionId: BucketDefinitionId;
|
|
24
|
+
start?: InternalOpId;
|
|
25
|
+
end: InternalOpId;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface FetchPartialBucketChecksumByBucket {
|
|
29
|
+
bucket: string;
|
|
30
|
+
start?: InternalOpId;
|
|
31
|
+
end: InternalOpId;
|
|
32
|
+
}
|
|
17
33
|
|
|
18
34
|
/**
|
|
19
35
|
* Checksum calculation options, primarily for tests.
|
|
@@ -30,28 +46,20 @@ export interface MongoChecksumOptions {
|
|
|
30
46
|
operationBatchLimit?: number;
|
|
31
47
|
|
|
32
48
|
storageConfig: StorageConfig;
|
|
49
|
+
mapping?: BucketDefinitionMapping;
|
|
33
50
|
}
|
|
34
51
|
|
|
35
52
|
const DEFAULT_BUCKET_BATCH_LIMIT = 200;
|
|
36
53
|
const DEFAULT_OPERATION_BATCH_LIMIT = 50_000;
|
|
37
54
|
|
|
38
|
-
|
|
39
|
-
* Checksum query implementation.
|
|
40
|
-
*
|
|
41
|
-
* General implementation flow is:
|
|
42
|
-
* 1. getChecksums() -> check cache for (partial) matches. If not found or partial match, query the remainder using computePartialChecksums().
|
|
43
|
-
* 2. computePartialChecksums() -> query bucket_state for partial matches. Query the remainder using computePartialChecksumsDirect().
|
|
44
|
-
* 3. computePartialChecksumsDirect() -> split into batches of 200 buckets at a time -> computePartialChecksumsInternal()
|
|
45
|
-
* 4. computePartialChecksumsInternal() -> aggregate over 50_000 operations in bucket_data at a time
|
|
46
|
-
*/
|
|
47
|
-
export class MongoChecksums {
|
|
55
|
+
export abstract class MongoChecksums {
|
|
48
56
|
private _cache: ChecksumCache | undefined;
|
|
49
57
|
private readonly storageConfig: StorageConfig;
|
|
50
58
|
|
|
51
59
|
constructor(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
60
|
+
protected readonly db: VersionedPowerSyncMongo,
|
|
61
|
+
protected readonly group_id: number,
|
|
62
|
+
protected readonly options: MongoChecksumOptions
|
|
55
63
|
) {
|
|
56
64
|
this.storageConfig = options.storageConfig;
|
|
57
65
|
}
|
|
@@ -74,7 +82,7 @@ export class MongoChecksums {
|
|
|
74
82
|
* Calculate checksums, utilizing the cache for partial checkums, and querying the remainder from
|
|
75
83
|
* the database (bucket_state + bucket_data).
|
|
76
84
|
*/
|
|
77
|
-
async getChecksums(checkpoint: InternalOpId, buckets:
|
|
85
|
+
async getChecksums(checkpoint: InternalOpId, buckets: BucketChecksumRequest[]): Promise<ChecksumMap> {
|
|
78
86
|
return this.cache.getChecksumMap(checkpoint, buckets);
|
|
79
87
|
}
|
|
80
88
|
|
|
@@ -95,41 +103,7 @@ export class MongoChecksums {
|
|
|
95
103
|
if (batch.length == 0) {
|
|
96
104
|
return new Map();
|
|
97
105
|
}
|
|
98
|
-
|
|
99
|
-
const preFilters: any[] = [];
|
|
100
|
-
for (let request of batch) {
|
|
101
|
-
if (request.start == null) {
|
|
102
|
-
preFilters.push({
|
|
103
|
-
_id: {
|
|
104
|
-
g: this.group_id,
|
|
105
|
-
b: request.bucket
|
|
106
|
-
},
|
|
107
|
-
'compacted_state.op_id': { $exists: true, $lte: request.end }
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const preStates = new Map<string, { opId: InternalOpId; checksum: BucketChecksum }>();
|
|
113
|
-
|
|
114
|
-
if (preFilters.length > 0) {
|
|
115
|
-
// For un-cached bucket checksums, attempt to use the compacted state first.
|
|
116
|
-
const states = await this.db.bucket_state
|
|
117
|
-
.find({
|
|
118
|
-
$or: preFilters
|
|
119
|
-
})
|
|
120
|
-
.toArray();
|
|
121
|
-
for (let state of states) {
|
|
122
|
-
const compactedState = state.compacted_state!;
|
|
123
|
-
preStates.set(state._id.b, {
|
|
124
|
-
opId: compactedState.op_id,
|
|
125
|
-
checksum: {
|
|
126
|
-
bucket: state._id.b,
|
|
127
|
-
checksum: Number(compactedState.checksum),
|
|
128
|
-
count: compactedState.count
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
106
|
+
const preStates = await this.fetchPreStates(batch);
|
|
133
107
|
|
|
134
108
|
const mappedRequests = batch.map((request) => {
|
|
135
109
|
let start = request.start;
|
|
@@ -198,11 +172,24 @@ export class MongoChecksums {
|
|
|
198
172
|
*
|
|
199
173
|
* `batch` must be limited to DEFAULT_BUCKET_BATCH_LIMIT buckets before calling this.
|
|
200
174
|
*/
|
|
201
|
-
|
|
175
|
+
protected abstract computePartialChecksumsInternal(batch: FetchPartialBucketChecksum[]): Promise<PartialChecksumMap>;
|
|
176
|
+
|
|
177
|
+
protected abstract fetchPreStates(
|
|
178
|
+
batch: FetchPartialBucketChecksum[]
|
|
179
|
+
): Promise<Map<string, { opId: InternalOpId; checksum: BucketChecksum }>>;
|
|
180
|
+
|
|
181
|
+
protected async computePartialChecksumsForCollection<
|
|
182
|
+
TRequest extends FetchPartialBucketChecksumByBucket,
|
|
183
|
+
TBucketDataDocument extends BucketDataDocumentBase
|
|
184
|
+
>(
|
|
185
|
+
batch: TRequest[],
|
|
186
|
+
collection: lib_mongo.mongo.Collection<TBucketDataDocument>,
|
|
187
|
+
createFilter: (request: TRequest) => any
|
|
188
|
+
): Promise<PartialChecksumMap> {
|
|
202
189
|
const batchLimit = this.options?.operationBatchLimit ?? DEFAULT_OPERATION_BATCH_LIMIT;
|
|
203
190
|
|
|
204
191
|
// Map requests by bucket. We adjust this as we get partial results.
|
|
205
|
-
let requests = new Map<string,
|
|
192
|
+
let requests = new Map<string, TRequest>();
|
|
206
193
|
for (let request of batch) {
|
|
207
194
|
requests.set(request.bucket, request);
|
|
208
195
|
}
|
|
@@ -210,23 +197,7 @@ export class MongoChecksums {
|
|
|
210
197
|
const partialChecksums = new Map<string, PartialOrFullChecksum>();
|
|
211
198
|
|
|
212
199
|
while (requests.size > 0) {
|
|
213
|
-
const filters
|
|
214
|
-
for (let request of requests.values()) {
|
|
215
|
-
filters.push({
|
|
216
|
-
_id: {
|
|
217
|
-
$gt: {
|
|
218
|
-
g: this.group_id,
|
|
219
|
-
b: request.bucket,
|
|
220
|
-
o: request.start ?? new bson.MinKey()
|
|
221
|
-
},
|
|
222
|
-
$lte: {
|
|
223
|
-
g: this.group_id,
|
|
224
|
-
b: request.bucket,
|
|
225
|
-
o: request.end
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
}
|
|
200
|
+
const filters = Array.from(requests.values(), createFilter);
|
|
230
201
|
|
|
231
202
|
// Historically, checksum may be stored as 'int' or 'double'.
|
|
232
203
|
// More recently, this should be a 'long'.
|
|
@@ -242,7 +213,7 @@ export class MongoChecksums {
|
|
|
242
213
|
// Returns: B[3-10], C[1-4]
|
|
243
214
|
// 3. Query: C[5-end]
|
|
244
215
|
// Returns: C[5-10]
|
|
245
|
-
const aggregate = await
|
|
216
|
+
const aggregate = await collection
|
|
246
217
|
.aggregate(
|
|
247
218
|
[
|
|
248
219
|
{
|
|
@@ -297,9 +268,8 @@ export class MongoChecksums {
|
|
|
297
268
|
limitReached = true;
|
|
298
269
|
const req = requests.get(bucket);
|
|
299
270
|
requests.set(bucket, {
|
|
300
|
-
|
|
301
|
-
start: doc.last_op
|
|
302
|
-
end: req!.end
|
|
271
|
+
...req!,
|
|
272
|
+
start: doc.last_op
|
|
303
273
|
});
|
|
304
274
|
} else {
|
|
305
275
|
// All done for this bucket
|
|
@@ -337,6 +307,15 @@ export class MongoChecksums {
|
|
|
337
307
|
}
|
|
338
308
|
}
|
|
339
309
|
|
|
310
|
+
export function emptyChecksumForRequest(
|
|
311
|
+
request: Pick<FetchPartialBucketChecksum | FetchPartialBucketChecksumV3, 'bucket' | 'start'>
|
|
312
|
+
): PartialOrFullChecksum {
|
|
313
|
+
if (request.start == null) {
|
|
314
|
+
return { bucket: request.bucket, count: 0, checksum: 0 };
|
|
315
|
+
}
|
|
316
|
+
return { bucket: request.bucket, partialCount: 0, partialChecksum: 0 };
|
|
317
|
+
}
|
|
318
|
+
|
|
340
319
|
/**
|
|
341
320
|
* Convert output of the $group stage into a checksum.
|
|
342
321
|
*/
|