Skip to content

Commit

Permalink
Revert "Avoid to reply on ROCKSDB_FALLOCATE_PRESENT in include/posix/…
Browse files Browse the repository at this point in the history
…io_posix.h"

This reverts commit c37223c.
  • Loading branch information
siying committed Oct 28, 2015
1 parent 28c8758 commit 2889df8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
8 changes: 8 additions & 0 deletions include/posix/io_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ 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,
Expand All @@ -87,9 +89,11 @@ 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 {
Expand Down Expand Up @@ -119,8 +123,10 @@ 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; }
Expand Down Expand Up @@ -150,7 +156,9 @@ 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 {
Expand Down
2 changes: 1 addition & 1 deletion util/env_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <list>

#ifdef OS_LINUX
#include <fcntl.h>
#include <linux/fs.h>
#include <stdlib.h>
#include <sys/stat.h>
Expand All @@ -27,6 +26,7 @@

#ifdef ROCKSDB_FALLOCATE_PRESENT
#include <errno.h>
#include <fcntl.h>
#endif

#include "rocksdb/env.h"
Expand Down
21 changes: 4 additions & 17 deletions util/io_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,8 @@ Status PosixMmapFile::InvalidateCache(size_t offset, size_t length) {
#endif
}

Status PosixMmapFile::Allocate(off_t offset, off_t len) {
#ifdef ROCKSDB_FALLOCATE_PRESENT
Status PosixMmapFile::Allocate(off_t offset, off_t len) {
TEST_KILL_RANDOM("PosixMmapFile::Allocate:0", rocksdb_kill_odds);
int alloc_status = 0;
if (allow_fallocate_) {
Expand All @@ -490,10 +490,8 @@ Status PosixMmapFile::Allocate(off_t offset, off_t len) {
} else {
return IOError(filename_, errno);
}
#else
return Status::NotSupported("PosixMmapFile::Allocate() not supported.");
#endif
}
#endif

/*
* PosixWritableFile
Expand Down Expand Up @@ -607,8 +605,8 @@ Status PosixWritableFile::InvalidateCache(size_t offset, size_t length) {
#endif
}

Status PosixWritableFile::Allocate(off_t offset, off_t len) {
#ifdef ROCKSDB_FALLOCATE_PRESENT
Status PosixWritableFile::Allocate(off_t offset, off_t len) {
TEST_KILL_RANDOM("PosixWritableFile::Allocate:0", rocksdb_kill_odds);
IOSTATS_TIMER_GUARD(allocate_nanos);
int alloc_status = 0;
Expand All @@ -621,31 +619,20 @@ 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
}
#endif

PosixDirectory::~PosixDirectory() { close(fd_); }

Expand Down

0 comments on commit 2889df8

Please sign in to comment.