@powersync/service-module-mongodb-storage 0.0.0-dev-20260225160713 → 0.0.0-dev-20260511080634
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +119 -6
- package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.js +1 -1
- package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.js.map +1 -1
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js +3 -3
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js.map +1 -1
- package/dist/migrations/db/migrations/1770213298299-storage-version.js.map +1 -1
- package/dist/storage/MongoBucketStorage.d.ts +5 -3
- package/dist/storage/MongoBucketStorage.js +53 -26
- package/dist/storage/MongoBucketStorage.js.map +1 -1
- package/dist/storage/MongoReportStorage.js.map +1 -1
- package/dist/storage/implementation/BucketDefinitionMapping.d.ts +17 -0
- package/dist/storage/implementation/BucketDefinitionMapping.js +58 -0
- package/dist/storage/implementation/BucketDefinitionMapping.js.map +1 -0
- package/dist/storage/implementation/MongoBucketBatch.d.ts +25 -21
- package/dist/storage/implementation/MongoBucketBatch.js +256 -210
- package/dist/storage/implementation/MongoBucketBatch.js.map +1 -1
- package/dist/storage/implementation/MongoBucketBatchShared.d.ts +5 -0
- package/dist/storage/implementation/MongoBucketBatchShared.js +8 -0
- package/dist/storage/implementation/MongoBucketBatchShared.js.map +1 -0
- package/dist/storage/implementation/MongoChecksums.d.ts +30 -19
- package/dist/storage/implementation/MongoChecksums.js +13 -71
- package/dist/storage/implementation/MongoChecksums.js.map +1 -1
- package/dist/storage/implementation/MongoCompactor.d.ts +99 -53
- package/dist/storage/implementation/MongoCompactor.js +265 -303
- package/dist/storage/implementation/MongoCompactor.js.map +1 -1
- package/dist/storage/implementation/MongoParameterCompactor.d.ts +12 -7
- package/dist/storage/implementation/MongoParameterCompactor.js +24 -9
- package/dist/storage/implementation/MongoParameterCompactor.js.map +1 -1
- package/dist/storage/implementation/MongoPersistedSyncRules.d.ts +14 -0
- package/dist/storage/implementation/MongoPersistedSyncRules.js +64 -0
- package/dist/storage/implementation/MongoPersistedSyncRules.js.map +1 -0
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.d.ts +3 -0
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.js +11 -7
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.js.map +1 -1
- package/dist/storage/implementation/MongoStorageProvider.js +1 -1
- package/dist/storage/implementation/MongoStorageProvider.js.map +1 -1
- package/dist/storage/implementation/MongoSyncBucketStorage.d.ts +54 -30
- package/dist/storage/implementation/MongoSyncBucketStorage.js +118 -472
- package/dist/storage/implementation/MongoSyncBucketStorage.js.map +1 -1
- package/dist/storage/implementation/MongoSyncRulesLock.d.ts +7 -5
- package/dist/storage/implementation/MongoSyncRulesLock.js +12 -10
- package/dist/storage/implementation/MongoSyncRulesLock.js.map +1 -1
- package/dist/storage/implementation/MongoWriteCheckpointAPI.d.ts +4 -4
- package/dist/storage/implementation/MongoWriteCheckpointAPI.js +1 -1
- package/dist/storage/implementation/MongoWriteCheckpointAPI.js.map +1 -1
- package/dist/storage/implementation/OperationBatch.js +3 -2
- package/dist/storage/implementation/OperationBatch.js.map +1 -1
- package/dist/storage/implementation/common/BucketDataDoc.d.ts +35 -0
- package/dist/storage/implementation/common/BucketDataDoc.js +2 -0
- package/dist/storage/implementation/common/BucketDataDoc.js.map +1 -0
- package/dist/storage/implementation/common/MongoSyncBucketStorageContext.d.ts +13 -0
- package/dist/storage/implementation/common/MongoSyncBucketStorageContext.js +2 -0
- package/dist/storage/implementation/common/MongoSyncBucketStorageContext.js.map +1 -0
- package/dist/storage/implementation/common/PersistedBatch.d.ts +108 -0
- package/dist/storage/implementation/common/PersistedBatch.js +237 -0
- package/dist/storage/implementation/common/PersistedBatch.js.map +1 -0
- package/dist/storage/implementation/common/SingleBucketStore.d.ts +54 -0
- package/dist/storage/implementation/common/SingleBucketStore.js +3 -0
- package/dist/storage/implementation/common/SingleBucketStore.js.map +1 -0
- package/dist/storage/implementation/common/SourceRecordStore.d.ts +36 -0
- package/dist/storage/implementation/common/SourceRecordStore.js +2 -0
- package/dist/storage/implementation/common/SourceRecordStore.js.map +1 -0
- package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.d.ts +27 -0
- package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.js +57 -0
- package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.js.map +1 -0
- package/dist/storage/implementation/createMongoSyncBucketStorage.d.ts +7 -0
- package/dist/storage/implementation/createMongoSyncBucketStorage.js +9 -0
- package/dist/storage/implementation/createMongoSyncBucketStorage.js.map +1 -0
- package/dist/storage/implementation/db.d.ts +38 -4
- package/dist/storage/implementation/db.js +80 -1
- package/dist/storage/implementation/db.js.map +1 -1
- package/dist/storage/implementation/models.d.ts +66 -25
- package/dist/storage/implementation/models.js +22 -2
- package/dist/storage/implementation/models.js.map +1 -1
- package/dist/storage/implementation/v1/MongoBucketBatchV1.d.ts +13 -0
- package/dist/storage/implementation/v1/MongoBucketBatchV1.js +22 -0
- package/dist/storage/implementation/v1/MongoBucketBatchV1.js.map +1 -0
- package/dist/storage/implementation/v1/MongoChecksumsV1.d.ts +12 -0
- package/dist/storage/implementation/v1/MongoChecksumsV1.js +56 -0
- package/dist/storage/implementation/v1/MongoChecksumsV1.js.map +1 -0
- package/dist/storage/implementation/v1/MongoCompactorV1.d.ts +23 -0
- package/dist/storage/implementation/v1/MongoCompactorV1.js +52 -0
- package/dist/storage/implementation/v1/MongoCompactorV1.js.map +1 -0
- package/dist/storage/implementation/v1/MongoParameterCompactorV1.d.ts +9 -0
- package/dist/storage/implementation/v1/MongoParameterCompactorV1.js +20 -0
- package/dist/storage/implementation/v1/MongoParameterCompactorV1.js.map +1 -0
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.d.ts +41 -0
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js +269 -0
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js.map +1 -0
- package/dist/storage/implementation/v1/PersistedBatchV1.d.ts +26 -0
- package/dist/storage/implementation/v1/PersistedBatchV1.js +183 -0
- package/dist/storage/implementation/v1/PersistedBatchV1.js.map +1 -0
- package/dist/storage/implementation/v1/SingleBucketStoreV1.d.ts +18 -0
- package/dist/storage/implementation/v1/SingleBucketStoreV1.js +57 -0
- package/dist/storage/implementation/v1/SingleBucketStoreV1.js.map +1 -0
- package/dist/storage/implementation/v1/SourceRecordStoreV1.d.ts +19 -0
- package/dist/storage/implementation/v1/SourceRecordStoreV1.js +105 -0
- package/dist/storage/implementation/v1/SourceRecordStoreV1.js.map +1 -0
- package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.d.ts +12 -0
- package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.js +20 -0
- package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.js.map +1 -0
- package/dist/storage/implementation/v1/models.d.ts +34 -0
- package/dist/storage/implementation/v1/models.js +37 -0
- package/dist/storage/implementation/v1/models.js.map +1 -0
- package/dist/storage/implementation/v3/MongoBucketBatchV3.d.ts +13 -0
- package/dist/storage/implementation/v3/MongoBucketBatchV3.js +34 -0
- package/dist/storage/implementation/v3/MongoBucketBatchV3.js.map +1 -0
- package/dist/storage/implementation/v3/MongoChecksumsV3.d.ts +15 -0
- package/dist/storage/implementation/v3/MongoChecksumsV3.js +84 -0
- package/dist/storage/implementation/v3/MongoChecksumsV3.js.map +1 -0
- package/dist/storage/implementation/v3/MongoCompactorV3.d.ts +23 -0
- package/dist/storage/implementation/v3/MongoCompactorV3.js +68 -0
- package/dist/storage/implementation/v3/MongoCompactorV3.js.map +1 -0
- package/dist/storage/implementation/v3/MongoParameterCompactorV3.d.ts +9 -0
- package/dist/storage/implementation/v3/MongoParameterCompactorV3.js +18 -0
- package/dist/storage/implementation/v3/MongoParameterCompactorV3.js.map +1 -0
- package/dist/storage/implementation/v3/MongoParameterLookupV3.d.ts +5 -0
- package/dist/storage/implementation/v3/MongoParameterLookupV3.js +9 -0
- package/dist/storage/implementation/v3/MongoParameterLookupV3.js.map +1 -0
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.d.ts +41 -0
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js +404 -0
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js.map +1 -0
- package/dist/storage/implementation/v3/PersistedBatchV3.d.ts +29 -0
- package/dist/storage/implementation/v3/PersistedBatchV3.js +259 -0
- package/dist/storage/implementation/v3/PersistedBatchV3.js.map +1 -0
- package/dist/storage/implementation/v3/SingleBucketStoreV3.d.ts +18 -0
- package/dist/storage/implementation/v3/SingleBucketStoreV3.js +48 -0
- package/dist/storage/implementation/v3/SingleBucketStoreV3.js.map +1 -0
- package/dist/storage/implementation/v3/SourceRecordStoreV3.d.ts +22 -0
- package/dist/storage/implementation/v3/SourceRecordStoreV3.js +164 -0
- package/dist/storage/implementation/v3/SourceRecordStoreV3.js.map +1 -0
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.d.ts +21 -0
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js +71 -0
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js.map +1 -0
- package/dist/storage/implementation/v3/models.d.ts +43 -0
- package/dist/storage/implementation/v3/models.js +34 -0
- package/dist/storage/implementation/v3/models.js.map +1 -0
- package/dist/storage/storage-index.d.ts +8 -5
- package/dist/storage/storage-index.js +8 -5
- package/dist/storage/storage-index.js.map +1 -1
- package/dist/utils/test-utils.d.ts +4 -1
- package/dist/utils/test-utils.js +15 -12
- package/dist/utils/test-utils.js.map +1 -1
- package/dist/utils/util.d.ts +13 -5
- package/dist/utils/util.js +40 -5
- package/dist/utils/util.js.map +1 -1
- package/package.json +9 -9
- package/src/migrations/db/migrations/1688556755264-initial-sync-rules.ts +1 -1
- package/src/migrations/db/migrations/1702295701188-sync-rule-state.ts +7 -7
- package/src/migrations/db/migrations/1770213298299-storage-version.ts +1 -1
- package/src/storage/MongoBucketStorage.ts +111 -55
- package/src/storage/MongoReportStorage.ts +2 -2
- package/src/storage/implementation/BucketDefinitionMapping.ts +72 -0
- package/src/storage/implementation/MongoBucketBatch.ts +322 -270
- package/src/storage/implementation/MongoBucketBatchShared.ts +11 -0
- package/src/storage/implementation/MongoChecksums.ts +54 -75
- package/src/storage/implementation/MongoCompactor.ts +411 -412
- package/src/storage/implementation/MongoParameterCompactor.ts +52 -26
- package/src/storage/implementation/MongoPersistedSyncRules.ts +76 -0
- package/src/storage/implementation/MongoPersistedSyncRulesContent.ts +19 -10
- package/src/storage/implementation/MongoStorageProvider.ts +1 -1
- package/src/storage/implementation/MongoSyncBucketStorage.ts +206 -466
- package/src/storage/implementation/MongoSyncRulesLock.ts +14 -16
- package/src/storage/implementation/MongoWriteCheckpointAPI.ts +7 -5
- package/src/storage/implementation/OperationBatch.ts +3 -2
- package/src/storage/implementation/common/BucketDataDoc.ts +37 -0
- package/src/storage/implementation/common/MongoSyncBucketStorageContext.ts +15 -0
- package/src/storage/implementation/common/PersistedBatch.ts +364 -0
- package/src/storage/implementation/common/SingleBucketStore.ts +63 -0
- package/src/storage/implementation/common/SourceRecordStore.ts +49 -0
- package/src/storage/implementation/common/VersionedPowerSyncMongoBase.ts +80 -0
- package/src/storage/implementation/createMongoSyncBucketStorage.ts +25 -0
- package/src/storage/implementation/db.ts +115 -8
- package/src/storage/implementation/models.ts +88 -28
- package/src/storage/implementation/v1/MongoBucketBatchV1.ts +32 -0
- package/src/storage/implementation/v1/MongoChecksumsV1.ts +75 -0
- package/src/storage/implementation/v1/MongoCompactorV1.ts +93 -0
- package/src/storage/implementation/v1/MongoParameterCompactorV1.ts +26 -0
- package/src/storage/implementation/v1/MongoSyncBucketStorageV1.ts +432 -0
- package/src/storage/implementation/v1/PersistedBatchV1.ts +230 -0
- package/src/storage/implementation/v1/SingleBucketStoreV1.ts +74 -0
- package/src/storage/implementation/v1/SourceRecordStoreV1.ts +156 -0
- package/src/storage/implementation/v1/VersionedPowerSyncMongoV1.ts +28 -0
- package/src/storage/implementation/v1/models.ts +84 -0
- package/src/storage/implementation/v3/MongoBucketBatchV3.ts +44 -0
- package/src/storage/implementation/v3/MongoChecksumsV3.ts +120 -0
- package/src/storage/implementation/v3/MongoCompactorV3.ts +107 -0
- package/src/storage/implementation/v3/MongoParameterCompactorV3.ts +24 -0
- package/src/storage/implementation/v3/MongoParameterLookupV3.ts +12 -0
- package/src/storage/implementation/v3/MongoSyncBucketStorageV3.ts +545 -0
- package/src/storage/implementation/v3/PersistedBatchV3.ts +318 -0
- package/src/storage/implementation/v3/SingleBucketStoreV3.ts +68 -0
- package/src/storage/implementation/v3/SourceRecordStoreV3.ts +226 -0
- package/src/storage/implementation/v3/VersionedPowerSyncMongoV3.ts +112 -0
- package/src/storage/implementation/v3/models.ts +96 -0
- package/src/storage/storage-index.ts +8 -5
- package/src/utils/test-utils.ts +15 -12
- package/src/utils/util.ts +53 -9
- package/test/src/__snapshots__/storage.test.ts.snap +201 -0
- package/test/src/__snapshots__/storage_compacting.test.ts.snap +17 -0
- package/test/src/__snapshots__/storage_sync.test.ts.snap +1393 -16
- package/test/src/connection-report-storage.test.ts +3 -3
- package/test/src/setup.ts +1 -1
- package/test/src/storage.test.ts +10 -8
- package/test/src/storage_compacting.test.ts +146 -46
- package/test/src/storage_sync.test.ts +404 -56
- package/test/src/util.ts +3 -3
- package/test/tsconfig.json +0 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/storage/implementation/PersistedBatch.d.ts +0 -64
- package/dist/storage/implementation/PersistedBatch.js +0 -323
- package/dist/storage/implementation/PersistedBatch.js.map +0 -1
- package/src/storage/implementation/PersistedBatch.ts +0 -401
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { INITIALIZED_MONGO_REPORT_STORAGE_FACTORY } from './util.js';
|
|
1
|
+
import { MongoReportStorage } from '@module/storage/MongoReportStorage.js';
|
|
3
2
|
import { register, ReportUserData } from '@powersync/service-core-tests';
|
|
4
3
|
import { event_types } from '@powersync/service-types';
|
|
5
|
-
import {
|
|
4
|
+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
5
|
+
import { INITIALIZED_MONGO_REPORT_STORAGE_FACTORY } from './util.js';
|
|
6
6
|
|
|
7
7
|
const userData = register.REPORT_TEST_USERS;
|
|
8
8
|
const dates = register.REPORT_TEST_DATES;
|
package/test/src/setup.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { container } from '@powersync/lib-services-framework';
|
|
2
|
-
import { beforeAll, beforeEach } from 'vitest';
|
|
3
2
|
import { METRICS_HELPER } from '@powersync/service-core-tests';
|
|
3
|
+
import { beforeAll, beforeEach } from 'vitest';
|
|
4
4
|
|
|
5
5
|
beforeAll(async () => {
|
|
6
6
|
// Executes for every test file
|
package/test/src/storage.test.ts
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
|
+
import { mongoTestStorageFactoryGenerator } from '@module/utils/test-utils.js';
|
|
1
2
|
import { register } from '@powersync/service-core-tests';
|
|
2
3
|
import { describe } from 'vitest';
|
|
3
|
-
import { INITIALIZED_MONGO_STORAGE_FACTORY } from './util.js';
|
|
4
4
|
import { env } from './env.js';
|
|
5
|
-
import {
|
|
5
|
+
import { INITIALIZED_MONGO_STORAGE_FACTORY, TEST_STORAGE_VERSIONS } from './util.js';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
for (let storageVersion of TEST_STORAGE_VERSIONS) {
|
|
8
|
+
describe(`Mongo Sync Bucket Storage - Parameters - v${storageVersion}`, () =>
|
|
9
|
+
register.registerDataStorageParameterTests({ ...INITIALIZED_MONGO_STORAGE_FACTORY, storageVersion }));
|
|
9
10
|
|
|
10
|
-
describe(
|
|
11
|
-
|
|
11
|
+
describe(`Mongo Sync Bucket Storage - Data - v${storageVersion}`, () =>
|
|
12
|
+
register.registerDataStorageDataTests({ ...INITIALIZED_MONGO_STORAGE_FACTORY, storageVersion }));
|
|
12
13
|
|
|
13
|
-
describe(
|
|
14
|
-
|
|
14
|
+
describe(`Mongo Sync Bucket Storage - Checkpoints - v${storageVersion}`, () =>
|
|
15
|
+
register.registerDataStorageCheckpointTests({ ...INITIALIZED_MONGO_STORAGE_FACTORY, storageVersion }));
|
|
16
|
+
}
|
|
15
17
|
|
|
16
18
|
describe('Sync Bucket Validation', register.registerBucketValidationTests);
|
|
17
19
|
|
|
@@ -1,43 +1,53 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { VersionedPowerSyncMongoV3 } from '@module/storage/implementation/v3/VersionedPowerSyncMongoV3.js';
|
|
2
|
+
import { storage, SyncRulesBucketStorage, updateSyncRulesFromYaml } from '@powersync/service-core';
|
|
3
|
+
import { bucketRequest, register, test_utils } from '@powersync/service-core-tests';
|
|
2
4
|
import { describe, expect, test } from 'vitest';
|
|
3
5
|
import { INITIALIZED_MONGO_STORAGE_FACTORY } from './util.js';
|
|
4
|
-
import { storage, SyncRulesBucketStorage, updateSyncRulesFromYaml } from '@powersync/service-core';
|
|
5
6
|
|
|
6
7
|
describe('Mongo Sync Bucket Storage Compact', () => {
|
|
7
8
|
register.registerCompactTests(INITIALIZED_MONGO_STORAGE_FACTORY);
|
|
8
9
|
|
|
9
10
|
describe('with blank bucket_state', () => {
|
|
10
11
|
// This can happen when migrating from older service versions, that did not populate bucket_state yet.
|
|
11
|
-
const populate = async (bucketStorage: SyncRulesBucketStorage) => {
|
|
12
|
-
await bucketStorage.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
12
|
+
const populate = async (bucketStorage: SyncRulesBucketStorage, sourceTableIndex: number) => {
|
|
13
|
+
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
14
|
+
|
|
15
|
+
const sourceTable = await test_utils.resolveTestTable(
|
|
16
|
+
writer,
|
|
17
|
+
'test',
|
|
18
|
+
['id'],
|
|
19
|
+
INITIALIZED_MONGO_STORAGE_FACTORY,
|
|
20
|
+
sourceTableIndex
|
|
21
|
+
);
|
|
22
|
+
await writer.markAllSnapshotDone('1/1');
|
|
23
|
+
|
|
24
|
+
await writer.save({
|
|
25
|
+
sourceTable,
|
|
26
|
+
tag: storage.SaveOperationTag.INSERT,
|
|
27
|
+
after: {
|
|
28
|
+
id: 't1',
|
|
29
|
+
owner_id: 'u1'
|
|
30
|
+
},
|
|
31
|
+
afterReplicaId: test_utils.rid('t1')
|
|
32
|
+
});
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
await writer.save({
|
|
35
|
+
sourceTable,
|
|
36
|
+
tag: storage.SaveOperationTag.INSERT,
|
|
37
|
+
after: {
|
|
38
|
+
id: 't2',
|
|
39
|
+
owner_id: 'u2'
|
|
40
|
+
},
|
|
41
|
+
afterReplicaId: test_utils.rid('t2')
|
|
34
42
|
});
|
|
35
43
|
|
|
44
|
+
await writer.commit('1/1');
|
|
45
|
+
|
|
36
46
|
return bucketStorage.getCheckpoint();
|
|
37
47
|
};
|
|
38
48
|
|
|
39
49
|
const setup = async () => {
|
|
40
|
-
await using factory = await INITIALIZED_MONGO_STORAGE_FACTORY();
|
|
50
|
+
await using factory = await INITIALIZED_MONGO_STORAGE_FACTORY.factory();
|
|
41
51
|
const syncRules = await factory.updateSyncRules(
|
|
42
52
|
updateSyncRulesFromYaml(`
|
|
43
53
|
bucket_definitions:
|
|
@@ -47,16 +57,23 @@ bucket_definitions:
|
|
|
47
57
|
`)
|
|
48
58
|
);
|
|
49
59
|
const bucketStorage = factory.getInstance(syncRules);
|
|
50
|
-
const { checkpoint } = await populate(bucketStorage);
|
|
60
|
+
const { checkpoint } = await populate(bucketStorage, 1);
|
|
51
61
|
|
|
52
62
|
return { bucketStorage, checkpoint, factory, syncRules };
|
|
53
63
|
};
|
|
54
64
|
|
|
55
65
|
test('full compact', async () => {
|
|
56
66
|
const { bucketStorage, checkpoint, factory, syncRules } = await setup();
|
|
67
|
+
const storageDb = bucketStorage.db;
|
|
57
68
|
|
|
58
69
|
// Simulate bucket_state from old version not being available
|
|
59
|
-
|
|
70
|
+
if (storageDb.storageConfig.incrementalReprocessing) {
|
|
71
|
+
// This should actually never happen on V3, but we test this anyway.
|
|
72
|
+
// Can remove this if it causes issues in the future.
|
|
73
|
+
await (storageDb as VersionedPowerSyncMongoV3).bucketStateV3(bucketStorage.group_id).deleteMany({});
|
|
74
|
+
} else {
|
|
75
|
+
await factory.db.bucket_state.deleteMany({});
|
|
76
|
+
}
|
|
60
77
|
|
|
61
78
|
await bucketStorage.compact({
|
|
62
79
|
clearBatchLimit: 200,
|
|
@@ -68,27 +85,27 @@ bucket_definitions:
|
|
|
68
85
|
signal: null as any
|
|
69
86
|
});
|
|
70
87
|
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
);
|
|
75
|
-
expect(checksumAfter.get(
|
|
76
|
-
bucket:
|
|
88
|
+
const users = ['u1', 'u2'];
|
|
89
|
+
const userRequests = users.map((user) => bucketRequest(syncRules, `by_user["${user}"]`));
|
|
90
|
+
const [u1Request, u2Request] = userRequests;
|
|
91
|
+
const checksumAfter = await bucketStorage.getChecksums(checkpoint, userRequests);
|
|
92
|
+
expect(checksumAfter.get(u1Request.bucket)).toEqual({
|
|
93
|
+
bucket: u1Request.bucket,
|
|
77
94
|
checksum: -659469718,
|
|
78
95
|
count: 1
|
|
79
96
|
});
|
|
80
|
-
expect(checksumAfter.get(
|
|
81
|
-
bucket:
|
|
97
|
+
expect(checksumAfter.get(u2Request.bucket)).toEqual({
|
|
98
|
+
bucket: u2Request.bucket,
|
|
82
99
|
checksum: 430217650,
|
|
83
100
|
count: 1
|
|
84
101
|
});
|
|
85
102
|
});
|
|
86
103
|
|
|
87
104
|
test('populatePersistentChecksumCache', async () => {
|
|
88
|
-
// Populate old
|
|
105
|
+
// Populate old replication stream
|
|
89
106
|
const { factory } = await setup();
|
|
90
107
|
|
|
91
|
-
//
|
|
108
|
+
// Now populate another replication stream (bucket definition name changed)
|
|
92
109
|
const syncRules = await factory.updateSyncRules(
|
|
93
110
|
updateSyncRulesFromYaml(`
|
|
94
111
|
bucket_definitions:
|
|
@@ -98,8 +115,9 @@ bucket_definitions:
|
|
|
98
115
|
`)
|
|
99
116
|
);
|
|
100
117
|
const bucketStorage = factory.getInstance(syncRules);
|
|
118
|
+
const storageDb = (bucketStorage as any).db;
|
|
101
119
|
|
|
102
|
-
await populate(bucketStorage);
|
|
120
|
+
await populate(bucketStorage, 2);
|
|
103
121
|
const { checkpoint } = await bucketStorage.getCheckpoint();
|
|
104
122
|
|
|
105
123
|
// Default is to small small numbers - should be a no-op
|
|
@@ -122,21 +140,103 @@ bucket_definitions:
|
|
|
122
140
|
});
|
|
123
141
|
expect(result2.buckets).toEqual(0);
|
|
124
142
|
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
);
|
|
129
|
-
expect(checksumAfter.get(
|
|
130
|
-
bucket:
|
|
143
|
+
const users = ['u1', 'u2'];
|
|
144
|
+
const userRequests = users.map((user) => bucketRequest(syncRules, `by_user2["${user}"]`));
|
|
145
|
+
const [u1Request, u2Request] = userRequests;
|
|
146
|
+
const checksumAfter = await bucketStorage.getChecksums(checkpoint, userRequests);
|
|
147
|
+
expect(checksumAfter.get(u1Request.bucket)).toEqual({
|
|
148
|
+
bucket: u1Request.bucket,
|
|
131
149
|
checksum: -659469718,
|
|
132
150
|
count: 1
|
|
133
151
|
});
|
|
134
|
-
expect(checksumAfter.get(
|
|
135
|
-
bucket:
|
|
152
|
+
expect(checksumAfter.get(u2Request.bucket)).toEqual({
|
|
153
|
+
bucket: u2Request.bucket,
|
|
136
154
|
checksum: 430217650,
|
|
137
155
|
count: 1
|
|
138
156
|
});
|
|
139
157
|
});
|
|
158
|
+
|
|
159
|
+
test('dirty bucket discovery handles bigint bucket_state bytes', async () => {
|
|
160
|
+
await using factory = await INITIALIZED_MONGO_STORAGE_FACTORY.factory();
|
|
161
|
+
const syncRules = await factory.updateSyncRules(
|
|
162
|
+
updateSyncRulesFromYaml(`
|
|
163
|
+
bucket_definitions:
|
|
164
|
+
global:
|
|
165
|
+
data: [select * from test]
|
|
166
|
+
`)
|
|
167
|
+
);
|
|
168
|
+
const bucketStorage = factory.getInstance(syncRules);
|
|
169
|
+
const storageDb = bucketStorage.db;
|
|
170
|
+
|
|
171
|
+
// This simulates bucket_state created using bigint bytes.
|
|
172
|
+
// This typically happens when buckets get very large (> 2GiB). We don't want to create that much
|
|
173
|
+
// data in the tests, so we directly insert the bucket_state here.
|
|
174
|
+
if (storageDb.storageConfig.incrementalReprocessing) {
|
|
175
|
+
const bucketStateCollection = (storageDb as VersionedPowerSyncMongoV3).bucketStateV3(bucketStorage.group_id);
|
|
176
|
+
await bucketStateCollection.insertOne({
|
|
177
|
+
_id: {
|
|
178
|
+
d: '1',
|
|
179
|
+
b: 'global[]'
|
|
180
|
+
},
|
|
181
|
+
last_op: 5n,
|
|
182
|
+
compacted_state: {
|
|
183
|
+
op_id: 3n,
|
|
184
|
+
count: 3,
|
|
185
|
+
checksum: 0n,
|
|
186
|
+
bytes: 7n
|
|
187
|
+
},
|
|
188
|
+
estimate_since_compact: {
|
|
189
|
+
count: 2,
|
|
190
|
+
bytes: 5n
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
} else {
|
|
194
|
+
await factory.db.bucket_state.insertOne({
|
|
195
|
+
_id: {
|
|
196
|
+
g: bucketStorage.group_id,
|
|
197
|
+
b: 'global[]'
|
|
198
|
+
},
|
|
199
|
+
last_op: 5n,
|
|
200
|
+
compacted_state: {
|
|
201
|
+
op_id: 3n,
|
|
202
|
+
count: 3,
|
|
203
|
+
checksum: 0n,
|
|
204
|
+
bytes: 7n
|
|
205
|
+
},
|
|
206
|
+
estimate_since_compact: {
|
|
207
|
+
count: 2,
|
|
208
|
+
bytes: 5n
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// This test uses a couple of "internal" APIs of the compactor.
|
|
214
|
+
const compactor = bucketStorage.createMongoCompactor({ maxOpId: 5n });
|
|
215
|
+
|
|
216
|
+
const dirtyBuckets = compactor.dirtyBucketBatches({
|
|
217
|
+
minBucketChanges: 1,
|
|
218
|
+
minChangeRatio: 0.39
|
|
219
|
+
});
|
|
220
|
+
const firstBatch = await dirtyBuckets.next();
|
|
221
|
+
|
|
222
|
+
expect(firstBatch.done).toBe(false);
|
|
223
|
+
expect(firstBatch.value).toHaveLength(1);
|
|
224
|
+
expect(firstBatch.value[0].bucket).toBe('global[]');
|
|
225
|
+
expect(firstBatch.value[0].estimatedCount).toBe(5);
|
|
226
|
+
expect(typeof firstBatch.value[0].estimatedCount).toBe('number');
|
|
227
|
+
expect(firstBatch.value[0].dirtyRatio).toBeCloseTo(5 / 12);
|
|
228
|
+
|
|
229
|
+
const checksumBuckets = await (compactor as any).dirtyBucketBatchForChecksums({
|
|
230
|
+
minBucketChanges: 1
|
|
231
|
+
});
|
|
232
|
+
expect(checksumBuckets).toEqual([
|
|
233
|
+
{
|
|
234
|
+
bucket: 'global[]',
|
|
235
|
+
definitionId: storageDb.storageConfig.incrementalReprocessing ? '1' : null,
|
|
236
|
+
estimatedCount: 5
|
|
237
|
+
}
|
|
238
|
+
]);
|
|
239
|
+
});
|
|
140
240
|
});
|
|
141
241
|
});
|
|
142
242
|
|