@powersync/service-core 0.0.0-dev-20260602073133 → 0.0.0-dev-20260803144812
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 +83 -4
- package/dist/api/RouteAPI.d.ts +42 -14
- package/dist/api/diagnostics.d.ts +12 -1
- package/dist/api/diagnostics.js +34 -22
- package/dist/api/diagnostics.js.map +1 -1
- package/dist/entry/commands/compact-action.js +5 -1
- package/dist/entry/commands/compact-action.js.map +1 -1
- package/dist/modules/AbstractModule.d.ts +6 -2
- package/dist/modules/AbstractModule.js.map +1 -1
- package/dist/replication/AbstractReplicator.d.ts +26 -7
- package/dist/replication/AbstractReplicator.js +148 -68
- package/dist/replication/AbstractReplicator.js.map +1 -1
- package/dist/replication/ReplicationModule.d.ts +3 -3
- package/dist/replication/ReplicationModule.js.map +1 -1
- package/dist/routes/RouterEngine.d.ts +1 -0
- package/dist/routes/RouterEngine.js +6 -1
- package/dist/routes/RouterEngine.js.map +1 -1
- package/dist/routes/configure-fastify.d.ts +95 -56
- package/dist/routes/configure-fastify.js +15 -2
- package/dist/routes/configure-fastify.js.map +1 -1
- package/dist/routes/endpoints/admin.d.ts +24 -24
- package/dist/routes/endpoints/admin.js +46 -35
- package/dist/routes/endpoints/admin.js.map +1 -1
- package/dist/routes/endpoints/checkpointing.d.ts +62 -0
- package/dist/routes/endpoints/checkpointing.js +65 -7
- package/dist/routes/endpoints/checkpointing.js.map +1 -1
- package/dist/routes/endpoints/socket-route.js +3 -2
- package/dist/routes/endpoints/socket-route.js.map +1 -1
- package/dist/routes/endpoints/sync-rules.js +22 -13
- package/dist/routes/endpoints/sync-rules.js.map +1 -1
- package/dist/routes/endpoints/sync-stream.js +1 -1
- package/dist/routes/endpoints/sync-stream.js.map +1 -1
- package/dist/runner/teardown.js +8 -8
- package/dist/runner/teardown.js.map +1 -1
- package/dist/storage/BucketStorageBatch.d.ts +63 -17
- package/dist/storage/BucketStorageBatch.js.map +1 -1
- package/dist/storage/BucketStorageFactory.d.ts +22 -27
- package/dist/storage/BucketStorageFactory.js +4 -18
- package/dist/storage/BucketStorageFactory.js.map +1 -1
- package/dist/storage/CheckpointChecksumInvalidatedError.d.ts +12 -0
- package/dist/storage/CheckpointChecksumInvalidatedError.js +17 -0
- package/dist/storage/CheckpointChecksumInvalidatedError.js.map +1 -0
- package/dist/storage/ChecksumCache.d.ts +11 -6
- package/dist/storage/ChecksumCache.js +5 -4
- package/dist/storage/ChecksumCache.js.map +1 -1
- package/dist/storage/ParsedSyncConfigSet.d.ts +23 -0
- package/dist/storage/ParsedSyncConfigSet.js +2 -0
- package/dist/storage/ParsedSyncConfigSet.js.map +1 -0
- package/dist/storage/PersistedReplicationStream.d.ts +32 -0
- package/dist/storage/PersistedReplicationStream.js +26 -0
- package/dist/storage/PersistedReplicationStream.js.map +1 -0
- package/dist/storage/PersistedSyncConfigContent.d.ts +63 -0
- package/dist/storage/PersistedSyncConfigContent.js +125 -0
- package/dist/storage/PersistedSyncConfigContent.js.map +1 -0
- package/dist/storage/PersistedSyncConfigStatus.d.ts +13 -0
- package/dist/storage/PersistedSyncConfigStatus.js +2 -0
- package/dist/storage/PersistedSyncConfigStatus.js.map +1 -0
- package/dist/storage/SourceEntity.d.ts +6 -0
- package/dist/storage/SourceTable.d.ts +21 -3
- package/dist/storage/SourceTable.js +26 -3
- package/dist/storage/SourceTable.js.map +1 -1
- package/dist/storage/SyncRulesBucketStorage.d.ts +119 -21
- package/dist/storage/SyncRulesBucketStorage.js +3 -0
- package/dist/storage/SyncRulesBucketStorage.js.map +1 -1
- package/dist/storage/WriteCheckpointAPI.d.ts +60 -3
- package/dist/storage/WriteCheckpointAPI.js +33 -0
- package/dist/storage/WriteCheckpointAPI.js.map +1 -1
- package/dist/storage/implementation/BucketDefinitionMapping.d.ts +117 -0
- package/dist/storage/implementation/BucketDefinitionMapping.js +277 -0
- package/dist/storage/implementation/BucketDefinitionMapping.js.map +1 -0
- package/dist/storage/implementation/IncrementalReprocessingCompatibility.d.ts +6 -0
- package/dist/storage/implementation/IncrementalReprocessingCompatibility.js +31 -0
- package/dist/storage/implementation/IncrementalReprocessingCompatibility.js.map +1 -0
- package/dist/storage/implementation/IncrementalReprocessingSyncConfigLog.d.ts +17 -0
- package/dist/storage/implementation/IncrementalReprocessingSyncConfigLog.js +62 -0
- package/dist/storage/implementation/IncrementalReprocessingSyncConfigLog.js.map +1 -0
- package/dist/storage/implementation/ReplicationStreamStorageIds.d.ts +15 -0
- package/dist/storage/implementation/ReplicationStreamStorageIds.js +20 -0
- package/dist/storage/implementation/ReplicationStreamStorageIds.js.map +1 -0
- package/dist/storage/storage-index.d.ts +9 -1
- package/dist/storage/storage-index.js +9 -1
- package/dist/storage/storage-index.js.map +1 -1
- package/dist/sync/BucketChecksumState.d.ts +12 -2
- package/dist/sync/BucketChecksumState.js +69 -21
- package/dist/sync/BucketChecksumState.js.map +1 -1
- package/dist/sync/RequestTracker.d.ts +7 -0
- package/dist/sync/RequestTracker.js +12 -0
- package/dist/sync/RequestTracker.js.map +1 -1
- package/dist/sync/sync.js +154 -41
- package/dist/sync/sync.js.map +1 -1
- package/dist/sync/util.d.ts +5 -0
- package/dist/sync/util.js +9 -0
- package/dist/sync/util.js.map +1 -1
- package/dist/system/ServiceContext.d.ts +2 -0
- package/dist/system/ServiceContext.js +2 -0
- package/dist/system/ServiceContext.js.map +1 -1
- package/dist/tracing/PerformanceTracer.d.ts +23 -1
- package/dist/tracing/PerformanceTracer.js +11 -0
- package/dist/tracing/PerformanceTracer.js.map +1 -1
- package/dist/util/checkpointing.d.ts +4 -8
- package/dist/util/checkpointing.js +1 -16
- package/dist/util/checkpointing.js.map +1 -1
- package/dist/util/config/compound-config-collector.js +18 -2
- package/dist/util/config/compound-config-collector.js.map +1 -1
- package/dist/util/config/defaults.d.ts +2 -0
- package/dist/util/config/defaults.js +2 -0
- package/dist/util/config/defaults.js.map +1 -1
- package/dist/util/config/types.d.ts +3 -1
- package/dist/util/lsn.d.ts +4 -0
- package/dist/util/lsn.js +10 -0
- package/dist/util/lsn.js.map +1 -1
- package/dist/util/util-index.d.ts +1 -0
- package/dist/util/util-index.js +1 -0
- package/dist/util/util-index.js.map +1 -1
- package/dist/util/utils.d.ts +1 -1
- package/dist/util/utils.js +1 -1
- package/dist/util/write-checkpoint-batcher.d.ts +19 -0
- package/dist/util/write-checkpoint-batcher.js +100 -0
- package/dist/util/write-checkpoint-batcher.js.map +1 -0
- package/package.json +6 -7
- package/src/api/RouteAPI.ts +43 -14
- package/src/api/diagnostics.ts +43 -26
- package/src/entry/commands/compact-action.ts +7 -1
- package/src/modules/AbstractModule.ts +6 -2
- package/src/replication/AbstractReplicator.ts +181 -72
- package/src/replication/ReplicationModule.ts +2 -3
- package/src/routes/RouterEngine.ts +7 -1
- package/src/routes/configure-fastify.ts +25 -2
- package/src/routes/endpoints/admin.ts +72 -50
- package/src/routes/endpoints/checkpointing.ts +79 -8
- package/src/routes/endpoints/socket-route.ts +3 -2
- package/src/routes/endpoints/sync-rules.ts +23 -13
- package/src/routes/endpoints/sync-stream.ts +1 -1
- package/src/runner/teardown.ts +8 -8
- package/src/storage/BucketStorageBatch.ts +64 -18
- package/src/storage/BucketStorageFactory.ts +30 -39
- package/src/storage/CheckpointChecksumInvalidatedError.ts +17 -0
- package/src/storage/ChecksumCache.ts +27 -14
- package/src/storage/ParsedSyncConfigSet.ts +25 -0
- package/src/storage/PersistedReplicationStream.ts +55 -0
- package/src/storage/PersistedSyncConfigContent.ts +192 -0
- package/src/storage/PersistedSyncConfigStatus.ts +14 -0
- package/src/storage/SourceEntity.ts +6 -0
- package/src/storage/SourceTable.ts +34 -3
- package/src/storage/SyncRulesBucketStorage.ts +138 -22
- package/src/storage/WriteCheckpointAPI.ts +108 -3
- package/src/storage/implementation/BucketDefinitionMapping.ts +436 -0
- package/src/storage/implementation/IncrementalReprocessingCompatibility.ts +41 -0
- package/src/storage/implementation/IncrementalReprocessingSyncConfigLog.ts +109 -0
- package/src/storage/implementation/ReplicationStreamStorageIds.ts +21 -0
- package/src/storage/storage-index.ts +10 -1
- package/src/sync/BucketChecksumState.ts +103 -21
- package/src/sync/RequestTracker.ts +20 -0
- package/src/sync/sync.ts +183 -48
- package/src/sync/util.ts +12 -0
- package/src/system/ServiceContext.ts +7 -0
- package/src/tracing/PerformanceTracer.ts +41 -1
- package/src/util/checkpointing.ts +4 -22
- package/src/util/config/compound-config-collector.ts +25 -1
- package/src/util/config/defaults.ts +2 -0
- package/src/util/config/types.ts +3 -1
- package/src/util/lsn.ts +9 -0
- package/src/util/util-index.ts +1 -0
- package/src/util/utils.ts +1 -1
- package/src/util/write-checkpoint-batcher.ts +142 -0
- package/test/src/AbstractReplicator.test.ts +115 -0
- package/test/src/checksum_cache.test.ts +22 -0
- package/test/src/config.test.ts +102 -0
- package/test/src/diagnostics.test.ts +62 -34
- package/test/src/module-loader.test.ts +33 -1
- package/test/src/routes/admin.test.ts +182 -18
- package/test/src/routes/checkpointing.test.ts +54 -0
- package/test/src/routes/mocks.ts +6 -2
- package/test/src/storage/SourceTable.test.ts +89 -0
- package/test/src/sync/BucketChecksumState.test.ts +98 -12
- package/test/src/sync/util.test.ts +13 -1
- package/test/src/util/checkpointing.test.ts +249 -0
- package/tsconfig.json +1 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/storage/PersistedSyncRulesContent.d.ts +0 -59
- package/dist/storage/PersistedSyncRulesContent.js +0 -100
- package/dist/storage/PersistedSyncRulesContent.js.map +0 -1
- package/src/storage/PersistedSyncRulesContent.ts +0 -174
package/CHANGELOG.md
CHANGED
|
@@ -1,15 +1,94 @@
|
|
|
1
1
|
# @powersync/service-core
|
|
2
2
|
|
|
3
|
-
## 0.0.0-dev-
|
|
3
|
+
## 0.0.0-dev-20260803144812
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 2189250: Add `/sync/checkpoint-request` for client-supplied checkpoint request ids, previously called write checkpoint ids. The route returns the stored `checkpoint_request_id`, storage now treats managed request ids as monotonic per user/client, custom checkpoint request ids continue to use the existing `checkpoint` field for backwards compatibility, and `checkpoint_requested_at` metadata lets compact jobs remove expired request-derived checkpoint records.
|
|
8
|
+
|
|
9
|
+
This release includes storage migrations for the checkpoint request metadata. Self-hosters should run migrations as part of the upgrade.
|
|
10
|
+
|
|
11
|
+
- 922f974: Add experimental support for storing bucket data chunks on S3.
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- c4860c9: Improve Postgres sync throughput by reading bucket data with ordered, per-bucket index range scans that stop once the requested batch is full.
|
|
16
|
+
- 483415d: Clarify whether too-many-buckets log breakdowns are grouped by sync stream or legacy bucket definition, and include up
|
|
17
|
+
to 100 entries.
|
|
18
|
+
- aab068b: [MongoDB Storage V3] Add has_clear_op field and simplify checksum queries.
|
|
19
|
+
- 37591e9: Lock replication slots before clearing data, preventing concurrent clearing.
|
|
20
|
+
- Updated dependencies [2189250]
|
|
21
|
+
- Updated dependencies [8daa300]
|
|
22
|
+
- Updated dependencies [df5663b]
|
|
23
|
+
- Updated dependencies [be42e25]
|
|
24
|
+
- Updated dependencies [cb4c627]
|
|
25
|
+
- @powersync/lib-services-framework@0.0.0-dev-20260803144812
|
|
26
|
+
- @powersync/service-types@0.0.0-dev-20260803144812
|
|
27
|
+
- @powersync/service-sync-rules@0.0.0-dev-20260803144812
|
|
28
|
+
- @powersync/service-rsocket-router@0.0.0-dev-20260803144812
|
|
29
|
+
|
|
30
|
+
## 1.23.3
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- ea31f64: Potential fix and improved stack trace for 'evicted' errors.
|
|
35
|
+
- Updated dependencies [ea71bf3]
|
|
36
|
+
- Updated dependencies [edc6ed4]
|
|
37
|
+
- @powersync/service-sync-rules@0.39.0
|
|
38
|
+
- @powersync/lib-services-framework@0.9.8
|
|
39
|
+
- @powersync/service-rsocket-router@0.2.24
|
|
40
|
+
|
|
41
|
+
## 1.23.2
|
|
42
|
+
|
|
43
|
+
### Patch Changes
|
|
44
|
+
|
|
45
|
+
- 71d4a0a: Add logs for checkpoint_complete to assist with debugging. Remove "sync lock" logs.
|
|
46
|
+
- e4f683d: [MongoDB Storage] Add experimental option to allow reading data from secondaries.
|
|
47
|
+
- 71d4a0a: Fix edge case where the service can return incomplete data. This could happen when using bucket priorities, and a checkpoint is invalidated by the compact process while syncing.
|
|
48
|
+
- c2edf86: Add `api.parameters.bucket_count_cache_ttl_minutes` configuration option.
|
|
49
|
+
- df9ab1e: Batch concurrent write checkpoint requests and increase request limits to improve throughput.
|
|
50
|
+
- Updated dependencies [a6ae678]
|
|
51
|
+
- Updated dependencies [c2edf86]
|
|
52
|
+
- @powersync/service-sync-rules@0.38.1
|
|
53
|
+
- @powersync/service-types@0.16.1
|
|
54
|
+
- @powersync/lib-services-framework@0.9.7
|
|
55
|
+
- @powersync/service-rsocket-router@0.2.23
|
|
56
|
+
|
|
57
|
+
## 1.23.1
|
|
58
|
+
|
|
59
|
+
### Patch Changes
|
|
60
|
+
|
|
61
|
+
- 7e65360: Restructure replication locks for updated sync config.
|
|
62
|
+
|
|
63
|
+
## 1.23.0
|
|
64
|
+
|
|
65
|
+
### Minor Changes
|
|
66
|
+
|
|
67
|
+
- a91a08f: [Experimental] Enable incremental reprocessing for MongoDB source + MongoDB storage. This includes significant changes to the v3 storage format.
|
|
68
|
+
|
|
69
|
+
### Patch Changes
|
|
70
|
+
|
|
71
|
+
- Updated dependencies [a91a08f]
|
|
72
|
+
- Updated dependencies [184c39f]
|
|
73
|
+
- Updated dependencies [c3f75df]
|
|
74
|
+
- Updated dependencies [4bd35ea]
|
|
75
|
+
- @powersync/service-types@0.16.0
|
|
76
|
+
- @powersync/service-sync-rules@0.38.0
|
|
77
|
+
- @powersync/lib-services-framework@0.9.6
|
|
78
|
+
- @powersync/service-rsocket-router@0.2.22
|
|
79
|
+
|
|
80
|
+
## 1.22.0
|
|
4
81
|
|
|
5
82
|
### Minor Changes
|
|
6
83
|
|
|
7
84
|
- e2bf1ad: [Internal] rework resolveTables to handle multiple SourceTables.
|
|
8
85
|
- 92cc83b: Add the experimental `unstable_sqlite_expression_engine` sync config option to evaluate Sync Streams with SQLite.
|
|
9
86
|
- 15e2466: [MongoDB] Support snapshotting concurrently with streaming in storage v3+.
|
|
87
|
+
- ebeaa3b: [Postgres] Skip storing a redundant copy of replicated rows in `current_data` for tables with `REPLICA IDENTITY FULL`.
|
|
10
88
|
|
|
11
89
|
### Patch Changes
|
|
12
90
|
|
|
91
|
+
- 17fd96b: Fix duration logs for "Processing batch"
|
|
13
92
|
- 6e2a57e: Refactor HydratedSyncConfig to support multiple SyncConfigs.
|
|
14
93
|
- ec6df9f: Add a custom Fastify error handler so uncaught errors honour the negotiated `Content-Encoding` (gzip/zstd) instead of returning a header that doesn't match the body.
|
|
15
94
|
- 99d33d5: Normalize socket addresses to bare hostnames before IP-range validation, so direct-IP literals with any port form are recognized as IPs.
|
|
@@ -25,9 +104,9 @@
|
|
|
25
104
|
- Updated dependencies [92cc83b]
|
|
26
105
|
- Updated dependencies [0aab0f9]
|
|
27
106
|
- Updated dependencies [a94b6c3]
|
|
28
|
-
- @powersync/service-sync-rules@0.
|
|
29
|
-
- @powersync/lib-services-framework@0.
|
|
30
|
-
- @powersync/service-rsocket-router@0.
|
|
107
|
+
- @powersync/service-sync-rules@0.37.0
|
|
108
|
+
- @powersync/lib-services-framework@0.9.5
|
|
109
|
+
- @powersync/service-rsocket-router@0.2.21
|
|
31
110
|
|
|
32
111
|
## 1.21.0
|
|
33
112
|
|
package/dist/api/RouteAPI.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SyncConfig, TablePattern } from '@powersync/service-sync-rules';
|
|
2
2
|
import * as types from '@powersync/service-types';
|
|
3
|
-
import {
|
|
3
|
+
import { ParseSyncConfigOptions, SyncRulesBucketStorage } from '../storage/storage-index.js';
|
|
4
4
|
export interface PatternResult {
|
|
5
5
|
schema: string;
|
|
6
6
|
pattern: string;
|
|
@@ -20,7 +20,8 @@ export interface SlotWalBudgetOptions {
|
|
|
20
20
|
slotName: string;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* Source-specific capabilities used by admin routes, sync config validation,
|
|
24
|
+
* checkpointing, diagnostics, and the sync API.
|
|
24
25
|
*/
|
|
25
26
|
export interface RouteAPI {
|
|
26
27
|
/**
|
|
@@ -33,16 +34,17 @@ export interface RouteAPI {
|
|
|
33
34
|
*/
|
|
34
35
|
getConnectionStatus(): Promise<types.ConnectionStatusV2>;
|
|
35
36
|
/**
|
|
36
|
-
*
|
|
37
|
+
* Expand sync config table patterns into table metadata from the source connection.
|
|
38
|
+
*
|
|
39
|
+
* This is used by validation and diagnostics paths to explain what will be
|
|
40
|
+
* replicated for the current sync config.
|
|
37
41
|
*
|
|
38
42
|
* @param tablePatterns A set of table patterns which typically come from
|
|
39
43
|
* the tables listed in sync config definitions.
|
|
40
44
|
*
|
|
41
45
|
* @param sqlSyncRules
|
|
42
|
-
* @returns
|
|
43
|
-
*
|
|
44
|
-
* tables to ensure syncing should function according to the input
|
|
45
|
-
* pattern. Debug errors and warnings are reported per table.
|
|
46
|
+
* @returns Matching tables or collections, their columns or fields where available,
|
|
47
|
+
* and per-table warnings or errors for the requested table patterns.
|
|
46
48
|
*/
|
|
47
49
|
getDebugTablesInfo(tablePatterns: TablePattern[], sqlSyncRules: SyncConfig): Promise<PatternResult[]>;
|
|
48
50
|
/**
|
|
@@ -59,13 +61,26 @@ export interface RouteAPI {
|
|
|
59
61
|
/**
|
|
60
62
|
* Get the current LSN or equivalent replication HEAD position identifier.
|
|
61
63
|
*
|
|
62
|
-
* The position is provided to the callback
|
|
63
|
-
*
|
|
64
|
+
* The position is provided to the callback so the caller can persist its
|
|
65
|
+
* write-checkpoint mapping before the source adapter forces any required
|
|
66
|
+
* source-side marker or keepalive. The callback returns whether storage
|
|
67
|
+
* actually needs a source marker: when `shouldAdvance` is true the adapter
|
|
68
|
+
* must ensure that the replication stream will observe this position or a
|
|
69
|
+
* greater one, even when the source is otherwise idle. When it is false, the
|
|
70
|
+
* adapter may skip the source marker.
|
|
71
|
+
*
|
|
72
|
+
* Reading the head and forcing the marker happen within a single source
|
|
73
|
+
* session/connection where applicable, so the marker is causally ordered
|
|
74
|
+
* after the head that was handed to the callback.
|
|
64
75
|
*/
|
|
65
76
|
createReplicationHead<T>(callback: ReplicationHeadCallback<T>): Promise<T>;
|
|
66
77
|
/**
|
|
67
|
-
* @returns The
|
|
68
|
-
*
|
|
78
|
+
* @returns The connected source schema in service-friendly table and column
|
|
79
|
+
* formats. Strict-schema sources should include actual tables,
|
|
80
|
+
* collections, columns, and types. Schemaless sources should return
|
|
81
|
+
* the best metadata available and document validation limitations in
|
|
82
|
+
* their adapter behavior. This is typically used to validate sync
|
|
83
|
+
* config and generate client schemas.
|
|
69
84
|
*/
|
|
70
85
|
getConnectionSchema(): Promise<types.DatabaseSchema[]>;
|
|
71
86
|
/**
|
|
@@ -78,8 +93,21 @@ export interface RouteAPI {
|
|
|
78
93
|
*/
|
|
79
94
|
shutdown(): Promise<void>;
|
|
80
95
|
/**
|
|
81
|
-
* Get
|
|
96
|
+
* Get source-specific sync config parsing defaults, such as the default
|
|
97
|
+
* schema or database to use when sync config references an unqualified table
|
|
98
|
+
* name.
|
|
99
|
+
*
|
|
100
|
+
* This is used wherever sync config is parsed for this source, including
|
|
101
|
+
* validation, diagnostics, and sync routing.
|
|
102
|
+
*/
|
|
103
|
+
getParseSyncRulesOptions(): ParseSyncConfigOptions;
|
|
104
|
+
}
|
|
105
|
+
export interface ReplicationHeadResult<T> {
|
|
106
|
+
response: T;
|
|
107
|
+
/**
|
|
108
|
+
* True when storage needs the source to force a later observable position.
|
|
109
|
+
* False when storage can prove no marker is needed.
|
|
82
110
|
*/
|
|
83
|
-
|
|
111
|
+
shouldAdvance: boolean;
|
|
84
112
|
}
|
|
85
|
-
export type ReplicationHeadCallback<T> = (head: string) => Promise<T
|
|
113
|
+
export type ReplicationHeadCallback<T> = (head: string) => Promise<ReplicationHeadResult<T>>;
|
|
@@ -12,10 +12,21 @@ export interface DiagnosticsOptions {
|
|
|
12
12
|
* If false, uses placeholder values for e.g. initial_replication_done.
|
|
13
13
|
*/
|
|
14
14
|
live_status: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Whether this is the active sync config or not.
|
|
17
|
+
*/
|
|
18
|
+
active: boolean;
|
|
15
19
|
/**
|
|
16
20
|
* Check against the source postgres connection.
|
|
17
21
|
*/
|
|
18
22
|
check_connection: boolean;
|
|
19
23
|
}
|
|
20
24
|
export declare const DEFAULT_DATASOURCE_ID = "default";
|
|
21
|
-
export declare function getSyncRulesStatus(
|
|
25
|
+
export declare function getSyncRulesStatus(apiHandler: RouteAPI, syncConfig: storage.PersistedSyncConfigContent | null, options: DiagnosticsOptions,
|
|
26
|
+
/**
|
|
27
|
+
* Storage instance for the replication stream of this config.
|
|
28
|
+
*
|
|
29
|
+
* Required to populate live status (snapshot/checkpoint info). The content object
|
|
30
|
+
* itself is no longer a replication stream, so the caller must resolve this.
|
|
31
|
+
*/
|
|
32
|
+
systemStorage?: storage.SyncRulesBucketStorage): Promise<SyncRulesStatus | undefined>;
|
package/dist/api/diagnostics.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import { logger } from '@powersync/lib-services-framework';
|
|
1
|
+
import { logger, ServiceAssertionError } from '@powersync/lib-services-framework';
|
|
2
2
|
import { DEFAULT_TAG } from '@powersync/service-sync-rules';
|
|
3
3
|
import { syncConfigYamlErrorToReplicationError } from '../util/errors.js';
|
|
4
4
|
export const DEFAULT_DATASOURCE_ID = 'default';
|
|
5
|
-
export async function getSyncRulesStatus(
|
|
6
|
-
|
|
5
|
+
export async function getSyncRulesStatus(apiHandler, syncConfig, options,
|
|
6
|
+
/**
|
|
7
|
+
* Storage instance for the replication stream of this config.
|
|
8
|
+
*
|
|
9
|
+
* Required to populate live status (snapshot/checkpoint info). The content object
|
|
10
|
+
* itself is no longer a replication stream, so the caller must resolve this.
|
|
11
|
+
*/
|
|
12
|
+
systemStorage) {
|
|
13
|
+
if (syncConfig == null) {
|
|
7
14
|
return undefined;
|
|
8
15
|
}
|
|
9
16
|
const include_content = options.include_content ?? false;
|
|
@@ -13,12 +20,17 @@ export async function getSyncRulesStatus(bucketStorage, apiHandler, sync_rules,
|
|
|
13
20
|
let parsed;
|
|
14
21
|
let persisted;
|
|
15
22
|
try {
|
|
16
|
-
persisted =
|
|
17
|
-
parsed
|
|
23
|
+
persisted = syncConfig.parsed(apiHandler.getParseSyncRulesOptions());
|
|
24
|
+
// A content object represents a single sync config, so its parsed result has exactly one entry.
|
|
25
|
+
const [singleConfig] = persisted.syncConfigs;
|
|
26
|
+
if (singleConfig == null) {
|
|
27
|
+
throw new ServiceAssertionError('Expected one sync config');
|
|
28
|
+
}
|
|
29
|
+
parsed = singleConfig;
|
|
18
30
|
}
|
|
19
31
|
catch (e) {
|
|
20
32
|
return {
|
|
21
|
-
content: include_content ?
|
|
33
|
+
content: include_content ? syncConfig.sync_rules_content : undefined,
|
|
22
34
|
connections: [],
|
|
23
35
|
errors: [{ level: 'fatal', message: e.message, ts: now }]
|
|
24
36
|
};
|
|
@@ -28,8 +40,7 @@ export async function getSyncRulesStatus(bucketStorage, apiHandler, sync_rules,
|
|
|
28
40
|
// This method can run under some situations if no connection is configured yet.
|
|
29
41
|
// It will return a default tag in such a case. This default tag is not module specific.
|
|
30
42
|
const tag = sourceConfig.tag ?? DEFAULT_TAG;
|
|
31
|
-
const
|
|
32
|
-
const status = await systemStorage?.getStatus();
|
|
43
|
+
const status = live_status ? await systemStorage?.getStatus() : undefined;
|
|
33
44
|
let replication_lag_bytes = undefined;
|
|
34
45
|
let slot_wal_budget = undefined;
|
|
35
46
|
let tables_flat = [];
|
|
@@ -57,10 +68,10 @@ export async function getSyncRulesStatus(bucketStorage, apiHandler, sync_rules,
|
|
|
57
68
|
// Ignore
|
|
58
69
|
logger.warn(`Unable to get replication lag`, e);
|
|
59
70
|
}
|
|
60
|
-
if (apiHandler.getSlotWalBudget &&
|
|
71
|
+
if (apiHandler.getSlotWalBudget && syncConfig.replicationStreamName) {
|
|
61
72
|
try {
|
|
62
73
|
slot_wal_budget = await apiHandler.getSlotWalBudget({
|
|
63
|
-
slotName:
|
|
74
|
+
slotName: syncConfig.replicationStreamName
|
|
64
75
|
});
|
|
65
76
|
}
|
|
66
77
|
catch (e) {
|
|
@@ -103,11 +114,12 @@ export async function getSyncRulesStatus(bucketStorage, apiHandler, sync_rules,
|
|
|
103
114
|
});
|
|
104
115
|
}
|
|
105
116
|
const errors = tables_flat.flatMap((info) => info.errors);
|
|
106
|
-
|
|
117
|
+
const statusSource = await syncConfig.getSyncConfigStatus();
|
|
118
|
+
if (statusSource?.last_fatal_error) {
|
|
107
119
|
errors.push({
|
|
108
120
|
level: 'fatal',
|
|
109
|
-
message:
|
|
110
|
-
ts:
|
|
121
|
+
message: statusSource.last_fatal_error,
|
|
122
|
+
ts: statusSource.last_fatal_error_ts?.toISOString()
|
|
111
123
|
});
|
|
112
124
|
}
|
|
113
125
|
errors.push(...syncRuleErrors.map((error) => syncConfigYamlErrorToReplicationError(error, now)));
|
|
@@ -127,10 +139,10 @@ export async function getSyncRulesStatus(bucketStorage, apiHandler, sync_rules,
|
|
|
127
139
|
});
|
|
128
140
|
}
|
|
129
141
|
}
|
|
130
|
-
if (live_status &&
|
|
142
|
+
if (live_status && options.active) {
|
|
131
143
|
// Check replication lag for active replication stream.
|
|
132
144
|
// Right now we exclude mysql, since it we don't have consistent keepalives for it.
|
|
133
|
-
if (
|
|
145
|
+
if (statusSource?.last_checkpoint_ts == null && statusSource?.last_keepalive_ts == null) {
|
|
134
146
|
errors.push({
|
|
135
147
|
level: 'warning',
|
|
136
148
|
message: 'No checkpoint found, cannot calculate replication lag',
|
|
@@ -138,7 +150,7 @@ export async function getSyncRulesStatus(bucketStorage, apiHandler, sync_rules,
|
|
|
138
150
|
});
|
|
139
151
|
}
|
|
140
152
|
else {
|
|
141
|
-
const lastTime = Math.max(
|
|
153
|
+
const lastTime = Math.max(statusSource.last_checkpoint_ts?.getTime() ?? 0, statusSource.last_keepalive_ts?.getTime() ?? 0);
|
|
142
154
|
const lagSeconds = Math.round((Date.now() - lastTime) / 1000);
|
|
143
155
|
// On idle instances, keepalive messages are only persisted every 60 seconds.
|
|
144
156
|
// So we use 5 minutes as a threshold for warnings, and 15 minutes for critical.
|
|
@@ -161,17 +173,17 @@ export async function getSyncRulesStatus(bucketStorage, apiHandler, sync_rules,
|
|
|
161
173
|
}
|
|
162
174
|
}
|
|
163
175
|
return {
|
|
164
|
-
content: include_content ?
|
|
176
|
+
content: include_content ? syncConfig.sync_rules_content : undefined,
|
|
165
177
|
connections: [
|
|
166
178
|
{
|
|
167
179
|
id: sourceConfig.id ?? DEFAULT_DATASOURCE_ID,
|
|
168
180
|
tag: tag,
|
|
169
|
-
slot_name:
|
|
170
|
-
initial_replication_done: status?.
|
|
181
|
+
slot_name: syncConfig.replicationStreamName,
|
|
182
|
+
initial_replication_done: status?.snapshotDone ?? false,
|
|
171
183
|
// TODO: Rename?
|
|
172
|
-
last_lsn: status?.
|
|
173
|
-
last_checkpoint_ts:
|
|
174
|
-
last_keepalive_ts:
|
|
184
|
+
last_lsn: status?.resumeLsn ?? undefined,
|
|
185
|
+
last_checkpoint_ts: statusSource?.last_checkpoint_ts?.toISOString(),
|
|
186
|
+
last_keepalive_ts: statusSource?.last_keepalive_ts?.toISOString(),
|
|
175
187
|
replication_lag_bytes: replication_lag_bytes,
|
|
176
188
|
wal_status: slot_wal_budget?.wal_status,
|
|
177
189
|
safe_wal_size: slot_wal_budget?.safe_wal_size,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../../src/api/diagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;
|
|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KAAK,CAAC,CAAC;QAClC,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAClB,SAAS;QACX,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACd,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -15,6 +15,7 @@ const HEAP_LIMIT = v8.getHeapStatistics().heap_size_limit;
|
|
|
15
15
|
* Limit to 1024MB overall.
|
|
16
16
|
*/
|
|
17
17
|
const COMPACT_MEMORY_LIMIT_MB = Math.min(HEAP_LIMIT / 1024 / 1024 - 128, 1024);
|
|
18
|
+
const MINUTE_MS = 60 * 1000;
|
|
18
19
|
export function registerCompactAction(program) {
|
|
19
20
|
const compactCommand = program
|
|
20
21
|
.command(COMMAND_NAME)
|
|
@@ -66,7 +67,8 @@ export function registerCompactAction(program) {
|
|
|
66
67
|
// Start the storage engine in order to create the appropriate BucketStorage
|
|
67
68
|
await serviceContext.lifeCycleEngine.start();
|
|
68
69
|
const bucketStorage = serviceContext.storageEngine.activeBucketStorage;
|
|
69
|
-
const
|
|
70
|
+
const deleteCheckpointRequestsBefore = new Date(Date.now() - config.api_parameters.checkpoint_request_retention_minutes * MINUTE_MS);
|
|
71
|
+
const active = (await bucketStorage.getActiveSyncConfig())?.storage;
|
|
70
72
|
if (active == null) {
|
|
71
73
|
logger.info('No active instance to compact');
|
|
72
74
|
return;
|
|
@@ -77,6 +79,7 @@ export function registerCompactAction(program) {
|
|
|
77
79
|
memoryLimitMB: COMPACT_MEMORY_LIMIT_MB,
|
|
78
80
|
compactBuckets: buckets,
|
|
79
81
|
compactParameterData: compactParameters ?? false,
|
|
82
|
+
deleteCheckpointRequestsBefore,
|
|
80
83
|
signal: abortController.signal
|
|
81
84
|
});
|
|
82
85
|
}
|
|
@@ -84,6 +87,7 @@ export function registerCompactAction(program) {
|
|
|
84
87
|
await active.compact({
|
|
85
88
|
memoryLimitMB: COMPACT_MEMORY_LIMIT_MB,
|
|
86
89
|
compactParameterData: compactParameters ?? true,
|
|
90
|
+
deleteCheckpointRequestsBefore,
|
|
87
91
|
signal: abortController.signal
|
|
88
92
|
});
|
|
89
93
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compact-action.js","sourceRoot":"","sources":["../../../src/entry/commands/compact-action.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,MAAM,MAAM,8BAA8B,CAAC;AACvD,OAAO,KAAK,KAAK,MAAM,0BAA0B,CAAC;AAElD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE9E,MAAM,YAAY,GAAG,SAAS,CAAC;AAE/B;;GAEG;AACH,MAAM,UAAU,GAAG,EAAE,CAAC,iBAAiB,EAAE,CAAC,eAAe,CAAC;AAE1D;;;;GAIG;AACH,MAAM,uBAAuB,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,GAAG,IAAI,GAAG,IAAI,GAAG,GAAG,EAAE,IAAI,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"compact-action.js","sourceRoot":"","sources":["../../../src/entry/commands/compact-action.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,MAAM,MAAM,8BAA8B,CAAC;AACvD,OAAO,KAAK,KAAK,MAAM,0BAA0B,CAAC;AAElD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,C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CAAC,OAAO,EAAE,CAAC;YACrB,2CAA2C;YAC3C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import winston from 'winston';
|
|
2
|
-
import {
|
|
2
|
+
import { PersistedReplicationStream } from '../storage/storage-index.js';
|
|
3
3
|
import { ServiceContextContainer } from '../system/ServiceContext.js';
|
|
4
4
|
export interface TearDownOptions {
|
|
5
5
|
/**
|
|
6
6
|
* If required, tear down any configuration/state for the specific replication stream
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
replicationStreams?: PersistedReplicationStream[];
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Use replicationStreams.
|
|
11
|
+
*/
|
|
12
|
+
syncRules?: PersistedReplicationStream[];
|
|
9
13
|
}
|
|
10
14
|
export interface AbstractModuleOptions {
|
|
11
15
|
name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractModule.js","sourceRoot":"","sources":["../../src/modules/AbstractModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"AbstractModule.js","sourceRoot":"","sources":["../../src/modules/AbstractModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAoB3D,MAAM,OAAgB,cAAc;IAGF;IAFtB,MAAM,CAAiB;IAEjC,YAAgC,OAA8B;QAA9B,YAAO,GAAP,OAAO,CAAuB;QAC5D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,UAAU,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACjE,CAAC;IAYD,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;CACF"}
|
|
@@ -28,19 +28,18 @@ export interface AbstractReplicatorOptions {
|
|
|
28
28
|
export declare abstract class AbstractReplicator<T extends AbstractReplicationJob = AbstractReplicationJob> {
|
|
29
29
|
private options;
|
|
30
30
|
protected logger: winston.Logger;
|
|
31
|
-
private
|
|
31
|
+
private lastReplicationStreamInfoLogs;
|
|
32
32
|
/**
|
|
33
|
-
* Map of replication jobs by replication stream id. Usually there is only one running job, but there could be two
|
|
34
|
-
* transitioning to a new replication stream.
|
|
33
|
+
* Map of replication jobs by replication stream job id. Usually there is only one running job, but there could be two
|
|
34
|
+
* when transitioning to a new replication stream.
|
|
35
35
|
*/
|
|
36
36
|
private replicationJobs;
|
|
37
37
|
/**
|
|
38
|
-
* Map of
|
|
38
|
+
* Map of replication stream ids to promises that are clearing the replication stream.
|
|
39
39
|
*
|
|
40
|
-
* We primarily do this to keep track of what we're currently clearing
|
|
41
|
-
* use the Promise value.
|
|
40
|
+
* We primarily do this to keep track of what we're currently clearing.
|
|
42
41
|
*/
|
|
43
|
-
|
|
42
|
+
protected readonly clearingJobs: Map<number, Promise<void>>;
|
|
44
43
|
/**
|
|
45
44
|
* Used for replication lag computation.
|
|
46
45
|
*/
|
|
@@ -48,6 +47,11 @@ export declare abstract class AbstractReplicator<T extends AbstractReplicationJo
|
|
|
48
47
|
private lastPing;
|
|
49
48
|
private abortController;
|
|
50
49
|
protected constructor(options: AbstractReplicatorOptions);
|
|
50
|
+
/**
|
|
51
|
+
* Create the source-specific replication job for a locked storage stream.
|
|
52
|
+
*
|
|
53
|
+
* The job owns the per-stream snapshot and streaming work for this attempt.
|
|
54
|
+
*/
|
|
51
55
|
abstract createJob(options: CreateJobOptions): T;
|
|
52
56
|
/**
|
|
53
57
|
* Clean up any configuration or state for the specified replication stream on the datasource.
|
|
@@ -64,8 +68,23 @@ export declare abstract class AbstractReplicator<T extends AbstractReplicationJo
|
|
|
64
68
|
stop(): Promise<void>;
|
|
65
69
|
private runLoop;
|
|
66
70
|
private refresh;
|
|
71
|
+
private logReplicationStreamInfoOnce;
|
|
72
|
+
private clearReplicationStreamInfoLog;
|
|
73
|
+
/**
|
|
74
|
+
* When we load sync config from the filesystem/config source, we ignore any config loaded by other processes.
|
|
75
|
+
* The idea is that if a different process loads updated config, that process should process it, not this one.
|
|
76
|
+
*
|
|
77
|
+
* This specifically helps for cases with rolling deploys.
|
|
78
|
+
*
|
|
79
|
+
* This does not apply when sync config is loaded from the database/API, instead of in the config.
|
|
80
|
+
*/
|
|
81
|
+
private shouldHandleReplicationStream;
|
|
67
82
|
protected createJobId(syncRuleId: number): string;
|
|
83
|
+
protected terminateStoppedReplicationStream(replicationStream: storage.PersistedReplicationStream, syncRuleStorage: storage.SyncRulesBucketStorage): Promise<void>;
|
|
68
84
|
protected terminateSyncRules(syncRuleStorage: storage.SyncRulesBucketStorage): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Check source connectivity using the replicator's decoded connection config.
|
|
87
|
+
*/
|
|
69
88
|
abstract testConnection(): Promise<ConnectionTestResult>;
|
|
70
89
|
/**
|
|
71
90
|
* Measure replication lag in milliseconds.
|