Skip to main content

Durable Transaction Settlement

A persistent transaction can be committed before all of its values have been copied into the normal key/value store. This is possible because Kahuna records the proposed values and an authoritative commit decision separately. Reads can use that decision to find committed values while the remaining work finishes. This means that commit doesn't have to wait for that work.

That remaining work is called settlement. This page explains what it does, why it can run after commit returns, and how Kahuna preserves enough state to recover from a failure. If transaction coordinators and participants are new to you, start with Transaction Lifecycle.

Basic Concepts​

TermMeaning in this page
ParticipantA partition that contains keys modified by the transaction. A transaction can have several participants.
Prepared intentA replicated record containing a proposed key change and its transaction identity. It preserves the value while the participant waits for the transaction's decision. Preparation alone does not mean commit.
Canonical decisionThe authoritative transaction record. It changes from Undecided to Commit or Abort; participants follow that outcome.
MaterializationInstalling the change of a committed intent into the normal key/value projection, for example a value or a deletion. A projection is the state used to serve ordinary key/value operations.
SettlementFinishing participant work from the decision and removing prepared intents. On commit, the values must be installed before their intents are removed. On abort, the proposed changes are discarded.
Replica and Raft logA replica stores a partition's replicated state. Raft orders the records that replicas apply. A log index identifies a position in that ordered history.
WALWrite-ahead log: stored records that can be replayed to reconstruct state. Process-loss durability requires persistent WAL storage and durable write settings.
Backend flushWriting materialized rows to the configured storage backend. Applying a change in memory and flushing it are separate events.
Commit HLCThe transaction's commit timestamp, expressed as a Hybrid Logical Clock value. It determines historical visibility; settlement can happen later.
Completion receiptMetadata proving that a participant already applied a committed change, useful when work is retried or recovered.
PITRPoint-in-time recovery: restoring a backup and replaying history up to a chosen time.

There are three distinct milestones.

  1. The transaction commits.
  2. Its values are materialized.
  3. The resulting rows are flushed.

Commit doesn't wait for all backend rows to be flushed. Recovery relies on the replicated log and transaction metadata until those rows are durable.

Walk Through a Committed Transaction​

Suppose a persistent transaction changes Alice's balance from 100 to 90 and Bob's from 50 to 60. Both participants prepare their proposed values, then the coordinator establishes the canonical Commit decision.

MomentWhere the new values areWhat it means for the caller
Prepared, and UndecidedIn replicated prepared intents.They are proposed changes. The caller cannot treat preparation as a successful commit.
Canonical decision is CommitThey can be in prepared intents.The persistent transaction has committed. Reads that encounter those intents resolve the decision to determine visibility.
Materialized and settledIn the normal key/value projection; prepared intents have been removed.The same committed changes can now be served, and the pending intents aren't needed.
Backend rows flushedIn durable backend rows, with the required recovery metadata persisted.The application-durability floor can advance past the corresponding log work when all of its requirements are satisfied.

With the default deferred settlement, the commit call can return at the second row. A read does not return Alice's old balance merely because background settlement has not finished. It resolves the committed intent, locally or through the leader holding the canonical record.

An undecided intent requires a wait or a retryable result. Its outcome isn't guessed. A later direct write can also supersede a lingering intent: a strictly newer revision does so, and a same-revision extend does so when its modification timestamp is later than the intent's commit HLC and visible to the requested snapshot. See Transaction Reads and Locks for those visibility rules.

This shows the logical order. The installation and removal records differ between the default and opt-in paths described below. Backend flushing is asynchronous and can already be in progress during settlement.

Choosing Settlement Behavior​

Two independent choices control settlement: when the finalizer waits for it, and how replicas install the values. A finalizer is the server code driving commit or rollback to its outcome.

SettingDefaultWhat it controls
DurableDeferredSettlementtrueCommit can return after the canonical decision is durable, and settlement continues in the background. false waits for settlement before it returns success. It doesn't mean that all backend rows are flushed.
DurableMaterializeOnResolvefalseUse separate materialization records. true installs values while applying the settlement record, before removing intents.
DurableMaterializeByReferencetrueWith separate materialization records, identify the prepared intent. Its value bytes aren't copied into another record. false uses value-carrying records. The setting doesn't have an effect when DurableMaterializeOnResolve is enabled.

These settings are available on KahunaConfiguration and EmbeddedKahunaOptions. Kahuna.Server currently exposes none of these three settings as command-line options. They do not select a storage backend or make an in-memory embedded host survive process loss; configure persistent storage and WAL separately.

