Skip to content

Commit

Permalink
Fix NewRandomRWFile and ReuseWritableFile in KeyManagedEncryptedEnv (f…
Browse files Browse the repository at this point in the history
…acebook#167)

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>
Signed-off-by: tabokie <xy.tao@outlook.com>
(cherry picked from commit 63586f2)
  • Loading branch information
yiwu-arbug authored and acelyc111 committed Jul 25, 2023
1 parent 2b16003 commit 20b4572
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 @@ -358,7 +358,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 @@ -386,7 +389,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 20b4572

Please sign in to comment.