Skip to content

Retry RangeDigest publication after the distributor regains its lock - #14700

Open
tclinkenbeard-oai wants to merge 2 commits into
apple:mainfrom
tclinkenbeard-oai:dev/tclinkenbeard/range-digest-local-retry
Open

tclinkenbeard-oai wants to merge 2 commits into
apple:mainfrom
tclinkenbeard-oai:dev/tclinkenbeard/range-digest-local-retry

Conversation

@tclinkenbeard-oai

Copy link
Copy Markdown
Collaborator

A RangeDigest audit can finish all its range tasks just as the data distributor (DD) loses the move-keys lock. The final transaction gets movekeys_conflict, and the DD drops the audit from memory while its persisted state is still Running. When data distribution is re-enabled, the same DD can reacquire the lock. It has already loaded pending audits at startup, so the original audit stays Running until the client times out.

Use the existing audit retry loop when a RangeDigest loses the lock before dispatch or while publishing the completed digest. Both points have zero outstanding range tasks. Keep the original ID reserved and wait DD_ENABLED_CHECK_DELAY between lock conflicts. A prolonged lock loss can cause repeated metadata reads, spaced one second apart by default. Other retryable errors use the audit's normal retry budget.

Before dispatch, each attempt checks the current lock and verifies that the original record is still Running and belongs to this DD. The audit rebuilds the digest and counts from persisted range progress. A retry checks that it still owns the in-memory entry before replacing it, so cancellation can retire the audit during the wait. On exit, the DD detaches its RangeDigest entries and cancels their actors.

Regression coverage

RangeDigestLockRecovery uses a simulated cluster to order the client's setDDMode transaction, the DD's lock acquisition and the audit's final write. It pauses publication after the root is computed and exercises rejection of the stale write both before and after the same DD reacquires the lock. It also injects one operation_failed during a metadata read on retry.

The test reads the original audit ID, checks its owner and compares the persisted digest, key count and byte count with an independent scan. It also checks that a duplicate launch returns the pending ID and that a cancelled record stays Failed after a later audit completes.

Validation

With only the regression fixture applied, seed 862407215 found the original audit still Running 121 simulated seconds after the same DD regained the lock. On 0bc213aa223d, that seed and 12 additional seeds passed all three cases. The traces showed one successful publication per completed audit and no repeated storage tasks. RangeDigestValidation and the native and simulated /DataDistribution/Audit/ unit checks also passed.

The directed fixture keeps connections stable and disables random faults so the same DD can exercise both lock orderings. The new lock retry applies only to RangeDigest when no child work is outstanding. Conflicts during active range work and failures to persist an error remain outside its scope.

A distributor can regain the move-keys lock without rerunning audit initialization. Retain the reservation and retry the original audit under the current lock at boundaries with no outstanding child tasks. Reuse the audit's normal error handling and cancel its core when the distributor exits. Exercise both lock orderings, cancellation and a failed metadata read.
@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.

@tclinkenbeard-oai tclinkenbeard-oai left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generated by Codex.

What problem is this PR trying to solve? (ELI10)

Imagine the storage servers have finished making a fingerprint of the database. Just before the data distributor saves the result, someone pauses data distribution. That takes away the distributor’s permission to write. The write fails, and the distributor forgets the job even though its saved status still says Running. If the same distributor gets permission back, it skips the startup step that loads unfinished jobs. Anyone waiting on that audit ID can time out. Old conflict handler · One-time audit initialization

How does this PR solve the problem? (ELI10 and review walkthrough)

The distributor keeps the job number while it waits. Once it has permission again, it uses the saved pieces of the fingerprint to finish the original job.

  1. A lock conflict qualifies for this retry before any range work starts or when the finished fingerprint is ready to publish. The distributor resets the tentative result in memory, keeps the ID reserved during the delay, and checks that the same job still occupies the slot before starting another attempt. Lock conflicts at these two points leave the ordinary retry budget intact. Retry conditions and budget · Reset and restart
  2. The next attempt reads the lock and the saved audit together. The record must still be Running and belong to this distributor. After the read returns, the distributor checks that its local job and lock are still current before sending work. Check the saved record · Check ownership after the wait
  3. Completed ranges are skipped during dispatch. The distributor checks coverage, rebuilds the fingerprint and both counts, then writes Complete and clears the saved pieces in one transaction. A rejected write therefore leaves the pieces available for another attempt. Skip completed ranges · Rebuild the result · Commit under the lock

What is it trying to do?

Let a RangeDigest audit survive lock loss at either end of its range work without requiring a new distributor or a second client request.

Is it correct?

