# A failed LevelDB write can reappear after reopening

## Result and boundary

On 2026-11-30, Hesela ran LevelDB 1.23 with a WAL-only wrapper around its default
POSIX Env. Once armed, the wrapper called the real backend Sync, required its
success, then returned an injected IOError to LevelDB. This changes an
acknowledgment, not the stored bytes or the result of the real synchronization.

The attempted key update returned an error. The still-open database returned
the old value and rejected a subsequent write. Ordinary close/reopen recovered
the first update; the rejected later key was absent. The synchronous control
and the armed asynchronous control succeeded. In the asynchronous control the
fault was not reached.

All three cases agreed in two builds of the probe, with and without NDEBUG.
The linked engine was the same Release build. Checks use explicit conditions,
not assert macros that disappear with NDEBUG. These are deterministic cases,
not six independent samples of hardware behavior.

## Reproduce

Prerequisites: a C++17 compiler, CMake, Node.js, curl and tar. No root, mounts,
device writes, kernel changes or service installation are needed. The probe
creates a unique temporary subdirectory below the supplied output directory
and removes only that owned database tree after success.

Fetch the upstream source at this exact commit:

https://codeload.github.com/google/leveldb/tar.gz/99b3c03b3284f5886f9ef9a4ef703d57373e61be

Expected archive SHA-256:
bc87b9bbc5674c91246a89813355e78401759761342cc049e1c3d56350a8a9d1

Place run.mjs and probe.cc together. Extract the verified archive and run:

    node run.mjs /absolute/path/to/leveldb-99b3c03b3284f5886f9ef9a4ef703d57373e61be /absolute/path/to/output

The runner disables upstream tests, benchmarks, installation and optional
compression/checksum/allocator libraries. It builds the engine with two jobs,
compiles both probes and compares their actual observations. results.json
records versions, source-file hashes, the environment and all case outcomes.
Raw probe output and compile logs are retained in the output directory.

Upstream LevelDB is BSD-3-Clause licensed; its LICENSE hash is recorded.
This package contains the Hesela fixture, not a redistributed engine binary.
manifest.json binds the published fixture and result bytes.

## Interpretation

The implementation at db/db_impl.cc, DBImpl::Write, appends a log record before
Sync and inserts it into the memtable only after success. On a Sync error it
records a background error, preventing further writes. Its own comment states
that the log record may or may not be recovered on reopening.

The fixture demonstrates the recovered-record outcome. It does not model
a backend sync failure, loss of the record, an interrupted close, a process crash,
a power cut, a failing physical device or partial WAL corruption. It is not a
durability benchmark. The asynchronous case includes a later successful
synchronous write and normal close; its recovery is not evidence of power-loss
safety for asynchronous writes. Do not infer probabilities from the case count.
Application-specific reconciliation and safe retry design remain separate.

## Primary research context

Pillai, Chidambaram, Alagappan, Al-Kiswany, Arpaci-Dusseau and Arpaci-Dusseau,
All File Systems Are Not Created Equal: On the Complexity of Crafting
Crash-Consistent Applications, OSDI 2014, pp. 433-448:
https://www.usenix.org/conference/osdi14/technical-sessions/presentation/pillai

Sections 3.1 and 3.6 describe workload-specific checkers and incomplete coverage.
Section 4 investigates LevelDB 1.10 and 1.15, not 1.23. ALICE constructs crash
states under persistence models; this fixture only changes a Sync acknowledgment
and closes normally. It is not an ALICE reproduction or a test of whether
those historical vulnerabilities remain in current releases.

Pinned implementation:
https://github.com/google/leveldb/blob/99b3c03b3284f5886f9ef9a4ef703d57373e61be/db/db_impl.cc

Pinned environment API:
https://github.com/google/leveldb/blob/99b3c03b3284f5886f9ef9a4ef703d57373e61be/include/leveldb/env.h

Related analysis:
https://hesela.com/analyses/rocksdb-wal-flush-manifest-boundaries/#leveldb-sync-ack
