IF Commons GitHub

physical/dump

Written to: 5 requirements: 5 proved, 0 partly, 0 failing, 0 with no test recorded. 0008-sql-dump FR-001, 0008-sql-dump FR-002, 0008-sql-dump FR-003, 0008-sql-dump FR-004, 0008-sql-dump FR-005

The dump of a database that merges, and what is done with one. The mergeable tables (the version rows and the blobs) are the whole of what a dump carries: one INSERT for each row, the text the command sqlite3 x.db ".dump --data-only <tables>" writes. Replaying such a text into a database that has the layout (the schema is made first, since a dump has none) in one transaction adds the rows it does not hold and ignores the rest, so that the replay of any number of dumps, in any order, twice and overlapping, is the replay of their union: that is the merge. dumpText makes the dump in the same form, in key order; parseDump reads a dump as its rows and nothing else (the comments the command writes are skipped), and refuses any text that is anything but plain inserts of literals into the two tables, so that a dump is data and never a program; importDumps replays dumps through the store of the database (its trust stands in front of the rows) and then makes the index of search again and checks every row and blob.

import { dumpText, importDumps } from "./dump.ts";
const text = await dumpText(a.port, a.facts.naming);
const done = await importDumps(b, [text]);

Source: commons/anyfs-sql/src/physical/dump.ts

8 of 12 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

DumpManifesttypeno test imports it
type DumpManifest = { readonly format: 1; readonly replica: ReplicaId; readonly sha256: string; readonly versions: number; readonly blobs: number; readonly signature: string };

What a replica that signs says of a dump it made: which replica made it, the SHA-256 of its text and how many rows and blobs it holds, in its key. A dump is data that anything can write, so under signed trust a dump is replayed only with a manifest whose signature holds; what is signed is the digest with the counts (<sha256>:<rows>:<blobs>) under the domain anyfs-dump/1, so that a signature of a delta or an epoch is never one of a dump. The file next to a dump is named <replica>.sql.sig.

Importedtypeno test imports it
type Imported = { readonly versions: number; readonly blobs: number; readonly findings: readonly MergeFinding[] };

What replaying dumps did: the rows and blobs that were new, and what is wrong with the database after.

SignedDumptypeno test imports it
type SignedDump = { readonly text: string; readonly manifest: DumpManifest };

A dump with the manifest that was signed for it.

dumpArgvfunction
function dumpArgv(file: string, naming: Naming): readonly string[]

The command that makes the dump of a database file with the real sqlite3: the data of the mergeable tables alone, as one INSERT for each row, and no schema.

Imported by 32 tests of the run (32 passed, 0 failed): the library's results

manifestTextconst
const manifestText: (m: DumpManifest) => string

The text of a manifest, as it is kept in <replica>.sql.sig.

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

parseManifestfunction
function parseManifest(source: string): Result<DumpManifest, string>

A manifest from its text, or why it is not one.

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

signDumpfunction
function signDump(text: string, naming: Naming, signer: Signer): Promise<Result<SignedDump, string>>

Signs a dump: the manifest of its text, from the rows it holds.

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

dumpTablesfunctionno test imports it
function dumpTables(naming: Naming): readonly [string, string]

The tables a dump carries, by the names they have in a store with a naming: the version rows and the blobs.

dumpTextfunction
function dumpText(port: SqlPort, naming: Naming): Promise<string>

The dump of a database as text, in key order: one INSERT for each version row and for each blob. A SQLite database gives it in the form the command makes (the engine's quote); any other engine gives the rows in its own form (see redump).

Imported by 25 tests of the run (25 passed, 0 failed): the library's results

importDumpsfunction
function importDumps(store: SqlStore, inputs: readonly (string | SignedDump)[]): Promise<Result<Imported, string>>

Replays dumps into the database of a store: the schema is there (the store made it), every dump is read as rows before anything is written (a text that is not a dump of plain inserts changes nothing), the rows are replayed in one transaction through the trigger that refuses a replica the database does not trust (and the whole replay is undone where one is refused), the index of search is made again, and every row and blob is checked.

Imported by 32 tests of the run (32 passed, 0 failed): the library's results

parseDumpfunction
function parseDump(text: string, naming: Naming): Result<Dump, string>

A dump read as its rows, or why the text is not a dump: the line of the first thing that is not a plain insert of literals into a table of the dump.

Imported by 19 tests of the run (19 passed, 0 failed): the library's results

redumpTextfunction
function redumpText(text: string, target: "duckdb" | "postgres" | "sqlite", naming: Naming): Result<string, string>

A dump written in the form of another engine, from the text of a dump of any form: what a SQLite dump becomes for PostgreSQL or DuckDB.

Imported by 11 tests of the run (11 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.