diff --git a/encryption/encryption.cc b/encryption/encryption.cc index 038e7d907fa..435022766fb 100644 --- a/encryption/encryption.cc +++ b/encryption/encryption.cc @@ -352,7 +352,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; } @@ -379,7 +382,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; }