Skip to content

A guard protects only a commit that conflicts on it

An extra write record or a lease epoch stops a bad commit only if it is a conflict dependency of that commit. That means a normal read in the same transaction, or an explicit read-conflict key. In fdyno's TLA+ models and simulator, three variants lacked that dependency. The first let a retry apply an increment twice. The second let a late original commit delete another client's write. The third let a worker commit after its lease was taken over.

Update: extra write records removed

An extra write record was the record that builds before cdb6320c wrote for every write request. Later builds, including v0.1, write none. After an unknown commit, fdyno retries only a tokened transaction; every other write returns HTTP 500 transaction outcome may be unknown (fdyno's own retries). The extra write record results below describe the builds that had them.

Scope

These are results from models and a simulator, not from a production cluster. A bounded TLA+ model checks every reachable state of a small protocol; it does not run the binary. The simulator runs fdyno's real Go handlers and retry loop against a modeled FoundationDB client. It does not run the C client, the network or disks. The three write schedules below each need a proposed or deliberately broken variant; none is shipped behavior. The restore-window case at the end is different: a real bug in accepting restores that a native run reproduced, now fixed.

Why the guard must be a conflict dependency

FoundationDB uses optimistic concurrency control. A transaction reads at one read version. At commit, FoundationDB compares the keys and ranges this transaction read with the keys that other transactions wrote after that read version. If they overlap, the commit is rejected; fdyno retries at a newer version while the request's context and budget allow.

So the commit check covers only this transaction's own read-conflict ranges. A normal read adds one. A transaction can also add one explicitly, without reading the value (which reads are conflict-checked). The check does not cover a value read in an earlier transaction or a snapshot read. It also does not cover a decision the client made from a lost reply.

Where the guard is What the commit check does
In T's read-conflict ranges A write to the guard after T's read version rejects T.
Read as a snapshot in T No conflict on the guard; T may commit anyway.
Read in an earlier transaction T0 No conflict on the guard; T0's read proves nothing about T.

A retry without an extra write record applies twice

The rule. One API request applies its effect at most once, across all of fdyno's internal attempts.

The extra write record model checked a proposal: skip the extra write record for simple writes. These had no condition, no returned values, no index, no stream and no TTL. The model found this schedule:

  1. The first attempt of SET n = n + 1 reads n = 0.
  2. It commits n = 1, but FoundationDB returns commit_unknown_result.
  3. The retry has no record of the first attempt. It reads n = 1 and commits n = 2.

Each transaction is valid, and their order is serializable. The API operation is wrong: one request, two increments. The database cannot see this, because the error is in how one request maps to two transactions.

The proposal was rejected. Those builds wrote the extra write record in the same transaction as the effect. A retry read the extra write record first; if the earlier attempt committed, it returned the stored result instead of writing again. Cleanup also had to keep the extra write record until the request could no longer retry. The extra write record covered one HTTP request; a new HTTP request, including an SDK resend, got a new one.

Step-through: a lost commit reply (commit_unknown_result), a conflict, and a write without an extra write record, inside one HTTP request.

A late original commit deletes another write

On builds before cdb6320c: an extra write record that the retry reads is not enough if the original attempt is still in flight. A commit has three events that need not happen at the same time: the submission, the effect in the database, and the reply. The simulator separates them.

In the late-original matrix, the harness freezes a submitted attempt, returns commit_unknown_result, and lets the retry commit. An independent writer then commits. Only then does the frozen original resolve.

A frozen original commit after commit_unknown_result. The retry commits first; an independent writer commits next; then the frozen original resolves. With the fast path's extra write record read conflict it is rejected. In the control with that conflict dropped and no native barrier, it applies a second time and removes the other writer's value.

An attempt that reads the item conflicts through that read. A blind write on the fast path reads no item. So before it writes its extra write record, it adds a read conflict on that record's key. The retry committed that extra write record, so FoundationDB rejects the original. The control drops that one read conflict and also assumes no native conflict barrier. Then, in this control, a frozen REMOVE applies a second time, after the other writer, and removes that writer's value.

Two limits apply. One set of cases models the pinned native client's conflict barrier before an unknown result. With that barrier, the attempt's own conflict protects the control. The control removes the barrier on purpose. Its failure is an assumption control, not evidence that the native client behaves that way.

An expired lease is not a write fence

The rule. No worker write commits after another process takes over the lease for that pass.

In the lease model, a worker starts a transaction and reads its lease epoch. It pauses. A peer takes over and writes a new epoch. The old worker wakes and submits its prepared mutations, which can touch keys the peer never touched.

If the epoch read is a snapshot read, the old worker's commit succeeds. The old epoch was valid at its read version, and the snapshot read recorded no conflict. If the epoch read is a normal read in the worker's own transaction, the takeover writes into its read-conflict range, and FoundationDB rejects the commit. The retry sees the new epoch and stops. Reading the epoch in an earlier transaction would not protect this commit.

A worker reads its lease epoch, prepares work on one key, and pauses. A peer takes over, writes a new epoch and works on another key. With a snapshot epoch read, the old worker's commit succeeds after the takeover. With a serializable read, the takeover conflicts with it and the commit is rejected.

The lease decides when a peer may start. The epoch read decides what the old owner can still commit. fdyno uses the normal read.

The model found that a change to a snapshot read would pass every lease test. Each test's takeover touched the same keys as the old holder's write. The model let the keys be independent. Source pattern checks now catch that change. No stale write in a deployed cluster is reported here.

This case is not a conflict. The restore-window preflight read the table metadata at one snapshot but omitted the retained-history floor. The PITR window model found it. The advertised earliest restore time was max(enable time, now - period). After the trimmer removed old history and an operator then raised the period, that formula advertised history that no longer existed. A native diagnostic reproduced it: restore failed only after copying, and export accepted the missing interval.

The window now also takes the retained-history floor, read with the table metadata at one read version. Restore and export reject a cut below that floor before they create a job; a cut exactly at the floor is valid. The preflight does not pin history: a later trim or PITR setting change can still fail the job, and existing checks catch that.

How the checks were made to find these

Each case needed a check that could see it. Three methods did the work.

A model with free choices. The lease tests passed the snapshot variant because their schedules were too kind. The model let a peer touch different keys and let the old owner pause at any point. A bounded model check then explores every order within its bounds.

Separate submission, effect and reply. A test that delivers a commit's reply at the same step as its effect cannot produce a late original. The simulator chooses when each modeled callback fires. Seeds choose requests, faults and callback order, so a failing schedule replays exactly.

An oracle that does not share the code, and controls that must fail. The oracle computes the expected items and responses without fdyno's mutation code. An increment is a good probe: two applications leave a different value from one, even when both replies look correct. Each of these checks has a broken variant that must fail. The models have the proposal without an extra write record and the snapshot epoch read (model inventory). The late-original matrix has the dropped extra write record conflict. In the simulator's worker scene, the stale-fence control skips the worker's epoch and owner checks, and the stale-worker check must then fail (worker scene). A control proves that the check can tell the failure apart. It does not claim that the passing binary has the bug.

What this does not show

  • A bounded model is exact only within its bounds. The extra write record model does not cover more than one late original, resends across HTTP requests without a token, or BatchWriteItem chunks (not covered).
  • The simulator schedules modeled I/O boundaries, not every Go instruction or native callback.
  • None of the three cases is a stale or duplicate write observed on a deployed cluster. The restore-window case above is the one that a native run reproduced.

What to do with this

Make every guard a conflict dependency of the commit it guards: the idempotency record, the lease or epoch, the version you check. Read it with a normal read in that transaction, or add an explicit read-conflict key. A guard read in an earlier transaction, or as a snapshot, is advice, not a fence. Then test it with a schedule where the reply arrives late and the owner changes in between. Keep a broken variant that the test must catch.