Developer beta 0.1.0-beta.1 documentation. The build is not available for download yet; these pages describe the beta as built and tested on Linux x86-64.

Recovery

HolaDB is crash-safe by construction; there is nothing to run after a crash. On the next open (holadb serve, query, doctor, …) it:

  • replays the write-ahead log of every table and discards a torn tail (an incomplete last record from a crash mid-write: its terminal marker is missing and nothing valid follows it). A complete record whose bytes were damaged is corruption, never discarded: the table refuses to open and names the record;
  • undoes a CREATE TABLE or DROP TABLE a crash interrupted (the DDL journal names the engine table to remove);
  • replays the transaction journal and skips the write batches of any transaction that has no commit marker, so a multi-table commit is all or nothing;
  • rebuilds secondary indexes and checks the persisted record index against a replay (a rejected index is rebuilt, never trusted). A table directory also holds INDEX-DELTA-<n> files — the rows each seal changed, chained on the INDEX base — which the open applies after verifying them; a missing or damaged delta only means the segments after it are replayed, and the server’s checkpointer folds the deltas back into the base over time (--index-compact-*, Configuration);
  • needs no lock cleanup: the process lock is an operating-system file lock that the kernel released with the crashed process (LOCK keeps the old pid for doctor).

What is checked, and when

Every sealed storage segment file has a hash recorded in the table’s manifest.

  • When the database is opened (server start, and every offline command), each segment file is read once and compared with its hash. A file that does not match, or is missing, stops the open with corruption detected in segment N. Nothing is written by a refused open.
  • When a segment is decoded (the first time something reads from it), its sections are verified again; data from a segment that fails is never returned.
  • holadb verify and holadb doctor check every segment, every index against a replay, and every row against its schema.

What is not checked: a segment file that is damaged while the server is running is not noticed by ordinary statements, because rows are answered from the record index and from memory. It is found by holadb verify (offline), or when the server is next started. Run verify on a schedule that suits your storage, and after any hardware event.

The check at open costs one sequential read of the segment files. It can be skipped with holadb serve --segment-check lazy. That is meant for one case: a database the check refuses, opened so that the rows it can still serve are exported before restoring from a backup.

Seeing what happened

holadb doctor ./shop
✓ holadb: version 0.1.0-beta.1
✓ directory: ./shop (4,512,332 bytes on disk)
✓ lock: free (last held by process 4123)
✓ catalog file: schema version 7, 3 table(s)
✓ recovery: recovered: users: 212 torn WAL bytes discarded; 1 aborted transaction(s) rolled back
✓ segments: 5 sealed segment(s) verified against their hashes
✓ index t1: materialised state matches replay (12304 records, 12817 events)
…

The server logs the same summary at start (database opened with wal_records_replayed, torn_tail_bytes, aborted_transactions).

When verification fails

holadb verify or doctor printing a ✗ for a segment or an index — or the server refusing to start with corruption detected in segment N — means bytes on disk do not match their hashes. Restore from a backup. The rows themselves may still be intact in the record index: holadb serve --segment-check lazy opens such a database so that they can be exported first, but a database in that state must not be kept in service. If the failure is in a persisted index only, holadb engine rebuild-index <dir> <engine-table> rebuilds it from the authoritative storage (and removes the delta files it supersedes).

After an uncertain outcome

A client told UncertainOutcome (SQLSTATE 08007) about a write: restart the server (it refuses writes until then), then compare the recovered position with the one in the message — at least as high means the write was applied (see Transactions).

Restoring to a point

With write-ahead-log archiving on (--archive), a backup plus the archive restore the database to the last archived commit or to any earlier one: holadb restore <backup> <dir> --archive <archive> [--to-position N] (Restore).

What recovery does not do

It does not undo committed transactions and it does not repair storage that fails its hashes; both need a backup.

“The directory … exists, but this database does not list a table of that name”

CREATE TABLE reports this when a directory under tables/ has the name the new table needs, the database does not list a table of that name, and the directory is not an unfinished table creation (it holds rows, segments, unreadable files, or files that are not a table’s). HolaDB never removes such a directory on its own. An unfinished creation left by a crash is removed automatically; so is the directory of a DROP TABLE that was interrupted after it took effect.

To continue: stop the server, move the named directory out of the data directory (keep it if its content may matter), start the server, and repeat the statement.