@powersync/service-core 0.0.0-dev-20250617143654 → 0.0.0-dev-20250618131818
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 +5 -4
- package/dist/replication/AbstractReplicator.d.ts +2 -1
- package/dist/replication/AbstractReplicator.js +8 -3
- package/dist/replication/AbstractReplicator.js.map +1 -1
- package/dist/storage/BucketStorageBatch.d.ts +9 -7
- package/dist/storage/SyncRulesBucketStorage.d.ts +5 -2
- package/dist/storage/SyncRulesBucketStorage.js.map +1 -1
- package/package.json +4 -4
- package/src/replication/AbstractReplicator.ts +10 -4
- package/src/storage/BucketStorageBatch.ts +10 -8
- package/src/storage/SyncRulesBucketStorage.ts +6 -2
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @powersync/service-core
|
|
2
2
|
|
|
3
|
-
## 0.0.0-dev-
|
|
3
|
+
## 0.0.0-dev-20250618131818
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -11,13 +11,14 @@
|
|
|
11
11
|
### Patch Changes
|
|
12
12
|
|
|
13
13
|
- 08b7aa9: Add checks for RLS affecting replication.
|
|
14
|
+
- 1907356: Cleanly interrupt clearing of storage when the process is stopped/restarted.
|
|
14
15
|
- f9e8673: [MongoDB Storage] Handle connection errors on startup
|
|
15
16
|
- Updated dependencies [0ccd470]
|
|
16
17
|
- Updated dependencies [951b010]
|
|
17
18
|
- Updated dependencies [f9e8673]
|
|
18
|
-
- @powersync/service-types@0.0.0-dev-
|
|
19
|
-
- @powersync/lib-services-framework@0.0.0-dev-
|
|
20
|
-
- @powersync/service-rsocket-router@0.0.0-dev-
|
|
19
|
+
- @powersync/service-types@0.0.0-dev-20250618131818
|
|
20
|
+
- @powersync/lib-services-framework@0.0.0-dev-20250618131818
|
|
21
|
+
- @powersync/service-rsocket-router@0.0.0-dev-20250618131818
|
|
21
22
|
|
|
22
23
|
## 1.12.1
|
|
23
24
|
|
|
@@ -38,8 +38,8 @@ export declare abstract class AbstractReplicator<T extends AbstractReplicationJo
|
|
|
38
38
|
* Used for replication lag computation.
|
|
39
39
|
*/
|
|
40
40
|
private activeReplicationJob;
|
|
41
|
-
private stopped;
|
|
42
41
|
private lastPing;
|
|
42
|
+
private abortController;
|
|
43
43
|
protected constructor(options: AbstractReplicatorOptions);
|
|
44
44
|
abstract createJob(options: CreateJobOptions): T;
|
|
45
45
|
/**
|
|
@@ -52,6 +52,7 @@ export declare abstract class AbstractReplicator<T extends AbstractReplicationJo
|
|
|
52
52
|
protected get syncRuleProvider(): SyncRulesProvider;
|
|
53
53
|
protected get rateLimiter(): ErrorRateLimiter;
|
|
54
54
|
protected get metrics(): MetricsEngine;
|
|
55
|
+
protected get stopped(): boolean | undefined;
|
|
55
56
|
start(): Promise<void>;
|
|
56
57
|
stop(): Promise<void>;
|
|
57
58
|
private runLoop;
|
|
@@ -21,9 +21,9 @@ export class AbstractReplicator {
|
|
|
21
21
|
* Used for replication lag computation.
|
|
22
22
|
*/
|
|
23
23
|
activeReplicationJob = undefined;
|
|
24
|
-
stopped = false;
|
|
25
24
|
// First ping is only after 5 minutes, not when starting
|
|
26
25
|
lastPing = hrtime.bigint();
|
|
26
|
+
abortController;
|
|
27
27
|
constructor(options) {
|
|
28
28
|
this.options = options;
|
|
29
29
|
this.logger = logger.child({ name: `Replicator:${options.id}` });
|
|
@@ -43,7 +43,11 @@ export class AbstractReplicator {
|
|
|
43
43
|
get metrics() {
|
|
44
44
|
return this.options.metricsEngine;
|
|
45
45
|
}
|
|
46
|
+
get stopped() {
|
|
47
|
+
return this.abortController?.signal.aborted;
|
|
48
|
+
}
|
|
46
49
|
async start() {
|
|
50
|
+
this.abortController = new AbortController();
|
|
47
51
|
this.runLoop().catch((e) => {
|
|
48
52
|
this.logger.error('Data source fatal replication error', e);
|
|
49
53
|
container.reporter.captureException(e);
|
|
@@ -64,7 +68,7 @@ export class AbstractReplicator {
|
|
|
64
68
|
});
|
|
65
69
|
}
|
|
66
70
|
async stop() {
|
|
67
|
-
this.
|
|
71
|
+
this.abortController?.abort();
|
|
68
72
|
let promises = [];
|
|
69
73
|
for (const job of this.replicationJobs.values()) {
|
|
70
74
|
promises.push(job.stop());
|
|
@@ -194,6 +198,7 @@ export class AbstractReplicator {
|
|
|
194
198
|
const stopped = await this.storage.getStoppedSyncRules();
|
|
195
199
|
for (let syncRules of stopped) {
|
|
196
200
|
try {
|
|
201
|
+
// TODO: Do this in the "background", allowing the periodic refresh to continue
|
|
197
202
|
const syncRuleStorage = this.storage.getInstance(syncRules, { skipLifecycleHooks: true });
|
|
198
203
|
await this.terminateSyncRules(syncRuleStorage);
|
|
199
204
|
}
|
|
@@ -208,7 +213,7 @@ export class AbstractReplicator {
|
|
|
208
213
|
async terminateSyncRules(syncRuleStorage) {
|
|
209
214
|
this.logger.info(`Terminating sync rules: ${syncRuleStorage.group_id}...`);
|
|
210
215
|
await this.cleanUp(syncRuleStorage);
|
|
211
|
-
await syncRuleStorage.terminate();
|
|
216
|
+
await syncRuleStorage.terminate({ signal: this.abortController?.signal, clearStorage: true });
|
|
212
217
|
this.logger.info(`Successfully terminated sync rules: ${syncRuleStorage.group_id}`);
|
|
213
218
|
}
|
|
214
219
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractReplicator.js","sourceRoot":"","sources":["../../src/replication/AbstractReplicator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAStC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,YAAY;AACZ,MAAM,aAAa,GAAG,WAAc,GAAG,IAAI,CAAC;AAkB5C;;;;GAIG;AACH,MAAM,OAAgB,kBAAkB;IAmBR;IAlBpB,MAAM,CAAiB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AK,CAAC,kBAAkB,CAAC,eAA+C;QAChF,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2B,eAAe,CAAC,QAAQ,KAAK,CAAC,CAAC;QAC3E,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;QACpC,MAAM,eAAe,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;QAC9F,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,uCAAuC,eAAe,CAAC,QAAQ,EAAE,CAAC,CAAC;IACtF,CAAC;IAID;;;;;;;;;;;;;;;;;OAiBG;IACH,KAAK,CAAC,uBAAuB;QAC3B,OAAO,IAAI,CAAC,oBAAoB,EAAE,uBAAuB,EAAE,CAAC;IAC9D,CAAC;CACF"}
|
|
@@ -31,7 +31,7 @@ export interface BucketStorageBatch extends ObserverClient<BucketBatchStorageLis
|
|
|
31
31
|
*
|
|
32
32
|
* @returns null if there are no changes to flush.
|
|
33
33
|
*/
|
|
34
|
-
flush(): Promise<FlushedResult | null>;
|
|
34
|
+
flush(options?: BatchBucketFlushOptions): Promise<FlushedResult | null>;
|
|
35
35
|
/**
|
|
36
36
|
* Flush and commit any saved ops. This creates a new checkpoint by default.
|
|
37
37
|
*
|
|
@@ -131,12 +131,7 @@ export interface BucketBatchStorageListener {
|
|
|
131
131
|
export interface FlushedResult {
|
|
132
132
|
flushed_op: InternalOpId;
|
|
133
133
|
}
|
|
134
|
-
export interface
|
|
135
|
-
/**
|
|
136
|
-
* Creates a new checkpoint even if there were no persisted operations.
|
|
137
|
-
* Defaults to true.
|
|
138
|
-
*/
|
|
139
|
-
createEmptyCheckpoints?: boolean;
|
|
134
|
+
export interface BatchBucketFlushOptions {
|
|
140
135
|
/**
|
|
141
136
|
* The timestamp of the first change in this batch, according to the source database.
|
|
142
137
|
*
|
|
@@ -144,4 +139,11 @@ export interface BucketBatchCommitOptions {
|
|
|
144
139
|
*/
|
|
145
140
|
oldestUncommittedChange?: Date | null;
|
|
146
141
|
}
|
|
142
|
+
export interface BucketBatchCommitOptions extends BatchBucketFlushOptions {
|
|
143
|
+
/**
|
|
144
|
+
* Creates a new checkpoint even if there were no persisted operations.
|
|
145
|
+
* Defaults to true.
|
|
146
|
+
*/
|
|
147
|
+
createEmptyCheckpoints?: boolean;
|
|
148
|
+
}
|
|
147
149
|
export type ResolvedBucketBatchCommitOptions = Required<BucketBatchCommitOptions>;
|
|
@@ -35,7 +35,7 @@ export interface SyncRulesBucketStorage extends ObserverClient<SyncRulesBucketSt
|
|
|
35
35
|
/**
|
|
36
36
|
* Clear the storage, without changing state.
|
|
37
37
|
*/
|
|
38
|
-
clear(): Promise<void>;
|
|
38
|
+
clear(options?: ClearStorageOptions): Promise<void>;
|
|
39
39
|
autoActivate(): Promise<void>;
|
|
40
40
|
/**
|
|
41
41
|
* Record a replication error.
|
|
@@ -167,7 +167,10 @@ export interface CompactOptions {
|
|
|
167
167
|
/** Minimum of 1 */
|
|
168
168
|
moveBatchQueryLimit?: number;
|
|
169
169
|
}
|
|
170
|
-
export interface
|
|
170
|
+
export interface ClearStorageOptions {
|
|
171
|
+
signal?: AbortSignal;
|
|
172
|
+
}
|
|
173
|
+
export interface TerminateOptions extends ClearStorageOptions {
|
|
171
174
|
/**
|
|
172
175
|
* If true, also clear the storage before terminating.
|
|
173
176
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SyncRulesBucketStorage.js","sourceRoot":"","sources":["../../src/storage/SyncRulesBucketStorage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SyncRulesBucketStorage.js","sourceRoot":"","sources":["../../src/storage/SyncRulesBucketStorage.ts"],"names":[],"mappings":"AA4RA,MAAM,CAAC,MAAM,yBAAyB,GAAsB;IAC1D,kBAAkB,EAAE,IAAI,GAAG,EAAU;IACrC,qBAAqB,EAAE,IAAI;IAC3B,uBAAuB,EAAE,IAAI,GAAG,EAAU;IAC1C,0BAA0B,EAAE,IAAI;CACjC,CAAC"}
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.0.0-dev-
|
|
8
|
+
"version": "0.0.0-dev-20250618131818",
|
|
9
9
|
"main": "dist/index.js",
|
|
10
10
|
"license": "FSL-1.1-Apache-2.0",
|
|
11
11
|
"type": "module",
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
"uuid": "^11.1.0",
|
|
33
33
|
"winston": "^3.13.0",
|
|
34
34
|
"yaml": "^2.3.2",
|
|
35
|
-
"@powersync/lib-services-framework": "0.0.0-dev-
|
|
35
|
+
"@powersync/lib-services-framework": "0.0.0-dev-20250618131818",
|
|
36
36
|
"@powersync/service-jsonbig": "0.17.10",
|
|
37
|
-
"@powersync/service-rsocket-router": "0.0.0-dev-
|
|
37
|
+
"@powersync/service-rsocket-router": "0.0.0-dev-20250618131818",
|
|
38
38
|
"@powersync/service-sync-rules": "0.27.0",
|
|
39
|
-
"@powersync/service-types": "0.0.0-dev-
|
|
39
|
+
"@powersync/service-types": "0.0.0-dev-20250618131818"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/async": "^3.2.24",
|
|
@@ -48,11 +48,11 @@ export abstract class AbstractReplicator<T extends AbstractReplicationJob = Abst
|
|
|
48
48
|
*/
|
|
49
49
|
private activeReplicationJob: T | undefined = undefined;
|
|
50
50
|
|
|
51
|
-
private stopped = false;
|
|
52
|
-
|
|
53
51
|
// First ping is only after 5 minutes, not when starting
|
|
54
52
|
private lastPing = hrtime.bigint();
|
|
55
53
|
|
|
54
|
+
private abortController: AbortController | undefined;
|
|
55
|
+
|
|
56
56
|
protected constructor(private options: AbstractReplicatorOptions) {
|
|
57
57
|
this.logger = logger.child({ name: `Replicator:${options.id}` });
|
|
58
58
|
}
|
|
@@ -85,7 +85,12 @@ export abstract class AbstractReplicator<T extends AbstractReplicationJob = Abst
|
|
|
85
85
|
return this.options.metricsEngine;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
protected get stopped() {
|
|
89
|
+
return this.abortController?.signal.aborted;
|
|
90
|
+
}
|
|
91
|
+
|
|
88
92
|
public async start(): Promise<void> {
|
|
93
|
+
this.abortController = new AbortController();
|
|
89
94
|
this.runLoop().catch((e) => {
|
|
90
95
|
this.logger.error('Data source fatal replication error', e);
|
|
91
96
|
container.reporter.captureException(e);
|
|
@@ -107,7 +112,7 @@ export abstract class AbstractReplicator<T extends AbstractReplicationJob = Abst
|
|
|
107
112
|
}
|
|
108
113
|
|
|
109
114
|
public async stop(): Promise<void> {
|
|
110
|
-
this.
|
|
115
|
+
this.abortController?.abort();
|
|
111
116
|
let promises: Promise<void>[] = [];
|
|
112
117
|
for (const job of this.replicationJobs.values()) {
|
|
113
118
|
promises.push(job.stop());
|
|
@@ -241,6 +246,7 @@ export abstract class AbstractReplicator<T extends AbstractReplicationJob = Abst
|
|
|
241
246
|
const stopped = await this.storage.getStoppedSyncRules();
|
|
242
247
|
for (let syncRules of stopped) {
|
|
243
248
|
try {
|
|
249
|
+
// TODO: Do this in the "background", allowing the periodic refresh to continue
|
|
244
250
|
const syncRuleStorage = this.storage.getInstance(syncRules, { skipLifecycleHooks: true });
|
|
245
251
|
await this.terminateSyncRules(syncRuleStorage);
|
|
246
252
|
} catch (e) {
|
|
@@ -256,7 +262,7 @@ export abstract class AbstractReplicator<T extends AbstractReplicationJob = Abst
|
|
|
256
262
|
protected async terminateSyncRules(syncRuleStorage: storage.SyncRulesBucketStorage) {
|
|
257
263
|
this.logger.info(`Terminating sync rules: ${syncRuleStorage.group_id}...`);
|
|
258
264
|
await this.cleanUp(syncRuleStorage);
|
|
259
|
-
await syncRuleStorage.terminate();
|
|
265
|
+
await syncRuleStorage.terminate({ signal: this.abortController?.signal, clearStorage: true });
|
|
260
266
|
this.logger.info(`Successfully terminated sync rules: ${syncRuleStorage.group_id}`);
|
|
261
267
|
}
|
|
262
268
|
|
|
@@ -39,7 +39,7 @@ export interface BucketStorageBatch extends ObserverClient<BucketBatchStorageLis
|
|
|
39
39
|
*
|
|
40
40
|
* @returns null if there are no changes to flush.
|
|
41
41
|
*/
|
|
42
|
-
flush(): Promise<FlushedResult | null>;
|
|
42
|
+
flush(options?: BatchBucketFlushOptions): Promise<FlushedResult | null>;
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* Flush and commit any saved ops. This creates a new checkpoint by default.
|
|
@@ -161,13 +161,7 @@ export interface FlushedResult {
|
|
|
161
161
|
flushed_op: InternalOpId;
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
export interface
|
|
165
|
-
/**
|
|
166
|
-
* Creates a new checkpoint even if there were no persisted operations.
|
|
167
|
-
* Defaults to true.
|
|
168
|
-
*/
|
|
169
|
-
createEmptyCheckpoints?: boolean;
|
|
170
|
-
|
|
164
|
+
export interface BatchBucketFlushOptions {
|
|
171
165
|
/**
|
|
172
166
|
* The timestamp of the first change in this batch, according to the source database.
|
|
173
167
|
*
|
|
@@ -176,4 +170,12 @@ export interface BucketBatchCommitOptions {
|
|
|
176
170
|
oldestUncommittedChange?: Date | null;
|
|
177
171
|
}
|
|
178
172
|
|
|
173
|
+
export interface BucketBatchCommitOptions extends BatchBucketFlushOptions {
|
|
174
|
+
/**
|
|
175
|
+
* Creates a new checkpoint even if there were no persisted operations.
|
|
176
|
+
* Defaults to true.
|
|
177
|
+
*/
|
|
178
|
+
createEmptyCheckpoints?: boolean;
|
|
179
|
+
}
|
|
180
|
+
|
|
179
181
|
export type ResolvedBucketBatchCommitOptions = Required<BucketBatchCommitOptions>;
|
|
@@ -48,7 +48,7 @@ export interface SyncRulesBucketStorage
|
|
|
48
48
|
/**
|
|
49
49
|
* Clear the storage, without changing state.
|
|
50
50
|
*/
|
|
51
|
-
clear(): Promise<void>;
|
|
51
|
+
clear(options?: ClearStorageOptions): Promise<void>;
|
|
52
52
|
|
|
53
53
|
autoActivate(): Promise<void>;
|
|
54
54
|
|
|
@@ -210,7 +210,11 @@ export interface CompactOptions {
|
|
|
210
210
|
moveBatchQueryLimit?: number;
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
export interface
|
|
213
|
+
export interface ClearStorageOptions {
|
|
214
|
+
signal?: AbortSignal;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export interface TerminateOptions extends ClearStorageOptions {
|
|
214
218
|
/**
|
|
215
219
|
* If true, also clear the storage before terminating.
|
|
216
220
|
*/
|