Repository navigation
Design changes to pass encryption_block_size to fdbbackup command and remove knob - #13126
Conversation
Result of foundationdb-pr-clang-73 on Linux RHEL 9
|
Result of foundationdb-pr-73 on Linux RHEL 9
|
Result of foundationdb-pr-cluster-tests-73 on Linux RHEL 9
|
saintstack
left a comment
There was a problem hiding this comment.
LGTM.
Asked my 'friend'. They had following comments that might be of help....
A) IBackupContainer::openContainer cache key does not include encryption settings (potential hazard)
In fdbclient/BackupContainer.actor.cpp, openContainer(url, proxy, encryptionKeyFileName, encryptionBlockSize) still caches by url only (except you added a simulation-only skip-cache for file://).
That means in production, two callers opening the same URL with different encryptionBlockSize (or different key file) could reuse a cached container instance with stale settings.
You partially mitigated this later by:
explicitly calling bc->setEncryptionBlockSize(desc.encryptionBlockSize) in restore if encrypted, because cached container may have blockSize=0
That helps for restore, but it doesn’t fully address the general caching semantic: the cached object can carry the wrong encryption configuration.
Suggested fix (important):
Either include (url, encryptionKeyFileName, encryptionBlockSize) in the cache key, or
Make openContainer always “normalize” container state by setting block size/key file on return (careful: key material + setup futures), or
Remove caching for encrypted containers (at least when encryption params differ), not just file:// in simulation.
B) Writing encryption metadata: filename reuse + compatibility
You changed BackupContainerFileSystem::encryptionMetadataFileName() to return:
"properties/file_level_encryption"
But historically, that path (and the fileLevelEncryption() property) appears to have been used as a VersionProperty (numeric). Now you’re writing JSON into the same file.
This is likely intentional (and matches the PR’s “design change”), but it’s a compatibility landmine:
Older binaries expecting a numeric property may now fail to parse it (depending on how/when they read it).
Newer code now treats “file not found” as “not encrypted”, but treats malformed JSON as backup_invalid_info() → hard failure.
If this backport is for release-7.3, you probably control compat expectations, but you should be explicit in the PR description (or code comment) about minimum version compatibility for encrypted backups.
Possible improvement:
Use a new filename (e.g. properties/encryption_metadata.json) and keep file_level_encryption as the simple legacy indicator (or write both for a transition period).
A.) seems like could be a hard to detect issue if it ever happened and B.) might show up in backport case. See what you think @akankshamahajan15
|
Let me think more about backward compatibility issue. |
0b592dc to
f547563
Compare
|
Addressed the backward compatibility changes:
Once we roll out encryption, restore needs encryption block size which will be in new format. Will add these changes in main as well. Looking at the cache thing if it's needed or not... |
|
In Cache encryption block size and key is not needed because these are per process. However, when user again calls fdbbackup start or other command, it will be a new cache (cache is per process). |
|
@saintstack thank you the review. I have addressed the issues. |
Result of foundationdb-pr-clang-73 on Linux RHEL 9
|
Result of foundationdb-pr-73 on Linux RHEL 9
|
Result of foundationdb-pr-cluster-tests-73 on Linux RHEL 9
|
767e632 to
3907257
Compare
Result of foundationdb-pr-cluster-tests-73 on Linux RHEL 9
|
Result of foundationdb-pr-cluster-tests-73 on Linux RHEL 9
|
Result of foundationdb-pr-clang-73 on Linux RHEL 9
|
Result of foundationdb-pr-clang-73 on Linux RHEL 9
|
Result of foundationdb-pr-73 on Linux RHEL 9
|
Result of foundationdb-pr-73 on Linux RHEL 9
|
3907257 to
2fd987c
Compare
Result of foundationdb-pr-cluster-tests-73 on Linux RHEL 9
|
Result of foundationdb-pr-clang-73 on Linux RHEL 9
|
Result of foundationdb-pr-73 on Linux RHEL 9
|
2fd987c to
3825749
Compare
There was a problem hiding this comment.
Pull request overview
This backport updates FoundationDB’s backup/restore tooling and container implementations to make the file-level encryption block size a per-backup attribute (passed through APIs and metadata) instead of relying on a process-wide Flow knob, and threads the new parameter through fdbbackup/fdbdecode, backup agents, and async file encryption wrappers.
Changes:
- Add
--encryption-block-sizetofdbbackup startand plumbencryptionBlockSizethroughFileBackupAgent/IBackupContainerAPIs and tuple serialization. - Refactor
AsyncFileEncryptedto require an explicit block size and removeFLOW_KNOBS->ENCRYPTION_BLOCK_SIZEusage (and related OPEN_ENCRYPTED wrapping in Net2/Sim2 filesystems). - Store/read encryption metadata via a properties JSON file and surface the block size in
describeBackup()output and JSON.
Reviewed changes
Copilot reviewed 38 out of 38 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/slow/ParallelRestoreOldBackupCorrectnessMultiCycles.toml | Pins encrypted = false for restore-correctness workload configuration. |
| tests/slow/ParallelRestoreOldBackupCorrectnessCycle.toml | Pins encrypted = false for restore-correctness workload configuration. |
| tests/slow/ParallelRestoreOldBackupCorrectnessAtomicOp.toml | Pins encrypted = false for restore-correctness workload configuration. |
| tests/slow/ParallelRestoreNewBackupCorrectnessMultiCycles.toml | Pins encrypted = false for restore-correctness workload configuration. |
| tests/slow/ParallelRestoreNewBackupCorrectnessCycle.toml | Pins encrypted = false for restore-correctness workload configuration. |
| tests/slow/ParallelRestoreNewBackupCorrectnessAtomicOp.toml | Pins encrypted = false for restore-correctness workload configuration. |
| flow/Knobs.cpp | Removes the ENCRYPTION_BLOCK_SIZE Flow knob initialization. |
| flow/include/flow/Knobs.h | Removes the ENCRYPTION_BLOCK_SIZE Flow knob declaration. |
| fdbserver/workloads/SubmitBackup.actor.cpp | Passes default encryption block size into submitBackup for encrypted workloads. |
| fdbserver/workloads/RestoreMultiRanges.actor.cpp | Passes default encryption block size into submitBackup for encrypted workloads. |
| fdbserver/workloads/IncrementalBackup.actor.cpp | Updates container open/submitBackup calls to include block size argument. |
| fdbserver/workloads/BlobRestoreWorkload.actor.cpp | Updates container open call to include block size argument. |
| fdbserver/workloads/BackupCorrectness.actor.cpp | Threads encryption block size through backup submit and container re-open. |
| fdbserver/workloads/BackupAndParallelRestoreCorrectness.actor.cpp | Threads encryption block size through backup submit and container re-open. |
| fdbserver/Status.actor.cpp | Updates mutation-log container open call signature. |
| fdbserver/RestoreController.actor.cpp | Updates container open call signature. |
| fdbserver/include/fdbserver/RestoreLoader.actor.h | Updates container open call signature. |
| fdbserver/include/fdbserver/RestoreController.actor.h | Updates container open call signature. |
| fdbserver/BlobMigrator.actor.cpp | Updates mutation-log container open call signature. |
| fdbserver/BlobManager.actor.cpp | Updates mutation-log container open call signature. |
| fdbrpc/sim2.actor.cpp | Removes filesystem-layer OPEN_ENCRYPTED wrapping of AsyncFileEncrypted. |
| fdbrpc/Net2FileSystem.cpp | Removes filesystem-layer OPEN_ENCRYPTED wrapping of AsyncFileEncrypted. |
| fdbrpc/include/fdbrpc/AsyncFileEncrypted.h | Changes AsyncFileEncrypted ctor to require block size; stores it as a member. |
| fdbrpc/AsyncFileEncrypted.actor.cpp | Uses per-instance block size; updates unit test to wrap raw file explicitly. |
| fdbclient/include/fdbclient/BackupContainerS3BlobStore.h | Adds encryption block size parameter to S3 container ctor. |
| fdbclient/include/fdbclient/BackupContainerLocalDirectory.h | Adds encryption block size parameter to local-dir container ctor. |
| fdbclient/include/fdbclient/BackupContainerFileSystem.h | Adds encryption block size plumbing + metadata API adjustments. |
| fdbclient/include/fdbclient/BackupContainer.h | Adds encryptionBlockSize to BackupDescription and updates openContainer signature. |
| fdbclient/include/fdbclient/BackupAgent.actor.h | Adds DEFAULT_ENCRYPTION_BLOCK_SIZE; extends submitBackup signature; tuple adds block size. |
| fdbclient/FileBackupAgent.actor.cpp | Persists metadata with block size; extends submit/restore paths to carry block size. |
| fdbclient/BackupContainerS3BlobStore.actor.cpp | Wraps encrypted reads/writes with AsyncFileEncrypted(..., blockSize). |
| fdbclient/BackupContainerLocalDirectory.actor.cpp | Wraps encrypted reads/writes with AsyncFileEncrypted(..., blockSize) and removes OPEN_ENCRYPTED usage. |
| fdbclient/BackupContainerFileSystem.actor.cpp | Implements JSON encryption metadata read/write and uses it in describeBackup(). |
| fdbclient/BackupContainer.actor.cpp | Extends openContainer signature and adds simulation-only cache bypass for file:// URLs. |
| fdbbackup/include/fdbbackup/FileConverter.h | Adds --encryption-key-file option for decode tooling. |
| fdbbackup/FileDecoder.actor.cpp | Adds decode CLI support for encryption key + threads block size from describeBackup(). |
| fdbbackup/FileConverter.actor.cpp | Updates container open call signature. |
| fdbbackup/backup.actor.cpp | Adds --encryption-block-size option and threads block size into start submit path. |
Comments suppressed due to low confidence (2)
fdbbackup/backup.actor.cpp:3121
- In
modifyBackup, the new container is opened without an encryption block size, but you immediately persistbc->getEncryptionBlockSize()into the container metadata. For encrypted backups this is likely still 0, which will later causeAsyncFileEncryptedto assert (block size must be >0) or make restores impossible. When changing destination URLs, the block size should be carried over from the existing backup config/container (e.g.,prevContainer->getEncryptionBlockSize()), and set onbcbefore callingwriteEncryptionMetadata().
options.encryptionKeyFile.present() ? options.encryptionKeyFile.get() : "None")
.detail("EncryptionBlockSize", prevContainer->getEncryptionBlockSize());
bc = openBackupContainer(exeBackup.toString().c_str(),
options.destURL.get(),
options.proxy,
options.encryptionKeyFile,
prevContainer->getEncryptionBlockSize());
try {
wait(timeoutError(bc->create(), 30));
} catch (Error& e) {
if (e.code() == error_code_actor_cancelled)
throw;
fprintf(stderr,
"ERROR: Could not create backup container at '%s': %s\n",
options.destURL.get().c_str(),
e.what());
fdbrpc/AsyncFileEncrypted.actor.cpp:252
- Both write/read loops can stall forever if
randomInt(0, 100)returns 0, producingchunkSize == 0and leavingbytesWritten/bytesReadunchanged. Use a non-zero random range (e.g.randomInt(1, 100)) or clampchunkSizeto at least 1 whenbytes > 0.
int flags = IAsyncFile::OPEN_READWRITE | IAsyncFile::OPEN_CREATE | IAsyncFile::OPEN_ATOMIC_WRITE_AND_CREATE |
IAsyncFile::OPEN_UNBUFFERED | IAsyncFile::OPEN_UNCACHED | IAsyncFile::OPEN_NO_AIO;
state Reference<IAsyncFile> raw_file =
wait(IAsyncFileSystem::filesystem()->open(joinPath(params.getDataDir(), "test-encrypted-file"), flags, 0600));
state Reference<AsyncFileEncrypted> file =
makeReference<AsyncFileEncrypted>(raw_file, AsyncFileEncrypted::Mode::APPEND_ONLY, encryptionBlockSize);
state int bytesWritten = 0;
state int chunkSize;
while (bytesWritten < bytes) {
chunkSize = std::min(deterministicRandom()->randomInt(0, 100), bytes - bytesWritten);
wait(file->write(&writeBuffer[bytesWritten], chunkSize, bytesWritten));
bytesWritten += chunkSize;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Result of foundationdb-pr-clang-73 on Linux RHEL 9
|
Result of foundationdb-pr-73 on Linux RHEL 9
|
Result of foundationdb-pr-cluster-tests-73 on Linux RHEL 9
|
Result of foundationdb-pr-clang-73 on Linux RHEL 9
|
Result of foundationdb-pr-73 on Linux RHEL 9
|
Result of foundationdb-pr-cluster-tests-73 on Linux RHEL 9
|
3825749 to
93916cc
Compare
Result of foundationdb-pr-clang-73 on Linux RHEL 9
|
Result of foundationdb-pr-73 on Linux RHEL 9
|
Result of foundationdb-pr-cluster-tests-73 on Linux RHEL 9
|
| bool exists = wait(bc->exists()); | ||
| if (!exists) { | ||
| wait(bc->create()); | ||
| ACTOR static Future<Void> writeEncryptionMetadataIfNotExists(Reference<BackupContainerFileSystem> bc, |
There was a problem hiding this comment.
No possibility the existing file mismatches the block size we have or whether encryption is on or off?
There was a problem hiding this comment.
We have separate checks for that.
… remove knob (apple#13126) (cherry picked from commit df1c404)
Backport PR
100k Simulation running Completed:
20260502-043739-7.3_ak_encryption_7-6162934df37729cd compressed=True data_size=35578026 duration=4548529 ended=100000 fail=1 fail_fast=10 max_runs=100000 pass=99999 priority=100 remaining=0 runtime=1:14:24 sanity=False started=100000 stopped=20260502-055203 submitted=20260502-043739 timeout=5400 username=7.3_ak_encryption_7One failure unrelated to this change in SwizzledLargeApiCorrectness.toml