From 448c49bd01b9bf50829fd7cdf5d0c3c319c4fc69 Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Thu, 3 Dec 2026 08:31:59 +0530 Subject: [PATCH] Align native checkpoint failure guidance with Rustdoc --- CHANGELOG.md | 2 +- docs/DURABILITY.md | 4 ++-- docs/ERROR_REFERENCE.md | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5e8424f53..718a369df8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -233,7 +233,7 @@ Known issues for v2.x are in [#421](https://github.com/project-minigraf/minigraf - **A file shorter than one page is refused at open with `STG-045` unless it is a torn first write** (#506). Open treated any file under 4 KiB as a new database, because it holds no whole page, and a read-write open wrote a new empty database over it. A database cut below one page by an interrupted copy, or an unrelated file at the path, was silently replaced. Now such a file opens as a new database only when its bytes are zeros or a prefix of the first meta page a new database writes (what a crash during creation can leave, the rule a torn full page 0 already followed); anything else is `STG-045`, read-write and read-only, and the file is not modified. A zero-length file is still a new database. New code `STG-045`. Also fixed in v2.0.5. -- **A failed checkpoint is never retried on the same handle** (#390). A checkpoint that failed after it may have written (a failed write, a full disk, a failed `fsync`) could be retried by the next checkpoint. After a failed `fsync` the operating system may have dropped the written pages, and the checkpoint's meta page may have reached the disk although the call failed; a retry could then overwrite pages that meta references, and a crash during the retry left a file that failed to read with `STG-029`. Now every later write, checkpoint and index rebuild through that handle fails with the new `STG-046`, queries keep working, and the close-time checkpoint is skipped. Reopening the database recovers everything committed: it is all in the WAL. A `rebuild_indexes()` refused with `STG-041` writes nothing and does not count as failed. A fault-injection matrix now covers EIO, torn and short writes, a full disk and failed fsyncs at every write and sync of transacts, checkpoints, the close-time checkpoint and index rebuilds. +- **A failed checkpoint is never retried on the same handle** (#390). A checkpoint that failed after it may have written (a failed write, a full disk, a failed `fsync`) could be retried by the next checkpoint. After a failed `fsync` the operating system may have dropped the written pages, and the checkpoint's meta page may have reached the disk although the call failed; a retry could then overwrite pages that meta references, and a crash during the retry left a file that failed to read with `STG-029`. Now every later write, checkpoint and index rebuild through that handle fails with the new `STG-046`, queries keep working, and the close-time checkpoint is skipped. On reopen the database reads the newest complete checkpoint and replays the WAL. An unsynced `Normal` entry may be lost on power failure; reopen and check whether the write took effect before retrying. A `rebuild_indexes()` refused with `STG-041` writes nothing and does not count as failed. A fault-injection matrix now covers EIO, torn and short writes, a full disk and failed fsyncs at every write and sync of transacts, checkpoints, the close-time checkpoint and index rebuilds. - **A commit made after a torn WAL entry is no longer lost on recovery** (#513). Recovery replays the WAL up to its first partial or damaged entry, but the writer appended after the end of the file. After a crash during an append, the next session's commits went in after the partial entry, so a second crash before any checkpoint lost them, although each had been fsynced and reported as committed. A failed append (short write, full disk, I/O error) did the same to the next commit through that handle. Opening a database for writing now cuts the WAL back to the end of its last valid entry, and syncs it, before anything is appended. After a failed append, every later write through that handle fails with the new `WAL-007` until the database is reopened or a `checkpoint()` succeeds. The transaction whose append failed is not applied; after a reopen it is either there in full (its entry reached the disk) or not at all. Affected every release since v0.5.0. Also fixed in v2.0.5. diff --git a/docs/DURABILITY.md b/docs/DURABILITY.md index f227a3a7c3..1cccf9d95e 100644 --- a/docs/DURABILITY.md +++ b/docs/DURABILITY.md @@ -179,9 +179,9 @@ A read-only open (`OpenOptions::read_only(true)`) applies the WAL in memory but When a write or sync fails (a full disk, an I/O error), the call that hit it returns the error, with the operating system's message in it. The handle then protects the file: - **A WAL write fails.** The transaction is not applied in memory. Whether it is durable is unknown: if its entry reached the disk whole, it comes back on the next open. Every later write through the handle fails with `WAL-007` until the database is reopened or a `checkpoint()` succeeds. Queries keep working. -- **A checkpoint fails** (automatic, explicit, at close, or in `rebuild_indexes()`). It is never retried on that handle, because after a failed `fsync` the kernel may have dropped the written pages while marking them clean. Every later write, checkpoint and index rebuild fails with `STG-046`; queries keep working; the close-time checkpoint is skipped. Nothing committed is lost: the WAL still holds every committed transaction, and `app.graph` holds either the previous checkpoint or the failed one complete. +- **A checkpoint fails** (automatic, explicit, at close, or in `rebuild_indexes()`). It is never retried on that handle, because after a failed `fsync` the kernel may have dropped the written pages while marking them clean. Every later write, checkpoint and index rebuild fails with `STG-046`; queries keep working; the close-time checkpoint is skipped. On reopen, the database reads the newest complete checkpoint and replays the WAL. An unsynced WAL entry in `Normal` mode may be lost if power fails. -An automatic checkpoint runs inside the write that reaches the threshold. If it fails, that `transact` or `commit()` returns the error **although its transaction is already committed**: it is in the WAL and in memory. Before you retry a write that returned an I/O error, reopen and check whether it is there. +An automatic checkpoint runs inside the write that reaches the threshold. If it fails, `transact` or `commit()` can return an error after the WAL entry was written and the facts were applied in memory. Before retrying a write that returned an I/O error, reopen the database and check whether the write took effect. To recover from either: fix the cause (free disk space, check the device and the kernel log), drop every clone of the handle, and open the database again. diff --git a/docs/ERROR_REFERENCE.md b/docs/ERROR_REFERENCE.md index f309d1c751..fbcd2e53d9 100644 --- a/docs/ERROR_REFERENCE.md +++ b/docs/ERROR_REFERENCE.md @@ -3157,7 +3157,7 @@ let mut out = LogWriter::create("memory.v2.graph", OpenOptions::new())?; **Cause**: A checkpoint (automatic, `checkpoint()`, `rebuild_indexes()`, or the one on close) failed with an I/O error after it may have written pages: a failed write, a full disk, or a failed `fsync`. After a failed `fsync` the operating system may have dropped the written pages while marking them clean, so a second `fsync` can report success for data that never reached the disk (the PostgreSQL "fsyncgate" problem). The checkpoint's meta page may also have reached the disk although the call failed; a retry would then overwrite pages that page references. So the handle never retries: every later write, checkpoint and index rebuild through it fails with STG-046. -Nothing committed is lost. Every committed transaction is still in the WAL, and the `.graph` file holds either the previous checkpoint or the failed one complete. Queries through the handle keep working. The close-time checkpoint is skipped. +For a native file database, reopening reads the newest complete checkpoint and replays the WAL. An unsynced WAL entry in `Normal` mode may be lost if power fails. Queries through the handle keep working, and closing it skips the checkpoint. In OPFS mode a failed write, short write or flush has the same failed-handle rule: later writes/checkpoints fail with STG-046 while reads and `close()` keep @@ -3182,7 +3182,7 @@ retry anything. - Fix the cause (free disk space, check the device and the kernel log), then drop every clone of the handle and open the database again. Opening picks the newest complete checkpoint and replays the WAL. - Do not copy the `.graph` file without its `.wal` while the handle is in this state. -**Scenario**: The disk fills during an automatic checkpoint, so the `transact` that triggered it fails with the I/O error (its transaction is already in the WAL and applied). The next `transact` fails with STG-046 until the database is reopened. +**Scenario**: The disk fills during an automatic checkpoint. The triggering `transact` can return an I/O error after writing the WAL entry and applying the facts in memory. The next `transact` fails with STG-046 until the database is reopened. Reopen and check whether the write took effect before retrying it. ---