Yes. The regression forces the stale write both before and after the same distributor reacquires the lock. It checks the original ID and owner, compares the fingerprint and counts against an independent scan, and verifies that a duplicate launch returns the pending ID. The cancellation case checks that the cancelled record still says Failed after a later audit succeeds. Order the conflict and reacquisition · Check the original result · Recheck cancellation

I reviewed the code and public CI without running builds or tests. The sole failing check is unrelated. The PR Builder log reports a Go data race on restoreDelay between Kubernetes monitor test cleanup and its file watcher. PR Builder report and log

Are there bugs?

I found no correctness bug in the retry. A prolonged pause keeps the audit slot occupied and can cost a lock read per retry interval. Cancellation can release the slot, and distributor shutdown detaches the entries before cancelling their actors. Client cancellation · Distributor shutdown

Are there omissions?

The fixture exercises recovery by the same distributor. Shutdown during the retry delay is covered by code inspection only. The fingerprint still requires quiescent data throughout the audit, including the pause. Quiescence requirement

Are there better ways of doing things?

Reusing the existing audit loop keeps ownership checks, range recovery, and publication on one path. I’d keep that design.

Should this CL be LGTMd?

Yes, LGTM.

@tclinkenbeard-oai
tclinkenbeard-oai marked this pull request as ready for review December 2, 2026 20:12
@foundationdb-ci

Copy link
Copy Markdown
Contributor

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

  • Commit ID: c4ee54c
  • Duration 0:47:59
  • 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-ide on Linux RHEL 9

  • Commit ID: c4ee54c
  • Duration 2:00:38
  • Result: ❌ FAILED
  • Error: Build has timed out.
  • 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: c4ee54c
  • Duration 3:00:41
  • Result: ❌ FAILED
  • Error: Build has timed out.
  • 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 on Linux RHEL 9

  • Commit ID: c4ee54c
  • Duration 3:00:53
  • Result: ❌ FAILED
  • Error: Build has timed out.
  • 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

  • Commit ID: c4ee54c
  • Duration 4:11:06
  • Result: ❌ FAILED
  • Error: `Error while executing command: # compatible with bash and zsh
    ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ${HOME}/.ssh_key
    -o ServerAliveInterval=9 ec2-user@${MAC_EC2_HOST} "
    set -e -o noclobber
    BUILDNUM=${CODEBUILD_BUILD_NUMBER}
    WAIT_TIME=14400 # 4 hours
    LOCK_STALE=4500 # 75 minutes
    LOCK=/tmp/ci.lock
    "'

macOS stat flags, not linux compatible

lock_mtime() { stat -f %m $LOCK || echo 0 }
I=0
while ! (echo $BUILDNUM >$LOCK) 2>/dev/null ; do
if (( ++I >= WAIT_TIME )); then
echo "timeout waiting for ci.lock after $I seconds"
exit 3
fi
if (( $(date +%s) - $(lock_mtime) >= LOCK_STALE )); then
echo "lock expired after $LOCK_STALE seconds ..."
# racy but sleep so chances are low
sleep $(( 3 + RANDOM % 8 ))
if (( $(date +%s) - $(lock_mtime) >= LOCK_STALE )); then
echo "lock holder is gone"
rm -f $LOCK
else
echo "new lock holder"
fi
fi
sleep 1
done
echo "acquired ci.lock"
'
. Reason: exit status 3`

  • 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-m1 on macOS

  • Commit ID: c4ee54c
  • Duration 4:11:39
  • Result: ❌ FAILED
  • Error: `Error while executing command: # compatible with bash and zsh
    ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ${HOME}/.ssh_key
    -o ServerAliveInterval=9 ec2-user@${MAC_EC2_HOST} "
    set -e -o noclobber
    BUILDNUM=${CODEBUILD_BUILD_NUMBER}
    WAIT_TIME=14400 # 4 hours
    LOCK_STALE=4500 # 75 minutes
    LOCK=/tmp/ci.lock
    "'

macOS stat flags, not linux compatible

lock_mtime() { stat -f %m $LOCK || echo 0 }
I=0
while ! (echo $BUILDNUM >$LOCK) 2>/dev/null ; do
if (( ++I >= WAIT_TIME )); then
echo "timeout waiting for ci.lock after $I seconds"
exit 3
fi
if (( $(date +%s) - $(lock_mtime) >= LOCK_STALE )); then
echo "lock expired after $LOCK_STALE seconds ..."
# racy but sleep so chances are low
sleep $(( 3 + RANDOM % 8 ))
if (( $(date +%s) - $(lock_mtime) >= LOCK_STALE )); then
echo "lock holder is gone"
rm -f $LOCK
else
echo "new lock holder"
fi
fi
sleep 1
done
echo "acquired ci.lock"
'
. Reason: exit status 3`

  • 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: c4ee54c
  • Duration 5:39:21
  • 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)

This branch has not been deployed

No deployments
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.

2 participants