For an application using the defaults, settlement requires no client-side value replay. After a successful commit, don't rerun the business changes only because settlement is pending. If finalization returns MustRetry, resolve the same transaction identity. Don't assume that it rolled back. See the outcome guidance.

Materialization records (default)​

With DurableMaterializeOnResolve = false, committed participant work is installed with separate records.

  1. The canonical decision establishes commit.
  2. The finalizer proposes one key/value materialization record per modified key.
  3. Replicas apply those records to install the committed values.
  4. The finalizer submits a settlement delta to finish participant work and remove the intents.

A delta is a record that describes changes to replicated state. It isn't a complete copy of that state. If materialization fails, the intent remains available for recovery; Kahuna does not remove the only durable copy of the proposed value first.

By default, each MaterializeIntent record names the prepared intent, and it doesn't repeat the value bytes. Each replica gets the value from its local prepared-intent store. This is by-reference materialization. The reference points to replicated transaction state. It doesn't point to a value that the client supplies later.

Setting DurableMaterializeByReference = false produces value-carrying materialization records instead. Both encodings are supported by normal application of new log records and by WAL replay after restart. By-reference records avoid copying the value through another log entry; that entry reduction alone does not establish a latency or throughput guarantee. PITR reconstructs by-reference mutations from prepares in the replayed history.

Compatibility details​

For compatibility with older logs, logged key/value type 30 is also decoded as by-reference materialization. The actor-only DropLeaderState message isn't logged, despite sharing that value in an older build.

Materialization at settlement apply (opt-in)​

DurableMaterializeOnResolve = true moves installation into the application of the settlement record. Apply means a replica consumes a committed log record at its position in the ordered history.

For example, these options enable that path in an embedded host.

var options = new EmbeddedKahunaOptions
{
DurableMaterializeOnResolve = true,
DurableDeferredSettlement = true
};

This example shows only the settlement settings. Configure persistent backend and WAL options separately if the host must recover after process loss, and follow the rolling-upgrade requirements before enabling the new encoding on a cluster.

With this option enabled, settlement has these steps.

  1. The canonical decision establishes commit first, as usual.
  2. No separate per-key materialization record is proposed.
  3. The settlement delta carries commit-resolve commands with MaterializeOnResolve and the commit HLC, followed by intent removals.
  4. Each replica installs values from its local prepared intents before applying their removals.

A resolve command tells a participant to finish an intent according to the transaction's decision. The finalizer and participant recovery use the same settlement builder. DurableMaterializeByReference doesn't have an effect on this path, because separate materialization records aren't used.

This saves per-key materialization entries. It preserves prepare and decision work, and does not combine unrelated transactions into one atomic operation. DurableDeferredSettlement controls separately whether commit waits for settlement.

Relationship to the one-phase fast path​

An eligible transaction can bundle preparation and its commit decision into a one-phase proposal. Materializing settlement remains a later operation: it is submitted only after canonical commit is established and the abort fence passes. The abort fence is the check guarding settlement against proceeding with an abort outcome.

With this separation, PITR can replay materializing settlement, and it doesn't need to reconstruct the apply-time validation gate of the earlier one-phase decision. A leader may install a value locally before settlement as a best-effort head start, but that local shortcut is not required for the replicated materializing settlement to proceed.

Durability, replay and recovery​

Replay after a range move​

A node can catch up the source and destination partition logs in a different order. Settlement records the (transaction ID, epoch, key) identity even when the local intent is absent. A later prepare checks settled identities across the node's partition slices and is rejected as a settled replay while that identity is retained. The staged-base fence compares against the log slice that first carried the prepare. It doesn't treat a newer destination seed as the earlier state of the source log. These checks prevent replay from recreating a settled intent when a key moves between prepare and settlement.

Keeping the log until derived rows are durable​

One materializing settlement record can produce several backend rows at the same Raft log index, plus completion receipts. A flush of one of those rows isn't enough, because the others can need the log for recovery.

The application-durability floor tracks which applied log work must remain available because its resulting state is not yet durable. It protects that index until all derived rows are flushed and the required store snapshots, including receipts, are durable. Removing intents in memory alone does not permit WAL retention to advance past that work.

A settled intent whose row waits for flush is retained for restart replay and included in the durable intent snapshot. This retained recovery copy is distinct from the live prepared intent that settlement removed.

What happens after a failure or duplicate attempt​

