@powersync/service-module-mongodb-storage 0.17.0 → 0.18.1
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 +27 -0
- package/dist/storage/MongoBucketStorage.d.ts +34 -16
- package/dist/storage/MongoBucketStorage.js +219 -70
- package/dist/storage/MongoBucketStorage.js.map +1 -1
- package/dist/storage/implementation/MongoBucketBatch.d.ts +42 -23
- package/dist/storage/implementation/MongoBucketBatch.js +61 -44
- package/dist/storage/implementation/MongoBucketBatch.js.map +1 -1
- package/dist/storage/implementation/MongoChecksums.d.ts +10 -9
- package/dist/storage/implementation/MongoChecksums.js +3 -111
- package/dist/storage/implementation/MongoChecksums.js.map +1 -1
- package/dist/storage/implementation/MongoCompactor.d.ts +2 -0
- package/dist/storage/implementation/MongoCompactor.js +18 -9
- package/dist/storage/implementation/MongoCompactor.js.map +1 -1
- package/dist/storage/implementation/MongoHydrationState.d.ts +11 -0
- package/dist/storage/implementation/MongoHydrationState.js +49 -0
- package/dist/storage/implementation/MongoHydrationState.js.map +1 -0
- package/dist/storage/implementation/MongoParameterCompactor.d.ts +6 -5
- package/dist/storage/implementation/MongoParameterCompactor.js +24 -1
- package/dist/storage/implementation/MongoParameterCompactor.js.map +1 -1
- package/dist/storage/implementation/MongoParsedSyncConfigSet.d.ts +13 -0
- package/dist/storage/implementation/MongoParsedSyncConfigSet.js +64 -0
- package/dist/storage/implementation/MongoParsedSyncConfigSet.js.map +1 -0
- package/dist/storage/implementation/MongoPersistedReplicationStream.d.ts +36 -0
- package/dist/storage/implementation/MongoPersistedReplicationStream.js +90 -0
- package/dist/storage/implementation/MongoPersistedReplicationStream.js.map +1 -0
- package/dist/storage/implementation/MongoPersistedSyncConfigContent.d.ts +25 -0
- package/dist/storage/implementation/MongoPersistedSyncConfigContent.js +123 -0
- package/dist/storage/implementation/MongoPersistedSyncConfigContent.js.map +1 -0
- package/dist/storage/implementation/MongoStorageProvider.js +5 -2
- package/dist/storage/implementation/MongoStorageProvider.js.map +1 -1
- package/dist/storage/implementation/MongoSyncBucketStorage.d.ts +41 -23
- package/dist/storage/implementation/MongoSyncBucketStorage.js +51 -43
- package/dist/storage/implementation/MongoSyncBucketStorage.js.map +1 -1
- package/dist/storage/implementation/MongoSyncRulesLock.d.ts +1 -1
- package/dist/storage/implementation/MongoSyncRulesLock.js +3 -3
- package/dist/storage/implementation/MongoSyncRulesLock.js.map +1 -1
- package/dist/storage/implementation/common/MongoSyncBucketStorageCheckpoint.d.ts +6 -0
- package/dist/storage/implementation/common/MongoSyncBucketStorageCheckpoint.js +2 -0
- package/dist/storage/implementation/common/MongoSyncBucketStorageCheckpoint.js.map +1 -0
- package/dist/storage/implementation/common/PersistedBatch.d.ts +1 -2
- package/dist/storage/implementation/common/PersistedBatch.js +5 -0
- package/dist/storage/implementation/common/PersistedBatch.js.map +1 -1
- package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.js +1 -1
- package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.js.map +1 -1
- package/dist/storage/implementation/createMongoSyncBucketStorage.d.ts +2 -2
- package/dist/storage/implementation/createMongoSyncBucketStorage.js +4 -4
- package/dist/storage/implementation/createMongoSyncBucketStorage.js.map +1 -1
- package/dist/storage/implementation/db.js +9 -14
- package/dist/storage/implementation/db.js.map +1 -1
- package/dist/storage/implementation/models.d.ts +4 -13
- package/dist/storage/implementation/models.js.map +1 -1
- package/dist/storage/implementation/v1/MongoBucketBatchV1.d.ts +9 -1
- package/dist/storage/implementation/v1/MongoBucketBatchV1.js +42 -26
- package/dist/storage/implementation/v1/MongoBucketBatchV1.js.map +1 -1
- package/dist/storage/implementation/v1/MongoChecksumsV1.js +114 -3
- package/dist/storage/implementation/v1/MongoChecksumsV1.js.map +1 -1
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.d.ts +15 -17
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js +47 -45
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js.map +1 -1
- package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.d.ts +2 -1
- package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.js +3 -0
- package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.js.map +1 -1
- package/dist/storage/implementation/v1/models.d.ts +10 -1
- package/dist/storage/implementation/v3/MongoBucketBatchV3.d.ts +8 -4
- package/dist/storage/implementation/v3/MongoBucketBatchV3.js +286 -259
- package/dist/storage/implementation/v3/MongoBucketBatchV3.js.map +1 -1
- package/dist/storage/implementation/v3/MongoChecksumsV3.d.ts +27 -7
- package/dist/storage/implementation/v3/MongoChecksumsV3.js +202 -18
- package/dist/storage/implementation/v3/MongoChecksumsV3.js.map +1 -1
- package/dist/storage/implementation/v3/MongoCompactorV3.d.ts +19 -2
- package/dist/storage/implementation/v3/MongoCompactorV3.js +511 -22
- package/dist/storage/implementation/v3/MongoCompactorV3.js.map +1 -1
- package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.d.ts +62 -0
- package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.js +350 -0
- package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.js.map +1 -0
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.d.ts +40 -28
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js +232 -116
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js.map +1 -1
- package/dist/storage/implementation/v3/PersistedBatchV3.d.ts +1 -1
- package/dist/storage/implementation/v3/PersistedBatchV3.js +43 -20
- package/dist/storage/implementation/v3/PersistedBatchV3.js.map +1 -1
- package/dist/storage/implementation/v3/SingleBucketStoreV3.js +52 -16
- package/dist/storage/implementation/v3/SingleBucketStoreV3.js.map +1 -1
- package/dist/storage/implementation/v3/SourceRecordStoreV3.d.ts +3 -3
- package/dist/storage/implementation/v3/SourceRecordStoreV3.js +13 -11
- package/dist/storage/implementation/v3/SourceRecordStoreV3.js.map +1 -1
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.d.ts +13 -12
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js +29 -27
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js.map +1 -1
- package/dist/storage/implementation/v3/bucket-format.d.ts +4 -0
- package/dist/storage/implementation/v3/bucket-format.js +58 -0
- package/dist/storage/implementation/v3/bucket-format.js.map +1 -0
- package/dist/storage/implementation/v3/chunking.d.ts +10 -0
- package/dist/storage/implementation/v3/chunking.js +28 -0
- package/dist/storage/implementation/v3/chunking.js.map +1 -0
- package/dist/storage/implementation/v3/models.d.ts +64 -21
- package/dist/storage/implementation/v3/models.js +11 -28
- package/dist/storage/implementation/v3/models.js.map +1 -1
- package/dist/storage/implementation/v3/source-table-utils.d.ts +55 -0
- package/dist/storage/implementation/v3/source-table-utils.js +214 -0
- package/dist/storage/implementation/v3/source-table-utils.js.map +1 -0
- package/dist/storage/storage-index.d.ts +4 -4
- package/dist/storage/storage-index.js +4 -4
- package/dist/storage/storage-index.js.map +1 -1
- package/dist/types/types.d.ts +2 -2
- package/dist/utils/test-utils.d.ts +1 -2
- package/dist/utils/test-utils.js +5 -1
- package/dist/utils/test-utils.js.map +1 -1
- package/dist/utils/util.d.ts +1 -1
- package/dist/utils/util.js +3 -2
- package/dist/utils/util.js.map +1 -1
- package/package.json +9 -19
- package/src/storage/MongoBucketStorage.ts +334 -87
- package/src/storage/implementation/MongoBucketBatch.ts +86 -58
- package/src/storage/implementation/MongoChecksums.ts +6 -138
- package/src/storage/implementation/MongoCompactor.ts +19 -9
- package/src/storage/implementation/MongoHydrationState.ts +61 -0
- package/src/storage/implementation/MongoParameterCompactor.ts +24 -5
- package/src/storage/implementation/MongoParsedSyncConfigSet.ts +88 -0
- package/src/storage/implementation/MongoPersistedReplicationStream.ts +118 -0
- package/src/storage/implementation/MongoPersistedSyncConfigContent.ts +154 -0
- package/src/storage/implementation/MongoStorageProvider.ts +5 -2
- package/src/storage/implementation/MongoSyncBucketStorage.ts +70 -56
- package/src/storage/implementation/MongoSyncRulesLock.ts +7 -4
- package/src/storage/implementation/common/MongoSyncBucketStorageCheckpoint.ts +7 -0
- package/src/storage/implementation/common/PersistedBatch.ts +7 -3
- package/src/storage/implementation/common/VersionedPowerSyncMongoBase.ts +1 -1
- package/src/storage/implementation/createMongoSyncBucketStorage.ts +21 -7
- package/src/storage/implementation/db.ts +11 -19
- package/src/storage/implementation/models.ts +4 -14
- package/src/storage/implementation/v1/MongoBucketBatchV1.ts +55 -34
- package/src/storage/implementation/v1/MongoChecksumsV1.ts +137 -4
- package/src/storage/implementation/v1/MongoSyncBucketStorageV1.ts +70 -64
- package/src/storage/implementation/v1/VersionedPowerSyncMongoV1.ts +11 -1
- package/src/storage/implementation/v1/models.ts +11 -1
- package/src/storage/implementation/v3/MongoBucketBatchV3.ts +358 -314
- package/src/storage/implementation/v3/MongoChecksumsV3.ts +262 -26
- package/src/storage/implementation/v3/MongoCompactorV3.ts +646 -29
- package/src/storage/implementation/v3/MongoStoppedSyncConfigCleanup.ts +480 -0
- package/src/storage/implementation/v3/MongoSyncBucketStorageV3.ts +315 -157
- package/src/storage/implementation/v3/PersistedBatchV3.ts +62 -36
- package/src/storage/implementation/v3/SingleBucketStoreV3.ts +59 -19
- package/src/storage/implementation/v3/SourceRecordStoreV3.ts +12 -12
- package/src/storage/implementation/v3/VersionedPowerSyncMongoV3.ts +41 -36
- package/src/storage/implementation/v3/bucket-format.ts +70 -0
- package/src/storage/implementation/v3/chunking.ts +38 -0
- package/src/storage/implementation/v3/models.ts +93 -55
- package/src/storage/implementation/v3/source-table-utils.ts +392 -0
- package/src/storage/storage-index.ts +12 -4
- package/src/utils/test-utils.ts +6 -3
- package/src/utils/util.ts +3 -2
- package/test/src/__snapshots__/storage.test.ts.snap +0 -75
- package/test/src/__snapshots__/storage_sync.test.ts.snap +48 -48
- package/test/src/cleanup-stopped-sync-configs.test.ts +648 -0
- package/test/src/storage.test.ts +11 -11
- package/test/src/storage_compacting.test.ts +1956 -6
- package/test/src/storage_sync.test.ts +1077 -68
- package/test/src/storeCurrentData.test.ts +17 -7
- package/test/src/util.ts +2 -1
- package/tsconfig.json +1 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/storage/implementation/BucketDefinitionMapping.d.ts +0 -15
- package/dist/storage/implementation/BucketDefinitionMapping.js +0 -58
- package/dist/storage/implementation/BucketDefinitionMapping.js.map +0 -1
- package/dist/storage/implementation/MongoPersistedSyncRules.d.ts +0 -14
- package/dist/storage/implementation/MongoPersistedSyncRules.js +0 -67
- package/dist/storage/implementation/MongoPersistedSyncRules.js.map +0 -1
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.d.ts +0 -29
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.js +0 -76
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.js.map +0 -1
- package/dist/storage/implementation/common/MongoSyncBucketStorageContext.d.ts +0 -13
- package/dist/storage/implementation/common/MongoSyncBucketStorageContext.js +0 -2
- package/dist/storage/implementation/common/MongoSyncBucketStorageContext.js.map +0 -1
- package/dist/storage/implementation/v3/MongoParameterCompactorV3.d.ts +0 -9
- package/dist/storage/implementation/v3/MongoParameterCompactorV3.js +0 -18
- package/dist/storage/implementation/v3/MongoParameterCompactorV3.js.map +0 -1
- package/dist/storage/implementation/v3/MongoParameterLookupV3.d.ts +0 -4
- package/dist/storage/implementation/v3/MongoParameterLookupV3.js +0 -9
- package/dist/storage/implementation/v3/MongoParameterLookupV3.js.map +0 -1
- package/src/storage/implementation/BucketDefinitionMapping.ts +0 -75
- package/src/storage/implementation/MongoPersistedSyncRules.ts +0 -82
- package/src/storage/implementation/MongoPersistedSyncRulesContent.ts +0 -101
- package/src/storage/implementation/common/MongoSyncBucketStorageContext.ts +0 -15
- package/src/storage/implementation/v3/MongoParameterCompactorV3.ts +0 -24
- package/src/storage/implementation/v3/MongoParameterLookupV3.ts +0 -11
|
@@ -18,16 +18,12 @@ import { ParameterLookupRows, ScopedParameterLookup, SqliteJsonRow } from '@powe
|
|
|
18
18
|
import * as bson from 'bson';
|
|
19
19
|
import { idPrefixFilter, mapOpEntry, readSingleBatch, setSessionSnapshotTime } from '../../../utils/util.js';
|
|
20
20
|
import { MongoBucketStorage } from '../../MongoBucketStorage.js';
|
|
21
|
-
import {
|
|
22
|
-
MongoSyncBucketStorageCheckpoint,
|
|
23
|
-
MongoSyncBucketStorageContext
|
|
24
|
-
} from '../common/MongoSyncBucketStorageContext.js';
|
|
21
|
+
import { MongoSyncBucketStorageCheckpoint } from '../common/MongoSyncBucketStorageCheckpoint.js';
|
|
25
22
|
import { SourceKey } from '../models.js';
|
|
26
|
-
import { MongoBucketBatchOptions } from '../MongoBucketBatch.js';
|
|
27
23
|
import { MongoChecksums } from '../MongoChecksums.js';
|
|
28
24
|
import { MongoCompactOptions, MongoCompactor } from '../MongoCompactor.js';
|
|
29
25
|
import { MongoParameterCompactor } from '../MongoParameterCompactor.js';
|
|
30
|
-
import {
|
|
26
|
+
import { MongoPersistedReplicationStream } from '../MongoPersistedReplicationStream.js';
|
|
31
27
|
import { MongoSyncBucketStorage, MongoSyncBucketStorageOptions } from '../MongoSyncBucketStorage.js';
|
|
32
28
|
import {
|
|
33
29
|
BucketDataDocumentV1,
|
|
@@ -42,33 +38,64 @@ import { MongoCompactorV1 } from './MongoCompactorV1.js';
|
|
|
42
38
|
import { MongoParameterCompactorV1 } from './MongoParameterCompactorV1.js';
|
|
43
39
|
import { VersionedPowerSyncMongoV1 } from './VersionedPowerSyncMongoV1.js';
|
|
44
40
|
|
|
41
|
+
export interface MongoSyncBucketStorageContextV1 {
|
|
42
|
+
db: VersionedPowerSyncMongoV1;
|
|
43
|
+
replicationStreamId: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
45
46
|
export class MongoSyncBucketStorageV1 extends MongoSyncBucketStorage {
|
|
46
|
-
// Declare types to be more specific
|
|
47
47
|
declare readonly db: VersionedPowerSyncMongoV1;
|
|
48
48
|
declare readonly checksums: MongoChecksumsV1;
|
|
49
49
|
|
|
50
50
|
constructor(
|
|
51
51
|
factory: MongoBucketStorage,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
replicationStreamId: number,
|
|
53
|
+
replicationStream: MongoPersistedReplicationStream,
|
|
54
|
+
replicationStreamName: string,
|
|
55
55
|
writeCheckpointMode: storage.WriteCheckpointMode | undefined,
|
|
56
56
|
options: MongoSyncBucketStorageOptions
|
|
57
57
|
) {
|
|
58
|
-
super(factory,
|
|
58
|
+
super(factory, replicationStreamId, replicationStream, replicationStreamName, writeCheckpointMode, options);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
protected async initializeVersionStorage(): Promise<void> {}
|
|
62
62
|
|
|
63
|
-
protected
|
|
64
|
-
|
|
63
|
+
protected async fetchPersistedOpHead(): Promise<InternalOpId | null> {
|
|
64
|
+
const doc = (await this.db.sync_rules.findOne(
|
|
65
|
+
{ _id: this.replicationStreamId },
|
|
66
|
+
{ projection: { keepalive_op: 1, last_checkpoint: 1 } }
|
|
67
|
+
)) as SyncRuleDocumentV1;
|
|
68
|
+
// keepalive_op covers ops not yet in a checkpoint (cleared once checkpointed),
|
|
69
|
+
// so the head is the max of the two.
|
|
70
|
+
const keepaliveOp = doc?.keepalive_op == null ? null : BigInt(doc.keepalive_op);
|
|
71
|
+
const lastCheckpoint = doc?.last_checkpoint ?? null;
|
|
72
|
+
if (keepaliveOp == null && lastCheckpoint == null) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
return (keepaliveOp ?? 0n) > (lastCheckpoint ?? 0n) ? keepaliveOp : lastCheckpoint;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
protected async createWriterImpl(options: storage.CreateWriterOptions): Promise<storage.BucketStorageBatch> {
|
|
79
|
+
const doc = (await this.db.sync_rules.findOne(
|
|
80
|
+
{
|
|
81
|
+
_id: this.replicationStreamId
|
|
82
|
+
},
|
|
83
|
+
{ projection: { last_checkpoint_lsn: 1, keepalive_op: 1, snapshot_lsn: 1 } }
|
|
84
|
+
)) as SyncRuleDocumentV1;
|
|
85
|
+
|
|
86
|
+
return new MongoBucketBatchV1({
|
|
87
|
+
...this.writerBatchOptions(options),
|
|
88
|
+
// Resume from the last consistent checkpoint, or the in-progress snapshot position if it is newer.
|
|
89
|
+
resumeFromLsn: maxLsn(doc?.last_checkpoint_lsn, doc?.snapshot_lsn),
|
|
90
|
+
keepaliveOp: doc?.keepalive_op ? BigInt(doc.keepalive_op) : null
|
|
91
|
+
});
|
|
65
92
|
}
|
|
66
93
|
|
|
67
94
|
protected async fetchCheckpointState(
|
|
68
95
|
session: mongo.ClientSession
|
|
69
96
|
): Promise<{ checkpoint: bigint; lsn: string | null } | null> {
|
|
70
97
|
const doc = (await this.db.sync_rules.findOne(
|
|
71
|
-
{ _id: this.
|
|
98
|
+
{ _id: this.replicationStreamId },
|
|
72
99
|
{
|
|
73
100
|
session,
|
|
74
101
|
projection: { _id: 1, state: 1, last_checkpoint: 1, last_checkpoint_lsn: 1, snapshot_done: 1 }
|
|
@@ -83,26 +110,10 @@ export class MongoSyncBucketStorageV1 extends MongoSyncBucketStorage {
|
|
|
83
110
|
};
|
|
84
111
|
}
|
|
85
112
|
|
|
86
|
-
protected async getWriterSyncState() {
|
|
87
|
-
const doc = (await this.db.sync_rules.findOne(
|
|
88
|
-
{
|
|
89
|
-
_id: this.group_id
|
|
90
|
-
},
|
|
91
|
-
{ projection: { last_checkpoint_lsn: 1, keepalive_op: 1, snapshot_lsn: 1 } }
|
|
92
|
-
)) as SyncRuleDocumentV1;
|
|
93
|
-
const checkpointLsn = doc?.last_checkpoint_lsn ?? null;
|
|
94
|
-
return {
|
|
95
|
-
lastCheckpointLsn: checkpointLsn,
|
|
96
|
-
resumeFromLsn: maxLsn(checkpointLsn, doc?.snapshot_lsn),
|
|
97
|
-
keepaliveOp: doc?.keepalive_op ? BigInt(doc.keepalive_op) : null,
|
|
98
|
-
syncConfigId: null
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
113
|
protected async terminateSyncRuleState(): Promise<void> {
|
|
103
114
|
await this.db.sync_rules.updateOne(
|
|
104
115
|
{
|
|
105
|
-
_id: this.
|
|
116
|
+
_id: this.replicationStreamId
|
|
106
117
|
},
|
|
107
118
|
{
|
|
108
119
|
$set: {
|
|
@@ -114,18 +125,16 @@ export class MongoSyncBucketStorageV1 extends MongoSyncBucketStorage {
|
|
|
114
125
|
);
|
|
115
126
|
}
|
|
116
127
|
|
|
117
|
-
protected async getStatusImpl(): Promise<storage.
|
|
128
|
+
protected async getStatusImpl(): Promise<storage.ReplicationStreamStatus> {
|
|
118
129
|
const doc = (await this.db.sync_rules.findOne(
|
|
119
130
|
{
|
|
120
|
-
_id: this.
|
|
131
|
+
_id: this.replicationStreamId
|
|
121
132
|
},
|
|
122
133
|
{
|
|
123
134
|
projection: {
|
|
124
135
|
snapshot_done: 1,
|
|
125
136
|
last_checkpoint_lsn: 1,
|
|
126
|
-
|
|
127
|
-
snapshot_lsn: 1,
|
|
128
|
-
keepalive_op: 1
|
|
137
|
+
snapshot_lsn: 1
|
|
129
138
|
}
|
|
130
139
|
}
|
|
131
140
|
)) as SyncRuleDocumentV1;
|
|
@@ -134,18 +143,15 @@ export class MongoSyncBucketStorageV1 extends MongoSyncBucketStorage {
|
|
|
134
143
|
}
|
|
135
144
|
|
|
136
145
|
return {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
active: doc.state == storage.SyncRuleState.ACTIVE,
|
|
140
|
-
checkpoint_lsn: doc.last_checkpoint_lsn,
|
|
141
|
-
keepalive_op: doc.keepalive_op == null ? null : BigInt(doc.keepalive_op)
|
|
146
|
+
snapshotDone: doc.snapshot_done && doc.last_checkpoint_lsn != null,
|
|
147
|
+
resumeLsn: maxLsn(doc.snapshot_lsn, doc.last_checkpoint_lsn)
|
|
142
148
|
};
|
|
143
149
|
}
|
|
144
150
|
|
|
145
151
|
protected async clearSyncRuleState(): Promise<void> {
|
|
146
152
|
await this.db.sync_rules.updateOne(
|
|
147
153
|
{
|
|
148
|
-
_id: this.
|
|
154
|
+
_id: this.replicationStreamId
|
|
149
155
|
},
|
|
150
156
|
{
|
|
151
157
|
$set: {
|
|
@@ -164,10 +170,9 @@ export class MongoSyncBucketStorageV1 extends MongoSyncBucketStorage {
|
|
|
164
170
|
}
|
|
165
171
|
|
|
166
172
|
protected createMongoChecksums(options: MongoSyncBucketStorageOptions): MongoChecksums {
|
|
167
|
-
return new MongoChecksumsV1(this.db, this.
|
|
173
|
+
return new MongoChecksumsV1(this.db, this.replicationStreamId, {
|
|
168
174
|
...options.checksumOptions,
|
|
169
|
-
storageConfig: options?.storageConfig
|
|
170
|
-
mapping: this.sync_rules.mapping
|
|
175
|
+
storageConfig: options?.storageConfig
|
|
171
176
|
});
|
|
172
177
|
}
|
|
173
178
|
|
|
@@ -179,14 +184,13 @@ export class MongoSyncBucketStorageV1 extends MongoSyncBucketStorage {
|
|
|
179
184
|
checkpoint: InternalOpId,
|
|
180
185
|
options: storage.CompactOptions
|
|
181
186
|
): MongoParameterCompactor {
|
|
182
|
-
return new MongoParameterCompactorV1(this.db, this.
|
|
187
|
+
return new MongoParameterCompactorV1(this.db, this.replicationStreamId, checkpoint, options);
|
|
183
188
|
}
|
|
184
189
|
|
|
185
|
-
protected
|
|
190
|
+
protected get versionContext(): MongoSyncBucketStorageContextV1 {
|
|
186
191
|
return {
|
|
187
192
|
db: this.db,
|
|
188
|
-
|
|
189
|
-
mapping: this.mapping
|
|
193
|
+
replicationStreamId: this.replicationStreamId
|
|
190
194
|
};
|
|
191
195
|
}
|
|
192
196
|
|
|
@@ -212,7 +216,7 @@ export class MongoSyncBucketStorageV1 extends MongoSyncBucketStorage {
|
|
|
212
216
|
() =>
|
|
213
217
|
this.db.bucket_data.deleteMany(
|
|
214
218
|
{
|
|
215
|
-
_id: idPrefixFilter<BucketDataKeyV1>({ g: this.
|
|
219
|
+
_id: idPrefixFilter<BucketDataKeyV1>({ g: this.replicationStreamId }, ['b', 'o'])
|
|
216
220
|
},
|
|
217
221
|
{ maxTimeMS: lib_mongo.db.MONGO_CLEAR_OPERATION_TIMEOUT_MS }
|
|
218
222
|
),
|
|
@@ -226,7 +230,7 @@ export class MongoSyncBucketStorageV1 extends MongoSyncBucketStorage {
|
|
|
226
230
|
() =>
|
|
227
231
|
this.db.parameterIndexV1.deleteMany(
|
|
228
232
|
{
|
|
229
|
-
'key.g': this.
|
|
233
|
+
'key.g': this.replicationStreamId
|
|
230
234
|
},
|
|
231
235
|
{ maxTimeMS: lib_mongo.db.MONGO_CLEAR_OPERATION_TIMEOUT_MS }
|
|
232
236
|
),
|
|
@@ -240,7 +244,7 @@ export class MongoSyncBucketStorageV1 extends MongoSyncBucketStorage {
|
|
|
240
244
|
() =>
|
|
241
245
|
this.db.sourceRecordsV1.deleteMany(
|
|
242
246
|
{
|
|
243
|
-
_id: idPrefixFilter<SourceKey>({ g: this.
|
|
247
|
+
_id: idPrefixFilter<SourceKey>({ g: this.replicationStreamId }, ['t', 'k'])
|
|
244
248
|
},
|
|
245
249
|
{ maxTimeMS: lib_mongo.db.MONGO_CLEAR_OPERATION_TIMEOUT_MS }
|
|
246
250
|
),
|
|
@@ -254,7 +258,7 @@ export class MongoSyncBucketStorageV1 extends MongoSyncBucketStorage {
|
|
|
254
258
|
() =>
|
|
255
259
|
this.db.bucketStateV1.deleteMany(
|
|
256
260
|
{
|
|
257
|
-
_id: idPrefixFilter<BucketStateDocument['_id']>({ g: this.
|
|
261
|
+
_id: idPrefixFilter<BucketStateDocument['_id']>({ g: this.replicationStreamId }, ['b'])
|
|
258
262
|
},
|
|
259
263
|
{ maxTimeMS: lib_mongo.db.MONGO_CLEAR_OPERATION_TIMEOUT_MS }
|
|
260
264
|
),
|
|
@@ -266,9 +270,9 @@ export class MongoSyncBucketStorageV1 extends MongoSyncBucketStorage {
|
|
|
266
270
|
await this.clearDeleteMany(
|
|
267
271
|
'source tables',
|
|
268
272
|
() =>
|
|
269
|
-
this.db.
|
|
273
|
+
this.db.sourceTablesV1(this.replicationStreamId).deleteMany(
|
|
270
274
|
{
|
|
271
|
-
group_id: this.
|
|
275
|
+
group_id: this.replicationStreamId
|
|
272
276
|
},
|
|
273
277
|
{ maxTimeMS: lib_mongo.db.MONGO_CLEAR_OPERATION_TIMEOUT_MS }
|
|
274
278
|
),
|
|
@@ -290,7 +294,7 @@ export class MongoSyncBucketStorageV1 extends MongoSyncBucketStorage {
|
|
|
290
294
|
}
|
|
291
295
|
|
|
292
296
|
export async function getParameterSetsV1(
|
|
293
|
-
ctx:
|
|
297
|
+
ctx: MongoSyncBucketStorageContextV1,
|
|
294
298
|
checkpoint: MongoSyncBucketStorageCheckpoint,
|
|
295
299
|
lookups: ScopedParameterLookup[],
|
|
296
300
|
limit: number
|
|
@@ -306,7 +310,7 @@ export async function getParameterSetsV1(
|
|
|
306
310
|
[
|
|
307
311
|
{
|
|
308
312
|
$match: {
|
|
309
|
-
'key.g': ctx.
|
|
313
|
+
'key.g': ctx.replicationStreamId,
|
|
310
314
|
lookup: { $in: lookupFilter },
|
|
311
315
|
_id: { $lte: checkpoint.checkpoint }
|
|
312
316
|
}
|
|
@@ -364,7 +368,7 @@ export async function getParameterSetsV1(
|
|
|
364
368
|
}
|
|
365
369
|
|
|
366
370
|
export async function* getBucketDataBatchV1(
|
|
367
|
-
ctx:
|
|
371
|
+
ctx: MongoSyncBucketStorageContextV1,
|
|
368
372
|
checkpoint: utils.InternalOpId,
|
|
369
373
|
dataBuckets: storage.BucketDataRequest[],
|
|
370
374
|
options?: storage.BucketDataBatchOptions
|
|
@@ -383,12 +387,12 @@ export async function* getBucketDataBatchV1(
|
|
|
383
387
|
filters.push({
|
|
384
388
|
_id: {
|
|
385
389
|
$gt: {
|
|
386
|
-
g: ctx.
|
|
390
|
+
g: ctx.replicationStreamId,
|
|
387
391
|
b: name,
|
|
388
392
|
o: start
|
|
389
393
|
},
|
|
390
394
|
$lte: {
|
|
391
|
-
g: ctx.
|
|
395
|
+
g: ctx.replicationStreamId,
|
|
392
396
|
b: name,
|
|
393
397
|
o: end as any
|
|
394
398
|
}
|
|
@@ -399,6 +403,8 @@ export async function* getBucketDataBatchV1(
|
|
|
399
403
|
const batchLimit = options?.limit ?? storage.DEFAULT_DOCUMENT_BATCH_LIMIT;
|
|
400
404
|
const chunkSizeLimitBytes = options?.chunkLimitBytes ?? storage.DEFAULT_DOCUMENT_CHUNK_LIMIT_BYTES;
|
|
401
405
|
|
|
406
|
+
// raw: true returns Buffers, but the driver typing doesn't reflect that
|
|
407
|
+
// without an explicit cast to FindCursor<Buffer>.
|
|
402
408
|
const cursor = ctx.db.bucket_data.find(
|
|
403
409
|
{
|
|
404
410
|
$or: filters
|
|
@@ -481,14 +487,14 @@ export async function* getBucketDataBatchV1(
|
|
|
481
487
|
}
|
|
482
488
|
|
|
483
489
|
export async function getDataBucketChangesV1(
|
|
484
|
-
ctx:
|
|
490
|
+
ctx: MongoSyncBucketStorageContextV1,
|
|
485
491
|
options: GetCheckpointChangesOptions
|
|
486
492
|
): Promise<Pick<CheckpointChanges, 'updatedDataBuckets' | 'invalidateDataBuckets'>> {
|
|
487
493
|
const limit = 1000;
|
|
488
494
|
const bucketStateUpdates = await ctx.db.bucketStateV1
|
|
489
495
|
.find(
|
|
490
496
|
{
|
|
491
|
-
'_id.g': ctx.
|
|
497
|
+
'_id.g': ctx.replicationStreamId,
|
|
492
498
|
last_op: { $gt: options.lastCheckpoint.checkpoint }
|
|
493
499
|
},
|
|
494
500
|
{
|
|
@@ -512,7 +518,7 @@ export async function getDataBucketChangesV1(
|
|
|
512
518
|
}
|
|
513
519
|
|
|
514
520
|
export async function getParameterBucketChangesV1(
|
|
515
|
-
ctx:
|
|
521
|
+
ctx: MongoSyncBucketStorageContextV1,
|
|
516
522
|
options: GetCheckpointChangesOptions
|
|
517
523
|
): Promise<Pick<CheckpointChanges, 'updatedParameterLookups' | 'invalidateParameterBuckets'>> {
|
|
518
524
|
const limit = 1000;
|
|
@@ -520,7 +526,7 @@ export async function getParameterBucketChangesV1(
|
|
|
520
526
|
.find(
|
|
521
527
|
{
|
|
522
528
|
_id: { $gt: options.lastCheckpoint.checkpoint, $lte: options.nextCheckpoint.checkpoint },
|
|
523
|
-
'key.g': ctx.
|
|
529
|
+
'key.g': ctx.replicationStreamId
|
|
524
530
|
},
|
|
525
531
|
{
|
|
526
532
|
projection: {
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { mongo } from '@powersync/lib-service-mongodb';
|
|
2
2
|
import { BaseVersionedPowerSyncMongo } from '../common/VersionedPowerSyncMongoBase.js';
|
|
3
3
|
import { CommonSourceTableDocument } from '../models.js';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
BucketDataDocumentV1,
|
|
6
|
+
BucketParameterDocument,
|
|
7
|
+
BucketStateDocumentV1,
|
|
8
|
+
CurrentDataDocument,
|
|
9
|
+
SourceTableDocumentV1
|
|
10
|
+
} from './models.js';
|
|
5
11
|
|
|
6
12
|
export class VersionedPowerSyncMongoV1 extends BaseVersionedPowerSyncMongo {
|
|
7
13
|
get sourceRecordsV1(): mongo.Collection<CurrentDataDocument> {
|
|
@@ -16,6 +22,10 @@ export class VersionedPowerSyncMongoV1 extends BaseVersionedPowerSyncMongo {
|
|
|
16
22
|
return this.upstream.source_tables as any as mongo.Collection<CommonSourceTableDocument>;
|
|
17
23
|
}
|
|
18
24
|
|
|
25
|
+
sourceTablesV1(_replicationStreamId: number): mongo.Collection<SourceTableDocumentV1> {
|
|
26
|
+
return this.upstream.source_tables as any as mongo.Collection<SourceTableDocumentV1>;
|
|
27
|
+
}
|
|
28
|
+
|
|
19
29
|
async initializeStreamStorage(_replicationStreamId: number): Promise<void> {}
|
|
20
30
|
|
|
21
31
|
get bucketDataV1(): mongo.Collection<BucketDataDocumentV1> {
|
|
@@ -78,7 +78,7 @@ export interface SourceTableDocumentV1 extends SourceTableDocument {
|
|
|
78
78
|
group_id: number;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
export interface SyncRuleDocumentV1 extends SyncRuleDocumentBase, SyncRuleCheckpointFields
|
|
81
|
+
export interface SyncRuleDocumentV1 extends SyncRuleDocumentBase, SyncRuleCheckpointFields {
|
|
82
82
|
content: string;
|
|
83
83
|
serialized_plan?: SerializedSyncPlan | null;
|
|
84
84
|
|
|
@@ -88,6 +88,16 @@ export interface SyncRuleDocumentV1 extends SyncRuleDocumentBase, SyncRuleCheckp
|
|
|
88
88
|
* Can only be false if state == PROCESSING.
|
|
89
89
|
*/
|
|
90
90
|
snapshot_done: boolean;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Goes together with no_checkpoint_before.
|
|
94
|
+
*
|
|
95
|
+
* If a keepalive is triggered that creates the checkpoint > no_checkpoint_before,
|
|
96
|
+
* then the checkpoint must be equal to this keepalive_op.
|
|
97
|
+
*
|
|
98
|
+
* string for legacy reasons - it's always a number.
|
|
99
|
+
*/
|
|
100
|
+
keepalive_op: string | null;
|
|
91
101
|
}
|
|
92
102
|
|
|
93
103
|
export interface BucketStateDocumentV1 extends BucketStateDocumentBase {
|