Skip to content

Backport to 7.4: add retry limit to startMoveKeys to prevent infinite loops (#13176) - #13782

Merged
saintstack merged 3 commits into
apple:release-7.4from
saintstack:backport_13176
Aug 15, 2026
Merged

saintstack merged 3 commits into
apple:release-7.4from
saintstack:backport_13176

Conversation

@saintstack

@saintstack saintstack commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Add START_MOVE_KEYS_MAX_RETRIES knob (default 50, BUGGIFY=10) and throw start_move_keys_too_many_retries when exceeded. Wire the new error into DDRelocationQueue (same light-weight re-queue handler as finish_move_keys_too_many_retries and move_to_removed_server) and normalDDQueueErrors so DD does not restart. Also propagate actor_cancelled before the retry limit check in startMoveKeys.

20260724-003619-stack-backport-7.4-eac563f902694355 compressed=True data_size=41563174 duration=3238562 ended=100000 fail=5 fail_fast=10 max_runs=100000 pass=99995 priority=100 remaining=0 runtime=0:31:27 sanity=False started=100000 stopped=20260724-010746 submitted=20260724-003619 timeout=5400 username=stack-backport-7.4

The 5 failures are all 'RandomSeed="1520625388" SourceVersion="ac41ec01f6c2b74a6c1432bb75f874a9c3ab2dd2" Time="1784853672" BuggifyEnabled="0" DeterminismCheck="0" FaultInjectionEnabled="1" TestFile="tests/fast/MinimumThroughput.toml"'. I'll fix in a different PR. The failures are not related to here.

(They are fixed over in #13783)

…(PR 13176)

Add START_MOVE_KEYS_MAX_RETRIES knob (default 50, BUGGIFY=10) and throw
start_move_keys_too_many_retries when exceeded. Wire the new error into
DDRelocationQueue (same light-weight re-queue handler as
finish_move_keys_too_many_retries and move_to_removed_server) and
normalDDQueueErrors so DD does not restart. Also propagate actor_cancelled
before the retry limit check in startMoveKeys.
@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@saintstack

Copy link
Copy Markdown
Contributor Author

RandomSeed="1264945544" SourceVersion="27f7192f47c366c7f668f79f1de23e05fecd8959" Time="1786731900" BuggifyEnabled="1" DeterminismCheck="0" OldBinary="fdbserver-7.4.5" FaultInjectionEnabled="1" TestFile="tests/restarting/from_7.3.0/UpgradeAndBackupRestore-1.toml"

RandomSeed="1264945545" SourceVersion="1d9b495d6ba7f4390bba1bb4d51c38f4ed4a2055" Time="1786731930" BuggifyEnabled="1" DeterminismCheck="0" FaultInjectionEnabled="1" TestFile="tests/restarting/from_7.3.0/UpgradeAndBackupRestore-2.toml"

@saintstack saintstack closed this Aug 14, 2026
@saintstack saintstack reopened this Aug 14, 2026
@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@saintstack saintstack closed this Aug 14, 2026
@saintstack saintstack reopened this Aug 14, 2026
@saintstack saintstack closed this Aug 14, 2026
@saintstack saintstack reopened this Aug 14, 2026
@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@saintstack

Copy link
Copy Markdown
Contributor Author

20260814-231424-stack_74-839e90b192b66d53 compressed=True data_size=41591418 duration=3488173 ended=100000 fail=1 fail_fast=10 max_runs=100000 pass=99999 priority=100 remaining=0 runtime=0:32:13 sanity=False started=100000 stopped=20260814-234637 submitted=20260814-231424 timeout=5400 username=stack_74

RandomSeed="640037351" SourceVersion="52c07a3b28e2d59e276c2c72ef98dc23a969b0bb" Time="1786749351" BuggifyEnabled="1" DeterminismCheck="0" FaultInjectionEnabled="1" TestFile="tests/fast/DataLossRecovery.toml"

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@saintstack saintstack closed this Aug 15, 2026
@saintstack saintstack reopened this Aug 15, 2026
@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-clang on Linux RHEL 9

  • Commit ID: 52c07a3
  • Duration 0:43:02
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-clang-arm on Linux RHEL 9

  • Commit ID: 52c07a3
  • Duration 0:45:43
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr on Linux RHEL 9

  • Commit ID: 52c07a3
  • Duration 0:50:31
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-cluster-tests on Linux RHEL 9

  • Commit ID: 52c07a3
  • Duration 1:28:51
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)
  • Cluster Test Logs zip file of the test logs (available for 30 days)

@foundationdb-ci

This comment has been minimized.

@saintstack
saintstack merged commit a4be168 into apple:release-7.4 Aug 15, 2026
4 checks passed
@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-macos-m1 on macOS 14.x

  • Commit ID: 52c07a3
  • Duration 2:00:16
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-macos on macOS 14.x

  • Commit ID: 52c07a3
  • Duration 4:23:55
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

saintstack pushed a commit to saintstack/foundationdb that referenced this pull request Aug 24, 2026
main has buggified FINISH_MOVE_KEYS_MAX_RETRIES to 10 since apple#13176 ("Fix
finishMoveKeys infinite loop when destination servers are dead"). apple#13782
backported apple#13176 to release-7.4 on 2026-08-15 but carried only the
startMoveKeys half -- its title says as much -- so 7.4 ended up with
START_MOVE_KEYS_MAX_RETRIES buggified and FINISH_MOVE_KEYS_MAX_RETRIES
not. Restore it, in the BUGGIFY macro form release-7.4 uses rather than
main's buggify() function. The cap drops from ~4 min of cumulative
backoff to ~31s.

Separately, retryAfterPostWaitChange threw without a CODE_PROBE, so
there was no way to measure whether the give-up this branch adds is
reached at all. Probe it as rare: all three call sites need a concurrent
reassignment to land inside the waitForShardReady window, so the throw
is at least as rare as they are.

Do not read the knob change as coverage for that new give-up. Measured
in ensemble 20260822-215625 (100k, pass=100000), with the cap at 10:

  finishMove* giving up after a post-wait change                  0
  finishMoveKeys dest changed during waitForShardReady            0
  finishMoveShards dest changed during waitForShardReady          0
  finishMoveShards data move deleted during waitForShardReady     0
  finishMoveShards data move phase changed during waitForShardReady   0

It cannot reach those branches and no knob value can, because taking
them requires a concurrent reassignment inside the wait window. A later
commit forces them directly, which is what actually closes that gap.

It does not measurably help the pre-existing catch-handler give-up
either: finishMoveKeys giving up after max retries came in at 6 hits
over 100k runs and 5 over 250k, flat where run count grew 2.5x, while
the start-side equivalent scaled 27 -> 45 as expected. So those hits are
near-noise. The reason to carry this commit is parity with main, not a
demonstrated coverage gain, and it costs nothing: 250k passed clean with
it (20260823-024949).

Note for anyone tracing the history: this was expected to interact badly
with the absence of apple#13647 on release-7.4, where the catch-handler
give-up counts every error kind toward a budget it only checks on
transaction_too_old, so ten benign not_committed retries in one chunk
plus one transaction_too_old would abandon a move. Both the 100k and
250k campaigns were clean, so that did not materialise and apple#13647 is not
a prerequisite for this change.
saintstack added a commit that referenced this pull request Aug 28, 2026
…transaction (#13364) (#13642)

* Backport 0887ae6 from main to release-7.4

DD finishMoveKeys: move waitForShardReady outside transaction (#13364)
* DD finishMove*: drop the transaction across waitForShardReady

SERVER_READY_QUORUM_TIMEOUT (15s) was used inside a transaction with a
~5s lifetime (MAX_WRITE_TRANSACTION_LIFE_VERSIONS). When destination
servers were slow to respond, the wait alone consumed the txn budget,
and commits failed with transaction_too_old — retries too, cascading
into the DD pipeline stalls observed in incidents.

Restructure both finish-move functions (finishMoveKeys / finishMoveShards,
dispatched on SHARD_ENCODE_LOCATION_METADATA) into a two-transaction
pattern with the wait in between:

  Transaction 1: read keyServers / serverTags / serverList (and dataMove
                 metadata for finishMoveShards) via the new
                 readShardState() helper. Save the read version and
                 drop the transaction (tr.reset()).
  Wait:          waitForShardReady — runs OUTSIDE any transaction;
                 the 15s timeout is now safe.
  Transaction 2: re-verify via destUnchanged() (dest hasn't changed,
                 dataMove still in Running phase for finishMoveShards),
                 then commit metadata writes.

If the destination changed during the wait, the inner loop retries from
the top — same as today's behaviour on transient errors, just without
burning the txn budget on the wait itself.

Verification & retry details:

* destUnchanged() loops every sub-range, not just keyServers[0]. The
  keys-flavor (`expectedDataMoveId={}`) tolerates empty-dest entries
  whose src ⊆ expectedDest — matching the planning loop's
  `alreadyMoved = dest2.empty() && isSubset` branch, which lets sibling
  iterations of OUR move that already completed pass through. A foreign
  src on an empty-dest entry signals a different move owns the range
  and forces a retry to avoid clobbering it. The shards-flavor uses
  the dataMoveId stamp as the per-sub-range invariant.

* All retry paths (dest-changed, data-move-deleted, phase-changed, plus
  the count-mismatch else-branch in finishMoveShards) are bounded by
  FINISH_MOVE_KEYS_MAX_RETRIES and back off via finishMoveKeysBackoff().
  Without the cap the dest-changed branch could livelock; the shards-
  side count-mismatch path was previously unbounded.

* Txn 2's writes use the post-wait snapshot: keyServersValue uses
  reread.uidToTagMap; finishMoveShards introduces a postWaitDataMove
  local so the partial-complete / deleteCheckpoints / dataMoveValue
  writes reflect the fresh dataMove state.

* runPreCheck=false is set inline on each retry path. The
  partial-complete success-continue deliberately leaves runPreCheck
  alone so chunks 2..N of a multi-transaction move each get their own
  AUDIT_DATAMOVE_PRE_CHECK.

* finishMoveShards now takes finishMoveKeysParallelismLock per
  iteration (mirroring finishMoveKeys). The lock had been function-
  scoped and released mid-iteration before the wait, so retries ran
  lockless and silently exceeded MOVE_KEYS_PARALLELISM.

* taskID = TaskPriority::MoveKeys is restored on txn 2 in both functions
  (tr.reset() drops it).

* New CODE_PROBEs ("dest changed", "data move deleted",
  "phase changed") are marked probe::decoration::rare; reaching them
  requires a concurrent reassignment racing into the wait window.

* SHARD_READY_DELAY is buggified to 5.0s to exercise the slow-dest
  scenario in simulation.

Validation:

* k8s rig: 3 transaction_too_old events vs 360,289 in the prior run
  without the patch; 0 OOMs.
* Simulation (DDPipelineStall.toml, knob ON): cascade trigger
  eliminated; transaction_too_old goes to zero; residual
  TryFinishMoveShardsError events are not_committed which retry
  cleanly.

* Formatting

* DD finishMove*: make the retry budget per-KRM-chunk

finishMoveShards never reset `retries` between KRM chunks. The counter
is function-scoped and the partial-complete path commits then continues
with the count intact, so chunk count drains a budget meant to bound
"this chunk is stuck". A move split into N chunks that each hit a few
benign conflicts exhausts it while no individual chunk was struggling.

In finishMoveShards the budget is only consulted by
retryAfterPostWaitChange; the dest-not-ready path and both catch-handler
paths increment without ever throwing on it. So benign retries do
nothing but poison the budget for the post-wait-change branches, making
a late chunk abandon the whole move on the first concurrent reassignment
it sees.

finishMoveKeys already reset on successful commit, but not on
FinishMoveKeysNothingToDo, which also advances to the next chunk.

Replace the bare int with FinishMoveRetryBudget:

  attempts()            read-only; tracing and backoff
  recordRetry(max)      [[nodiscard]]; spends one attempt, reports
                        exhaustion
  recordRetryUncapped() finishMoveShards paths that retry indefinitely
  chunkCompleted()      chunk committed, or needed no work

Reset at all three chunk-advance points: finishMoveShards after a
successful commit (covers the full-complete and partial-complete exits),
finishMoveKeys after a successful commit, and finishMoveKeys on
FinishMoveKeysNothingToDo.

Adds TEST_CASE /fdbserver/MoveKeys/finishMoveRetryBudgetIsPerChunk,
pinning that N chunks each spending the full per-chunk allowance never
exhausts the budget.

Validated: 100k pass in ensembles 20260822-215625 and 20260823-000642.

* DD moveKeys: let direct callers reissue after a give-up error

finishMoveShards had no retry cap before this branch, so
finish_move_keys_too_many_retries is newly reachable from it when
SHARD_ENCODE_LOCATION_METADATA is on. Two of the four callers that drive
moveKeys() directly mishandle it:

  PhysicalShardMove              routes every non-movekeys_conflict
                                 error to tr.onError(). 1252 is not in
                                 onError's retryable set, so it rethrows
                                 out of moveShard(). This workload is by
                                 construction the shard-encode path.
  IDDTxnProcessorApiCorrectness  rethrows anything but
                                 movekeys_conflict.

DataLossRecovery already handled it. RandomMoveKeys rethrows into a
KeyRangeActorMap holding a bare Future<Void> with no waiter, so the
error is dropped rather than failing.

Hoist DataLossRecovery's local predicate to MoveKeys.actor.h as
retryableDataMoveError(), with MOVE_MAX_REISSUES, so all three workloads
share one definition instead of each carrying a copy of the switch. The
set is normalDDQueueErrors() minus movekeys_conflict (retried without
spending a reissue) and broken_promise (a genuinely dead process must
still surface). That adds start_move_keys_too_many_retries relative to
the old local set. move_to_removed_server stays excluded: a workload
that hand-picked its destinations should not silently tolerate one
disappearing.

Reachability was low before the injection added two commits later -- the
post-wait-change branches need a concurrent reassignment inside the wait
window, and these workloads hold moveKeysLock against DD.

In IDDTxnProcessorApiCorrectness a reissue re-runs the mock move after
the real one partially applied. Safe: the mock move is idempotent for
identical params and the real move converges on the same final state, so
verifyInitDataEqual() still compares like with like. The bare throw
stays ahead of every wait() in the catch block so the rethrow never
crosses an actor continuation split.

Validated: 100k pass in ensembles 20260822-215625 and 20260823-000642.

* DD finishMove*: restore the retry-cap buggify from #13176

main has buggified FINISH_MOVE_KEYS_MAX_RETRIES to 10 since #13176 ("Fix
finishMoveKeys infinite loop when destination servers are dead"). #13782
backported #13176 to release-7.4 on 2026-08-15 but carried only the
startMoveKeys half -- its title says as much -- so 7.4 ended up with
START_MOVE_KEYS_MAX_RETRIES buggified and FINISH_MOVE_KEYS_MAX_RETRIES
not. Restore it, in the BUGGIFY macro form release-7.4 uses rather than
main's buggify() function. The cap drops from ~4 min of cumulative
backoff to ~31s.

Separately, retryAfterPostWaitChange threw without a CODE_PROBE, so
there was no way to measure whether the give-up this branch adds is
reached at all. Probe it as rare: all three call sites need a concurrent
reassignment to land inside the waitForShardReady window, so the throw
is at least as rare as they are.

Do not read the knob change as coverage for that new give-up. Measured
in ensemble 20260822-215625 (100k, pass=100000), with the cap at 10:

  finishMove* giving up after a post-wait change                  0
  finishMoveKeys dest changed during waitForShardReady            0
  finishMoveShards dest changed during waitForShardReady          0
  finishMoveShards data move deleted during waitForShardReady     0
  finishMoveShards data move phase changed during waitForShardReady   0

It cannot reach those branches and no knob value can, because taking
them requires a concurrent reassignment inside the wait window. A later
commit forces them directly, which is what actually closes that gap.

It does not measurably help the pre-existing catch-handler give-up
either: finishMoveKeys giving up after max retries came in at 6 hits
over 100k runs and 5 over 250k, flat where run count grew 2.5x, while
the start-side equivalent scaled 27 -> 45 as expected. So those hits are
near-noise. The reason to carry this commit is parity with main, not a
demonstrated coverage gain, and it costs nothing: 250k passed clean with
it (20260823-024949).

Note for anyone tracing the history: this was expected to interact badly
with the absence of #13647 on release-7.4, where the catch-handler
give-up counts every error kind toward a budget it only checks on
transaction_too_old, so ten benign not_committed retries in one chunk
plus one transaction_too_old would abandon a move. Both the 100k and
250k campaigns were clean, so that did not materialise and #13647 is not
a prerequisite for this change.

* DD finishMove*: document the serverKeys read-conflict-range gap

Comments only, no behaviour change.

Moving waitForShardReady out of the committing transaction discards
txn1's read conflict ranges. With V1 = txn1's read version, V2 = txn2's,
C = txn2's commit version, only some of that coverage is replaced:

  keyServers (V1,V2]  txn2 re-reads at V2 and destUnchanged() compares.
  keyServers (V2,C]   txn2's krmGetRanges is a non-snapshot read.
  serverKeys (V2,C]   krmSetRangeCoalescing adds explicit read conflict
                      ranges.
  serverKeys (V1,V2]  nothing.

The pre-existing serverKeys coverage did not come from the keyServers
read -- finishMoveKeys never reads serverKeys -- but from
krmSetRangeCoalescing, which probes with Snapshot::True and then calls
addReadConflictRange itself; running at V1 that spanned (V1,C].

serverKeys over (V1,V2] is safe only because every writer that revokes a
server's ownership also writes keyServers for the same range in the same
transaction, so the V2 re-read sees it. That invariant held for every
writer when this was audited, but nothing stated it, so record it at the
serverKeysRange declaration and put the coverage table at the tr.reset()
where it starts to matter.

Enforcing it in the resolver rather than relying on it is a behaviour
change with its own cost (|dest| extra reads inside the transaction this
restructure exists to protect) and no test that can fail without it, so
it lands on main first.

* DD finishMove*: inject post-wait dest changes, fix two probe decorations

Ensemble 20260822-215625 (100k, pass=100000) showed the knob buggify
added in the previous commit does not reach the post-wait branches at
all:

  finishMoveKeys dest changed during waitForShardReady               0
  finishMoveShards dest changed during waitForShardReady             0
  finishMoveShards data move deleted during waitForShardReady        0
  finishMoveShards data move phase changed during waitForShardReady  0
  finishMove* giving up after a post-wait change                     0

Expected in hindsight: taking those branches requires a concurrent
reassignment to land inside the waitForShardReady window, and no knob
value makes that more likely. Lowering the cap only changes what happens
once a branch is already taken.

Force it directly instead -- destUnchanged() returns false under
BUGGIFY_WITH_PROB at 1%. That is a branch both callers already handle by
retrying the whole iteration, so it is safe to inject, and it covers
both the keys and shards flavours from one place. Probability kept low
because each hit costs a re-read plus finishMoveKeysBackoff() before the
retry.

Also drop probe::decoration::rare from both "reread keyServers boundary
shorter than planning" probes. They were marked rare on the assumption
that a concurrent split or value-size growth mid-wait is unusual; the
campaign hit them 205 and 448 times, largely because MOVE_KEYS_KRM_LIMIT
buggifies to 2. Rare probes are exempt from the missed-probe check, so
leaving the decoration on would hide a future regression that stopped
exercising them.

Verified in ensemble 20260823-000642 (100k, pass=100000):

  finishMove* injecting a post-wait dest change                   1034
  finishMoveKeys dest changed during waitForShardReady             374
  finishMoveShards dest changed during waitForShardReady           660
  finishMove* giving up after a post-wait change                     1

374 + 660 = 1034, so every injected hit propagated into a real branch
and both flavours are covered. The give-up tail is reached only
marginally -- it needs eleven injected retries inside one chunk at
p=0.01 -- but it is reached, and the campaign still passed. The data
move deleted and phase changed branches stay at zero and stay rare;
reaching those needs a real cleanUpDataMove racing the wait.

Confirmed again at 250k in ensemble 20260823-024949 (pass=250000):

  finishMove* injecting a post-wait dest change                  2183
  finishMoveKeys dest changed during waitForShardReady            821
  finishMoveShards dest changed during waitForShardReady         1362
  finishMove* giving up after a post-wait change                    3

821 + 1362 = 2183 again, so the invariant holds at 2.1x the volume, and
the give-up tail tracks run count (1 at 100k, 3 at 250k) rather than
being a one-off.

Signed-off-by: spraza, ploxiln, sbodagala
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants