@powersync/service-module-postgres 0.11.1 → 0.12.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 +20 -0
- package/dist/module/PostgresModule.d.ts +1 -1
- package/dist/module/PostgresModule.js +7 -5
- package/dist/module/PostgresModule.js.map +1 -1
- package/dist/replication/WalStream.d.ts +3 -1
- package/dist/replication/WalStream.js +10 -7
- package/dist/replication/WalStream.js.map +1 -1
- package/dist/replication/WalStreamReplicationJob.js +1 -0
- package/dist/replication/WalStreamReplicationJob.js.map +1 -1
- package/dist/replication/WalStreamReplicator.js +1 -0
- package/dist/replication/WalStreamReplicator.js.map +1 -1
- package/package.json +7 -7
- package/src/module/PostgresModule.ts +7 -6
- package/src/replication/WalStream.ts +11 -8
- package/src/replication/WalStreamReplicationJob.ts +1 -0
- package/src/replication/WalStreamReplicator.ts +1 -0
- package/test/src/large_batch.test.ts +5 -4
- package/test/src/setup.ts +2 -3
- package/test/src/slow_tests.test.ts +18 -11
- package/test/src/wal_stream.test.ts +15 -20
- package/test/src/wal_stream_utils.ts +8 -2
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as bson from 'bson';
|
|
2
|
-
import { afterEach, describe, expect, test } from 'vitest';
|
|
2
|
+
import { afterEach, beforeAll, describe, expect, test } from 'vitest';
|
|
3
3
|
import { WalStream, WalStreamOptions } from '../../src/replication/WalStream.js';
|
|
4
4
|
import { env } from './env.js';
|
|
5
5
|
import {
|
|
@@ -15,8 +15,8 @@ import * as pgwire from '@powersync/service-jpgwire';
|
|
|
15
15
|
import { SqliteRow } from '@powersync/service-sync-rules';
|
|
16
16
|
|
|
17
17
|
import { PgManager } from '@module/replication/PgManager.js';
|
|
18
|
-
import { storage } from '@powersync/service-core';
|
|
19
|
-
import { test_utils } from '@powersync/service-core-tests';
|
|
18
|
+
import { createCoreReplicationMetrics, initializeCoreReplicationMetrics, storage } from '@powersync/service-core';
|
|
19
|
+
import { METRICS_HELPER, test_utils } from '@powersync/service-core-tests';
|
|
20
20
|
import * as mongo_storage from '@powersync/service-module-mongodb-storage';
|
|
21
21
|
import * as postgres_storage from '@powersync/service-module-postgres-storage';
|
|
22
22
|
import * as timers from 'node:timers/promises';
|
|
@@ -49,6 +49,11 @@ function defineSlowTests(factory: storage.TestStorageFactory) {
|
|
|
49
49
|
let abortController: AbortController | undefined;
|
|
50
50
|
let streamPromise: Promise<void> | undefined;
|
|
51
51
|
|
|
52
|
+
beforeAll(async () => {
|
|
53
|
+
createCoreReplicationMetrics(METRICS_HELPER.metricsEngine);
|
|
54
|
+
initializeCoreReplicationMetrics(METRICS_HELPER.metricsEngine);
|
|
55
|
+
});
|
|
56
|
+
|
|
52
57
|
afterEach(async () => {
|
|
53
58
|
// This cleans up, similar to WalStreamTestContext.dispose().
|
|
54
59
|
// These tests are a little more complex than what is supported by WalStreamTestContext.
|
|
@@ -98,7 +103,8 @@ bucket_definitions:
|
|
|
98
103
|
const options: WalStreamOptions = {
|
|
99
104
|
abort_signal: abortController.signal,
|
|
100
105
|
connections,
|
|
101
|
-
storage: storage
|
|
106
|
+
storage: storage,
|
|
107
|
+
metrics: METRICS_HELPER.metricsEngine
|
|
102
108
|
};
|
|
103
109
|
walStream = new WalStream(options);
|
|
104
110
|
|
|
@@ -344,13 +350,14 @@ bucket_definitions:
|
|
|
344
350
|
const connections = new PgManager(TEST_CONNECTION_OPTIONS, {});
|
|
345
351
|
const replicationConnection = await connections.replicationConnection();
|
|
346
352
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
353
|
+
abortController = new AbortController();
|
|
354
|
+
const options: WalStreamOptions = {
|
|
355
|
+
abort_signal: abortController.signal,
|
|
356
|
+
connections,
|
|
357
|
+
storage: storage,
|
|
358
|
+
metrics: METRICS_HELPER.metricsEngine
|
|
359
|
+
};
|
|
360
|
+
walStream = new WalStream(options);
|
|
354
361
|
|
|
355
362
|
await storage.clear();
|
|
356
363
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { MissingReplicationSlotError } from '@module/replication/WalStream.js';
|
|
2
|
-
import {
|
|
3
|
-
import { putOp, removeOp } from '@powersync/service-core-tests';
|
|
2
|
+
import { storage } from '@powersync/service-core';
|
|
3
|
+
import { METRICS_HELPER, putOp, removeOp } from '@powersync/service-core-tests';
|
|
4
4
|
import { pgwireRows } from '@powersync/service-jpgwire';
|
|
5
5
|
import * as crypto from 'crypto';
|
|
6
6
|
import { describe, expect, test } from 'vitest';
|
|
7
7
|
import { env } from './env.js';
|
|
8
8
|
import { INITIALIZED_MONGO_STORAGE_FACTORY, INITIALIZED_POSTGRES_STORAGE_FACTORY } from './util.js';
|
|
9
9
|
import { WalStreamTestContext } from './wal_stream_utils.js';
|
|
10
|
+
import { ReplicationMetric } from '@powersync/service-types';
|
|
10
11
|
|
|
11
12
|
const BASIC_SYNC_RULES = `
|
|
12
13
|
bucket_definitions:
|
|
@@ -40,9 +41,8 @@ bucket_definitions:
|
|
|
40
41
|
|
|
41
42
|
await context.replicateSnapshot();
|
|
42
43
|
|
|
43
|
-
const startRowCount = (await
|
|
44
|
-
const startTxCount =
|
|
45
|
-
(await Metrics.getInstance().getMetricValueForTests('powersync_transactions_replicated_total')) ?? 0;
|
|
44
|
+
const startRowCount = (await METRICS_HELPER.getMetricValueForTests(ReplicationMetric.ROWS_REPLICATED)) ?? 0;
|
|
45
|
+
const startTxCount = (await METRICS_HELPER.getMetricValueForTests(ReplicationMetric.TRANSACTIONS_REPLICATED)) ?? 0;
|
|
46
46
|
|
|
47
47
|
context.startStreaming();
|
|
48
48
|
|
|
@@ -55,9 +55,8 @@ bucket_definitions:
|
|
|
55
55
|
const data = await context.getBucketData('global[]');
|
|
56
56
|
|
|
57
57
|
expect(data).toMatchObject([putOp('test_data', { id: test_id, description: 'test1', num: 1152921504606846976n })]);
|
|
58
|
-
const endRowCount = (await
|
|
59
|
-
const endTxCount =
|
|
60
|
-
(await Metrics.getInstance().getMetricValueForTests('powersync_transactions_replicated_total')) ?? 0;
|
|
58
|
+
const endRowCount = (await METRICS_HELPER.getMetricValueForTests(ReplicationMetric.ROWS_REPLICATED)) ?? 0;
|
|
59
|
+
const endTxCount = (await METRICS_HELPER.getMetricValueForTests(ReplicationMetric.TRANSACTIONS_REPLICATED)) ?? 0;
|
|
61
60
|
expect(endRowCount - startRowCount).toEqual(1);
|
|
62
61
|
expect(endTxCount - startTxCount).toEqual(1);
|
|
63
62
|
});
|
|
@@ -77,9 +76,8 @@ bucket_definitions:
|
|
|
77
76
|
|
|
78
77
|
await context.replicateSnapshot();
|
|
79
78
|
|
|
80
|
-
const startRowCount = (await
|
|
81
|
-
const startTxCount =
|
|
82
|
-
(await Metrics.getInstance().getMetricValueForTests('powersync_transactions_replicated_total')) ?? 0;
|
|
79
|
+
const startRowCount = (await METRICS_HELPER.getMetricValueForTests(ReplicationMetric.ROWS_REPLICATED)) ?? 0;
|
|
80
|
+
const startTxCount = (await METRICS_HELPER.getMetricValueForTests(ReplicationMetric.TRANSACTIONS_REPLICATED)) ?? 0;
|
|
83
81
|
|
|
84
82
|
context.startStreaming();
|
|
85
83
|
|
|
@@ -90,9 +88,8 @@ bucket_definitions:
|
|
|
90
88
|
const data = await context.getBucketData('global[]');
|
|
91
89
|
|
|
92
90
|
expect(data).toMatchObject([putOp('test_DATA', { id: test_id, description: 'test1' })]);
|
|
93
|
-
const endRowCount = (await
|
|
94
|
-
const endTxCount =
|
|
95
|
-
(await Metrics.getInstance().getMetricValueForTests('powersync_transactions_replicated_total')) ?? 0;
|
|
91
|
+
const endRowCount = (await METRICS_HELPER.getMetricValueForTests(ReplicationMetric.ROWS_REPLICATED)) ?? 0;
|
|
92
|
+
const endTxCount = (await METRICS_HELPER.getMetricValueForTests(ReplicationMetric.TRANSACTIONS_REPLICATED)) ?? 0;
|
|
96
93
|
expect(endRowCount - startRowCount).toEqual(1);
|
|
97
94
|
expect(endTxCount - startTxCount).toEqual(1);
|
|
98
95
|
});
|
|
@@ -274,9 +271,8 @@ bucket_definitions:
|
|
|
274
271
|
|
|
275
272
|
await context.replicateSnapshot();
|
|
276
273
|
|
|
277
|
-
const startRowCount = (await
|
|
278
|
-
const startTxCount =
|
|
279
|
-
(await Metrics.getInstance().getMetricValueForTests('powersync_transactions_replicated_total')) ?? 0;
|
|
274
|
+
const startRowCount = (await METRICS_HELPER.getMetricValueForTests(ReplicationMetric.ROWS_REPLICATED)) ?? 0;
|
|
275
|
+
const startTxCount = (await METRICS_HELPER.getMetricValueForTests(ReplicationMetric.TRANSACTIONS_REPLICATED)) ?? 0;
|
|
280
276
|
|
|
281
277
|
context.startStreaming();
|
|
282
278
|
|
|
@@ -287,9 +283,8 @@ bucket_definitions:
|
|
|
287
283
|
const data = await context.getBucketData('global[]');
|
|
288
284
|
|
|
289
285
|
expect(data).toMatchObject([]);
|
|
290
|
-
const endRowCount = (await
|
|
291
|
-
const endTxCount =
|
|
292
|
-
(await Metrics.getInstance().getMetricValueForTests('powersync_transactions_replicated_total')) ?? 0;
|
|
286
|
+
const endRowCount = (await METRICS_HELPER.getMetricValueForTests(ReplicationMetric.ROWS_REPLICATED)) ?? 0;
|
|
287
|
+
const endTxCount = (await METRICS_HELPER.getMetricValueForTests(ReplicationMetric.TRANSACTIONS_REPLICATED)) ?? 0;
|
|
293
288
|
|
|
294
289
|
// There was a transaction, but we should not replicate any actual data
|
|
295
290
|
expect(endRowCount - startRowCount).toEqual(0);
|
|
@@ -2,12 +2,14 @@ import { PgManager } from '@module/replication/PgManager.js';
|
|
|
2
2
|
import { PUBLICATION_NAME, WalStream, WalStreamOptions } from '@module/replication/WalStream.js';
|
|
3
3
|
import {
|
|
4
4
|
BucketStorageFactory,
|
|
5
|
+
createCoreReplicationMetrics,
|
|
6
|
+
initializeCoreReplicationMetrics,
|
|
5
7
|
InternalOpId,
|
|
6
8
|
OplogEntry,
|
|
7
9
|
storage,
|
|
8
10
|
SyncRulesBucketStorage
|
|
9
11
|
} from '@powersync/service-core';
|
|
10
|
-
import { test_utils } from '@powersync/service-core-tests';
|
|
12
|
+
import { METRICS_HELPER, test_utils } from '@powersync/service-core-tests';
|
|
11
13
|
import * as pgwire from '@powersync/service-jpgwire';
|
|
12
14
|
import { clearTestDb, getClientCheckpoint, TEST_CONNECTION_OPTIONS } from './util.js';
|
|
13
15
|
|
|
@@ -41,7 +43,10 @@ export class WalStreamTestContext implements AsyncDisposable {
|
|
|
41
43
|
constructor(
|
|
42
44
|
public factory: BucketStorageFactory,
|
|
43
45
|
public connectionManager: PgManager
|
|
44
|
-
) {
|
|
46
|
+
) {
|
|
47
|
+
createCoreReplicationMetrics(METRICS_HELPER.metricsEngine);
|
|
48
|
+
initializeCoreReplicationMetrics(METRICS_HELPER.metricsEngine);
|
|
49
|
+
}
|
|
45
50
|
|
|
46
51
|
async [Symbol.asyncDispose]() {
|
|
47
52
|
await this.dispose();
|
|
@@ -101,6 +106,7 @@ export class WalStreamTestContext implements AsyncDisposable {
|
|
|
101
106
|
}
|
|
102
107
|
const options: WalStreamOptions = {
|
|
103
108
|
storage: this.storage,
|
|
109
|
+
metrics: METRICS_HELPER.metricsEngine,
|
|
104
110
|
connections: this.connectionManager,
|
|
105
111
|
abort_signal: this.abortController.signal
|
|
106
112
|
};
|