Skip to content

Commit

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

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>
  • Loading branch information
yiwu-arbug authored Apr 20, 2020
1 parent 24bf91d commit e61028d
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 @@ -352,7 +352,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 All @@ -379,7 +382,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 e61028d

Please sign in to comment.