From 556972e964026a95edecb28cf70a6f36013dd3aa Mon Sep 17 00:00:00 2001 From: Zhichao Cao Date: Tue, 2 Jun 2020 15:02:25 -0700 Subject: [PATCH] Replace Status with IOStatus in CopyFile and CreateFile (#6916) Summary: Replace Status with IOStatus in CopyFile and CreateFile. Pull Request resolved: https://github.com/facebook/rocksdb/pull/6916 Test Plan: pass make asan_check Reviewed By: cheng-chang Differential Revision: D21843775 Pulled By: zhichao-cao fbshipit-source-id: 524d4a0fcf47f0941b923da0346e0de71607f5f6 --- file/file_util.cc | 57 ++++++++++++++++++++++++----------------------- file/file_util.h | 10 ++++----- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/file/file_util.cc b/file/file_util.cc index c231bf7d1..8ee2bc490 100644 --- a/file/file_util.cc +++ b/file/file_util.cc @@ -17,30 +17,31 @@ namespace ROCKSDB_NAMESPACE { // Utility function to copy a file up to a specified length -Status CopyFile(FileSystem* fs, const std::string& source, - const std::string& destination, uint64_t size, bool use_fsync) { +IOStatus CopyFile(FileSystem* fs, const std::string& source, + const std::string& destination, uint64_t size, + bool use_fsync) { const FileOptions soptions; - Status s; + IOStatus io_s; std::unique_ptr src_reader; std::unique_ptr dest_writer; { std::unique_ptr srcfile; - s = fs->NewSequentialFile(source, soptions, &srcfile, nullptr); - if (!s.ok()) { - return s; + io_s = fs->NewSequentialFile(source, soptions, &srcfile, nullptr); + if (!io_s.ok()) { + return io_s; } std::unique_ptr destfile; - s = fs->NewWritableFile(destination, soptions, &destfile, nullptr); - if (!s.ok()) { - return s; + io_s = fs->NewWritableFile(destination, soptions, &destfile, nullptr); + if (!io_s.ok()) { + return io_s; } if (size == 0) { // default argument means copy everything - s = fs->GetFileSize(source, IOOptions(), &size, nullptr); - if (!s.ok()) { - return s; + io_s = fs->GetFileSize(source, IOOptions(), &size, nullptr); + if (!io_s.ok()) { + return io_s; } } src_reader.reset(new SequentialFileReader(std::move(srcfile), source)); @@ -52,16 +53,16 @@ Status CopyFile(FileSystem* fs, const std::string& source, Slice slice; while (size > 0) { size_t bytes_to_read = std::min(sizeof(buffer), static_cast(size)); - s = src_reader->Read(bytes_to_read, &slice, buffer); - if (!s.ok()) { - return s; + io_s = status_to_io_status(src_reader->Read(bytes_to_read, &slice, buffer)); + if (!io_s.ok()) { + return io_s; } if (slice.size() == 0) { - return Status::Corruption("file too small"); + return IOStatus::Corruption("file too small"); } - s = dest_writer->Append(slice); - if (!s.ok()) { - return s; + io_s = dest_writer->Append(slice); + if (!io_s.ok()) { + return io_s; } size -= slice.size(); } @@ -69,22 +70,22 @@ Status CopyFile(FileSystem* fs, const std::string& source, } // Utility function to create a file with the provided contents -Status CreateFile(FileSystem* fs, const std::string& destination, - const std::string& contents, bool use_fsync) { +IOStatus CreateFile(FileSystem* fs, const std::string& destination, + const std::string& contents, bool use_fsync) { const EnvOptions soptions; - Status s; + IOStatus io_s; std::unique_ptr dest_writer; std::unique_ptr destfile; - s = fs->NewWritableFile(destination, soptions, &destfile, nullptr); - if (!s.ok()) { - return s; + io_s = fs->NewWritableFile(destination, soptions, &destfile, nullptr); + if (!io_s.ok()) { + return io_s; } dest_writer.reset( new WritableFileWriter(std::move(destfile), destination, soptions)); - s = dest_writer->Append(Slice(contents)); - if (!s.ok()) { - return s; + io_s = dest_writer->Append(Slice(contents)); + if (!io_s.ok()) { + return io_s; } return dest_writer->Sync(use_fsync); } diff --git a/file/file_util.h b/file/file_util.h index dd7d8f500..04694a5b9 100644 --- a/file/file_util.h +++ b/file/file_util.h @@ -16,12 +16,12 @@ namespace ROCKSDB_NAMESPACE { // use_fsync maps to options.use_fsync, which determines the way that // the file is synced after copying. -extern Status CopyFile(FileSystem* fs, const std::string& source, - const std::string& destination, uint64_t size, - bool use_fsync); +extern IOStatus CopyFile(FileSystem* fs, const std::string& source, + const std::string& destination, uint64_t size, + bool use_fsync); -extern Status CreateFile(FileSystem* fs, const std::string& destination, - const std::string& contents, bool use_fsync); +extern IOStatus CreateFile(FileSystem* fs, const std::string& destination, + const std::string& contents, bool use_fsync); extern Status DeleteDBFile(const ImmutableDBOptions* db_options, const std::string& fname,