Skip to content

Recover encrypted backup containers after key-read retries are exhausted - #14668

Draft
tclinkenbeard-oai wants to merge 2 commits into
apple:mainfrom
tclinkenbeard-oai:dev/tclinkenbeard/backup-key-io-retry
Draft

tclinkenbeard-oai wants to merge 2 commits into
apple:mainfrom
tclinkenbeard-oai:dev/tclinkenbeard/backup-key-io-retry

Conversation

@tclinkenbeard-oai

Copy link
Copy Markdown
Collaborator

An encrypted backup container retains the result of loading its key file. If all attempts to read the key fail with a disk error, later writes on that container keep returning the cached error even after the file becomes readable.

Start a fresh key load when a caller encounters that disk error. Concurrent callers share the new load, a successful load pins the key for the lifetime of the container, and a permanent key error still propagates. This extends the bounded retries within a single key load introduced in #14236.

The new regression and four adjacent encryption tests passed. An encrypted backup and restore simulation also passed, with all three backup tags completing.

@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 disk holding a backup’s encryption key stops responding. The backup agent tries several times, then remembers the failure. Even after the disk recovers, reopening that backup gives the agent the same container and the same error. The next write fails without reading the key again. Container reuse, previous key lookup

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

The next write tries the key file again. If the disk is back, the write can proceed. If the disk is still down, the agent can report the problem while it tries again.

  1. The container saves the filename alongside its first key read. A later lookup starts a new read only after io_error or io_timeout. Concurrent callers share that read, and the first successfully loaded key stays with the container. Initialization, key selection, disk errors
  2. An encrypted file waits for both the underlying file and the selected key. The callback holds the same key it waited for and passes it to the file wrapper. Encrypted file creation
  3. The agent waits for the initial key result. During a later read, it reports the previous disk error as success: false. Once that read succeeds, the next status update reports success. Status lookup, agent call site, reported result

What is it trying to do?

Let a long-lived backup agent resume encrypted reads and writes after a temporary disk failure, without restarting the agent or changing keys mid-backup.

Is it correct?

Yes. The container owns the replacement read, so completing a status query early leaves that read available to file operations. The first load can still outlast a status transaction, but subsequent transactions can publish the failure immediately while the retry runs. This also covers keys belonging to finished backups. Status transaction

Are there bugs?

I found no correctness bugs. A short key file produces invalid_encryption_key_file, which stays cached. A disk failure keeps the container in encrypted mode, so opening an encrypted payload still requires a usable key. Key validation, encryption mode and retry guard

Are there omissions?

The regression starts with a cached timeout and checks immediate status, shared key identity, recovery, and propagation of an invalid-key error. It exercises the container boundary directly. I reviewed the published diff without running builds or tests during this review. Public CI was in progress at review time. Regression, checks for the reviewed commit

Are there better ways of doing things?

Keeping the retry in the container gives local and blob-store files the same behavior. The separate status lookup also keeps the agent’s transaction logic simple.

Should this CL be LGTMd?

Yes, LGTM. File operations wait for a usable key, and a persistent disk error can be reported while recovery is underway.

@foundationdb-ci

Copy link
Copy Markdown
Contributor

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

  • Commit ID: 36c90a3
  • Duration 0:48:29
  • 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: 36c90a3
  • Duration 2:00:29
  • 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: 36c90a3
  • Duration 2:19:29
  • 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: 36c90a3
  • Duration 3:00:42
  • 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: 36c90a3
  • Duration 3:00:47
  • 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-m1 on macOS

  • Commit ID: 36c90a3
  • Duration 4:11:26
  • 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: 36c90a3
  • Duration 5:25:34
  • 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