@syncular/server 0.59.0 → 0.60.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/README.md +20 -16
- package/dist/admin.d.ts +32 -20
- package/dist/admin.js +42 -40
- package/dist/context.d.ts +6 -8
- package/dist/context.js +1 -3
- package/dist/d1-storage.js +42 -24
- package/dist/errors.js +8 -0
- package/dist/events.d.ts +35 -17
- package/dist/frame-bytes.js +24 -6
- package/dist/handler.js +486 -223
- package/dist/local-authority.js +7 -9
- package/dist/operations.d.ts +5 -2
- package/dist/operations.js +20 -29
- package/dist/postgres-storage.d.ts +24 -19
- package/dist/postgres-storage.js +249 -168
- package/dist/pull.d.ts +68 -53
- package/dist/pull.js +258 -287
- package/dist/push.d.ts +12 -3
- package/dist/push.js +95 -32
- package/dist/realtime.d.ts +17 -11
- package/dist/realtime.js +65 -90
- package/dist/relational-rows.d.ts +0 -57
- package/dist/relational-rows.js +4 -100
- package/dist/seed.js +10 -15
- package/dist/segment-download.d.ts +4 -1
- package/dist/segment-download.js +4 -2
- package/dist/sqlite-dialect.d.ts +36 -59
- package/dist/sqlite-dialect.js +255 -159
- package/dist/sqlite-storage.js +24 -20
- package/dist/storage-query.d.ts +30 -1
- package/dist/storage-query.js +68 -0
- package/dist/storage.d.ts +156 -54
- package/dist/storage.js +15 -0
- package/package.json +2 -2
- package/src/admin.ts +87 -59
- package/src/context.ts +7 -11
- package/src/d1-storage.ts +49 -33
- package/src/errors.ts +8 -0
- package/src/events.ts +36 -17
- package/src/frame-bytes.ts +26 -6
- package/src/handler.ts +628 -286
- package/src/local-authority.ts +10 -11
- package/src/operations.ts +44 -42
- package/src/postgres-storage.ts +336 -226
- package/src/pull.ts +394 -414
- package/src/push.ts +116 -21
- package/src/realtime.ts +85 -129
- package/src/relational-rows.ts +4 -107
- package/src/seed.ts +13 -19
- package/src/segment-download.ts +8 -3
- package/src/sqlite-dialect.ts +363 -204
- package/src/sqlite-storage.ts +45 -25
- package/src/storage-query.ts +102 -0
- package/src/storage.ts +185 -58
package/dist/local-authority.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* with no remote server, and later moves the authority's rows to a remote
|
|
5
5
|
* server with `attach` (§12.3).
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
7
|
+
import { decodeResponse, decodeRow, encodeRequest, encodeSparseRow, PROTOCOL_WIRE_VERSION, registrationDigest, } from '@syncular/core';
|
|
8
8
|
import { SyncError } from './errors.js';
|
|
9
9
|
import { handleSyncRequest } from './handler.js';
|
|
10
10
|
import { pruneCommitLog } from './prune.js';
|
|
@@ -138,18 +138,11 @@ export async function openLocalAuthority(options) {
|
|
|
138
138
|
return attachId;
|
|
139
139
|
};
|
|
140
140
|
const exchange = async (transport, frames) => {
|
|
141
|
-
const message =
|
|
141
|
+
const message = decodeResponse(await transport(encodeRequest({
|
|
142
142
|
wireVersion: PROTOCOL_WIRE_VERSION,
|
|
143
143
|
msgKind: 'request',
|
|
144
144
|
frames,
|
|
145
145
|
})));
|
|
146
|
-
if (message.msgKind !== 'response') {
|
|
147
|
-
throw new LocalAuthorityAttachError({
|
|
148
|
-
reason: 'request_failed',
|
|
149
|
-
code: 'sync.invalid_request',
|
|
150
|
-
retryable: false,
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
146
|
const header = message.frames[0];
|
|
154
147
|
if (header?.type === 'RESP_HEADER' && header.requiredSchemaVersion) {
|
|
155
148
|
throw new LocalAuthorityAttachError({
|
|
@@ -180,6 +173,9 @@ export async function openLocalAuthority(options) {
|
|
|
180
173
|
limitSnapshotRows: 0,
|
|
181
174
|
maxSnapshotPages: 0,
|
|
182
175
|
accept: 0b0011,
|
|
176
|
+
cursor: -1,
|
|
177
|
+
registrationDigest: registrationDigest([]),
|
|
178
|
+
echoDigest: new Uint8Array(),
|
|
183
179
|
},
|
|
184
180
|
]))[0];
|
|
185
181
|
const logEpoch = acquired?.type === 'RESP_HEADER' ? acquired.logEpoch : undefined;
|
|
@@ -353,6 +349,7 @@ export async function openLocalAuthority(options) {
|
|
|
353
349
|
const commit = {
|
|
354
350
|
type: 'PUSH_COMMIT',
|
|
355
351
|
clientCommitId: `${attachId}:undo:${attempt}:${start / ATTACH_OPERATION_BUDGET}`,
|
|
352
|
+
clientSeq: 0,
|
|
356
353
|
operations: deletes.slice(start, start + ATTACH_OPERATION_BUDGET),
|
|
357
354
|
};
|
|
358
355
|
const result = await send(commit);
|
|
@@ -453,6 +450,7 @@ function planAttach(database, schema, attachId) {
|
|
|
453
450
|
commits.push({
|
|
454
451
|
type: 'PUSH_COMMIT',
|
|
455
452
|
clientCommitId: `${attachId}:${commits.length}`,
|
|
453
|
+
clientSeq: 0,
|
|
456
454
|
operations,
|
|
457
455
|
});
|
|
458
456
|
operations = [];
|
package/dist/operations.d.ts
CHANGED
|
@@ -7,11 +7,14 @@ export interface RemoteQueryDependency {
|
|
|
7
7
|
readonly table: string;
|
|
8
8
|
readonly scopeKeys?: readonly string[];
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* The window units a scoped query reads (§4.8): the client's `WindowBase`
|
|
12
|
+
* (a variable and one value per other variable) and the variable's values.
|
|
13
|
+
*/
|
|
10
14
|
export interface RemoteQueryCoverage {
|
|
11
15
|
readonly base: {
|
|
12
|
-
readonly table: string;
|
|
13
16
|
readonly variable: string;
|
|
14
|
-
readonly fixedScopes?: Readonly<Record<string,
|
|
17
|
+
readonly fixedScopes?: Readonly<Record<string, string>>;
|
|
15
18
|
};
|
|
16
19
|
readonly units: readonly string[];
|
|
17
20
|
}
|
package/dist/operations.js
CHANGED
|
@@ -136,43 +136,34 @@ export function registerRemoteQuery(descriptor, options) {
|
|
|
136
136
|
throw syncError('operation.forbidden', 'live scope authorization is unavailable for this query');
|
|
137
137
|
}
|
|
138
138
|
const coverage = descriptor.coverage(params);
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
139
|
+
// A unit names every variable of a table it lets a query read in
|
|
140
|
+
// full: a variable left open would read rows outside the grant, and
|
|
141
|
+
// the wildcard fence (§3.2) has no counterpart in a SQL read.
|
|
142
|
+
const exact = (entry, declared) => {
|
|
143
|
+
const variables = new Set([
|
|
144
|
+
entry.base.variable,
|
|
145
|
+
...Object.keys(entry.base.fixedScopes ?? {}),
|
|
146
|
+
]);
|
|
147
|
+
return (variables.size === declared.size &&
|
|
148
|
+
[...declared].every((variable) => variables.has(variable)));
|
|
149
|
+
};
|
|
150
|
+
const declared = descriptor.tables.map((name) => schema.tables.get(name)?.declaredVariables);
|
|
151
|
+
if (declared.some((variables) => variables === undefined ||
|
|
152
|
+
!coverage.some((entry) => exact(entry, variables)))) {
|
|
148
153
|
throw syncError('operation.invalid_request', 'scoped remote query lacks complete generated scope coverage');
|
|
149
154
|
}
|
|
150
155
|
for (const entry of coverage) {
|
|
151
|
-
const table = schema.tables.get(entry.base.table);
|
|
152
156
|
const fixedScopes = entry.base.fixedScopes ?? {};
|
|
153
|
-
|
|
154
|
-
entry
|
|
155
|
-
|
|
156
|
-
]);
|
|
157
|
-
if (table === undefined ||
|
|
158
|
-
Object.prototype.hasOwnProperty.call(fixedScopes, entry.base.variable) ||
|
|
159
|
-
coveredVariables.size !== table.declaredVariables.size ||
|
|
160
|
-
[...table.declaredVariables].some((variable) => !coveredVariables.has(variable))) {
|
|
161
|
-
throw syncError('operation.invalid_request', 'scoped remote query lacks complete generated scope coverage');
|
|
157
|
+
if (Object.hasOwn(fixedScopes, entry.base.variable) ||
|
|
158
|
+
!declared.some((variables) => variables !== undefined && exact(entry, variables))) {
|
|
159
|
+
throw syncError('operation.invalid_request', 'scoped remote query has invalid generated scope coverage');
|
|
162
160
|
}
|
|
163
161
|
if (entry.units.length === 0) {
|
|
164
162
|
throw syncError('operation.invalid_request', 'scoped remote query has an empty scope unit');
|
|
165
163
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
for (const [variable, values] of Object.entries(fixedScopes)) {
|
|
172
|
-
if (values.length === 0 ||
|
|
173
|
-
values.some((value) => !scopeAllowed(allowed, variable, value))) {
|
|
174
|
-
throw syncError('operation.forbidden');
|
|
175
|
-
}
|
|
164
|
+
if (entry.units.some((value) => !scopeAllowed(allowed, entry.base.variable, value)) ||
|
|
165
|
+
Object.entries(fixedScopes).some(([variable, value]) => !scopeAllowed(allowed, variable, value))) {
|
|
166
|
+
throw syncError('operation.forbidden');
|
|
176
167
|
}
|
|
177
168
|
}
|
|
178
169
|
}
|
|
@@ -9,13 +9,13 @@ import type { CommitPruneQuery, CommitPruneResult } from './storage.js';
|
|
|
9
9
|
*
|
|
10
10
|
* - both the commit log and the current-row table carry a (table, var,
|
|
11
11
|
* value) inverted scope index;
|
|
12
|
-
* - `
|
|
13
|
-
* (`
|
|
14
|
-
* index, then verify the full multi-variable match against the
|
|
15
|
-
* scope map — never a log or table scan;
|
|
12
|
+
* - `readLiveWindow`/`scanRows` select candidates through an index
|
|
13
|
+
* (`sync_change_scopes_by_key` / `sync_row_scopes`), ordered + LIMITed
|
|
14
|
+
* at the index, then verify the full multi-variable match against the
|
|
15
|
+
* stored scope map — never a log or table scan;
|
|
16
16
|
* - the candidate indexes are *covering* for their selection: the ordered
|
|
17
|
-
* column (`commit_seq` / `row_id`) sits in the index key after
|
|
18
|
-
*
|
|
17
|
+
* column (`commit_seq` / `row_id`) sits in the index key after the scope
|
|
18
|
+
* key, so the planner does an index range scan and returns
|
|
19
19
|
* already-ordered candidates without a heap sort. `test/postgres-explain
|
|
20
20
|
* .test.ts` asserts an `Index` node (never `Seq Scan`) so the regression
|
|
21
21
|
* cannot silently return.
|
|
@@ -36,21 +36,26 @@ import type { CommitPruneQuery, CommitPruneResult } from './storage.js';
|
|
|
36
36
|
* would leave gaps on rollback, which the pull-window arithmetic in §4.5
|
|
37
37
|
* does not tolerate). Cross-partition pushes never contend.
|
|
38
38
|
*/
|
|
39
|
-
import type {
|
|
39
|
+
import type { UnitScopes } from '@syncular/core';
|
|
40
40
|
import { type PgExecutor } from './pg-executor.js';
|
|
41
41
|
import type { CompiledSchema, CompiledTable } from './schema.js';
|
|
42
|
-
import type { AuthoritativeQueryRequest, AuthoritativeQueryResult, CheckpointDeclaration, ClientCursorInfo, ClientPushResult, ClientRecord, ClientRecordWriteOptions, CommitDetail, CommitMetadata, CommitMetadataQuery,
|
|
42
|
+
import type { AuthoritativeQueryRequest, AuthoritativeQueryResult, CheckpointDeclaration, ClientCursorInfo, ClientPushResult, ClientRecord, ClientRecordWriteOptions, CommitDetail, CommitMetadata, CommitMetadataQuery, IndexRowScanQuery, LiveWindow, LiveWindowQuery, PartitionRegistryEntry, PrunedReactionCounts, PushWatermark, ReactionClaimQuery, ReactionFailureUpdate, ReactionListQuery, ReactionPruneQuery, RowChangeRecord, RowChangesQuery, RowListQuery, RowScanQuery, ScopeActivityQuery, ScopeCommitActivity, ScopeValueHistoryQuery, ScopeValueQuery, ServerStorage, ServeGate, StorageTransaction, StoredCheckpoint, StoredPushResult, StoredReaction, StoredRow } from './storage.js';
|
|
43
43
|
/**
|
|
44
44
|
* Schema DDL. Applied by `PostgresServerStorage.migrate()` (idempotent).
|
|
45
45
|
*
|
|
46
46
|
* Covering index design (the reason this file exists):
|
|
47
|
-
* - `
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* - `
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
47
|
+
* - `sync_change_scopes_by_key (partition, var, value, commit_seq)`: the
|
|
48
|
+
* §4.5 live scan ranges once per unit key on the (partition, var, value)
|
|
49
|
+
* prefix across tables and returns `commit_seq` already ascending;
|
|
50
|
+
* - `sync_change_scopes_pk (partition, tbl, var, value, commit_seq)`:
|
|
51
|
+
* the §4.7 scope pin, erasure and pruning name the table;
|
|
52
|
+
* - `sync_row_scopes_pk (partition, tbl, var, value, row_id)`: the same
|
|
53
|
+
* shape for `scanRows`, ordered by `row_id`.
|
|
54
|
+
*
|
|
55
|
+
* The §6.3.2 watermark delete and the §9 settlement of results stored
|
|
56
|
+
* before wire version 4 (NULL `outbox_id`) range over the `(partition,
|
|
57
|
+
* client_id)` prefix of `sync_push_results`' PRIMARY KEY, which the
|
|
58
|
+
* watermark keeps to one request's results per outbox.
|
|
54
59
|
*
|
|
55
60
|
* `sync_row_scopes_by_row (partition, tbl, row_id)` is the one secondary
|
|
56
61
|
* scope index: `writeRowsOn` and `deleteRow` replace a row's scope entries
|
|
@@ -69,7 +74,7 @@ import type { AuthoritativeQueryRequest, AuthoritativeQueryResult, CheckpointDec
|
|
|
69
74
|
* set, §5.9.5) as an index range, never a scan. `postgres-explain
|
|
70
75
|
* .test.ts` asserts an `Index` node here too.
|
|
71
76
|
*/
|
|
72
|
-
export declare const POSTGRES_DDL = "\nCREATE TABLE IF NOT EXISTS sync_partitions(\n partition TEXT PRIMARY KEY,\n max_commit_seq BIGINT NOT NULL DEFAULT 0,\n horizon_seq BIGINT NOT NULL DEFAULT 0\n);\nCREATE TABLE IF NOT EXISTS sync_partition_registry(\n partition TEXT PRIMARY KEY,\n log_epoch TEXT NOT NULL,\n epoch_required BOOLEAN NOT NULL DEFAULT FALSE,\n last_authenticated_at_ms BIGINT NOT NULL\n);\nCREATE TABLE IF NOT EXISTS sync_row_scopes(\n partition TEXT NOT NULL, tbl TEXT NOT NULL,\n var TEXT NOT NULL, value TEXT NOT NULL, row_id TEXT NOT NULL,\n PRIMARY KEY(partition, tbl, var, value, row_id)\n);\nCREATE INDEX IF NOT EXISTS sync_row_scopes_by_row\n ON sync_row_scopes(partition, tbl, row_id);\nCREATE TABLE IF NOT EXISTS sync_commits(\n partition TEXT NOT NULL, commit_seq BIGINT NOT NULL,\n client_id TEXT NOT NULL, client_commit_id TEXT NOT NULL,\n actor_id TEXT NOT NULL, created_at_ms BIGINT NOT NULL,\n writer_version BIGINT,\n PRIMARY KEY(partition, commit_seq)\n);\nCREATE INDEX IF NOT EXISTS sync_commits_by_time\n ON sync_commits(partition, created_at_ms);\nCREATE TABLE IF NOT EXISTS sync_changes(\n partition TEXT NOT NULL, commit_seq BIGINT NOT NULL, idx INTEGER NOT NULL,\n tbl TEXT NOT NULL, row_id TEXT NOT NULL, op SMALLINT NOT NULL,\n row_version BIGINT, scopes JSONB NOT NULL, payload BYTEA,\n PRIMARY KEY(partition, commit_seq, idx)\n);\nCREATE INDEX IF NOT EXISTS sync_changes_by_table\n ON sync_changes(partition, commit_seq, tbl, idx);\nCREATE TABLE IF NOT EXISTS sync_change_scopes(\n partition TEXT NOT NULL, tbl TEXT NOT NULL,\n var TEXT NOT NULL, value TEXT NOT NULL, commit_seq BIGINT NOT NULL,\n PRIMARY KEY(partition, tbl, var, value, commit_seq)\n);\nCREATE TABLE IF NOT EXISTS sync_push_results(\n partition TEXT NOT NULL, client_id TEXT NOT NULL,\n client_commit_id TEXT NOT NULL, result JSONB NOT NULL,\n PRIMARY KEY(partition, client_id, client_commit_id)\n);\nCREATE TABLE IF NOT EXISTS sync_reactions(\n partition TEXT NOT NULL, idempotency_key TEXT NOT NULL,\n type TEXT NOT NULL, version INTEGER NOT NULL, payload JSONB NOT NULL,\n source_client_id TEXT NOT NULL, source_client_commit_id TEXT NOT NULL,\n source_commit_seq BIGINT NOT NULL, created_at_ms BIGINT NOT NULL,\n available_at_ms BIGINT NOT NULL, status TEXT NOT NULL,\n attempts INTEGER NOT NULL, max_attempts INTEGER NOT NULL,\n lease_owner TEXT, lease_expires_at_ms BIGINT, completed_at_ms BIGINT,\n last_failure JSONB,\n PRIMARY KEY(partition, idempotency_key),\n CHECK(status IN ('pending', 'leased', 'completed', 'dead-letter'))\n);\nCREATE INDEX IF NOT EXISTS sync_reactions_due\n ON sync_reactions(partition, status, available_at_ms, created_at_ms, idempotency_key);\nCREATE INDEX IF NOT EXISTS sync_reactions_lease\n ON sync_reactions(partition, status, lease_expires_at_ms);\nCREATE INDEX IF NOT EXISTS sync_reactions_completed\n ON sync_reactions(partition, status, completed_at_ms, idempotency_key);\nCREATE INDEX IF NOT EXISTS sync_reactions_dead_letter\n ON sync_reactions(partition, status, available_at_ms, idempotency_key);\nCREATE TABLE IF NOT EXISTS sync_clients(\n partition TEXT NOT NULL, client_id TEXT NOT NULL, actor_id TEXT NOT NULL,\n wire_version INTEGER NOT NULL DEFAULT 1,\n cursor BIGINT NOT NULL
|
|
77
|
+
export declare const POSTGRES_DDL = "\nCREATE TABLE IF NOT EXISTS sync_partitions(\n partition TEXT PRIMARY KEY,\n max_commit_seq BIGINT NOT NULL DEFAULT 0,\n horizon_seq BIGINT NOT NULL DEFAULT 0,\n delete_floor BIGINT NOT NULL DEFAULT 0\n);\nCREATE TABLE IF NOT EXISTS sync_partition_registry(\n partition TEXT PRIMARY KEY,\n log_epoch TEXT NOT NULL,\n epoch_required BOOLEAN NOT NULL DEFAULT FALSE,\n last_authenticated_at_ms BIGINT NOT NULL\n);\nCREATE TABLE IF NOT EXISTS sync_row_scopes(\n partition TEXT NOT NULL, tbl TEXT NOT NULL,\n var TEXT NOT NULL, value TEXT NOT NULL, row_id TEXT NOT NULL,\n PRIMARY KEY(partition, tbl, var, value, row_id)\n);\nCREATE INDEX IF NOT EXISTS sync_row_scopes_by_row\n ON sync_row_scopes(partition, tbl, row_id);\nCREATE TABLE IF NOT EXISTS sync_commits(\n partition TEXT NOT NULL, commit_seq BIGINT NOT NULL,\n client_id TEXT NOT NULL, client_commit_id TEXT NOT NULL,\n actor_id TEXT NOT NULL, created_at_ms BIGINT NOT NULL,\n writer_version BIGINT,\n PRIMARY KEY(partition, commit_seq)\n);\nCREATE INDEX IF NOT EXISTS sync_commits_by_time\n ON sync_commits(partition, created_at_ms);\nCREATE TABLE IF NOT EXISTS sync_changes(\n partition TEXT NOT NULL, commit_seq BIGINT NOT NULL, idx INTEGER NOT NULL,\n tbl TEXT NOT NULL, row_id TEXT NOT NULL, op SMALLINT NOT NULL,\n row_version BIGINT, scopes JSONB NOT NULL, payload BYTEA,\n PRIMARY KEY(partition, commit_seq, idx)\n);\nCREATE INDEX IF NOT EXISTS sync_changes_by_table\n ON sync_changes(partition, commit_seq, tbl, idx);\nCREATE TABLE IF NOT EXISTS sync_change_scopes(\n partition TEXT NOT NULL, tbl TEXT NOT NULL,\n var TEXT NOT NULL, value TEXT NOT NULL, commit_seq BIGINT NOT NULL,\n PRIMARY KEY(partition, tbl, var, value, commit_seq)\n);\nCREATE INDEX IF NOT EXISTS sync_change_scopes_by_key\n ON sync_change_scopes(partition, var, value, commit_seq);\nCREATE TABLE IF NOT EXISTS sync_push_results(\n partition TEXT NOT NULL, client_id TEXT NOT NULL,\n client_commit_id TEXT NOT NULL, result JSONB NOT NULL,\n outbox_id TEXT, client_seq BIGINT,\n PRIMARY KEY(partition, client_id, client_commit_id)\n);\nALTER TABLE sync_push_results ADD COLUMN IF NOT EXISTS outbox_id TEXT;\nALTER TABLE sync_push_results ADD COLUMN IF NOT EXISTS client_seq BIGINT;\nCREATE TABLE IF NOT EXISTS sync_push_watermarks(\n partition TEXT NOT NULL, client_id TEXT NOT NULL, outbox_id TEXT NOT NULL,\n through_seq BIGINT NOT NULL,\n PRIMARY KEY(partition, client_id, outbox_id)\n);\nCREATE TABLE IF NOT EXISTS sync_reactions(\n partition TEXT NOT NULL, idempotency_key TEXT NOT NULL,\n type TEXT NOT NULL, version INTEGER NOT NULL, payload JSONB NOT NULL,\n source_client_id TEXT NOT NULL, source_client_commit_id TEXT NOT NULL,\n source_commit_seq BIGINT NOT NULL, created_at_ms BIGINT NOT NULL,\n available_at_ms BIGINT NOT NULL, status TEXT NOT NULL,\n attempts INTEGER NOT NULL, max_attempts INTEGER NOT NULL,\n lease_owner TEXT, lease_expires_at_ms BIGINT, completed_at_ms BIGINT,\n last_failure JSONB,\n PRIMARY KEY(partition, idempotency_key),\n CHECK(status IN ('pending', 'leased', 'completed', 'dead-letter'))\n);\nCREATE INDEX IF NOT EXISTS sync_reactions_due\n ON sync_reactions(partition, status, available_at_ms, created_at_ms, idempotency_key);\nCREATE INDEX IF NOT EXISTS sync_reactions_lease\n ON sync_reactions(partition, status, lease_expires_at_ms);\nCREATE INDEX IF NOT EXISTS sync_reactions_completed\n ON sync_reactions(partition, status, completed_at_ms, idempotency_key);\nCREATE INDEX IF NOT EXISTS sync_reactions_dead_letter\n ON sync_reactions(partition, status, available_at_ms, idempotency_key);\nCREATE TABLE IF NOT EXISTS sync_clients(\n partition TEXT NOT NULL, client_id TEXT NOT NULL, actor_id TEXT NOT NULL,\n wire_version INTEGER NOT NULL DEFAULT 1,\n cursor BIGINT NOT NULL,\n updated_at_ms BIGINT NOT NULL,\n last_round_at_ms BIGINT, last_error_code TEXT,\n consecutive_failures INTEGER NOT NULL DEFAULT 0,\n schema_version INTEGER, units JSONB, registration_digest BYTEA,\n catching_up JSONB NOT NULL DEFAULT '[]',\n PRIMARY KEY(partition, client_id)\n);\nALTER TABLE sync_clients\n ADD COLUMN IF NOT EXISTS wire_version INTEGER NOT NULL DEFAULT 1;\nALTER TABLE sync_clients ADD COLUMN IF NOT EXISTS last_round_at_ms BIGINT;\nALTER TABLE sync_clients ADD COLUMN IF NOT EXISTS last_error_code TEXT;\nALTER TABLE sync_clients\n ADD COLUMN IF NOT EXISTS consecutive_failures INTEGER NOT NULL DEFAULT 0;\nALTER TABLE sync_clients ADD COLUMN IF NOT EXISTS schema_version INTEGER;\nALTER TABLE sync_clients ADD COLUMN IF NOT EXISTS units JSONB;\nALTER TABLE sync_clients ADD COLUMN IF NOT EXISTS registration_digest BYTEA;\nALTER TABLE sync_clients\n ADD COLUMN IF NOT EXISTS catching_up JSONB NOT NULL DEFAULT '[]';\n-- \u00A79: a database from before wire version 4 (its client records still hold\n-- subscriptions) starts the horizon at its last commit.\nUPDATE sync_partitions SET horizon_seq = max_commit_seq\n WHERE EXISTS (SELECT 1 FROM information_schema.columns\n WHERE table_schema = current_schema()\n AND table_name = 'sync_clients'\n AND column_name = 'subscriptions');\nALTER TABLE sync_clients DROP COLUMN IF EXISTS subscriptions;\nCREATE TABLE IF NOT EXISTS sync_blob_refs(\n partition TEXT NOT NULL, tbl TEXT NOT NULL, row_id TEXT NOT NULL,\n blob_id TEXT NOT NULL,\n PRIMARY KEY(partition, tbl, row_id, blob_id)\n);\nCREATE INDEX IF NOT EXISTS sync_blob_refs_by_blob\n ON sync_blob_refs(partition, blob_id);\nCREATE TABLE IF NOT EXISTS sync_tombstones(\n partition TEXT NOT NULL, tbl TEXT NOT NULL, row_id TEXT NOT NULL,\n commit_seq BIGINT NOT NULL, server_version BIGINT, scopes JSONB,\n PRIMARY KEY(partition, tbl, row_id)\n);\nALTER TABLE sync_tombstones ADD COLUMN IF NOT EXISTS server_version BIGINT;\nALTER TABLE sync_tombstones ADD COLUMN IF NOT EXISTS scopes JSONB;\nALTER TABLE sync_partitions\n ADD COLUMN IF NOT EXISTS delete_floor BIGINT NOT NULL DEFAULT 0;\nUPDATE sync_partitions SET delete_floor = t.version\n FROM (SELECT partition, max(server_version) AS version\n FROM sync_tombstones GROUP BY partition) t\n WHERE t.partition = sync_partitions.partition\n AND t.version > sync_partitions.delete_floor;\nCREATE TABLE IF NOT EXISTS sync_backfill_checkpoints(\n partition TEXT NOT NULL, name TEXT NOT NULL,\n schema_version INTEGER NOT NULL,\n state TEXT NOT NULL CHECK(state IN ('declared','backfilling','activated')),\n watermark BIGINT NOT NULL DEFAULT 0,\n owner_epoch BIGINT NOT NULL DEFAULT 0,\n observed_rows BIGINT NOT NULL DEFAULT 0,\n updated_at_ms BIGINT NOT NULL,\n PRIMARY KEY(partition, name)\n);\nCREATE TABLE IF NOT EXISTS sync_writer_fence(\n partition TEXT PRIMARY KEY,\n required_writer_version INTEGER NOT NULL\n);\n";
|
|
73
78
|
export declare class PostgresServerStorage implements ServerStorage {
|
|
74
79
|
#private;
|
|
75
80
|
constructor(exec: PgExecutor);
|
|
@@ -123,16 +128,15 @@ export declare class PostgresServerStorage implements ServerStorage {
|
|
|
123
128
|
pruneReactions(partition: string, query: ReactionPruneQuery): Promise<PrunedReactionCounts>;
|
|
124
129
|
latestScopedChangeSeq(partition: string, query: {
|
|
125
130
|
readonly table: string;
|
|
126
|
-
readonly
|
|
131
|
+
readonly scopes: UnitScopes;
|
|
127
132
|
}): Promise<number>;
|
|
128
|
-
|
|
133
|
+
readLiveWindow(partition: string, query: LiveWindowQuery): Promise<LiveWindow>;
|
|
129
134
|
scanRows(partition: string, query: RowScanQuery): Promise<StoredRow[]>;
|
|
130
135
|
scanRowsByIndex(partition: string, query: IndexRowScanQuery): Promise<StoredRow[]>;
|
|
131
136
|
getClientRecord(partition: string, clientId: string): Promise<ClientRecord | undefined>;
|
|
132
137
|
putClientRecord(partition: string, record: ClientRecord, options?: ClientRecordWriteOptions): Promise<void>;
|
|
133
138
|
recordClientRoundFailure(partition: string, clientId: string, actorId: string, errorCode: string, atMs: number): Promise<void>;
|
|
134
139
|
advanceClientCursor(partition: string, clientId: string, actorId: string, logEpoch: string, cursor: number, updatedAtMs: number): Promise<void>;
|
|
135
|
-
updateClientCursor(partition: string, clientId: string, cursor: number, updatedAtMs: number): Promise<void>;
|
|
136
140
|
getActiveClientCursorFloor(partition: string, cutoffMs: number): Promise<number | null>;
|
|
137
141
|
listClientCursors(partition: string): Promise<ClientCursorInfo[]>;
|
|
138
142
|
listRowsReferencingBlob(partition: string, blobId: string): Promise<{
|
|
@@ -150,6 +154,7 @@ export declare class PostgresServerStorage implements ServerStorage {
|
|
|
150
154
|
listRows(partition: string, query: RowListQuery): Promise<StoredRow[]>;
|
|
151
155
|
countRows(partition: string, table: string): Promise<number>;
|
|
152
156
|
listPushResults(partition: string, clientCommitId: string): Promise<ClientPushResult[]>;
|
|
157
|
+
listPushWatermarks(partition: string, clientCommitId: string): Promise<PushWatermark[]>;
|
|
153
158
|
scopeActivity(partition: string, query: ScopeActivityQuery): Promise<ScopeCommitActivity[]>;
|
|
154
159
|
listPartitions(): Promise<string[]>;
|
|
155
160
|
}
|