SituationRecovery behavior
Crash after canonical commit, before settlementThe committed prepared intents remain for the recovery sweep to install and settle. The crash does not turn the commit into an abort.
Rows installed, but not yet flushedRetained settled intents and protected log history provide reconstruction state until the durability requirements are met.
Settlement is applied againLive apply does not install an already removed intent again. Restart replay can reconstruct from retained settled intents while their rows are not yet durable.
Replica receives a whole-partition snapshotThe transfer includes intent state needed for subsequent materializing settlement.

Settlement is idempotent: repeating it for the same intent does not create a new transaction or independently apply the business operation again. This does not authorize the client to repeat its transaction body with a new identity after an unknown commit result.

Point-in-time recovery​

PITR expands a materializing resolve using its replayed prepare or the full backup's verified intent_frontier.pb. Recognized duplicate references after settlement are skipped; missing unknown sources fail restore closed. See Prepared-Intent Frontier. It filters the resulting row by the transaction's commit HLC. It doesn't use the time when settlement happened. For example, if a transaction commits before the restore target and settles afterward, settlement's later execution time does not change the committed value's logical timestamp.

A recent duplicate settlement is tolerated. If a materializing resolve has neither a replayed prepare nor recognized duplicate history, restore fails closed. It returns a failure, and a committed value isn't omitted silently. See Backups and Point-in-Time Recovery for backup cuts and restore constraints.

Rolling upgrades​

A producer is a node writing an encoding into the log; a reader is a replica or recovery tool applying that encoding. All readers must understand it before any producer enables it.

ChangeDuring the rolloutAfter all readers support the encoding
Upgrade from builds that don't support by-reference materializationSet DurableMaterializeByReference = false so producers keep writing value-carrying materialization records.Enable by-reference materialization if desired.
Enable materializing settlementKeep DurableMaterializeOnResolve = false.Enable it only after all replicas and relevant replay/restore tooling support materializing resolves.

An older node can interpret a materializing resolve as ordinary settlement. It then removes the intent, and it doesn't install the value. That causes silent data loss on that replica. This is why enabling the producer option must come after upgrading the readers.

Turning either producer option off is safe for nodes that support both encodings; existing records remain readable. It does not rewrite log history. Once new records have been written, disabling the option does not make a downgrade to an older reader safe.

Observing Settlement​

kahuna.kv.write.stage_entries{stage} counts dispatched log entries by the stage that produced them. Use it to distinguish materialization entries from the entries of the other stages.

When materialization-on-resolve is enabled, separate materialization entries can disappear while settlement entries remain. Compare this with the write-coalescing metrics; fewer entries alone are not proof of lower latency or higher throughput.

For the overall transaction flow, continue with Transaction Lifecycle. For visibility while settlement is pending, use Transaction Reads and Locks.

Restart Replay and Missing-Value Alarms​

This section is for contributors and operators investigating a missing-value alarm.

A prepared-intent snapshot records the applied position certified before its walk and the position reflected by its end. Restart replay treats entries already represented by that slice as history: an old prepare must not become a new live key holder simply because its original competing intent has since settled.

Historical prepares are kept temporarily as value sources for later by-reference records and materializing resolves. They are invisible to reads and conflict checks; removals discard them and restore completion clears the remaining history sources. Replay looks for the named value in live intents and replay history, and in retained settled intents. Before reporting a miss, it checks pending writes and backend state in newest-head order; a key that now belongs to another partition is accounted for separately.

Retained settled intents are released when the key's newest queued head is flushed. A stored row with the same revision isn't enough. An expiry change or a later mutation can share a revision. In this case, an intermediate flush must not remove the only remaining replay source while newer work for that key is pending.

A verified unresolved by-reference materialization is a missing committed value on this replica. During live apply, the first proven absence of both the named intent and sufficient local row state triggers containment. During restart, unresolved replay results gate the partition before it can campaign. Local requests return MustRetry and candidacy is withheld. Snapshot reseeding is then requested. Installation replaces the projection and clears the gate. This detects missing reconstruction sources. It doesn't detect arbitrary corruption with matching revisions.

MetricMeaning
kahuna.kv.materialization_intent_missingBy-reference materialization anomalies; should remain zero. Errors include the transaction identity and key, with the revision and log index.
kahuna.kv.restore_by_reference_unresolvedVerified unresolved materializations during restart; should remain zero.
kahuna.kv.restore_by_reference_resolvedReplay resolutions by source: live, history, retained, durable.

The two alarm counters are published at zero when partition restore finishes. This means that a healthy restore can produce an explicit zero series. Partitions that replayed materializations emit a Warning-level summary even when clean. An unresolved summary includes the count and the distinct keys, with the log-index range. Investigate nonzero alarms and the associated containment/reseed messages; a Warning summary with zero unresolved records is not itself evidence of data loss.