From cbf38af7051a57d3a80ec797c2af13eb5cc1b9d1 Mon Sep 17 00:00:00 2001 From: Deepak Ojha Date: Fri, 5 Feb 2021 12:39:05 -0800 Subject: [PATCH] Wal recovery failure with encryption due to zero bytes WAL size. (#7924) Summary: Fixes issue https://github.com/facebook/rocksdb/issues/7410 Pull Request resolved: https://github.com/facebook/rocksdb/pull/7924 Reviewed By: jay-zhuang Differential Revision: D26216805 Pulled By: ajkr fbshipit-source-id: 5720635ee06003269bfaf8c8616b3671974b08a8 --- env/env_encryption.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/env/env_encryption.cc b/env/env_encryption.cc index ca2542abb..8eec392ae 100644 --- a/env/env_encryption.cc +++ b/env/env_encryption.cc @@ -646,6 +646,15 @@ class EncryptedEnvImpl : public EnvWrapper { if (!status.ok()) { return status; } + uint64_t file_size; + status = EnvWrapper::GetFileSize(fname, &file_size); + if (!status.ok()) { + return status; + } + if (!file_size) { + *result = std::move(underlying); + return status; + } // Create cipher stream std::unique_ptr stream; size_t prefix_length; @@ -830,7 +839,7 @@ class EncryptedEnvImpl : public EnvWrapper { virtual Status GetFileSize(const std::string& fname, uint64_t* file_size) override { auto status = EnvWrapper::GetFileSize(fname, file_size); - if (!status.ok()) { + if (!status.ok() || !(*file_size)) { return status; } EncryptionProvider* provider;