@powersync/service-module-mongodb-storage 0.15.4 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +69 -0
- 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 +2 -2
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js.map +1 -1
- package/dist/storage/MongoBucketStorage.d.ts +8 -6
- package/dist/storage/MongoBucketStorage.js +153 -66
- package/dist/storage/MongoBucketStorage.js.map +1 -1
- package/dist/storage/implementation/BucketDefinitionMapping.d.ts +15 -0
- package/dist/storage/implementation/BucketDefinitionMapping.js +58 -0
- package/dist/storage/implementation/BucketDefinitionMapping.js.map +1 -0
- package/dist/storage/implementation/CheckpointState.d.ts +20 -0
- package/dist/storage/implementation/CheckpointState.js +31 -0
- package/dist/storage/implementation/CheckpointState.js.map +1 -0
- package/dist/storage/implementation/MongoBucketBatch.d.ts +48 -35
- package/dist/storage/implementation/MongoBucketBatch.js +118 -379
- 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 +29 -17
- package/dist/storage/implementation/MongoChecksums.js +13 -72
- package/dist/storage/implementation/MongoChecksums.js.map +1 -1
- package/dist/storage/implementation/MongoCompactor.d.ts +98 -58
- package/dist/storage/implementation/MongoCompactor.js +229 -296
- package/dist/storage/implementation/MongoCompactor.js.map +1 -1
- package/dist/storage/implementation/MongoParameterCompactor.d.ts +11 -6
- package/dist/storage/implementation/MongoParameterCompactor.js +11 -8
- package/dist/storage/implementation/MongoParameterCompactor.js.map +1 -1
- package/dist/storage/implementation/MongoPersistedSyncRules.d.ts +14 -0
- package/dist/storage/implementation/MongoPersistedSyncRules.js +67 -0
- package/dist/storage/implementation/MongoPersistedSyncRules.js.map +1 -0
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.d.ts +22 -5
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.js +56 -13
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.js.map +1 -1
- package/dist/storage/implementation/MongoSyncBucketStorage.d.ts +61 -32
- package/dist/storage/implementation/MongoSyncBucketStorage.js +85 -523
- package/dist/storage/implementation/MongoSyncBucketStorage.js.map +1 -1
- package/dist/storage/implementation/MongoSyncRulesLock.d.ts +10 -4
- package/dist/storage/implementation/MongoSyncRulesLock.js +19 -13
- package/dist/storage/implementation/MongoSyncRulesLock.js.map +1 -1
- package/dist/storage/implementation/MongoWriteCheckpointAPI.js +1 -1
- package/dist/storage/implementation/MongoWriteCheckpointAPI.js.map +1 -1
- package/dist/storage/implementation/OperationBatch.js +1 -1
- package/dist/storage/implementation/SyncRuleStateUpdate.d.ts +14 -0
- package/dist/storage/implementation/SyncRuleStateUpdate.js +36 -0
- package/dist/storage/implementation/SyncRuleStateUpdate.js.map +1 -0
- 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 +35 -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 +41 -36
- package/dist/storage/implementation/db.js +77 -99
- package/dist/storage/implementation/db.js.map +1 -1
- package/dist/storage/implementation/models.d.ts +79 -66
- package/dist/storage/implementation/models.js +20 -1
- package/dist/storage/implementation/models.js.map +1 -1
- package/dist/storage/implementation/v1/MongoBucketBatchV1.d.ts +27 -0
- package/dist/storage/implementation/v1/MongoBucketBatchV1.js +407 -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 +50 -0
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js +354 -0
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js.map +1 -0
- package/dist/storage/implementation/v1/PersistedBatchV1.d.ts +25 -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 +45 -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 +30 -0
- package/dist/storage/implementation/v3/MongoBucketBatchV3.js +463 -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 +4 -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 +63 -0
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js +508 -0
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js.map +1 -0
- package/dist/storage/implementation/v3/PersistedBatchV3.d.ts +28 -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 +22 -0
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js +74 -0
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js.map +1 -0
- package/dist/storage/implementation/v3/models.d.ts +101 -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 +6 -3
- package/dist/storage/storage-index.js +6 -3
- package/dist/storage/storage-index.js.map +1 -1
- package/dist/utils/util.d.ts +10 -3
- package/dist/utils/util.js +24 -3
- 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/storage/MongoBucketStorage.ts +254 -99
- package/src/storage/implementation/BucketDefinitionMapping.ts +75 -0
- package/src/storage/implementation/CheckpointState.ts +59 -0
- package/src/storage/implementation/MongoBucketBatch.ts +182 -490
- package/src/storage/implementation/MongoBucketBatchShared.ts +11 -0
- package/src/storage/implementation/MongoChecksums.ts +53 -75
- package/src/storage/implementation/MongoCompactor.ts +374 -404
- package/src/storage/implementation/MongoParameterCompactor.ts +37 -24
- package/src/storage/implementation/MongoPersistedSyncRules.ts +82 -0
- package/src/storage/implementation/MongoPersistedSyncRulesContent.ts +78 -16
- package/src/storage/implementation/MongoSyncBucketStorage.ts +179 -628
- package/src/storage/implementation/MongoSyncRulesLock.ts +20 -16
- package/src/storage/implementation/MongoWriteCheckpointAPI.ts +3 -1
- package/src/storage/implementation/OperationBatch.ts +1 -1
- package/src/storage/implementation/SyncRuleStateUpdate.ts +38 -0
- 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 +48 -0
- package/src/storage/implementation/common/VersionedPowerSyncMongoBase.ts +80 -0
- package/src/storage/implementation/createMongoSyncBucketStorage.ts +25 -0
- package/src/storage/implementation/db.ts +110 -131
- package/src/storage/implementation/models.ts +102 -79
- package/src/storage/implementation/v1/MongoBucketBatchV1.ts +509 -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 +543 -0
- package/src/storage/implementation/v1/PersistedBatchV1.ts +229 -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 +99 -0
- package/src/storage/implementation/v3/MongoBucketBatchV3.ts +607 -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 +11 -0
- package/src/storage/implementation/v3/MongoSyncBucketStorageV3.ts +678 -0
- package/src/storage/implementation/v3/PersistedBatchV3.ts +317 -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 +117 -0
- package/src/storage/implementation/v3/models.ts +164 -0
- package/src/storage/storage-index.ts +6 -3
- package/src/utils/util.ts +34 -5
- package/test/src/storage_compacting.test.ts +57 -29
- package/test/src/storage_sync.test.ts +767 -5
- package/test/src/storeCurrentData.test.ts +211 -0
- package/test/tsconfig.json +0 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/storage/implementation/PersistedBatch.d.ts +0 -71
- package/dist/storage/implementation/PersistedBatch.js +0 -354
- package/dist/storage/implementation/PersistedBatch.js.map +0 -1
- package/src/storage/implementation/PersistedBatch.ts +0 -432
|
@@ -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,4 +1,3 @@
|
|
|
1
|
-
import * as lib_mongo from '@powersync/lib-service-mongodb';
|
|
2
1
|
import {
|
|
3
2
|
addPartialChecksums,
|
|
4
3
|
bson,
|
|
@@ -13,8 +12,25 @@ import {
|
|
|
13
12
|
PartialChecksumMap,
|
|
14
13
|
PartialOrFullChecksum
|
|
15
14
|
} from '@powersync/service-core';
|
|
16
|
-
import { VersionedPowerSyncMongo } from './db.js';
|
|
17
|
-
|
|
15
|
+
import type { VersionedPowerSyncMongo } from './db.js';
|
|
16
|
+
|
|
17
|
+
import * as lib_mongo from '@powersync/lib-service-mongodb';
|
|
18
|
+
import { BucketDefinitionId } from '@powersync/service-sync-rules';
|
|
19
|
+
import { BucketDefinitionMapping } from './BucketDefinitionMapping.js';
|
|
20
|
+
import { BucketDataDocumentBase, StorageConfig } from './models.js';
|
|
21
|
+
|
|
22
|
+
export interface FetchPartialBucketChecksumV3 {
|
|
23
|
+
bucket: string;
|
|
24
|
+
definitionId: BucketDefinitionId;
|
|
25
|
+
start?: InternalOpId;
|
|
26
|
+
end: InternalOpId;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface FetchPartialBucketChecksumByBucket {
|
|
30
|
+
bucket: string;
|
|
31
|
+
start?: InternalOpId;
|
|
32
|
+
end: InternalOpId;
|
|
33
|
+
}
|
|
18
34
|
|
|
19
35
|
/**
|
|
20
36
|
* Checksum calculation options, primarily for tests.
|
|
@@ -31,28 +47,20 @@ export interface MongoChecksumOptions {
|
|
|
31
47
|
operationBatchLimit?: number;
|
|
32
48
|
|
|
33
49
|
storageConfig: StorageConfig;
|
|
50
|
+
mapping?: BucketDefinitionMapping;
|
|
34
51
|
}
|
|
35
52
|
|
|
36
53
|
const DEFAULT_BUCKET_BATCH_LIMIT = 200;
|
|
37
54
|
const DEFAULT_OPERATION_BATCH_LIMIT = 50_000;
|
|
38
55
|
|
|
39
|
-
|
|
40
|
-
* Checksum query implementation.
|
|
41
|
-
*
|
|
42
|
-
* General implementation flow is:
|
|
43
|
-
* 1. getChecksums() -> check cache for (partial) matches. If not found or partial match, query the remainder using computePartialChecksums().
|
|
44
|
-
* 2. computePartialChecksums() -> query bucket_state for partial matches. Query the remainder using computePartialChecksumsDirect().
|
|
45
|
-
* 3. computePartialChecksumsDirect() -> split into batches of 200 buckets at a time -> computePartialChecksumsInternal()
|
|
46
|
-
* 4. computePartialChecksumsInternal() -> aggregate over 50_000 operations in bucket_data at a time
|
|
47
|
-
*/
|
|
48
|
-
export class MongoChecksums {
|
|
56
|
+
export abstract class MongoChecksums {
|
|
49
57
|
private _cache: ChecksumCache | undefined;
|
|
50
58
|
private readonly storageConfig: StorageConfig;
|
|
51
59
|
|
|
52
60
|
constructor(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
61
|
+
protected readonly db: VersionedPowerSyncMongo,
|
|
62
|
+
protected readonly group_id: number,
|
|
63
|
+
protected readonly options: MongoChecksumOptions
|
|
56
64
|
) {
|
|
57
65
|
this.storageConfig = options.storageConfig;
|
|
58
66
|
}
|
|
@@ -96,41 +104,7 @@ export class MongoChecksums {
|
|
|
96
104
|
if (batch.length == 0) {
|
|
97
105
|
return new Map();
|
|
98
106
|
}
|
|
99
|
-
|
|
100
|
-
const preFilters: any[] = [];
|
|
101
|
-
for (let request of batch) {
|
|
102
|
-
if (request.start == null) {
|
|
103
|
-
preFilters.push({
|
|
104
|
-
_id: {
|
|
105
|
-
g: this.group_id,
|
|
106
|
-
b: request.bucket
|
|
107
|
-
},
|
|
108
|
-
'compacted_state.op_id': { $exists: true, $lte: request.end }
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const preStates = new Map<string, { opId: InternalOpId; checksum: BucketChecksum }>();
|
|
114
|
-
|
|
115
|
-
if (preFilters.length > 0) {
|
|
116
|
-
// For un-cached bucket checksums, attempt to use the compacted state first.
|
|
117
|
-
const states = await this.db.bucket_state
|
|
118
|
-
.find({
|
|
119
|
-
$or: preFilters
|
|
120
|
-
})
|
|
121
|
-
.toArray();
|
|
122
|
-
for (let state of states) {
|
|
123
|
-
const compactedState = state.compacted_state!;
|
|
124
|
-
preStates.set(state._id.b, {
|
|
125
|
-
opId: compactedState.op_id,
|
|
126
|
-
checksum: {
|
|
127
|
-
bucket: state._id.b,
|
|
128
|
-
checksum: Number(compactedState.checksum),
|
|
129
|
-
count: compactedState.count
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
}
|
|
107
|
+
const preStates = await this.fetchPreStates(batch);
|
|
134
108
|
|
|
135
109
|
const mappedRequests = batch.map((request) => {
|
|
136
110
|
let start = request.start;
|
|
@@ -199,11 +173,24 @@ export class MongoChecksums {
|
|
|
199
173
|
*
|
|
200
174
|
* `batch` must be limited to DEFAULT_BUCKET_BATCH_LIMIT buckets before calling this.
|
|
201
175
|
*/
|
|
202
|
-
|
|
176
|
+
protected abstract computePartialChecksumsInternal(batch: FetchPartialBucketChecksum[]): Promise<PartialChecksumMap>;
|
|
177
|
+
|
|
178
|
+
protected abstract fetchPreStates(
|
|
179
|
+
batch: FetchPartialBucketChecksum[]
|
|
180
|
+
): Promise<Map<string, { opId: InternalOpId; checksum: BucketChecksum }>>;
|
|
181
|
+
|
|
182
|
+
protected async computePartialChecksumsForCollection<
|
|
183
|
+
TRequest extends FetchPartialBucketChecksumByBucket,
|
|
184
|
+
TBucketDataDocument extends BucketDataDocumentBase
|
|
185
|
+
>(
|
|
186
|
+
batch: TRequest[],
|
|
187
|
+
collection: lib_mongo.mongo.Collection<TBucketDataDocument>,
|
|
188
|
+
createFilter: (request: TRequest) => any
|
|
189
|
+
): Promise<PartialChecksumMap> {
|
|
203
190
|
const batchLimit = this.options?.operationBatchLimit ?? DEFAULT_OPERATION_BATCH_LIMIT;
|
|
204
191
|
|
|
205
192
|
// Map requests by bucket. We adjust this as we get partial results.
|
|
206
|
-
let requests = new Map<string,
|
|
193
|
+
let requests = new Map<string, TRequest>();
|
|
207
194
|
for (let request of batch) {
|
|
208
195
|
requests.set(request.bucket, request);
|
|
209
196
|
}
|
|
@@ -211,23 +198,7 @@ export class MongoChecksums {
|
|
|
211
198
|
const partialChecksums = new Map<string, PartialOrFullChecksum>();
|
|
212
199
|
|
|
213
200
|
while (requests.size > 0) {
|
|
214
|
-
const filters
|
|
215
|
-
for (let request of requests.values()) {
|
|
216
|
-
filters.push({
|
|
217
|
-
_id: {
|
|
218
|
-
$gt: {
|
|
219
|
-
g: this.group_id,
|
|
220
|
-
b: request.bucket,
|
|
221
|
-
o: request.start ?? new bson.MinKey()
|
|
222
|
-
},
|
|
223
|
-
$lte: {
|
|
224
|
-
g: this.group_id,
|
|
225
|
-
b: request.bucket,
|
|
226
|
-
o: request.end
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
}
|
|
201
|
+
const filters = Array.from(requests.values(), createFilter);
|
|
231
202
|
|
|
232
203
|
// Historically, checksum may be stored as 'int' or 'double'.
|
|
233
204
|
// More recently, this should be a 'long'.
|
|
@@ -243,7 +214,7 @@ export class MongoChecksums {
|
|
|
243
214
|
// Returns: B[3-10], C[1-4]
|
|
244
215
|
// 3. Query: C[5-end]
|
|
245
216
|
// Returns: C[5-10]
|
|
246
|
-
const aggregate = await
|
|
217
|
+
const aggregate = await collection
|
|
247
218
|
.aggregate(
|
|
248
219
|
[
|
|
249
220
|
{
|
|
@@ -298,10 +269,8 @@ export class MongoChecksums {
|
|
|
298
269
|
limitReached = true;
|
|
299
270
|
const req = requests.get(bucket);
|
|
300
271
|
requests.set(bucket, {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
start: doc.last_op,
|
|
304
|
-
end: req!.end
|
|
272
|
+
...req!,
|
|
273
|
+
start: doc.last_op
|
|
305
274
|
});
|
|
306
275
|
} else {
|
|
307
276
|
// All done for this bucket
|
|
@@ -339,6 +308,15 @@ export class MongoChecksums {
|
|
|
339
308
|
}
|
|
340
309
|
}
|
|
341
310
|
|
|
311
|
+
export function emptyChecksumForRequest(
|
|
312
|
+
request: Pick<FetchPartialBucketChecksum | FetchPartialBucketChecksumV3, 'bucket' | 'start'>
|
|
313
|
+
): PartialOrFullChecksum {
|
|
314
|
+
if (request.start == null) {
|
|
315
|
+
return { bucket: request.bucket, count: 0, checksum: 0 };
|
|
316
|
+
}
|
|
317
|
+
return { bucket: request.bucket, partialCount: 0, partialChecksum: 0 };
|
|
318
|
+
}
|
|
319
|
+
|
|
342
320
|
/**
|
|
343
321
|
* Convert output of the $group stage into a checksum.
|
|
344
322
|
*/
|