@powersync/service-module-postgres-storage 0.1.0 → 0.1.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 +20 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/types/types.d.ts +4 -2
- package/dist/migrations/migration-utils.js +2 -1
- package/dist/migrations/migration-utils.js.map +1 -1
- package/dist/storage/PostgresCompactor.js +2 -2
- package/dist/storage/PostgresCompactor.js.map +1 -1
- package/dist/storage/PostgresSyncRulesStorage.js +205 -205
- package/dist/storage/PostgresSyncRulesStorage.js.map +1 -1
- package/dist/storage/batch/PostgresBucketBatch.js +4 -4
- package/dist/storage/batch/PostgresBucketBatch.js.map +1 -1
- package/dist/storage/sync-rules/PostgresPersistedSyncRulesContent.js +2 -2
- package/dist/storage/sync-rules/PostgresPersistedSyncRulesContent.js.map +1 -1
- package/dist/types/codecs.js +3 -2
- package/dist/types/codecs.js.map +1 -1
- package/package.json +8 -8
- package/src/migrations/migration-utils.ts +2 -1
- package/src/storage/PostgresCompactor.ts +4 -2
- package/src/storage/PostgresSyncRulesStorage.ts +666 -666
- package/src/storage/batch/PostgresBucketBatch.ts +13 -4
- package/src/storage/sync-rules/PostgresPersistedSyncRulesContent.ts +5 -2
- package/src/types/codecs.ts +3 -2
|
@@ -45,7 +45,8 @@ export declare const PostgresStorageConfig: t.Intersection<t.Codec<{
|
|
|
45
45
|
cacert?: string | undefined;
|
|
46
46
|
client_certificate?: string | undefined;
|
|
47
47
|
client_private_key?: string | undefined;
|
|
48
|
-
|
|
48
|
+
tls_servername?: string | undefined;
|
|
49
|
+
reject_ip_ranges?: string[] | undefined;
|
|
49
50
|
slot_name_prefix?: string | undefined;
|
|
50
51
|
}, {
|
|
51
52
|
type: string;
|
|
@@ -63,7 +64,8 @@ export declare const PostgresStorageConfig: t.Intersection<t.Codec<{
|
|
|
63
64
|
cacert?: string | undefined;
|
|
64
65
|
client_certificate?: string | undefined;
|
|
65
66
|
client_private_key?: string | undefined;
|
|
66
|
-
|
|
67
|
+
tls_servername?: string | undefined;
|
|
68
|
+
reject_ip_ranges?: string[] | undefined;
|
|
67
69
|
slot_name_prefix?: string | undefined;
|
|
68
70
|
}, string, t.CodecProps>, t.ObjectCodec<{
|
|
69
71
|
/**
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as lib_postgres from '@powersync/lib-service-postgres';
|
|
2
2
|
import { isPostgresStorageConfig, normalizePostgresStorageConfig, PostgresStorageConfig } from '../types/types.js';
|
|
3
3
|
import { STORAGE_SCHEMA_NAME } from '../utils/db.js';
|
|
4
|
+
import { ServiceAssertionError } from '@powersync/lib-services-framework';
|
|
4
5
|
export const openMigrationDB = (config) => {
|
|
5
6
|
if (!isPostgresStorageConfig(config)) {
|
|
6
|
-
throw new
|
|
7
|
+
throw new ServiceAssertionError(`Input storage configuration is not for Postgres`);
|
|
7
8
|
}
|
|
8
9
|
return new lib_postgres.DatabaseClient({
|
|
9
10
|
config: normalizePostgresStorageConfig(PostgresStorageConfig.decode(config)),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration-utils.js","sourceRoot":"","sources":["../../src/migrations/migration-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,iCAAiC,CAAC;AAEhE,OAAO,EAAE,uBAAuB,EAAE,8BAA8B,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AACnH,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"migration-utils.js","sourceRoot":"","sources":["../../src/migrations/migration-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,iCAAiC,CAAC;AAEhE,OAAO,EAAE,uBAAuB,EAAE,8BAA8B,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AACnH,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAE1E,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAoC,EAAE,EAAE;IACtE,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC,EAAE,CAAC;QACrC,MAAM,IAAI,qBAAqB,CAAC,iDAAiD,CAAC,CAAC;IACrF,CAAC;IACD,OAAO,IAAI,YAAY,CAAC,cAAc,CAAC;QACrC,MAAM,EAAE,8BAA8B,CAAC,qBAAqB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC5E,MAAM,EAAE,mBAAmB;KAC5B,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { logger } from '@powersync/lib-services-framework';
|
|
1
|
+
import { logger, ReplicationAssertionError } from '@powersync/lib-services-framework';
|
|
2
2
|
import { utils } from '@powersync/service-core';
|
|
3
3
|
import { BIGINT_MAX } from '../types/codecs.js';
|
|
4
4
|
import { models } from '../types/types.js';
|
|
@@ -248,7 +248,7 @@ export class PostgresCompactor {
|
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
else {
|
|
251
|
-
throw new
|
|
251
|
+
throw new ReplicationAssertionError(`Unexpected ${op.op} operation at ${this.group_id}:${bucket}:${op.op_id}`);
|
|
252
252
|
}
|
|
253
253
|
}
|
|
254
254
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PostgresCompactor.js","sourceRoot":"","sources":["../../src/storage/PostgresCompactor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"PostgresCompactor.js","sourceRoot":"","sources":["../../src/storage/PostgresCompactor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AACtF,OAAO,EAAW,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAGzD,OAAO,EAAE,UAA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;CACF"}
|
|
@@ -50,7 +50,7 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
50
50
|
var e = new Error(message);
|
|
51
51
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
52
|
});
|
|
53
|
-
import { DisposableObserver } from '@powersync/lib-services-framework';
|
|
53
|
+
import { DisposableObserver, ReplicationAssertionError } from '@powersync/lib-services-framework';
|
|
54
54
|
import { storage, utils } from '@powersync/service-core';
|
|
55
55
|
import { JSONBig } from '@powersync/service-jsonbig';
|
|
56
56
|
import * as uuid from 'uuid';
|
|
@@ -107,12 +107,12 @@ export class PostgresSyncRulesStorage extends DisposableObserver {
|
|
|
107
107
|
}
|
|
108
108
|
async reportError(e) {
|
|
109
109
|
const message = String(e.message ?? 'Replication failure');
|
|
110
|
-
await this.db.sql `
|
|
111
|
-
UPDATE sync_rules
|
|
112
|
-
SET
|
|
113
|
-
last_fatal_error = ${{ type: 'varchar', value: message }}
|
|
114
|
-
WHERE
|
|
115
|
-
id = ${{ type: 'int4', value: this.group_id }};
|
|
110
|
+
await this.db.sql `
|
|
111
|
+
UPDATE sync_rules
|
|
112
|
+
SET
|
|
113
|
+
last_fatal_error = ${{ type: 'varchar', value: message }}
|
|
114
|
+
WHERE
|
|
115
|
+
id = ${{ type: 'int4', value: this.group_id }};
|
|
116
116
|
`.execute();
|
|
117
117
|
}
|
|
118
118
|
compact(options) {
|
|
@@ -140,14 +140,14 @@ export class PostgresSyncRulesStorage extends DisposableObserver {
|
|
|
140
140
|
return this.writeCheckpointAPI.createManagedWriteCheckpoint(checkpoint);
|
|
141
141
|
}
|
|
142
142
|
async getCheckpoint() {
|
|
143
|
-
const checkpointRow = await this.db.sql `
|
|
144
|
-
SELECT
|
|
145
|
-
last_checkpoint,
|
|
146
|
-
last_checkpoint_lsn
|
|
147
|
-
FROM
|
|
148
|
-
sync_rules
|
|
149
|
-
WHERE
|
|
150
|
-
id = ${{ type: 'int4', value: this.group_id }}
|
|
143
|
+
const checkpointRow = await this.db.sql `
|
|
144
|
+
SELECT
|
|
145
|
+
last_checkpoint,
|
|
146
|
+
last_checkpoint_lsn
|
|
147
|
+
FROM
|
|
148
|
+
sync_rules
|
|
149
|
+
WHERE
|
|
150
|
+
id = ${{ type: 'int4', value: this.group_id }}
|
|
151
151
|
`
|
|
152
152
|
.decoded(pick(models.SyncRules, ['last_checkpoint', 'last_checkpoint_lsn']))
|
|
153
153
|
.first();
|
|
@@ -166,46 +166,46 @@ export class PostgresSyncRulesStorage extends DisposableObserver {
|
|
|
166
166
|
type_oid: typeof column.typeId !== 'undefined' ? Number(column.typeId) : column.typeId
|
|
167
167
|
}));
|
|
168
168
|
return this.db.transaction(async (db) => {
|
|
169
|
-
let sourceTableRow = await db.sql `
|
|
170
|
-
SELECT
|
|
171
|
-
*
|
|
172
|
-
FROM
|
|
173
|
-
source_tables
|
|
174
|
-
WHERE
|
|
175
|
-
group_id = ${{ type: 'int4', value: group_id }}
|
|
176
|
-
AND connection_id = ${{ type: 'int4', value: connection_id }}
|
|
177
|
-
AND relation_id = ${{ type: 'jsonb', value: { object_id: objectId } }}
|
|
178
|
-
AND schema_name = ${{ type: 'varchar', value: schema }}
|
|
179
|
-
AND table_name = ${{ type: 'varchar', value: table }}
|
|
180
|
-
AND replica_id_columns = ${{ type: 'jsonb', value: columns }}
|
|
169
|
+
let sourceTableRow = await db.sql `
|
|
170
|
+
SELECT
|
|
171
|
+
*
|
|
172
|
+
FROM
|
|
173
|
+
source_tables
|
|
174
|
+
WHERE
|
|
175
|
+
group_id = ${{ type: 'int4', value: group_id }}
|
|
176
|
+
AND connection_id = ${{ type: 'int4', value: connection_id }}
|
|
177
|
+
AND relation_id = ${{ type: 'jsonb', value: { object_id: objectId } }}
|
|
178
|
+
AND schema_name = ${{ type: 'varchar', value: schema }}
|
|
179
|
+
AND table_name = ${{ type: 'varchar', value: table }}
|
|
180
|
+
AND replica_id_columns = ${{ type: 'jsonb', value: columns }}
|
|
181
181
|
`
|
|
182
182
|
.decoded(models.SourceTable)
|
|
183
183
|
.first();
|
|
184
184
|
if (sourceTableRow == null) {
|
|
185
|
-
const row = await db.sql `
|
|
186
|
-
INSERT INTO
|
|
187
|
-
source_tables (
|
|
188
|
-
id,
|
|
189
|
-
group_id,
|
|
190
|
-
connection_id,
|
|
191
|
-
relation_id,
|
|
192
|
-
schema_name,
|
|
193
|
-
table_name,
|
|
194
|
-
replica_id_columns
|
|
195
|
-
)
|
|
196
|
-
VALUES
|
|
197
|
-
(
|
|
198
|
-
${{ type: 'varchar', value: uuid.v4() }},
|
|
199
|
-
${{ type: 'int4', value: group_id }},
|
|
200
|
-
${{ type: 'int4', value: connection_id }},
|
|
201
|
-
--- The objectId can be string | number, we store it as jsonb value
|
|
202
|
-
${{ type: 'jsonb', value: { object_id: objectId } }},
|
|
203
|
-
${{ type: 'varchar', value: schema }},
|
|
204
|
-
${{ type: 'varchar', value: table }},
|
|
205
|
-
${{ type: 'jsonb', value: columns }}
|
|
206
|
-
)
|
|
207
|
-
RETURNING
|
|
208
|
-
*
|
|
185
|
+
const row = await db.sql `
|
|
186
|
+
INSERT INTO
|
|
187
|
+
source_tables (
|
|
188
|
+
id,
|
|
189
|
+
group_id,
|
|
190
|
+
connection_id,
|
|
191
|
+
relation_id,
|
|
192
|
+
schema_name,
|
|
193
|
+
table_name,
|
|
194
|
+
replica_id_columns
|
|
195
|
+
)
|
|
196
|
+
VALUES
|
|
197
|
+
(
|
|
198
|
+
${{ type: 'varchar', value: uuid.v4() }},
|
|
199
|
+
${{ type: 'int4', value: group_id }},
|
|
200
|
+
${{ type: 'int4', value: connection_id }},
|
|
201
|
+
--- The objectId can be string | number, we store it as jsonb value
|
|
202
|
+
${{ type: 'jsonb', value: { object_id: objectId } }},
|
|
203
|
+
${{ type: 'varchar', value: schema }},
|
|
204
|
+
${{ type: 'varchar', value: table }},
|
|
205
|
+
${{ type: 'jsonb', value: columns }}
|
|
206
|
+
)
|
|
207
|
+
RETURNING
|
|
208
|
+
*
|
|
209
209
|
`
|
|
210
210
|
.decoded(models.SourceTable)
|
|
211
211
|
.first();
|
|
@@ -215,22 +215,22 @@ export class PostgresSyncRulesStorage extends DisposableObserver {
|
|
|
215
215
|
sourceTable.syncEvent = options.sync_rules.tableTriggersEvent(sourceTable);
|
|
216
216
|
sourceTable.syncData = options.sync_rules.tableSyncsData(sourceTable);
|
|
217
217
|
sourceTable.syncParameters = options.sync_rules.tableSyncsParameters(sourceTable);
|
|
218
|
-
const truncatedTables = await db.sql `
|
|
219
|
-
SELECT
|
|
220
|
-
*
|
|
221
|
-
FROM
|
|
222
|
-
source_tables
|
|
223
|
-
WHERE
|
|
224
|
-
group_id = ${{ type: 'int4', value: group_id }}
|
|
225
|
-
AND connection_id = ${{ type: 'int4', value: connection_id }}
|
|
226
|
-
AND id != ${{ type: 'varchar', value: sourceTableRow.id }}
|
|
227
|
-
AND (
|
|
228
|
-
relation_id = ${{ type: 'jsonb', value: { object_id: objectId } }}
|
|
229
|
-
OR (
|
|
230
|
-
schema_name = ${{ type: 'varchar', value: schema }}
|
|
231
|
-
AND table_name = ${{ type: 'varchar', value: table }}
|
|
232
|
-
)
|
|
233
|
-
)
|
|
218
|
+
const truncatedTables = await db.sql `
|
|
219
|
+
SELECT
|
|
220
|
+
*
|
|
221
|
+
FROM
|
|
222
|
+
source_tables
|
|
223
|
+
WHERE
|
|
224
|
+
group_id = ${{ type: 'int4', value: group_id }}
|
|
225
|
+
AND connection_id = ${{ type: 'int4', value: connection_id }}
|
|
226
|
+
AND id != ${{ type: 'varchar', value: sourceTableRow.id }}
|
|
227
|
+
AND (
|
|
228
|
+
relation_id = ${{ type: 'jsonb', value: { object_id: objectId } }}
|
|
229
|
+
OR (
|
|
230
|
+
schema_name = ${{ type: 'varchar', value: schema }}
|
|
231
|
+
AND table_name = ${{ type: 'varchar', value: table }}
|
|
232
|
+
)
|
|
233
|
+
)
|
|
234
234
|
`
|
|
235
235
|
.decoded(models.SourceTable)
|
|
236
236
|
.rows();
|
|
@@ -247,15 +247,15 @@ export class PostgresSyncRulesStorage extends DisposableObserver {
|
|
|
247
247
|
async startBatch(options, callback) {
|
|
248
248
|
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
249
249
|
try {
|
|
250
|
-
const syncRules = await this.db.sql `
|
|
251
|
-
SELECT
|
|
252
|
-
last_checkpoint_lsn,
|
|
253
|
-
no_checkpoint_before,
|
|
254
|
-
keepalive_op
|
|
255
|
-
FROM
|
|
256
|
-
sync_rules
|
|
257
|
-
WHERE
|
|
258
|
-
id = ${{ type: 'int4', value: this.group_id }}
|
|
250
|
+
const syncRules = await this.db.sql `
|
|
251
|
+
SELECT
|
|
252
|
+
last_checkpoint_lsn,
|
|
253
|
+
no_checkpoint_before,
|
|
254
|
+
keepalive_op
|
|
255
|
+
FROM
|
|
256
|
+
sync_rules
|
|
257
|
+
WHERE
|
|
258
|
+
id = ${{ type: 'int4', value: this.group_id }}
|
|
259
259
|
`
|
|
260
260
|
.decoded(pick(models.SyncRules, ['last_checkpoint_lsn', 'no_checkpoint_before', 'keepalive_op']))
|
|
261
261
|
.first();
|
|
@@ -293,32 +293,32 @@ export class PostgresSyncRulesStorage extends DisposableObserver {
|
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
295
|
async getParameterSets(checkpoint, lookups) {
|
|
296
|
-
const rows = await this.db.sql `
|
|
297
|
-
SELECT DISTINCT
|
|
298
|
-
ON (lookup, source_table, source_key) lookup,
|
|
299
|
-
source_table,
|
|
300
|
-
source_key,
|
|
301
|
-
id,
|
|
302
|
-
bucket_parameters
|
|
303
|
-
FROM
|
|
304
|
-
bucket_parameters
|
|
305
|
-
WHERE
|
|
306
|
-
group_id = ${{ type: 'int4', value: this.group_id }}
|
|
307
|
-
AND lookup = ANY (
|
|
308
|
-
SELECT
|
|
309
|
-
decode((FILTER ->> 0)::text, 'hex') -- Decode the hex string to bytea
|
|
310
|
-
FROM
|
|
296
|
+
const rows = await this.db.sql `
|
|
297
|
+
SELECT DISTINCT
|
|
298
|
+
ON (lookup, source_table, source_key) lookup,
|
|
299
|
+
source_table,
|
|
300
|
+
source_key,
|
|
301
|
+
id,
|
|
302
|
+
bucket_parameters
|
|
303
|
+
FROM
|
|
304
|
+
bucket_parameters
|
|
305
|
+
WHERE
|
|
306
|
+
group_id = ${{ type: 'int4', value: this.group_id }}
|
|
307
|
+
AND lookup = ANY (
|
|
308
|
+
SELECT
|
|
309
|
+
decode((FILTER ->> 0)::text, 'hex') -- Decode the hex string to bytea
|
|
310
|
+
FROM
|
|
311
311
|
jsonb_array_elements(${{
|
|
312
312
|
type: 'jsonb',
|
|
313
313
|
value: lookups.map((l) => storage.serializeLookupBuffer(l).toString('hex'))
|
|
314
|
-
}}) AS FILTER
|
|
315
|
-
)
|
|
316
|
-
AND id <= ${{ type: 'int8', value: BigInt(checkpoint) }}
|
|
317
|
-
ORDER BY
|
|
318
|
-
lookup,
|
|
319
|
-
source_table,
|
|
320
|
-
source_key,
|
|
321
|
-
id DESC
|
|
314
|
+
}}) AS FILTER
|
|
315
|
+
)
|
|
316
|
+
AND id <= ${{ type: 'int8', value: BigInt(checkpoint) }}
|
|
317
|
+
ORDER BY
|
|
318
|
+
lookup,
|
|
319
|
+
source_table,
|
|
320
|
+
source_key,
|
|
321
|
+
id DESC
|
|
322
322
|
`
|
|
323
323
|
.decoded(pick(models.BucketParameters, ['bucket_parameters']))
|
|
324
324
|
.rows();
|
|
@@ -375,21 +375,21 @@ export class PostgresSyncRulesStorage extends DisposableObserver {
|
|
|
375
375
|
* 1 million rows were only synced before a 5 minute timeout.
|
|
376
376
|
*/
|
|
377
377
|
for await (const rows of this.db.streamRows({
|
|
378
|
-
statement: `
|
|
379
|
-
SELECT
|
|
380
|
-
*
|
|
381
|
-
FROM
|
|
382
|
-
bucket_data
|
|
383
|
-
WHERE
|
|
384
|
-
group_id = $1
|
|
385
|
-
and op_id <= $2
|
|
386
|
-
and (
|
|
387
|
-
${filters.map((f, index) => `(bucket_name = $${index * 2 + 4} and op_id > $${index * 2 + 5})`).join(' OR ')}
|
|
388
|
-
)
|
|
389
|
-
ORDER BY
|
|
390
|
-
bucket_name ASC,
|
|
391
|
-
op_id ASC
|
|
392
|
-
LIMIT
|
|
378
|
+
statement: `
|
|
379
|
+
SELECT
|
|
380
|
+
*
|
|
381
|
+
FROM
|
|
382
|
+
bucket_data
|
|
383
|
+
WHERE
|
|
384
|
+
group_id = $1
|
|
385
|
+
and op_id <= $2
|
|
386
|
+
and (
|
|
387
|
+
${filters.map((f, index) => `(bucket_name = $${index * 2 + 4} and op_id > $${index * 2 + 5})`).join(' OR ')}
|
|
388
|
+
)
|
|
389
|
+
ORDER BY
|
|
390
|
+
bucket_name ASC,
|
|
391
|
+
op_id ASC
|
|
392
|
+
LIMIT
|
|
393
393
|
$3;`,
|
|
394
394
|
params: [
|
|
395
395
|
{ type: 'int4', value: this.group_id },
|
|
@@ -428,7 +428,7 @@ export class PostgresSyncRulesStorage extends DisposableObserver {
|
|
|
428
428
|
}
|
|
429
429
|
start ??= dataBuckets.get(bucket_name);
|
|
430
430
|
if (start == null) {
|
|
431
|
-
throw new
|
|
431
|
+
throw new ReplicationAssertionError(`data for unexpected bucket: ${bucket_name}`);
|
|
432
432
|
}
|
|
433
433
|
currentBatch = {
|
|
434
434
|
bucket: bucket_name,
|
|
@@ -471,25 +471,25 @@ export class PostgresSyncRulesStorage extends DisposableObserver {
|
|
|
471
471
|
if (!options || options?.clearStorage) {
|
|
472
472
|
await this.clear();
|
|
473
473
|
}
|
|
474
|
-
await this.db.sql `
|
|
475
|
-
UPDATE sync_rules
|
|
476
|
-
SET
|
|
477
|
-
state = ${{ type: 'varchar', value: storage.SyncRuleState.TERMINATED }},
|
|
478
|
-
snapshot_done = ${{ type: 'bool', value: false }}
|
|
479
|
-
WHERE
|
|
480
|
-
id = ${{ type: 'int4', value: this.group_id }}
|
|
474
|
+
await this.db.sql `
|
|
475
|
+
UPDATE sync_rules
|
|
476
|
+
SET
|
|
477
|
+
state = ${{ type: 'varchar', value: storage.SyncRuleState.TERMINATED }},
|
|
478
|
+
snapshot_done = ${{ type: 'bool', value: false }}
|
|
479
|
+
WHERE
|
|
480
|
+
id = ${{ type: 'int4', value: this.group_id }}
|
|
481
481
|
`.execute();
|
|
482
482
|
}
|
|
483
483
|
async getStatus() {
|
|
484
|
-
const syncRulesRow = await this.db.sql `
|
|
485
|
-
SELECT
|
|
486
|
-
snapshot_done,
|
|
487
|
-
last_checkpoint_lsn,
|
|
488
|
-
state
|
|
489
|
-
FROM
|
|
490
|
-
sync_rules
|
|
491
|
-
WHERE
|
|
492
|
-
id = ${{ type: 'int4', value: this.group_id }}
|
|
484
|
+
const syncRulesRow = await this.db.sql `
|
|
485
|
+
SELECT
|
|
486
|
+
snapshot_done,
|
|
487
|
+
last_checkpoint_lsn,
|
|
488
|
+
state
|
|
489
|
+
FROM
|
|
490
|
+
sync_rules
|
|
491
|
+
WHERE
|
|
492
|
+
id = ${{ type: 'int4', value: this.group_id }}
|
|
493
493
|
`
|
|
494
494
|
.decoded(pick(models.SyncRules, ['snapshot_done', 'last_checkpoint_lsn', 'state']))
|
|
495
495
|
.first();
|
|
@@ -503,65 +503,65 @@ export class PostgresSyncRulesStorage extends DisposableObserver {
|
|
|
503
503
|
};
|
|
504
504
|
}
|
|
505
505
|
async clear() {
|
|
506
|
-
await this.db.sql `
|
|
507
|
-
UPDATE sync_rules
|
|
508
|
-
SET
|
|
509
|
-
snapshot_done = FALSE,
|
|
510
|
-
last_checkpoint_lsn = NULL,
|
|
511
|
-
last_checkpoint = NULL,
|
|
512
|
-
no_checkpoint_before = NULL
|
|
513
|
-
WHERE
|
|
514
|
-
id = ${{ type: 'int4', value: this.group_id }}
|
|
506
|
+
await this.db.sql `
|
|
507
|
+
UPDATE sync_rules
|
|
508
|
+
SET
|
|
509
|
+
snapshot_done = FALSE,
|
|
510
|
+
last_checkpoint_lsn = NULL,
|
|
511
|
+
last_checkpoint = NULL,
|
|
512
|
+
no_checkpoint_before = NULL
|
|
513
|
+
WHERE
|
|
514
|
+
id = ${{ type: 'int4', value: this.group_id }}
|
|
515
515
|
`.execute();
|
|
516
|
-
await this.db.sql `
|
|
517
|
-
DELETE FROM bucket_data
|
|
518
|
-
WHERE
|
|
519
|
-
group_id = ${{ type: 'int4', value: this.group_id }}
|
|
516
|
+
await this.db.sql `
|
|
517
|
+
DELETE FROM bucket_data
|
|
518
|
+
WHERE
|
|
519
|
+
group_id = ${{ type: 'int4', value: this.group_id }}
|
|
520
520
|
`.execute();
|
|
521
|
-
await this.db.sql `
|
|
522
|
-
DELETE FROM bucket_parameters
|
|
523
|
-
WHERE
|
|
524
|
-
group_id = ${{ type: 'int4', value: this.group_id }}
|
|
521
|
+
await this.db.sql `
|
|
522
|
+
DELETE FROM bucket_parameters
|
|
523
|
+
WHERE
|
|
524
|
+
group_id = ${{ type: 'int4', value: this.group_id }}
|
|
525
525
|
`.execute();
|
|
526
|
-
await this.db.sql `
|
|
527
|
-
DELETE FROM current_data
|
|
528
|
-
WHERE
|
|
529
|
-
group_id = ${{ type: 'int4', value: this.group_id }}
|
|
526
|
+
await this.db.sql `
|
|
527
|
+
DELETE FROM current_data
|
|
528
|
+
WHERE
|
|
529
|
+
group_id = ${{ type: 'int4', value: this.group_id }}
|
|
530
530
|
`.execute();
|
|
531
|
-
await this.db.sql `
|
|
532
|
-
DELETE FROM source_tables
|
|
533
|
-
WHERE
|
|
534
|
-
group_id = ${{ type: 'int4', value: this.group_id }}
|
|
531
|
+
await this.db.sql `
|
|
532
|
+
DELETE FROM source_tables
|
|
533
|
+
WHERE
|
|
534
|
+
group_id = ${{ type: 'int4', value: this.group_id }}
|
|
535
535
|
`.execute();
|
|
536
536
|
}
|
|
537
537
|
async autoActivate() {
|
|
538
538
|
await this.db.transaction(async (db) => {
|
|
539
|
-
const syncRulesRow = await db.sql `
|
|
540
|
-
SELECT
|
|
541
|
-
state
|
|
542
|
-
FROM
|
|
543
|
-
sync_rules
|
|
544
|
-
WHERE
|
|
545
|
-
id = ${{ type: 'int4', value: this.group_id }}
|
|
539
|
+
const syncRulesRow = await db.sql `
|
|
540
|
+
SELECT
|
|
541
|
+
state
|
|
542
|
+
FROM
|
|
543
|
+
sync_rules
|
|
544
|
+
WHERE
|
|
545
|
+
id = ${{ type: 'int4', value: this.group_id }}
|
|
546
546
|
`
|
|
547
547
|
.decoded(pick(models.SyncRules, ['state']))
|
|
548
548
|
.first();
|
|
549
549
|
if (syncRulesRow && syncRulesRow.state == storage.SyncRuleState.PROCESSING) {
|
|
550
|
-
await db.sql `
|
|
551
|
-
UPDATE sync_rules
|
|
552
|
-
SET
|
|
553
|
-
state = ${{ type: 'varchar', value: storage.SyncRuleState.ACTIVE }}
|
|
554
|
-
WHERE
|
|
555
|
-
id = ${{ type: 'int4', value: this.group_id }}
|
|
550
|
+
await db.sql `
|
|
551
|
+
UPDATE sync_rules
|
|
552
|
+
SET
|
|
553
|
+
state = ${{ type: 'varchar', value: storage.SyncRuleState.ACTIVE }}
|
|
554
|
+
WHERE
|
|
555
|
+
id = ${{ type: 'int4', value: this.group_id }}
|
|
556
556
|
`.execute();
|
|
557
557
|
}
|
|
558
|
-
await db.sql `
|
|
559
|
-
UPDATE sync_rules
|
|
560
|
-
SET
|
|
561
|
-
state = ${{ type: 'varchar', value: storage.SyncRuleState.STOP }}
|
|
562
|
-
WHERE
|
|
563
|
-
state = ${{ type: 'varchar', value: storage.SyncRuleState.ACTIVE }}
|
|
564
|
-
AND id != ${{ type: 'int4', value: this.group_id }}
|
|
558
|
+
await db.sql `
|
|
559
|
+
UPDATE sync_rules
|
|
560
|
+
SET
|
|
561
|
+
state = ${{ type: 'varchar', value: storage.SyncRuleState.STOP }}
|
|
562
|
+
WHERE
|
|
563
|
+
state = ${{ type: 'varchar', value: storage.SyncRuleState.ACTIVE }}
|
|
564
|
+
AND id != ${{ type: 'int4', value: this.group_id }}
|
|
565
565
|
`.execute();
|
|
566
566
|
});
|
|
567
567
|
}
|
|
@@ -573,35 +573,35 @@ export class PostgresSyncRulesStorage extends DisposableObserver {
|
|
|
573
573
|
...b,
|
|
574
574
|
start: b.start ?? 0
|
|
575
575
|
}));
|
|
576
|
-
const results = await this.db.sql `
|
|
577
|
-
WITH
|
|
578
|
-
filter_data AS (
|
|
579
|
-
SELECT
|
|
580
|
-
FILTER ->> 'bucket' AS bucket_name,
|
|
581
|
-
(FILTER ->> 'start')::BIGINT AS start_op_id,
|
|
582
|
-
(FILTER ->> 'end')::BIGINT AS end_op_id
|
|
583
|
-
FROM
|
|
584
|
-
jsonb_array_elements(${{ type: 'jsonb', value: rangedBatch }}::jsonb) AS FILTER
|
|
585
|
-
)
|
|
586
|
-
SELECT
|
|
587
|
-
b.bucket_name AS bucket,
|
|
588
|
-
SUM(b.checksum) AS checksum_total,
|
|
589
|
-
COUNT(*) AS total,
|
|
590
|
-
MAX(
|
|
591
|
-
CASE
|
|
592
|
-
WHEN b.op = 'CLEAR' THEN 1
|
|
593
|
-
ELSE 0
|
|
594
|
-
END
|
|
595
|
-
) AS has_clear_op
|
|
596
|
-
FROM
|
|
597
|
-
bucket_data b
|
|
598
|
-
JOIN filter_data f ON b.bucket_name = f.bucket_name
|
|
599
|
-
AND b.op_id > f.start_op_id
|
|
600
|
-
AND b.op_id <= f.end_op_id
|
|
601
|
-
WHERE
|
|
602
|
-
b.group_id = ${{ type: 'int4', value: this.group_id }}
|
|
603
|
-
GROUP BY
|
|
604
|
-
b.bucket_name;
|
|
576
|
+
const results = await this.db.sql `
|
|
577
|
+
WITH
|
|
578
|
+
filter_data AS (
|
|
579
|
+
SELECT
|
|
580
|
+
FILTER ->> 'bucket' AS bucket_name,
|
|
581
|
+
(FILTER ->> 'start')::BIGINT AS start_op_id,
|
|
582
|
+
(FILTER ->> 'end')::BIGINT AS end_op_id
|
|
583
|
+
FROM
|
|
584
|
+
jsonb_array_elements(${{ type: 'jsonb', value: rangedBatch }}::jsonb) AS FILTER
|
|
585
|
+
)
|
|
586
|
+
SELECT
|
|
587
|
+
b.bucket_name AS bucket,
|
|
588
|
+
SUM(b.checksum) AS checksum_total,
|
|
589
|
+
COUNT(*) AS total,
|
|
590
|
+
MAX(
|
|
591
|
+
CASE
|
|
592
|
+
WHEN b.op = 'CLEAR' THEN 1
|
|
593
|
+
ELSE 0
|
|
594
|
+
END
|
|
595
|
+
) AS has_clear_op
|
|
596
|
+
FROM
|
|
597
|
+
bucket_data b
|
|
598
|
+
JOIN filter_data f ON b.bucket_name = f.bucket_name
|
|
599
|
+
AND b.op_id > f.start_op_id
|
|
600
|
+
AND b.op_id <= f.end_op_id
|
|
601
|
+
WHERE
|
|
602
|
+
b.group_id = ${{ type: 'int4', value: this.group_id }}
|
|
603
|
+
GROUP BY
|
|
604
|
+
b.bucket_name;
|
|
605
605
|
`.rows();
|
|
606
606
|
return new Map(results.map((doc) => {
|
|
607
607
|
return [
|