From c37223c0836d1637c628f9cef3acb5b55ad3d51b Mon Sep 17 00:00:00 2001 From: sdong Date: Tue, 27 Oct 2015 14:27:48 -0700 Subject: [PATCH] Avoid to reply on ROCKSDB_FALLOCATE_PRESENT in include/posix/io_posix.h Summary: include/posix/io_posix.h should not depend on ROCKSDB_FALLOCATE_PRESENT. Remove it. Test Plan: Build it with both of ROCKSDB_FALLOCATE_PRESENT defined and not defined. Reviewers: rven, yhchiang, anthony, kradhakrishnan, IslamAbdelRahman, igor Reviewed By: igor Subscribers: leveldb, dhruba Differential Revision: https://reviews.facebook.net/D49563 --- include/posix/io_posix.h | 8 -------- util/env_test.cc | 2 +- util/io_posix.cc | 21 +++++++++++++++++---- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/include/posix/io_posix.h b/include/posix/io_posix.h index 0e5da39d6..63c2b4628 100644 --- a/include/posix/io_posix.h +++ b/include/posix/io_posix.h @@ -68,10 +68,8 @@ class PosixWritableFile : public WritableFile { const std::string filename_; int fd_; uint64_t filesize_; -#ifdef ROCKSDB_FALLOCATE_PRESENT bool allow_fallocate_; bool fallocate_with_keep_size_; -#endif public: PosixWritableFile(const std::string& fname, int fd, @@ -89,11 +87,9 @@ class PosixWritableFile : public WritableFile { virtual bool IsSyncThreadSafe() const override; virtual uint64_t GetFileSize() override; virtual Status InvalidateCache(size_t offset, size_t length) override; -#ifdef ROCKSDB_FALLOCATE_PRESENT virtual Status Allocate(off_t offset, off_t len) override; virtual Status RangeSync(off_t offset, off_t nbytes) override; virtual size_t GetUniqueId(char* id, size_t max_size) const override; -#endif }; class PosixMmapReadableFile : public RandomAccessFile { @@ -123,10 +119,8 @@ class PosixMmapFile : public WritableFile { char* dst_; // Where to write next (in range [base_,limit_]) char* last_sync_; // Where have we synced up to uint64_t file_offset_; // Offset of base_ in file -#ifdef ROCKSDB_FALLOCATE_PRESENT bool allow_fallocate_; // If false, fallocate calls are bypassed bool fallocate_with_keep_size_; -#endif // Roundup x to a multiple of y static size_t Roundup(size_t x, size_t y) { return ((x + y - 1) / y) * y; } @@ -156,9 +150,7 @@ class PosixMmapFile : public WritableFile { virtual Status Fsync() override; virtual uint64_t GetFileSize() override; virtual Status InvalidateCache(size_t offset, size_t length) override; -#ifdef ROCKSDB_FALLOCATE_PRESENT virtual Status Allocate(off_t offset, off_t len) override; -#endif }; class PosixDirectory : public Directory { diff --git a/util/env_test.cc b/util/env_test.cc index 7f5e4b93b..a751b5a6b 100644 --- a/util/env_test.cc +++ b/util/env_test.cc @@ -18,6 +18,7 @@ #include #ifdef OS_LINUX +#include #include #include #include @@ -26,7 +27,6 @@ #ifdef ROCKSDB_FALLOCATE_PRESENT #include -#include #endif #include "rocksdb/env.h" diff --git a/util/io_posix.cc b/util/io_posix.cc index 535dade78..0df9a89a3 100644 --- a/util/io_posix.cc +++ b/util/io_posix.cc @@ -477,8 +477,8 @@ Status PosixMmapFile::InvalidateCache(size_t offset, size_t length) { #endif } -#ifdef ROCKSDB_FALLOCATE_PRESENT Status PosixMmapFile::Allocate(off_t offset, off_t len) { +#ifdef ROCKSDB_FALLOCATE_PRESENT TEST_KILL_RANDOM("PosixMmapFile::Allocate:0", rocksdb_kill_odds); int alloc_status = 0; if (allow_fallocate_) { @@ -490,8 +490,10 @@ Status PosixMmapFile::Allocate(off_t offset, off_t len) { } else { return IOError(filename_, errno); } -} +#else + return Status::NotSupported("PosixMmapFile::Allocate() not supported."); #endif +} /* * PosixWritableFile @@ -605,8 +607,8 @@ Status PosixWritableFile::InvalidateCache(size_t offset, size_t length) { #endif } -#ifdef ROCKSDB_FALLOCATE_PRESENT Status PosixWritableFile::Allocate(off_t offset, off_t len) { +#ifdef ROCKSDB_FALLOCATE_PRESENT TEST_KILL_RANDOM("PosixWritableFile::Allocate:0", rocksdb_kill_odds); IOSTATS_TIMER_GUARD(allocate_nanos); int alloc_status = 0; @@ -619,20 +621,31 @@ Status PosixWritableFile::Allocate(off_t offset, off_t len) { } else { return IOError(filename_, errno); } +#else + return Status::NotSupported("PosixWritableFile::Allocate() not supported."); +#endif } Status PosixWritableFile::RangeSync(off_t offset, off_t nbytes) { +#ifdef ROCKSDB_FALLOCATE_PRESENT if (sync_file_range(fd_, offset, nbytes, SYNC_FILE_RANGE_WRITE) == 0) { return Status::OK(); } else { return IOError(filename_, errno); } +#else + return Status::NotSupported("PosixWritableFile::RangeSync() not supported."); +#endif } size_t PosixWritableFile::GetUniqueId(char* id, size_t max_size) const { +#ifdef ROCKSDB_FALLOCATE_PRESENT return GetUniqueIdFromFile(fd_, id, max_size); -} +#else + // What we should do with it? + return 0; #endif +} PosixDirectory::~PosixDirectory() { close(fd_); }