Skip to main content

WAL and Persistence

Read this page to understand what a persistent write survives after it commits, and why a node's disk use grows or shrinks over time. Kahuna has two durability layers that serve different purposes.

  • Raft WAL: the authoritative replicated operation log managed by Kommander, Kahuna's Raft library.
  • Kahuna persistence backend: materialized lock and key/value state used for fast recovery and lookup.

The WAL records committed operations in order. The persistence backend stores the latest durable object state and selected revision data.

Raft WAL​

Each persistent mutation goes through a Raft partition. The partition leader appends a log entry and replicates it to followers. Once the entry is committed, Kahuna applies it to the in-memory state machine.

The Raft WAL has these responsibilities.

  • Preserving committed operation order
  • Allowing followers to catch up
  • Restoring uncheckpointed committed logs after restart
  • Keeping committed operations through leader failover

Kahuna uses Kommander for Raft. Depending on configuration, WAL storage can use RocksDB or SQLite, or memory.

Direct Write Coalescing​

Persistent partition writes use a leader-local partition write aggregator before they enter Raft. The aggregator can combine several kinds of proposals for the same partition into one ReplicateEntries call.

  • Non-transactional SET and DELETE, and EXTEND
  • Persistent lock proposals: acquire, extend, unlock
  • Durable transaction-finalization records
  • Durable settlement records

This optimization applies across requests. A SetManyKeyValues(...) call and independent single-key writes can land in the same partition queue if they target the same partition at the same time.

The aggregator does not coalesce ephemeral writes or open transaction staging. Ephemeral writes do not use Raft, and open transactions stage write intents through the transaction coordinator. Durable transaction records enter the aggregator when finalization writes durable entries: canonical records, prepared-intent deltas, materialization records, settlement deltas. By default, committed durable values materialize by reference to the prepared intent that each replica already has.

See Partition Write Coalescing for tuning options and metrics.

Materialized State​

Kahuna's persistence backend is represented by IPersistenceBackend. It stores these kinds of state.

  • Lock entries
  • Key/value entries
  • Key/value revisions
  • Bucket/prefix lookup data
  • Checkpointed transaction recovery metadata such as completion receipts and coordinator decisions

Kahuna includes three implementations.

  • MemoryPersistenceBackend
  • RocksDbPersistenceBackend
  • SqlitePersistenceBackend

Persistent lock and key/value actors keep hot state in memory. Dirty entries are queued to BackgroundWriterActor, which writes batches to the backend.

Background Flush​

BackgroundWriterActor batches writes with limits on item count and packet size. It retries failed backend writes with jittered backoff. If a storage write fails after the retries, the dequeued batch is retained in memory and retried on the next flush cycle. It isn't dropped. The partition remains unflushed. This means that checkpoints and WAL compaction can't advance past data whose only durable copy is the Raft log.

Kahuna also bounds this unflushed backlog. PersistenceMaxUnflushedItems and PersistenceMaxUnflushedBytes cap committed key/value state that is waiting for the background writer. When either bound is exceeded, ordinary persistent writes receive retryable backpressure. Terminal durable transaction work has reserved headroom to finish recovery-sensitive decisions and settlement.

This diagram shows the flush path, from a committed mutation to WAL compaction.

Checkpoints​

Checkpoints connect materialized persistence with Raft log compaction. Once dirty state for a partition has been written, the background writer can ask Raft to replicate a checkpoint for that partition. After checkpointing, the system does not need to replay all older logs to reconstruct the same state.

--checkpoint-interval controls how often a dirty partition is allowed to checkpoint after flushes. The interval starts when the partition first becomes dirty after its last checkpoint; later writes do not keep pushing the timer forward. This means that a continuously written partition can checkpoint periodically and keep its Raft WAL compactable. A shorter interval advances the WAL retention floor sooner and can reduce retained Raft log size, but it rewrites snapshots more often. A longer interval reduces checkpoint churn but lets the WAL grow further between compaction opportunities.

Durable transaction recovery metadata participates in this ordering. Transaction records and prepared-intent snapshots must be durable before the checkpoint allows WAL retention to move past log entries that may be needed to reconstruct them. The same rule applies to completion receipts.

PITR Retention​

Point-in-time recovery retains committed WAL entries beyond the latest materialized-state checkpoint on purpose. Kahuna derives a protected log position from PitrWindow and BaseSnapshotInterval. The position is approximately now - PitrWindow - BaseSnapshotInterval, and normal compaction can't cross it.

Full backups wait for the apply barrier and flush pending materialized writes. They then create a backend checkpoint and verify artifact sizes and checksums before they publish the manifest. Incremental backups then preserve committed WAL slices after that base image. Restore opens the checkpoint, verifies artifacts at point of use, and replays key/value mutations whose transaction commit HLC is at or before the selected timestamp. For the operational model and restore constraints, see Backups and Point-in-Time Recovery.

Revision Cleanup​

Persistent revision cleanup removes historical key~revision rows only if the count and age rules allow it, and the registered snapshot holds also allow it. Cleanup after writes is targeted by key and bounded by both PersistentRevisionCleanupBatchSize and PersistentRevisionCleanupTimeBudget. This means that a revision-heavy key can't starve the background flush path. Keys not reached within the time budget stay queued for the next cycle.

Persistent vs Ephemeral​

Only persistent state goes through Raft and materializes to the backend. Ephemeral objects are stored in memory. They take part in actor routing and expiration logic as usual, but they aren't restart-safe; see Durability Levels.

Settlement Durability Floors​

Opt-in materializing settlement can derive multiple key/value rows at one Raft index. The application-durability floor remains at that index until all derived rows and required transaction-store snapshots/receipts are durable. Removed intents whose rows await flush remain in the settled-intent restart snapshot. See Durable Settlement.

Archive revisions that wait for flush are retained beyond RevisionRetention. Historical disk fallback can return MustRetry. It doesn't answer from incomplete history. Destructive pruning first confirms local system-partition application and uses the protective registered-hold floor. See Snapshot Holds.