From 0470a0b28724bf9eac7a8a266e0bea390b637d9b Mon Sep 17 00:00:00 2001 From: Yingchun Lai Date: Tue, 8 Aug 2023 07:39:57 +0800 Subject: [PATCH] Fix NewRandomRWFile and ReuseWritableFile in KeyManagedEncryptedEnv (#6) https://github.com/apache/incubator-pegasus/issues/1575 Cherry-pick from https://github.com/tikv/rocksdb/commit/23605627930ad51ff57ec2f005481b9b905cc9a3 Summary: Fix NewRandomRWFile and ReuseWritableFile misuse of `GetFile()` and `NewFile()`. See inline comments. Test Plan: manual test with tikv Signed-off-by: Yi Wu Co-authored-by: yiwu-arbug --- encryption/encryption.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/encryption/encryption.cc b/encryption/encryption.cc index f6176ba84c7..426958ea9e6 100644 --- a/encryption/encryption.cc +++ b/encryption/encryption.cc @@ -361,7 +361,10 @@ Status KeyManagedEncryptedEnv::ReuseWritableFile( const std::string& fname, const std::string& old_fname, std::unique_ptr* result, const EnvOptions& options) { FileEncryptionInfo file_info; - Status s = key_manager_->GetFile(fname, &file_info); + // ReuseWritableFile is only used in the context of rotating WAL file and + // reuse them. Old content is discardable and new WAL records are to + // overwrite the file. So NewFile() should be called. + Status s = key_manager_->NewFile(fname, &file_info); if (!s.ok()) { return s; } @@ -389,7 +392,10 @@ Status KeyManagedEncryptedEnv::NewRandomRWFile( const std::string& fname, std::unique_ptr* result, const EnvOptions& options) { FileEncryptionInfo file_info; - Status s = key_manager_->NewFile(fname, &file_info); + // NewRandomRWFile is only used in the context of external file ingestion, + // for rewriting global seqno. So it should call GetFile() instead of + // NewFile(). + Status s = key_manager_->GetFile(fname, &file_info); if (!s.ok()) { return s; }