@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
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ErrorCode, ServiceError } from '@powersync/lib-services-framework';
|
|
2
|
-
import { InternalOpId,
|
|
3
|
-
import { SqliteJsonValue } from '@powersync/service-sync-rules';
|
|
2
|
+
import { InternalOpId, storage } from '@powersync/service-core';
|
|
3
|
+
import { ParameterIndexId, SqliteJsonValue } from '@powersync/service-sync-rules';
|
|
4
4
|
import { event_types } from '@powersync/service-types';
|
|
5
5
|
import * as bson from 'bson';
|
|
6
|
+
import type { CurrentDataDocument, SourceTableDocumentV1 } from './v1/models.js';
|
|
7
|
+
import type { CurrentBucketV3, CurrentDataDocumentV3, RecordedLookupV3, SourceTableDocumentV3 } from './v3/models.js';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Replica id uniquely identifying a row on the source database.
|
|
@@ -22,50 +24,53 @@ export interface SourceKey {
|
|
|
22
24
|
k: ReplicaId;
|
|
23
25
|
}
|
|
24
26
|
|
|
27
|
+
export interface SourceTableKey {
|
|
28
|
+
/** source table id */
|
|
29
|
+
t: bson.ObjectId;
|
|
30
|
+
/** source key */
|
|
31
|
+
k: ReplicaId;
|
|
32
|
+
}
|
|
33
|
+
|
|
25
34
|
export interface BucketDataKey {
|
|
26
|
-
/** group_id */
|
|
27
|
-
g: number;
|
|
28
35
|
/** bucket name */
|
|
29
36
|
b: string;
|
|
30
37
|
/** op_id */
|
|
31
38
|
o: bigint;
|
|
32
39
|
}
|
|
33
40
|
|
|
34
|
-
export interface CurrentDataDocument {
|
|
35
|
-
_id: SourceKey;
|
|
36
|
-
data: bson.Binary;
|
|
37
|
-
buckets: CurrentBucket[];
|
|
38
|
-
lookups: bson.Binary[];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface CurrentDataDocumentV3 {
|
|
42
|
-
_id: SourceKey;
|
|
43
|
-
data: bson.Binary;
|
|
44
|
-
buckets: CurrentBucket[];
|
|
45
|
-
lookups: bson.Binary[];
|
|
46
|
-
/**
|
|
47
|
-
* If set, this can be deleted, once there is a consistent checkpoint >= pending_delete.
|
|
48
|
-
*
|
|
49
|
-
* This must only be set if buckets = [], lookups = [].
|
|
50
|
-
*/
|
|
51
|
-
pending_delete?: bigint;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
41
|
export interface CurrentBucket {
|
|
55
42
|
bucket: string;
|
|
56
43
|
table: string;
|
|
57
44
|
id: string;
|
|
58
45
|
}
|
|
59
46
|
|
|
60
|
-
export interface
|
|
47
|
+
export interface BucketParameterDocumentBase<TKey> {
|
|
61
48
|
_id: bigint;
|
|
62
|
-
key:
|
|
49
|
+
key: TKey;
|
|
63
50
|
lookup: bson.Binary;
|
|
64
51
|
bucket_parameters: Record<string, SqliteJsonValue>[];
|
|
65
52
|
}
|
|
66
53
|
|
|
67
|
-
export interface
|
|
68
|
-
|
|
54
|
+
export interface TaggedBucketParameterDocument extends BucketParameterDocumentBase<SourceKey | SourceTableKey> {
|
|
55
|
+
index: ParameterIndexId;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function bucketParameterDocumentToTagged<TKey extends SourceKey | SourceTableKey>(
|
|
59
|
+
document: BucketParameterDocumentBase<TKey>,
|
|
60
|
+
index: ParameterIndexId
|
|
61
|
+
): TaggedBucketParameterDocument {
|
|
62
|
+
return {
|
|
63
|
+
...document,
|
|
64
|
+
index
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type OpType = 'PUT' | 'REMOVE' | 'MOVE' | 'CLEAR';
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Common properties for storage V1, storage V3 and in-memory BucketDataDoc.
|
|
72
|
+
*/
|
|
73
|
+
export interface BucketDataProperties {
|
|
69
74
|
op: OpType;
|
|
70
75
|
source_table?: bson.ObjectId;
|
|
71
76
|
source_key?: ReplicaId;
|
|
@@ -76,11 +81,22 @@ export interface BucketDataDocument {
|
|
|
76
81
|
target_op?: bigint | null;
|
|
77
82
|
}
|
|
78
83
|
|
|
79
|
-
export
|
|
84
|
+
export interface BucketDataDocumentBase extends BucketDataProperties {
|
|
85
|
+
_id: { b: string };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Internal-only tag used for v1 bucket_data rows before they are converted to the v1 on-disk shape.
|
|
90
|
+
*/
|
|
91
|
+
export const LEGACY_BUCKET_DATA_DEFINITION_ID = '0';
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Internal-only tag used for v1 bucket_parameters rows before they are converted to the v1 on-disk shape.
|
|
95
|
+
*/
|
|
96
|
+
export const LEGACY_BUCKET_PARAMETER_INDEX_ID = '0';
|
|
80
97
|
|
|
81
98
|
export interface SourceTableDocument {
|
|
82
99
|
_id: bson.ObjectId;
|
|
83
|
-
group_id: number;
|
|
84
100
|
connection_id: number;
|
|
85
101
|
relation_id: number | string | undefined;
|
|
86
102
|
schema_name: string;
|
|
@@ -100,20 +116,21 @@ export interface SourceTableDocumentSnapshotStatus {
|
|
|
100
116
|
/**
|
|
101
117
|
* Record the state of each bucket.
|
|
102
118
|
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
119
|
+
* The primary use case is to track when buckets are updated, for efficient incremental sync.
|
|
120
|
+
*
|
|
121
|
+
* The secondary use case is to track operation counts to determine whether or not a bucket should be compacted.
|
|
106
122
|
*
|
|
107
|
-
* Note:
|
|
123
|
+
* Note: For storage V1, there is no migration to populate this collection from existing data - it is only
|
|
108
124
|
* populated by new updates.
|
|
125
|
+
*
|
|
126
|
+
* For storage V3, these will always be present.
|
|
109
127
|
*/
|
|
110
|
-
export interface
|
|
128
|
+
export interface BucketStateDocumentBase {
|
|
111
129
|
_id: {
|
|
112
|
-
g: number;
|
|
113
130
|
b: string;
|
|
114
131
|
};
|
|
115
132
|
/**
|
|
116
|
-
* Important: There is an unique index on
|
|
133
|
+
* Important: There is an unique index on last_op per logical stream.
|
|
117
134
|
* That means the last_op must match an actual op in the bucket, and not the commit checkpoint.
|
|
118
135
|
*/
|
|
119
136
|
last_op: bigint;
|
|
@@ -139,18 +156,14 @@ export interface IdSequenceDocument {
|
|
|
139
156
|
op_id: bigint;
|
|
140
157
|
}
|
|
141
158
|
|
|
142
|
-
|
|
159
|
+
/**
|
|
160
|
+
* Base for sync_rules collection.
|
|
161
|
+
*/
|
|
162
|
+
export interface SyncRuleDocumentBase {
|
|
143
163
|
_id: number;
|
|
144
164
|
|
|
145
165
|
state: storage.SyncRuleState;
|
|
146
166
|
|
|
147
|
-
/**
|
|
148
|
-
* True if initial snapshot has been replicated.
|
|
149
|
-
*
|
|
150
|
-
* Can only be false if state == PROCESSING.
|
|
151
|
-
*/
|
|
152
|
-
snapshot_done: boolean;
|
|
153
|
-
|
|
154
167
|
/**
|
|
155
168
|
* This is now used for "resumeLsn".
|
|
156
169
|
*
|
|
@@ -164,31 +177,6 @@ export interface SyncRuleDocument {
|
|
|
164
177
|
*/
|
|
165
178
|
snapshot_lsn: string | undefined;
|
|
166
179
|
|
|
167
|
-
/**
|
|
168
|
-
* The last consistent checkpoint.
|
|
169
|
-
*
|
|
170
|
-
* There may be higher OpIds used in the database if we're in the middle of replicating a large transaction.
|
|
171
|
-
*/
|
|
172
|
-
last_checkpoint: bigint | null;
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* The LSN associated with the last consistent checkpoint.
|
|
176
|
-
*/
|
|
177
|
-
last_checkpoint_lsn: string | null;
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* If set, no new checkpoints may be created < this value.
|
|
181
|
-
*/
|
|
182
|
-
no_checkpoint_before: string | null;
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Goes together with no_checkpoint_before.
|
|
186
|
-
*
|
|
187
|
-
* If a keepalive is triggered that creates the checkpoint > no_checkpoint_before,
|
|
188
|
-
* then the checkpoint must be equal to this keepalive_op.
|
|
189
|
-
*/
|
|
190
|
-
keepalive_op: string | null;
|
|
191
|
-
|
|
192
180
|
slot_name: string | null;
|
|
193
181
|
|
|
194
182
|
/**
|
|
@@ -212,9 +200,6 @@ export interface SyncRuleDocument {
|
|
|
212
200
|
|
|
213
201
|
last_fatal_error_ts: Date | null;
|
|
214
202
|
|
|
215
|
-
content: string;
|
|
216
|
-
serialized_plan?: SerializedSyncPlan | null;
|
|
217
|
-
|
|
218
203
|
lock?: {
|
|
219
204
|
id: string;
|
|
220
205
|
expires_at: Date;
|
|
@@ -223,6 +208,35 @@ export interface SyncRuleDocument {
|
|
|
223
208
|
storage_version?: number;
|
|
224
209
|
}
|
|
225
210
|
|
|
211
|
+
export interface SyncRuleCheckpointFields<TKeepaliveOp extends string | bigint | null> {
|
|
212
|
+
/**
|
|
213
|
+
* The last consistent checkpoint.
|
|
214
|
+
*
|
|
215
|
+
* There may be higher OpIds used in the database if we're in the middle of replicating a large transaction.
|
|
216
|
+
*/
|
|
217
|
+
last_checkpoint: bigint | null;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* The LSN associated with the last consistent checkpoint.
|
|
221
|
+
*/
|
|
222
|
+
last_checkpoint_lsn: string | null;
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* If set, no new checkpoints may be created < this value.
|
|
226
|
+
*/
|
|
227
|
+
no_checkpoint_before: string | null;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Goes together with no_checkpoint_before.
|
|
231
|
+
*
|
|
232
|
+
* If a keepalive is triggered that creates the checkpoint > no_checkpoint_before,
|
|
233
|
+
* then the checkpoint must be equal to this keepalive_op.
|
|
234
|
+
*
|
|
235
|
+
* This is a string in V1, bigint in V3.
|
|
236
|
+
*/
|
|
237
|
+
keepalive_op: TKeepaliveOp;
|
|
238
|
+
}
|
|
239
|
+
|
|
226
240
|
export interface StorageConfig extends storage.StorageVersionConfig {
|
|
227
241
|
/**
|
|
228
242
|
* When true, bucket_data.checksum is guaranteed to be persisted as a Long.
|
|
@@ -231,9 +245,14 @@ export interface StorageConfig extends storage.StorageVersionConfig {
|
|
|
231
245
|
* a Long before summing.
|
|
232
246
|
*/
|
|
233
247
|
longChecksums: boolean;
|
|
248
|
+
/**
|
|
249
|
+
* Enables v3 MongoDB storage behavior used for incremental reprocessing.
|
|
250
|
+
*/
|
|
251
|
+
incrementalReprocessing: boolean;
|
|
234
252
|
}
|
|
235
253
|
|
|
236
254
|
const LONG_CHECKSUMS_STORAGE_VERSION = 2;
|
|
255
|
+
const INCREMENTAL_REPROCESSING_STORAGE_VERSION = storage.STORAGE_VERSION_3;
|
|
237
256
|
|
|
238
257
|
export function getMongoStorageConfig(storageVersion: number): StorageConfig {
|
|
239
258
|
const baseConfig = storage.STORAGE_VERSION_CONFIG[storageVersion];
|
|
@@ -241,18 +260,17 @@ export function getMongoStorageConfig(storageVersion: number): StorageConfig {
|
|
|
241
260
|
throw new ServiceError(ErrorCode.PSYNC_S1005, `Unsupported storage version ${storageVersion}`);
|
|
242
261
|
}
|
|
243
262
|
|
|
244
|
-
return {
|
|
263
|
+
return {
|
|
264
|
+
...baseConfig,
|
|
265
|
+
longChecksums: storageVersion >= LONG_CHECKSUMS_STORAGE_VERSION,
|
|
266
|
+
incrementalReprocessing: storageVersion >= INCREMENTAL_REPROCESSING_STORAGE_VERSION
|
|
267
|
+
};
|
|
245
268
|
}
|
|
246
269
|
|
|
247
270
|
export interface CheckpointEventDocument {
|
|
248
271
|
_id: bson.ObjectId;
|
|
249
272
|
}
|
|
250
273
|
|
|
251
|
-
export type SyncRuleCheckpointState = Pick<
|
|
252
|
-
SyncRuleDocument,
|
|
253
|
-
'last_checkpoint' | 'last_checkpoint_lsn' | '_id' | 'state'
|
|
254
|
-
>;
|
|
255
|
-
|
|
256
274
|
export interface CustomWriteCheckpointDocument {
|
|
257
275
|
_id: bson.ObjectId;
|
|
258
276
|
user_id: string;
|
|
@@ -286,3 +304,8 @@ export interface InstanceDocument {
|
|
|
286
304
|
}
|
|
287
305
|
|
|
288
306
|
export interface ClientConnectionDocument extends event_types.ClientConnection {}
|
|
307
|
+
|
|
308
|
+
export type CurrentDataDocumentId = CurrentDataDocument['_id'] | CurrentDataDocumentV3['_id'];
|
|
309
|
+
export type CommonCurrentBucket = CurrentBucket | CurrentBucketV3;
|
|
310
|
+
export type CommonCurrentLookup = bson.Binary | RecordedLookupV3;
|
|
311
|
+
export type CommonSourceTableDocument = SourceTableDocumentV1 | SourceTableDocumentV3;
|