Files
floci/docs
Ben Wart 4c49f23c80 feat(dynamodb): journal per-table items one record per item in wal mode (#6310)
* feat(dynamodb): journal per-table items one record per item in wal mode

With the per-table item layout, wal mode still kept the single-file
WalStorage, whose log record for any item write is the whole table and
whose compaction rewrites a snapshot of every table.

Give the partitioned item store a journal mode for wal. Each write
appends one record per changed item to dynamodb-items/journal.wal, and
compaction, on the WAL compaction interval, rewrites only the shards
changed since the last one and then empties the journal. Load replays
the journal over the shard files.

- Writes hold off compaction while they change memory and append their
  record, so the journal never drops a record whose change is not yet
  in a shard file; compaction waits until load has replayed the journal
- A change the journal cannot take is compacted into its shard at once,
  and the write fails if that fails too
- Replay stops at a torn or unreadable record, including one that
  decodes to null, and cuts it off
- A journal that cannot be emptied is reopened, so later writes are
  still appended

Part of #6293

* fix(dynamodb): journal changes to one key in the order they were applied

Changes held only the shared side of the compaction lock, so a second
write to the same item could update memory after the first and still
append its record ahead of it. Replay follows the journal, so a restart
before compaction restored the older value.

Hold a per-key lock across the in-memory update and the journal append.
Changes to different keys commute and stay concurrent.

* fix(dynamodb): stop appending to a journal after a failed write

A failed append could leave part of its record in the file while the
writer stayed open. If the fallback compaction also failed, the next
append succeeded behind the torn record, and replay cut it off with it,
losing a write the caller saw succeed.

Close the writer when a write fails, so every later change falls back to
compaction until a compaction replaces the file and reopens the journal.

* fix(dynamodb): treat a journal key that is not UTF-8 as unreadable

Replay decoded keys leniently, so corrupt key bytes became U+FFFD and
the record was applied to a different key, then kept by the next
compaction.

Decode journal strings with a strict UTF-8 decoder and end replay at a
record whose key or entry key does not decode, like any torn record.

* fix(dynamodb): fail load when the journal cannot be read

Replay logged an I/O error (or a failure to read the journal's size)
and returned normally, so load marked the store ready with records left
unapplied. The next compaction then wrote the partial state to the shard
files and emptied the journal, deleting writes that had been
acknowledged.

Replay now throws on any failure other than a torn or undecodable tail,
and load turns that into a startup failure that leaves the journal
untouched, as a failed migration does. A directory where the journal
goes still counts as holding no records.

* fix(dynamodb): fold a leftover wal journal when per-table runs in another mode

Only wal mode read journal.wal. A wal-mode run that ended without
compacting left its changes there, and a restart in persistent or
hybrid mode ignored them: they were lost, and a later return to wal
replayed them as stale changes over newer shard files.

On load in another mode, replay a non-empty journal.wal, write the
shards it changed and remove it. Fail to start, keeping the file, if a
shard cannot be written or the file cannot be removed.
2026-10-22 22:27:08 -04:00
..
2026-03-15 17:43:56 -05:00