Add missing methods to WritableFileWrapper (#4584)

Summary:
`WritableFileWrapper` was missing some newer methods that were added to `WritableFile`. Without these functions, the missing wrapper methods would fallback to using the default implementations in WritableFile instead of using the corresponding implementations in, say, `PosixWritableFile` or `WinWritableFile`.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4584

Differential Revision: D10559199

Pulled By: sagar0

fbshipit-source-id: 0d0f18a486aee727d5b8eebd3110a41988e27391
main
Sagar Vemuri 6 years ago committed by Facebook Github Bot
parent 0415244bfa
commit abb8ecb4cd
  1. 121
      env/env_test.cc
  2. 33
      include/rocksdb/env.h

121
env/env_test.cc vendored

@ -1368,50 +1368,110 @@ TEST_P(EnvPosixTestWithParam, WritableFileWrapper) {
inc(1); inc(1);
return Status::OK(); return Status::OK();
} }
Status Truncate(uint64_t /*size*/) override { return Status::OK(); }
Status Close() override { inc(2); return Status::OK(); } Status PositionedAppend(const Slice& /*data*/,
Status Flush() override { inc(3); return Status::OK(); } uint64_t /*offset*/) override {
Status Sync() override { inc(4); return Status::OK(); } inc(2);
Status Fsync() override { inc(5); return Status::OK(); } return Status::OK();
void SetIOPriority(Env::IOPriority /*pri*/) override { inc(6); } }
uint64_t GetFileSize() override { inc(7); return 0; }
Status Truncate(uint64_t /*size*/) override {
inc(3);
return Status::OK();
}
Status Close() override {
inc(4);
return Status::OK();
}
Status Flush() override {
inc(5);
return Status::OK();
}
Status Sync() override {
inc(6);
return Status::OK();
}
Status Fsync() override {
inc(7);
return Status::OK();
}
bool IsSyncThreadSafe() const override {
inc(8);
return true;
}
bool use_direct_io() const override {
inc(9);
return true;
}
size_t GetRequiredBufferAlignment() const override {
inc(10);
return 0;
}
void SetIOPriority(Env::IOPriority /*pri*/) override { inc(11); }
Env::IOPriority GetIOPriority() override {
inc(12);
return Env::IOPriority::IO_LOW;
}
void SetWriteLifeTimeHint(Env::WriteLifeTimeHint /*hint*/) override {
inc(13);
}
Env::WriteLifeTimeHint GetWriteLifeTimeHint() override {
inc(14);
return Env::WriteLifeTimeHint::WLTH_NOT_SET;
}
uint64_t GetFileSize() override {
inc(15);
return 0;
}
void SetPreallocationBlockSize(size_t /*size*/) override { inc(16); }
void GetPreallocationStatus(size_t* /*block_size*/, void GetPreallocationStatus(size_t* /*block_size*/,
size_t* /*last_allocated_block*/) override { size_t* /*last_allocated_block*/) override {
inc(8); inc(17);
} }
size_t GetUniqueId(char* /*id*/, size_t /*max_size*/) const override { size_t GetUniqueId(char* /*id*/, size_t /*max_size*/) const override {
inc(9); inc(18);
return 0; return 0;
} }
Status InvalidateCache(size_t /*offset*/, size_t /*length*/) override { Status InvalidateCache(size_t /*offset*/, size_t /*length*/) override {
inc(10); inc(19);
return Status::OK(); return Status::OK();
} }
protected: Status RangeSync(uint64_t /*offset*/, uint64_t /*nbytes*/) override {
Status Allocate(uint64_t /*offset*/, uint64_t /*len*/) override { inc(20);
inc(11);
return Status::OK(); return Status::OK();
} }
Status RangeSync(uint64_t /*offset*/, uint64_t /*nbytes*/) override {
inc(12); void PrepareWrite(size_t /*offset*/, size_t /*len*/) override { inc(21); }
Status Allocate(uint64_t /*offset*/, uint64_t /*len*/) override {
inc(22);
return Status::OK(); return Status::OK();
} }
public: public:
~Base() { ~Base() { inc(23); }
inc(13);
}
}; };
class Wrapper : public WritableFileWrapper { class Wrapper : public WritableFileWrapper {
public: public:
explicit Wrapper(WritableFile* target) : WritableFileWrapper(target) {} explicit Wrapper(WritableFile* target) : WritableFileWrapper(target) {}
void CallProtectedMethods() {
Allocate(0, 0);
RangeSync(0, 0);
}
}; };
int step = 0; int step = 0;
@ -1420,19 +1480,30 @@ TEST_P(EnvPosixTestWithParam, WritableFileWrapper) {
Base b(&step); Base b(&step);
Wrapper w(&b); Wrapper w(&b);
w.Append(Slice()); w.Append(Slice());
w.PositionedAppend(Slice(), 0);
w.Truncate(0);
w.Close(); w.Close();
w.Flush(); w.Flush();
w.Sync(); w.Sync();
w.Fsync(); w.Fsync();
w.IsSyncThreadSafe();
w.use_direct_io();
w.GetRequiredBufferAlignment();
w.SetIOPriority(Env::IOPriority::IO_HIGH); w.SetIOPriority(Env::IOPriority::IO_HIGH);
w.GetIOPriority();
w.SetWriteLifeTimeHint(Env::WriteLifeTimeHint::WLTH_NOT_SET);
w.GetWriteLifeTimeHint();
w.GetFileSize(); w.GetFileSize();
w.SetPreallocationBlockSize(0);
w.GetPreallocationStatus(nullptr, nullptr); w.GetPreallocationStatus(nullptr, nullptr);
w.GetUniqueId(nullptr, 0); w.GetUniqueId(nullptr, 0);
w.InvalidateCache(0, 0); w.InvalidateCache(0, 0);
w.CallProtectedMethods(); w.RangeSync(0, 0);
w.PrepareWrite(0, 0);
w.Allocate(0, 0);
} }
EXPECT_EQ(14, step); EXPECT_EQ(24, step);
} }
TEST_P(EnvPosixTestWithParam, PosixRandomRWFile) { TEST_P(EnvPosixTestWithParam, PosixRandomRWFile) {

@ -1224,36 +1224,57 @@ class WritableFileWrapper : public WritableFile {
Status Sync() override { return target_->Sync(); } Status Sync() override { return target_->Sync(); }
Status Fsync() override { return target_->Fsync(); } Status Fsync() override { return target_->Fsync(); }
bool IsSyncThreadSafe() const override { return target_->IsSyncThreadSafe(); } bool IsSyncThreadSafe() const override { return target_->IsSyncThreadSafe(); }
bool use_direct_io() const override { return target_->use_direct_io(); }
size_t GetRequiredBufferAlignment() const override {
return target_->GetRequiredBufferAlignment();
}
void SetIOPriority(Env::IOPriority pri) override { void SetIOPriority(Env::IOPriority pri) override {
target_->SetIOPriority(pri); target_->SetIOPriority(pri);
} }
Env::IOPriority GetIOPriority() override { return target_->GetIOPriority(); } Env::IOPriority GetIOPriority() override { return target_->GetIOPriority(); }
void SetWriteLifeTimeHint(Env::WriteLifeTimeHint hint) override {
target_->SetWriteLifeTimeHint(hint);
}
Env::WriteLifeTimeHint GetWriteLifeTimeHint() override {
return target_->GetWriteLifeTimeHint();
}
uint64_t GetFileSize() override { return target_->GetFileSize(); } uint64_t GetFileSize() override { return target_->GetFileSize(); }
void SetPreallocationBlockSize(size_t size) override {
target_->SetPreallocationBlockSize(size);
}
void GetPreallocationStatus(size_t* block_size, void GetPreallocationStatus(size_t* block_size,
size_t* last_allocated_block) override { size_t* last_allocated_block) override {
target_->GetPreallocationStatus(block_size, last_allocated_block); target_->GetPreallocationStatus(block_size, last_allocated_block);
} }
size_t GetUniqueId(char* id, size_t max_size) const override { size_t GetUniqueId(char* id, size_t max_size) const override {
return target_->GetUniqueId(id, max_size); return target_->GetUniqueId(id, max_size);
} }
Status InvalidateCache(size_t offset, size_t length) override { Status InvalidateCache(size_t offset, size_t length) override {
return target_->InvalidateCache(offset, length); return target_->InvalidateCache(offset, length);
} }
void SetPreallocationBlockSize(size_t size) override { Status RangeSync(uint64_t offset, uint64_t nbytes) override {
target_->SetPreallocationBlockSize(size); return target_->RangeSync(offset, nbytes);
} }
void PrepareWrite(size_t offset, size_t len) override { void PrepareWrite(size_t offset, size_t len) override {
target_->PrepareWrite(offset, len); target_->PrepareWrite(offset, len);
} }
protected:
Status Allocate(uint64_t offset, uint64_t len) override { Status Allocate(uint64_t offset, uint64_t len) override {
return target_->Allocate(offset, len); return target_->Allocate(offset, len);
} }
Status RangeSync(uint64_t offset, uint64_t nbytes) override {
return target_->RangeSync(offset, nbytes);
}
private: private:
WritableFile* target_; WritableFile* target_;

Loading…
Cancel
Save