Skip to content

Commit

Permalink
Fix NewRandomRWFile and ReuseWritableFile in KeyManagedEncryptedEnv (#6)
Browse files Browse the repository at this point in the history
apache/incubator-pegasus#1575

Cherry-pick from
tikv@2360562

Summary:
Fix NewRandomRWFile and ReuseWritableFile misuse of `GetFile()` and
`NewFile()`. See inline comments.

Test Plan:
manual test with tikv

Signed-off-by: Yi Wu <yiwu@pingcap.com>

Co-authored-by: yiwu-arbug <yiwu@pingcap.com>
  • Loading branch information
acelyc111 and yiwu-arbug committed Sep 15, 2023
1 parent 34aea41 commit c5ac8d5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions encryption/encryption.cc
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,10 @@ Status KeyManagedEncryptedEnv::ReuseWritableFile(
const std::string& fname, const std::string& old_fname,
std::unique_ptr<WritableFile>* 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;
}
Expand Down Expand Up @@ -389,7 +392,10 @@ Status KeyManagedEncryptedEnv::NewRandomRWFile(
const std::string& fname, std::unique_ptr<RandomRWFile>* 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;
}
Expand Down

0 comments on commit c5ac8d5

Please sign in to comment.