@powersync/service-module-mongodb 0.22.9-dev-20261204084200 → 0.23.0-dev-20261205085725
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 +18 -7
- package/dist/replication/MongoReplicationQueryProvider.d.ts +50 -5
- package/dist/replication/MongoReplicationQueryProvider.js +24 -1
- package/dist/replication/MongoReplicationQueryProvider.js.map +1 -1
- package/dist/replication/MongoSnapshotPartitionResume.d.ts +36 -0
- package/dist/replication/MongoSnapshotPartitionResume.js +95 -0
- package/dist/replication/MongoSnapshotPartitionResume.js.map +1 -0
- package/dist/replication/MongoSnapshotQuery.d.ts +5 -0
- package/dist/replication/MongoSnapshotQuery.js +15 -0
- package/dist/replication/MongoSnapshotQuery.js.map +1 -1
- package/dist/replication/MongoSnapshotter.js +144 -84
- package/dist/replication/MongoSnapshotter.js.map +1 -1
- package/dist/replication/estimateFilteredSnapshotCount.d.ts +12 -0
- package/dist/replication/estimateFilteredSnapshotCount.js +37 -0
- package/dist/replication/estimateFilteredSnapshotCount.js.map +1 -1
- package/package.json +9 -8
- package/src/replication/MongoReplicationQueryProvider.ts +73 -6
- package/src/replication/MongoSnapshotPartitionResume.ts +133 -0
- package/src/replication/MongoSnapshotQuery.ts +15 -0
- package/src/replication/MongoSnapshotter.ts +157 -93
- package/src/replication/estimateFilteredSnapshotCount.ts +43 -0
- package/test/src/filtering_example.test.ts +4 -2
- package/test/src/filtering_lifecycle.test.ts +3 -2
- package/test/src/partitioned_snapshot.test.ts +205 -0
- package/test/src/snapshot_query_provider.test.ts +26 -19
- package/test/src/snapshot_resume_key.test.ts +108 -0
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,18 +1,29 @@
|
|
|
1
1
|
# @powersync/service-module-mongodb
|
|
2
2
|
|
|
3
|
-
## 0.
|
|
3
|
+
## 0.23.0-dev-20261205085725
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 12564e4: Allow MongoDB replication query providers to split a table snapshot into partitions, each paged in `_id` order and resumable. Providers implement `getSnapshotPartitions` in place of `getSnapshotFilter`. This lets a filter such as a large `$in` be read in smaller batches of values, each served efficiently by an index such as `{ store_id: 1, _id: 1 }`.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 2a84275: Stop paging a bounded MongoDB snapshot query once it reaches the upper bound, instead of running one more query that returns nothing. Filtered snapshots that use an upper bound on the highest matching `_id` now finish their range after the page containing that document.
|
|
12
|
+
- @powersync/service-core@1.31.1-dev-20261205085725
|
|
13
|
+
|
|
14
|
+
## 0.22.9
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
|
6
17
|
|
|
7
|
-
-
|
|
18
|
+
- 88f65dd: Add `rust_evaluation` option to MongoDB storage configurations. When set to `force`, replicated rows are processed through an experimental Rust implementation of Sync Streams.
|
|
8
19
|
|
|
9
20
|
Note that the option required incremental reprocessing and `edition: 3` Sync Streams, doesn't support most SQL functions and expressions yet and only works for MongoDB source databases.
|
|
10
21
|
|
|
11
|
-
- Updated dependencies [
|
|
12
|
-
- @powersync/service-core@1.31.0
|
|
13
|
-
- @powersync/service-sync-rules@0.45.3
|
|
14
|
-
- @powersync/lib-services-framework@0.10.8
|
|
15
|
-
- @powersync/lib-service-mongodb@0.6.39
|
|
22
|
+
- Updated dependencies [88f65dd]
|
|
23
|
+
- @powersync/service-core@1.31.0
|
|
24
|
+
- @powersync/service-sync-rules@0.45.3
|
|
25
|
+
- @powersync/lib-services-framework@0.10.8
|
|
26
|
+
- @powersync/lib-service-mongodb@0.6.39
|
|
16
27
|
|
|
17
28
|
## 0.22.8
|
|
18
29
|
|
|
@@ -20,6 +20,40 @@ export interface MongoReplicationQueryProviderContext {
|
|
|
20
20
|
*/
|
|
21
21
|
defaultSchema: string;
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* One part of a table snapshot. The snapshot pages each partition in `_id` order, one partition after another.
|
|
25
|
+
*/
|
|
26
|
+
export interface MongoSnapshotPartition {
|
|
27
|
+
/**
|
|
28
|
+
* Stable identifier recorded in snapshot resume keys. The snapshotter treats it as opaque, but it must be unique
|
|
29
|
+
* within the plan and must not contain NUL characters, since resume keys store it as a BSON field name.
|
|
30
|
+
*/
|
|
31
|
+
id: string;
|
|
32
|
+
/**
|
|
33
|
+
* Find predicate selecting this partition's documents, or null to snapshot the whole collection.
|
|
34
|
+
* Filtered partitions use simple collation, combined with the `_id` continuation predicate.
|
|
35
|
+
*/
|
|
36
|
+
filter: mongo.Filter<mongo.Document> | null;
|
|
37
|
+
/**
|
|
38
|
+
* Optional superset of `filter` that MongoDB can count from index keys alone, used for progress estimates.
|
|
39
|
+
*/
|
|
40
|
+
estimateFilter?: mongo.Filter<mongo.Document>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* How a table snapshot is split into partitions.
|
|
44
|
+
*
|
|
45
|
+
* Together the partitions must match exactly the documents that streaming treats as selected. They should not
|
|
46
|
+
* overlap: overlapping partitions stay correct, because the snapshot writer skips rows it already wrote, but read the
|
|
47
|
+
* same documents more than once. The same sync config and source indexes must produce the same partitions, in the
|
|
48
|
+
* same order and with the same IDs, while a table's snapshot is in progress.
|
|
49
|
+
*/
|
|
50
|
+
export interface MongoSnapshotPartitionPlan {
|
|
51
|
+
/**
|
|
52
|
+
* Identifies the partitioning, so a resumed snapshot can detect a different plan and restart the table.
|
|
53
|
+
*/
|
|
54
|
+
fingerprint: string;
|
|
55
|
+
partitions: MongoSnapshotPartition[];
|
|
56
|
+
}
|
|
23
57
|
/**
|
|
24
58
|
* Adapts snapshot selection and the stream of source changes for one replication implementation.
|
|
25
59
|
* The MongoDB module owns cursor options, namespaces, BSON parsing, large-event reassembly and durable progress.
|
|
@@ -45,13 +79,15 @@ export interface MongoReplicationQueryProvider {
|
|
|
45
79
|
*/
|
|
46
80
|
openChangeStream(context: MongoReplicationStreamContext): AsyncIterableIterator<MongoReplicationStreamBatch>;
|
|
47
81
|
/**
|
|
48
|
-
* Returns
|
|
49
|
-
*
|
|
82
|
+
* Returns the partitions to snapshot for a physical source table. Return a single partition, for example with
|
|
83
|
+
* {@link singleSnapshotPartition}, for one filtered or unfiltered query. Snapshot selection must agree with the
|
|
50
84
|
* provider's streaming rules so both paths replicate the same set of documents.
|
|
51
|
-
* Expressions can be supplied as { $expr: ... }. The
|
|
52
|
-
* _id continuation predicate and uses simple collation whenever a filter is supplied.
|
|
85
|
+
* Expressions can be supplied as { $expr: ... }. The collection handle allows checks such as listing indexes.
|
|
53
86
|
*/
|
|
54
|
-
|
|
87
|
+
getSnapshotPartitions(options: {
|
|
88
|
+
table: SourceTable;
|
|
89
|
+
collection: mongo.Collection;
|
|
90
|
+
}): Promise<MongoSnapshotPartitionPlan>;
|
|
55
91
|
}
|
|
56
92
|
/**
|
|
57
93
|
* Creates a provider shared by a replication attempt's change stream, snapshotter and source probes.
|
|
@@ -61,6 +97,15 @@ export type MongoReplicationQueryProviderFactory = (context: MongoReplicationQue
|
|
|
61
97
|
* Uses the standard MongoDB reader and snapshot selection without additional filtering or event translation.
|
|
62
98
|
*/
|
|
63
99
|
export declare const DEFAULT_MONGO_REPLICATION_QUERY_PROVIDER: MongoReplicationQueryProvider;
|
|
100
|
+
/**
|
|
101
|
+
* A plan that snapshots the table with one query, optionally filtered.
|
|
102
|
+
*/
|
|
103
|
+
export declare function singleSnapshotPartition(filter: mongo.Filter<mongo.Document> | null): MongoSnapshotPartitionPlan;
|
|
104
|
+
/**
|
|
105
|
+
* Checks the parts of a plan's contract that the snapshotter relies on: at least one partition, and unique partition
|
|
106
|
+
* IDs that resume keys can store as BSON field names.
|
|
107
|
+
*/
|
|
108
|
+
export declare function assertSnapshotPartitionPlan(plan: MongoSnapshotPartitionPlan): void;
|
|
64
109
|
/**
|
|
65
110
|
* Places provider stages after namespace selection and before optional large-event splitting.
|
|
66
111
|
* This lets provider stages inspect complete events; the shared reader reassembles any resulting fragments.
|
|
@@ -1,10 +1,33 @@
|
|
|
1
|
+
import { ReplicationAssertionError } from '@powersync/lib-services-framework';
|
|
1
2
|
/**
|
|
2
3
|
* Uses the standard MongoDB reader and snapshot selection without additional filtering or event translation.
|
|
3
4
|
*/
|
|
4
5
|
export const DEFAULT_MONGO_REPLICATION_QUERY_PROVIDER = {
|
|
5
|
-
|
|
6
|
+
getSnapshotPartitions: async () => singleSnapshotPartition(null),
|
|
6
7
|
openChangeStream: ({ open }) => open({})
|
|
7
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* A plan that snapshots the table with one query, optionally filtered.
|
|
11
|
+
*/
|
|
12
|
+
export function singleSnapshotPartition(filter) {
|
|
13
|
+
return { fingerprint: 'single', partitions: [{ id: 'all', filter }] };
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Checks the parts of a plan's contract that the snapshotter relies on: at least one partition, and unique partition
|
|
17
|
+
* IDs that resume keys can store as BSON field names.
|
|
18
|
+
*/
|
|
19
|
+
export function assertSnapshotPartitionPlan(plan) {
|
|
20
|
+
if (plan.partitions.length == 0) {
|
|
21
|
+
throw new ReplicationAssertionError(`Snapshot partition plan ${JSON.stringify(plan.fingerprint)} has no partitions`);
|
|
22
|
+
}
|
|
23
|
+
const ids = new Set();
|
|
24
|
+
for (const { id } of plan.partitions) {
|
|
25
|
+
if (id.includes('\0') || ids.has(id)) {
|
|
26
|
+
throw new ReplicationAssertionError(`Snapshot partition plan ${JSON.stringify(plan.fingerprint)} has a duplicate partition ID or one containing a NUL character: ${JSON.stringify(id)}`);
|
|
27
|
+
}
|
|
28
|
+
ids.add(id);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
8
31
|
/**
|
|
9
32
|
* Places provider stages after namespace selection and before optional large-event splitting.
|
|
10
33
|
* This lets provider stages inspect complete events; the shared reader reassembles any resulting fragments.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongoReplicationQueryProvider.js","sourceRoot":"","sources":["../../src/replication/MongoReplicationQueryProvider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MongoReplicationQueryProvider.js","sourceRoot":"","sources":["../../src/replication/MongoReplicationQueryProvider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAsG9E;;GAEG;AACH,MAAM,CAAC,MAAM,wCAAwC,GAAkC;IACrF,qBAAqB,EAAE,KAAK,IAAI,EAAE,CAAC,uBAAuB,CAAC,IAAI,CAAC;IAChE,gBAAgB,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;CACzC,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,MAA2C;IACjF,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;AACxE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CAAC,IAAgC;IAC1E,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,yBAAyB,CACjC,2BAA2B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAChF,CAAC;IACJ,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;IAC9B,KAAK,MAAM,EAAE,EAAE,EAAE,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;QACrC,IAAI,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YACrC,MAAM,IAAI,yBAAyB,CACjC,2BAA2B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,oEAAoE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CACpJ,CAAC;QACJ,CAAC;QACD,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,8BAA8B,CAAC,OAiB9C;IACC,MAAM,QAAQ,GAAqB;QACjC,EAAE,aAAa,EAAE,OAAO,CAAC,aAAa,EAAE;QACxC,EAAE,MAAM,EAAE,OAAO,CAAC,cAAc,EAAE;QAClC,GAAG,OAAO,CAAC,cAAc;KAC1B,CAAC;IAEF,IAAI,OAAO,CAAC,sBAAsB,EAAE,CAAC;QACnC,QAAQ,CAAC,IAAI,CAAC,EAAE,4BAA4B,EAAE,EAAE,EAAE,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { MongoSnapshotPartitionPlan } from './MongoReplicationQueryProvider.js';
|
|
2
|
+
/**
|
|
3
|
+
* Progress of one started partition: finished, or the serialized `{ _id }` of its last copied document, as accepted by
|
|
4
|
+
* `ChunkedSnapshotQuery`.
|
|
5
|
+
*/
|
|
6
|
+
export type SnapshotPartitionProgress = {
|
|
7
|
+
done: true;
|
|
8
|
+
} | {
|
|
9
|
+
lastKey: Uint8Array;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Where a table snapshot continues.
|
|
13
|
+
*/
|
|
14
|
+
export interface SnapshotResumeState {
|
|
15
|
+
/**
|
|
16
|
+
* Progress by partition ID. Partitions without an entry have not started.
|
|
17
|
+
*/
|
|
18
|
+
progress: Map<string, SnapshotPartitionProgress>;
|
|
19
|
+
/**
|
|
20
|
+
* Why saved progress could not be used with the current plan. The table snapshot then restarts.
|
|
21
|
+
*/
|
|
22
|
+
discardedReason?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Finds where to continue a table snapshot from its saved key.
|
|
26
|
+
*
|
|
27
|
+
* Single-partition plans save `{ _id }`, the format used before partitions. Multi-partition plans save a
|
|
28
|
+
* `PartitionedResumeKey`. Progress saved under a different plan, or that doesn't match the plan's partitions, is
|
|
29
|
+
* discarded instead of misread.
|
|
30
|
+
*/
|
|
31
|
+
export declare function resolveSnapshotResumeState(plan: MongoSnapshotPartitionPlan, savedKey: Uint8Array | null | undefined): SnapshotResumeState;
|
|
32
|
+
/**
|
|
33
|
+
* Builds the saved key from the progress of every started partition. Single-partition plans keep the `{ _id }` of the
|
|
34
|
+
* last copied document; others save a `PartitionedResumeKey`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function encodeSnapshotResumeKey(plan: MongoSnapshotPartitionPlan, progress: ReadonlyMap<string, SnapshotPartitionProgress>): Uint8Array;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { ReplicationAssertionError } from '@powersync/lib-services-framework';
|
|
2
|
+
import { bson } from '@powersync/service-core';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
/**
|
|
5
|
+
* Saved progress of one partition: either the `_id` of its last copied document, or `done`.
|
|
6
|
+
*
|
|
7
|
+
* This uses zod rather than ts-codec, which the rest of the module uses: ts-codec objects drop unknown fields and its
|
|
8
|
+
* unions take the first branch that decodes, so an entry with both fields would silently read as one of them. Strict
|
|
9
|
+
* zod objects in a union accept exactly one shape. `_id` may be `null`, which MongoDB allows, but not missing.
|
|
10
|
+
*/
|
|
11
|
+
const PartitionProgress = z.union([
|
|
12
|
+
z.strictObject({ _id: z.unknown().refine((id) => id !== undefined) }),
|
|
13
|
+
z.strictObject({ done: z.literal(true) })
|
|
14
|
+
]);
|
|
15
|
+
/**
|
|
16
|
+
* Saved progress of a multi-partition snapshot.
|
|
17
|
+
*
|
|
18
|
+
* `partitions` maps the ID of every started partition to its progress; partitions without an entry have not started.
|
|
19
|
+
* Progress doesn't depend on partition order, so the same shape works whether partitions are copied one at a time, as
|
|
20
|
+
* now, or concurrently.
|
|
21
|
+
*
|
|
22
|
+
* There is deliberately no top-level `_id`: a service version that predates partitions reads `lastKey._id`, and
|
|
23
|
+
* without it pages the whole table again instead of resuming after one partition's `_id`.
|
|
24
|
+
*/
|
|
25
|
+
const PartitionedResumeKey = z.strictObject({
|
|
26
|
+
fingerprint: z.string(),
|
|
27
|
+
partitions: z.record(z.string(), PartitionProgress)
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* Finds where to continue a table snapshot from its saved key.
|
|
31
|
+
*
|
|
32
|
+
* Single-partition plans save `{ _id }`, the format used before partitions. Multi-partition plans save a
|
|
33
|
+
* `PartitionedResumeKey`. Progress saved under a different plan, or that doesn't match the plan's partitions, is
|
|
34
|
+
* discarded instead of misread.
|
|
35
|
+
*/
|
|
36
|
+
export function resolveSnapshotResumeState(plan, savedKey) {
|
|
37
|
+
if (savedKey == null) {
|
|
38
|
+
return { progress: new Map() };
|
|
39
|
+
}
|
|
40
|
+
const restart = (discardedReason) => ({ progress: new Map(), discardedReason });
|
|
41
|
+
const saved = bson.deserialize(savedKey, { useBigInt64: true });
|
|
42
|
+
const isIdKey = Object.keys(saved).length == 1 && '_id' in saved;
|
|
43
|
+
if (plan.partitions.length == 1) {
|
|
44
|
+
return isIdKey
|
|
45
|
+
? { progress: new Map([[plan.partitions[0].id, { lastKey: savedKey }]]) }
|
|
46
|
+
: restart('progress was saved for a partitioned snapshot, but the snapshot is no longer partitioned');
|
|
47
|
+
}
|
|
48
|
+
if (isIdKey) {
|
|
49
|
+
return restart(`progress was saved without partitions, but the snapshot uses partition plan ${JSON.stringify(plan.fingerprint)}`);
|
|
50
|
+
}
|
|
51
|
+
const parsed = PartitionedResumeKey.safeParse(saved);
|
|
52
|
+
if (!parsed.success) {
|
|
53
|
+
return restart('saved partition progress has an unsupported shape');
|
|
54
|
+
}
|
|
55
|
+
const key = parsed.data;
|
|
56
|
+
if (key.fingerprint !== plan.fingerprint) {
|
|
57
|
+
return restart(`progress was saved for partition plan ${JSON.stringify(key.fingerprint)}, but the snapshot uses ${JSON.stringify(plan.fingerprint)}`);
|
|
58
|
+
}
|
|
59
|
+
const ids = new Set(plan.partitions.map((partition) => partition.id));
|
|
60
|
+
// Re-read the _id values without promoting them, so resumed keys keep their exact BSON types.
|
|
61
|
+
const exact = bson.deserialize(savedKey, { promoteValues: false }).partitions;
|
|
62
|
+
const progress = new Map();
|
|
63
|
+
for (const [id, entry] of Object.entries(key.partitions)) {
|
|
64
|
+
if (!ids.has(id)) {
|
|
65
|
+
return restart(`saved progress names partition ${JSON.stringify(id)}, which partition plan ${JSON.stringify(key.fingerprint)} does not have`);
|
|
66
|
+
}
|
|
67
|
+
progress.set(id, 'done' in entry ? { done: true } : { lastKey: bson.serialize({ _id: exact[id]._id }) });
|
|
68
|
+
}
|
|
69
|
+
return { progress };
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Builds the saved key from the progress of every started partition. Single-partition plans keep the `{ _id }` of the
|
|
73
|
+
* last copied document; others save a `PartitionedResumeKey`.
|
|
74
|
+
*/
|
|
75
|
+
export function encodeSnapshotResumeKey(plan, progress) {
|
|
76
|
+
if (plan.partitions.length == 1) {
|
|
77
|
+
const only = progress.get(plan.partitions[0].id);
|
|
78
|
+
if (only == null || !('lastKey' in only)) {
|
|
79
|
+
throw new ReplicationAssertionError('A single-partition snapshot saves progress only after copying a page');
|
|
80
|
+
}
|
|
81
|
+
return only.lastKey;
|
|
82
|
+
}
|
|
83
|
+
const partitions = {};
|
|
84
|
+
for (const [id, entry] of progress) {
|
|
85
|
+
// The key must keep each _id's exact BSON type, as the single-partition key does by storing the raw bytes. A
|
|
86
|
+
// default round trip through JS values can change it, for example writing the double 1.0 back as the int32 1.
|
|
87
|
+
// promoteValues: false keeps every value in its BSON wrapper (Double, Int32, Long, ...), so it is serialized
|
|
88
|
+
// again unchanged.
|
|
89
|
+
partitions[id] =
|
|
90
|
+
'lastKey' in entry ? { _id: bson.deserialize(entry.lastKey, { promoteValues: false })._id } : { done: true };
|
|
91
|
+
}
|
|
92
|
+
const key = { fingerprint: plan.fingerprint, partitions };
|
|
93
|
+
return bson.serialize(key);
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=MongoSnapshotPartitionResume.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MongoSnapshotPartitionResume.js","sourceRoot":"","sources":["../../src/replication/MongoSnapshotPartitionResume.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAuBxB;;;;;;GAMG;AACH,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC;IAChC,CAAC,CAAC,YAAY,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,SAAS,CAAC,EAAE,CAAC;IACrE,CAAC,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;CAC1C,CAAC,CAAC;AAEH;;;;;;;;;GASG;AACH,MAAM,oBAAoB,GAAG,CAAC,CAAC,YAAY,CAAC;IAC1C,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;IACvB,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,iBAAiB,CAAC;CACpD,CAAC,CAAC;AAGH;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CACxC,IAAgC,EAChC,QAAuC;IAEvC,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;QACrB,OAAO,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC;IACjC,CAAC;IACD,MAAM,OAAO,GAAG,CAAC,eAAuB,EAAuB,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAE,EAAE,eAAe,EAAE,CAAC,CAAC;IAC7G,MAAM,KAAK,GAAG,I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AC;QAC9G,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IACD,MAAM,UAAU,GAAuC,EAAE,CAAC;IAC1D,KAAK,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,IAAI,QAAQ,EAAE,CAAC;QACnC,6GAA6G;QAC7G,8GAA8G;QAC9G,6GAA6G;QAC7G,mBAAmB;QACnB,UAAU,CAAC,EAAE,CAAC;YACZ,SAAS,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACjH,CAAC;IACD,MAAM,GAAG,GAAyB,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,UAAU,EAAE,CAAC;IAChF,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -12,6 +12,11 @@ export declare class ChunkedSnapshotQuery implements AsyncDisposable {
|
|
|
12
12
|
private batchSize;
|
|
13
13
|
private readonly filter;
|
|
14
14
|
private readonly upperKey;
|
|
15
|
+
/**
|
|
16
|
+
* Serialized `{ _id: upperKey }`. Reading a document with this key means the bounded range is complete.
|
|
17
|
+
*/
|
|
18
|
+
private readonly upperKeyBuffer;
|
|
19
|
+
private finished;
|
|
15
20
|
constructor(options: {
|
|
16
21
|
collection: mongo.Collection;
|
|
17
22
|
batchSize: number;
|
|
@@ -15,6 +15,11 @@ export class ChunkedSnapshotQuery {
|
|
|
15
15
|
batchSize;
|
|
16
16
|
filter;
|
|
17
17
|
upperKey;
|
|
18
|
+
/**
|
|
19
|
+
* Serialized `{ _id: upperKey }`. Reading a document with this key means the bounded range is complete.
|
|
20
|
+
*/
|
|
21
|
+
upperKeyBuffer;
|
|
22
|
+
finished = false;
|
|
18
23
|
constructor(options) {
|
|
19
24
|
this.lastKey = options.key ? bson.deserialize(options.key, { useBigInt64: true })._id : null;
|
|
20
25
|
this.lastCursor = null;
|
|
@@ -22,8 +27,13 @@ export class ChunkedSnapshotQuery {
|
|
|
22
27
|
this.batchSize = options.batchSize;
|
|
23
28
|
this.filter = options.filter ?? null;
|
|
24
29
|
this.upperKey = options.upperKey;
|
|
30
|
+
this.upperKeyBuffer =
|
|
31
|
+
options.upperKey === undefined ? null : Buffer.from(bson.serialize({ _id: options.upperKey }));
|
|
25
32
|
}
|
|
26
33
|
async nextChunk() {
|
|
34
|
+
if (this.finished) {
|
|
35
|
+
return { docs: [], lastKey: null, bytes: 0 };
|
|
36
|
+
}
|
|
27
37
|
let cursor = this.lastCursor;
|
|
28
38
|
let newCursor = false;
|
|
29
39
|
if (cursor == null || cursor.closed) {
|
|
@@ -83,6 +93,11 @@ export class ChunkedSnapshotQuery {
|
|
|
83
93
|
const lastDoc = docBatch[docBatch.length - 1];
|
|
84
94
|
const { id: lastKey, idBuffer } = parseDocumentId(lastDoc);
|
|
85
95
|
this.lastKey = lastKey;
|
|
96
|
+
// The upper bound is the last matching document, so reaching it saves a final query that would return nothing.
|
|
97
|
+
// If its re-serialized type differs from the source bytes, the final query still ends the range.
|
|
98
|
+
if (this.upperKeyBuffer?.equals(idBuffer)) {
|
|
99
|
+
this.finished = true;
|
|
100
|
+
}
|
|
86
101
|
return { docs: docBatch, lastKey: idBuffer, bytes };
|
|
87
102
|
}
|
|
88
103
|
async [Symbol.asyncDispose]() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongoSnapshotQuery.js","sourceRoot":"","sources":["../../src/replication/MongoSnapshotQuery.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,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