Apply modernize-use-override (3)

Summary:
Use C++11’s override and remove virtual where applicable.
Change are automatically generated.

bypass-lint
drop-conflicts

Reviewed By: igorsugak

Differential Revision: D14131816

fbshipit-source-id: f20e7f7cecf2e699d70f5fa036f72c0e3f59b50e
main
Michael Liu 6 years ago committed by Facebook Github Bot
parent ed995c6a69
commit 3c5d1b16b1
  1. 2
      db/version_builder_test.cc
  2. 29
      db/version_set.cc
  3. 11
      db/version_set_test.cc
  4. 2
      db/wal_manager.cc
  5. 23
      db/write_batch.cc
  6. 61
      db/write_batch_test.cc
  7. 2
      db/write_callback_test.cc
  8. 2
      db/write_controller_test.cc
  9. 10
      env/env_basic_test.cc
  10. 45
      env/env_chroot.cc
  11. 95
      env/env_encryption.cc
  12. 102
      env/env_posix.cc
  13. 18
      env/env_test.cc
  14. 44
      env/mock_env.cc
  15. 4
      env/mock_env_test.cc

@ -37,7 +37,7 @@ class VersionBuilderTest : public testing::Test {
size_being_compacted_.resize(options_.num_levels); size_being_compacted_.resize(options_.num_levels);
} }
~VersionBuilderTest() { ~VersionBuilderTest() override {
for (int i = 0; i < vstorage_.num_levels(); i++) { for (int i = 0; i < vstorage_.num_levels(); i++) {
for (auto* f : vstorage_.LevelFiles(i)) { for (auto* f : vstorage_.LevelFiles(i)) {
if (--f->refs == 0) { if (--f->refs == 0) {

@ -492,39 +492,38 @@ class LevelIterator final : public InternalIterator {
assert(flevel_ != nullptr && flevel_->num_files > 0); assert(flevel_ != nullptr && flevel_->num_files > 0);
} }
virtual ~LevelIterator() { delete file_iter_.Set(nullptr); } ~LevelIterator() override { delete file_iter_.Set(nullptr); }
virtual void Seek(const Slice& target) override; void Seek(const Slice& target) override;
virtual void SeekForPrev(const Slice& target) override; void SeekForPrev(const Slice& target) override;
virtual void SeekToFirst() override; void SeekToFirst() override;
virtual void SeekToLast() override; void SeekToLast() override;
virtual void Next() override; void Next() override;
virtual void Prev() override; void Prev() override;
virtual bool Valid() const override { return file_iter_.Valid(); } bool Valid() const override { return file_iter_.Valid(); }
virtual Slice key() const override { Slice key() const override {
assert(Valid()); assert(Valid());
return file_iter_.key(); return file_iter_.key();
} }
virtual Slice value() const override { Slice value() const override {
assert(Valid()); assert(Valid());
return file_iter_.value(); return file_iter_.value();
} }
virtual Status status() const override { Status status() const override {
return file_iter_.iter() ? file_iter_.status() : Status::OK(); return file_iter_.iter() ? file_iter_.status() : Status::OK();
} }
virtual void SetPinnedItersMgr( void SetPinnedItersMgr(PinnedIteratorsManager* pinned_iters_mgr) override {
PinnedIteratorsManager* pinned_iters_mgr) override {
pinned_iters_mgr_ = pinned_iters_mgr; pinned_iters_mgr_ = pinned_iters_mgr;
if (file_iter_.iter()) { if (file_iter_.iter()) {
file_iter_.SetPinnedItersMgr(pinned_iters_mgr); file_iter_.SetPinnedItersMgr(pinned_iters_mgr);
} }
} }
virtual bool IsKeyPinned() const override { bool IsKeyPinned() const override {
return pinned_iters_mgr_ && pinned_iters_mgr_->PinningEnabled() && return pinned_iters_mgr_ && pinned_iters_mgr_->PinningEnabled() &&
file_iter_.iter() && file_iter_.IsKeyPinned(); file_iter_.iter() && file_iter_.IsKeyPinned();
} }
virtual bool IsValuePinned() const override { bool IsValuePinned() const override {
return pinned_iters_mgr_ && pinned_iters_mgr_->PinningEnabled() && return pinned_iters_mgr_ && pinned_iters_mgr_->PinningEnabled() &&
file_iter_.iter() && file_iter_.IsValuePinned(); file_iter_.iter() && file_iter_.IsValuePinned();
} }

@ -25,7 +25,7 @@ class GenerateLevelFilesBriefTest : public testing::Test {
GenerateLevelFilesBriefTest() { } GenerateLevelFilesBriefTest() { }
~GenerateLevelFilesBriefTest() { ~GenerateLevelFilesBriefTest() override {
for (size_t i = 0; i < files_.size(); i++) { for (size_t i = 0; i < files_.size(); i++) {
delete files_[i]; delete files_[i];
} }
@ -79,9 +79,7 @@ class CountingLogger : public Logger {
public: public:
CountingLogger() : log_count(0) {} CountingLogger() : log_count(0) {}
using Logger::Logv; using Logger::Logv;
virtual void Logv(const char* /*format*/, va_list /*ap*/) override { void Logv(const char* /*format*/, va_list /*ap*/) override { log_count++; }
log_count++;
}
int log_count; int log_count;
}; };
@ -117,7 +115,7 @@ class VersionStorageInfoTest : public testing::Test {
mutable_cf_options_(options_), mutable_cf_options_(options_),
vstorage_(&icmp_, ucmp_, 6, kCompactionStyleLevel, nullptr, false) {} vstorage_(&icmp_, ucmp_, 6, kCompactionStyleLevel, nullptr, false) {}
~VersionStorageInfoTest() { ~VersionStorageInfoTest() override {
for (int i = 0; i < vstorage_.num_levels(); i++) { for (int i = 0; i < vstorage_.num_levels(); i++) {
for (auto* f : vstorage_.LevelFiles(i)) { for (auto* f : vstorage_.LevelFiles(i)) {
if (--f->refs == 0) { if (--f->refs == 0) {
@ -420,8 +418,7 @@ class FindLevelFileTest : public testing::Test {
FindLevelFileTest() : disjoint_sorted_files_(true) { } FindLevelFileTest() : disjoint_sorted_files_(true) { }
~FindLevelFileTest() { ~FindLevelFileTest() override {}
}
void LevelFileInit(size_t num = 0) { void LevelFileInit(size_t num = 0) {
char* mem = arena_.AllocateAligned(num * sizeof(FdWithKeyRange)); char* mem = arena_.AllocateAligned(num * sizeof(FdWithKeyRange));

@ -429,7 +429,7 @@ Status WalManager::ReadFirstLine(const std::string& fname,
Status* status; Status* status;
bool ignore_error; // true if db_options_.paranoid_checks==false bool ignore_error; // true if db_options_.paranoid_checks==false
virtual void Corruption(size_t bytes, const Status& s) override { void Corruption(size_t bytes, const Status& s) override {
ROCKS_LOG_WARN(info_log, "[WalManager] %s%s: dropping %d bytes; %s", ROCKS_LOG_WARN(info_log, "[WalManager] %s%s: dropping %d bytes; %s",
(this->ignore_error ? "(ignoring error) " : ""), fname, (this->ignore_error ? "(ignoring error) " : ""), fname,
static_cast<int>(bytes), s.ToString().c_str()); static_cast<int>(bytes), s.ToString().c_str());

@ -1094,10 +1094,8 @@ class MemTableInserter : public WriteBatch::Handler {
} }
protected: protected:
virtual bool WriteBeforePrepare() const override { bool WriteBeforePrepare() const override { return write_before_prepare_; }
return write_before_prepare_; bool WriteAfterCommit() const override { return write_after_commit_; }
}
virtual bool WriteAfterCommit() const override { return write_after_commit_; }
public: public:
// cf_mems should not be shared with concurrent inserters // cf_mems should not be shared with concurrent inserters
@ -1134,7 +1132,7 @@ class MemTableInserter : public WriteBatch::Handler {
assert(cf_mems_); assert(cf_mems_);
} }
~MemTableInserter() { ~MemTableInserter() override {
if (dup_dectector_on_) { if (dup_dectector_on_) {
reinterpret_cast<DuplicateDetector*> reinterpret_cast<DuplicateDetector*>
(&duplicate_detector_)->~DuplicateDetector(); (&duplicate_detector_)->~DuplicateDetector();
@ -1324,7 +1322,7 @@ class MemTableInserter : public WriteBatch::Handler {
return ret_status; return ret_status;
} }
virtual Status PutCF(uint32_t column_family_id, const Slice& key, Status PutCF(uint32_t column_family_id, const Slice& key,
const Slice& value) override { const Slice& value) override {
return PutCFImpl(column_family_id, key, value, kTypeValue); return PutCFImpl(column_family_id, key, value, kTypeValue);
} }
@ -1347,8 +1345,7 @@ class MemTableInserter : public WriteBatch::Handler {
return ret_status; return ret_status;
} }
virtual Status DeleteCF(uint32_t column_family_id, Status DeleteCF(uint32_t column_family_id, const Slice& key) override {
const Slice& key) override {
// optimize for non-recovery mode // optimize for non-recovery mode
if (UNLIKELY(write_after_commit_ && rebuilding_trx_ != nullptr)) { if (UNLIKELY(write_after_commit_ && rebuilding_trx_ != nullptr)) {
WriteBatchInternal::Delete(rebuilding_trx_, column_family_id, key); WriteBatchInternal::Delete(rebuilding_trx_, column_family_id, key);
@ -1381,8 +1378,7 @@ class MemTableInserter : public WriteBatch::Handler {
return ret_status; return ret_status;
} }
virtual Status SingleDeleteCF(uint32_t column_family_id, Status SingleDeleteCF(uint32_t column_family_id, const Slice& key) override {
const Slice& key) override {
// optimize for non-recovery mode // optimize for non-recovery mode
if (UNLIKELY(write_after_commit_ && rebuilding_trx_ != nullptr)) { if (UNLIKELY(write_after_commit_ && rebuilding_trx_ != nullptr)) {
WriteBatchInternal::SingleDelete(rebuilding_trx_, column_family_id, key); WriteBatchInternal::SingleDelete(rebuilding_trx_, column_family_id, key);
@ -1417,8 +1413,7 @@ class MemTableInserter : public WriteBatch::Handler {
return ret_status; return ret_status;
} }
virtual Status DeleteRangeCF(uint32_t column_family_id, Status DeleteRangeCF(uint32_t column_family_id, const Slice& begin_key,
const Slice& begin_key,
const Slice& end_key) override { const Slice& end_key) override {
// optimize for non-recovery mode // optimize for non-recovery mode
if (UNLIKELY(write_after_commit_ && rebuilding_trx_ != nullptr)) { if (UNLIKELY(write_after_commit_ && rebuilding_trx_ != nullptr)) {
@ -1471,7 +1466,7 @@ class MemTableInserter : public WriteBatch::Handler {
return ret_status; return ret_status;
} }
virtual Status MergeCF(uint32_t column_family_id, const Slice& key, Status MergeCF(uint32_t column_family_id, const Slice& key,
const Slice& value) override { const Slice& value) override {
assert(!concurrent_memtable_writes_); assert(!concurrent_memtable_writes_);
// optimize for non-recovery mode // optimize for non-recovery mode
@ -1585,7 +1580,7 @@ class MemTableInserter : public WriteBatch::Handler {
return ret_status; return ret_status;
} }
virtual Status PutBlobIndexCF(uint32_t column_family_id, const Slice& key, Status PutBlobIndexCF(uint32_t column_family_id, const Slice& key,
const Slice& value) override { const Slice& value) override {
// Same as PutCF except for value type. // Same as PutCF except for value type.
return PutCFImpl(column_family_id, key, value, kTypeBlobIndex); return PutCFImpl(column_family_id, key, value, kTypeBlobIndex);

@ -236,7 +236,7 @@ TEST_F(WriteBatchTest, SingleDeletion) {
namespace { namespace {
struct TestHandler : public WriteBatch::Handler { struct TestHandler : public WriteBatch::Handler {
std::string seen; std::string seen;
virtual Status PutCF(uint32_t column_family_id, const Slice& key, Status PutCF(uint32_t column_family_id, const Slice& key,
const Slice& value) override { const Slice& value) override {
if (column_family_id == 0) { if (column_family_id == 0) {
seen += "Put(" + key.ToString() + ", " + value.ToString() + ")"; seen += "Put(" + key.ToString() + ", " + value.ToString() + ")";
@ -246,8 +246,7 @@ namespace {
} }
return Status::OK(); return Status::OK();
} }
virtual Status DeleteCF(uint32_t column_family_id, Status DeleteCF(uint32_t column_family_id, const Slice& key) override {
const Slice& key) override {
if (column_family_id == 0) { if (column_family_id == 0) {
seen += "Delete(" + key.ToString() + ")"; seen += "Delete(" + key.ToString() + ")";
} else { } else {
@ -256,7 +255,7 @@ namespace {
} }
return Status::OK(); return Status::OK();
} }
virtual Status SingleDeleteCF(uint32_t column_family_id, Status SingleDeleteCF(uint32_t column_family_id,
const Slice& key) override { const Slice& key) override {
if (column_family_id == 0) { if (column_family_id == 0) {
seen += "SingleDelete(" + key.ToString() + ")"; seen += "SingleDelete(" + key.ToString() + ")";
@ -266,8 +265,7 @@ namespace {
} }
return Status::OK(); return Status::OK();
} }
virtual Status DeleteRangeCF(uint32_t column_family_id, Status DeleteRangeCF(uint32_t column_family_id, const Slice& begin_key,
const Slice& begin_key,
const Slice& end_key) override { const Slice& end_key) override {
if (column_family_id == 0) { if (column_family_id == 0) {
seen += "DeleteRange(" + begin_key.ToString() + ", " + seen += "DeleteRange(" + begin_key.ToString() + ", " +
@ -278,7 +276,7 @@ namespace {
} }
return Status::OK(); return Status::OK();
} }
virtual Status MergeCF(uint32_t column_family_id, const Slice& key, Status MergeCF(uint32_t column_family_id, const Slice& key,
const Slice& value) override { const Slice& value) override {
if (column_family_id == 0) { if (column_family_id == 0) {
seen += "Merge(" + key.ToString() + ", " + value.ToString() + ")"; seen += "Merge(" + key.ToString() + ", " + value.ToString() + ")";
@ -288,27 +286,27 @@ namespace {
} }
return Status::OK(); return Status::OK();
} }
virtual void LogData(const Slice& blob) override { void LogData(const Slice& blob) override {
seen += "LogData(" + blob.ToString() + ")"; seen += "LogData(" + blob.ToString() + ")";
} }
virtual Status MarkBeginPrepare(bool unprepare) override { Status MarkBeginPrepare(bool unprepare) override {
seen += seen +=
"MarkBeginPrepare(" + std::string(unprepare ? "true" : "false") + ")"; "MarkBeginPrepare(" + std::string(unprepare ? "true" : "false") + ")";
return Status::OK(); return Status::OK();
} }
virtual Status MarkEndPrepare(const Slice& xid) override { Status MarkEndPrepare(const Slice& xid) override {
seen += "MarkEndPrepare(" + xid.ToString() + ")"; seen += "MarkEndPrepare(" + xid.ToString() + ")";
return Status::OK(); return Status::OK();
} }
virtual Status MarkNoop(bool empty_batch) override { Status MarkNoop(bool empty_batch) override {
seen += "MarkNoop(" + std::string(empty_batch ? "true" : "false") + ")"; seen += "MarkNoop(" + std::string(empty_batch ? "true" : "false") + ")";
return Status::OK(); return Status::OK();
} }
virtual Status MarkCommit(const Slice& xid) override { Status MarkCommit(const Slice& xid) override {
seen += "MarkCommit(" + xid.ToString() + ")"; seen += "MarkCommit(" + xid.ToString() + ")";
return Status::OK(); return Status::OK();
} }
virtual Status MarkRollback(const Slice& xid) override { Status MarkRollback(const Slice& xid) override {
seen += "MarkRollback(" + xid.ToString() + ")"; seen += "MarkRollback(" + xid.ToString() + ")";
return Status::OK(); return Status::OK();
} }
@ -439,7 +437,7 @@ TEST_F(WriteBatchTest, DISABLED_ManyUpdates) {
struct NoopHandler : public WriteBatch::Handler { struct NoopHandler : public WriteBatch::Handler {
uint32_t num_seen = 0; uint32_t num_seen = 0;
char expected_char = 'A'; char expected_char = 'A';
virtual Status PutCF(uint32_t /*column_family_id*/, const Slice& key, Status PutCF(uint32_t /*column_family_id*/, const Slice& key,
const Slice& value) override { const Slice& value) override {
EXPECT_EQ(kKeyValueSize, key.size()); EXPECT_EQ(kKeyValueSize, key.size());
EXPECT_EQ(kKeyValueSize, value.size()); EXPECT_EQ(kKeyValueSize, value.size());
@ -454,23 +452,23 @@ TEST_F(WriteBatchTest, DISABLED_ManyUpdates) {
++num_seen; ++num_seen;
return Status::OK(); return Status::OK();
} }
virtual Status DeleteCF(uint32_t /*column_family_id*/, Status DeleteCF(uint32_t /*column_family_id*/,
const Slice& /*key*/) override { const Slice& /*key*/) override {
ADD_FAILURE(); ADD_FAILURE();
return Status::OK(); return Status::OK();
} }
virtual Status SingleDeleteCF(uint32_t /*column_family_id*/, Status SingleDeleteCF(uint32_t /*column_family_id*/,
const Slice& /*key*/) override { const Slice& /*key*/) override {
ADD_FAILURE(); ADD_FAILURE();
return Status::OK(); return Status::OK();
} }
virtual Status MergeCF(uint32_t /*column_family_id*/, const Slice& /*key*/, Status MergeCF(uint32_t /*column_family_id*/, const Slice& /*key*/,
const Slice& /*value*/) override { const Slice& /*value*/) override {
ADD_FAILURE(); ADD_FAILURE();
return Status::OK(); return Status::OK();
} }
virtual void LogData(const Slice& /*blob*/) override { ADD_FAILURE(); } void LogData(const Slice& /*blob*/) override { ADD_FAILURE(); }
virtual bool Continue() override { return num_seen < kNumUpdates; } bool Continue() override { return num_seen < kNumUpdates; }
} handler; } handler;
batch.Iterate(&handler); batch.Iterate(&handler);
@ -494,7 +492,7 @@ TEST_F(WriteBatchTest, DISABLED_LargeKeyValue) {
struct NoopHandler : public WriteBatch::Handler { struct NoopHandler : public WriteBatch::Handler {
int num_seen = 0; int num_seen = 0;
virtual Status PutCF(uint32_t /*column_family_id*/, const Slice& key, Status PutCF(uint32_t /*column_family_id*/, const Slice& key,
const Slice& value) override { const Slice& value) override {
EXPECT_EQ(kKeyValueSize, key.size()); EXPECT_EQ(kKeyValueSize, key.size());
EXPECT_EQ(kKeyValueSize, value.size()); EXPECT_EQ(kKeyValueSize, value.size());
@ -505,23 +503,23 @@ TEST_F(WriteBatchTest, DISABLED_LargeKeyValue) {
++num_seen; ++num_seen;
return Status::OK(); return Status::OK();
} }
virtual Status DeleteCF(uint32_t /*column_family_id*/, Status DeleteCF(uint32_t /*column_family_id*/,
const Slice& /*key*/) override { const Slice& /*key*/) override {
ADD_FAILURE(); ADD_FAILURE();
return Status::OK(); return Status::OK();
} }
virtual Status SingleDeleteCF(uint32_t /*column_family_id*/, Status SingleDeleteCF(uint32_t /*column_family_id*/,
const Slice& /*key*/) override { const Slice& /*key*/) override {
ADD_FAILURE(); ADD_FAILURE();
return Status::OK(); return Status::OK();
} }
virtual Status MergeCF(uint32_t /*column_family_id*/, const Slice& /*key*/, Status MergeCF(uint32_t /*column_family_id*/, const Slice& /*key*/,
const Slice& /*value*/) override { const Slice& /*value*/) override {
ADD_FAILURE(); ADD_FAILURE();
return Status::OK(); return Status::OK();
} }
virtual void LogData(const Slice& /*blob*/) override { ADD_FAILURE(); } void LogData(const Slice& /*blob*/) override { ADD_FAILURE(); }
virtual bool Continue() override { return num_seen < 2; } bool Continue() override { return num_seen < 2; }
} handler; } handler;
batch.Iterate(&handler); batch.Iterate(&handler);
@ -533,31 +531,30 @@ TEST_F(WriteBatchTest, Continue) {
struct Handler : public TestHandler { struct Handler : public TestHandler {
int num_seen = 0; int num_seen = 0;
virtual Status PutCF(uint32_t column_family_id, const Slice& key, Status PutCF(uint32_t column_family_id, const Slice& key,
const Slice& value) override { const Slice& value) override {
++num_seen; ++num_seen;
return TestHandler::PutCF(column_family_id, key, value); return TestHandler::PutCF(column_family_id, key, value);
} }
virtual Status DeleteCF(uint32_t column_family_id, Status DeleteCF(uint32_t column_family_id, const Slice& key) override {
const Slice& key) override {
++num_seen; ++num_seen;
return TestHandler::DeleteCF(column_family_id, key); return TestHandler::DeleteCF(column_family_id, key);
} }
virtual Status SingleDeleteCF(uint32_t column_family_id, Status SingleDeleteCF(uint32_t column_family_id,
const Slice& key) override { const Slice& key) override {
++num_seen; ++num_seen;
return TestHandler::SingleDeleteCF(column_family_id, key); return TestHandler::SingleDeleteCF(column_family_id, key);
} }
virtual Status MergeCF(uint32_t column_family_id, const Slice& key, Status MergeCF(uint32_t column_family_id, const Slice& key,
const Slice& value) override { const Slice& value) override {
++num_seen; ++num_seen;
return TestHandler::MergeCF(column_family_id, key, value); return TestHandler::MergeCF(column_family_id, key, value);
} }
virtual void LogData(const Slice& blob) override { void LogData(const Slice& blob) override {
++num_seen; ++num_seen;
TestHandler::LogData(blob); TestHandler::LogData(blob);
} }
virtual bool Continue() override { return num_seen < 5; } bool Continue() override { return num_seen < 5; }
} handler; } handler;
batch.Put(Slice("k1"), Slice("v1")); batch.Put(Slice("k1"), Slice("v1"));

@ -295,7 +295,7 @@ TEST_F(WriteCallbackTest, WriteWithCallbackTest) {
public: public:
PublishSeqCallback(DBImpl* db_impl_in) PublishSeqCallback(DBImpl* db_impl_in)
: db_impl_(db_impl_in) {} : db_impl_(db_impl_in) {}
virtual Status Callback(SequenceNumber last_seq, Status Callback(SequenceNumber last_seq,
bool /*not used*/) override { bool /*not used*/) override {
db_impl_->SetLastPublishedSequence(last_seq); db_impl_->SetLastPublishedSequence(last_seq);
return Status::OK(); return Status::OK();

@ -18,7 +18,7 @@ class TimeSetEnv : public EnvWrapper {
public: public:
explicit TimeSetEnv() : EnvWrapper(nullptr) {} explicit TimeSetEnv() : EnvWrapper(nullptr) {}
uint64_t now_micros_ = 6666; uint64_t now_micros_ = 6666;
virtual uint64_t NowNanos() override { return now_micros_ * std::milli::den; } uint64_t NowNanos() override { return now_micros_ * std::milli::den; }
}; };
TEST_F(WriteControllerTest, ChangeDelayRateTest) { TEST_F(WriteControllerTest, ChangeDelayRateTest) {

@ -21,7 +21,7 @@ class NormalizingEnvWrapper : public EnvWrapper {
explicit NormalizingEnvWrapper(Env* base) : EnvWrapper(base) {} explicit NormalizingEnvWrapper(Env* base) : EnvWrapper(base) {}
// Removes . and .. from directory listing // Removes . and .. from directory listing
virtual Status GetChildren(const std::string& dir, Status GetChildren(const std::string& dir,
std::vector<std::string>* result) override { std::vector<std::string>* result) override {
Status status = EnvWrapper::GetChildren(dir, result); Status status = EnvWrapper::GetChildren(dir, result);
if (status.ok()) { if (status.ok()) {
@ -35,7 +35,7 @@ class NormalizingEnvWrapper : public EnvWrapper {
} }
// Removes . and .. from directory listing // Removes . and .. from directory listing
virtual Status GetChildrenFileAttributes( Status GetChildrenFileAttributes(
const std::string& dir, std::vector<FileAttributes>* result) override { const std::string& dir, std::vector<FileAttributes>* result) override {
Status status = EnvWrapper::GetChildrenFileAttributes(dir, result); Status status = EnvWrapper::GetChildrenFileAttributes(dir, result);
if (status.ok()) { if (status.ok()) {
@ -60,11 +60,9 @@ class EnvBasicTestWithParam : public testing::Test,
test_dir_ = test::PerThreadDBPath(env_, "env_basic_test"); test_dir_ = test::PerThreadDBPath(env_, "env_basic_test");
} }
void SetUp() { void SetUp() override { env_->CreateDirIfMissing(test_dir_); }
env_->CreateDirIfMissing(test_dir_);
}
void TearDown() { void TearDown() override {
std::vector<std::string> files; std::vector<std::string> files;
env_->GetChildren(test_dir_, &files); env_->GetChildren(test_dir_, &files);
for (const auto& file : files) { for (const auto& file : files) {

45
env/env_chroot.cc vendored

@ -38,7 +38,7 @@ class ChrootEnv : public EnvWrapper {
#endif #endif
} }
virtual Status NewSequentialFile(const std::string& fname, Status NewSequentialFile(const std::string& fname,
std::unique_ptr<SequentialFile>* result, std::unique_ptr<SequentialFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
auto status_and_enc_path = EncodePathWithNewBasename(fname); auto status_and_enc_path = EncodePathWithNewBasename(fname);
@ -49,7 +49,7 @@ class ChrootEnv : public EnvWrapper {
options); options);
} }
virtual Status NewRandomAccessFile(const std::string& fname, Status NewRandomAccessFile(const std::string& fname,
std::unique_ptr<RandomAccessFile>* result, std::unique_ptr<RandomAccessFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
auto status_and_enc_path = EncodePathWithNewBasename(fname); auto status_and_enc_path = EncodePathWithNewBasename(fname);
@ -60,7 +60,7 @@ class ChrootEnv : public EnvWrapper {
options); options);
} }
virtual Status NewWritableFile(const std::string& fname, Status NewWritableFile(const std::string& fname,
std::unique_ptr<WritableFile>* result, std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
auto status_and_enc_path = EncodePathWithNewBasename(fname); auto status_and_enc_path = EncodePathWithNewBasename(fname);
@ -71,7 +71,7 @@ class ChrootEnv : public EnvWrapper {
options); options);
} }
virtual Status ReuseWritableFile(const std::string& fname, Status ReuseWritableFile(const std::string& fname,
const std::string& old_fname, const std::string& old_fname,
std::unique_ptr<WritableFile>* result, std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
@ -88,7 +88,7 @@ class ChrootEnv : public EnvWrapper {
options); options);
} }
virtual Status NewRandomRWFile(const std::string& fname, Status NewRandomRWFile(const std::string& fname,
std::unique_ptr<RandomRWFile>* result, std::unique_ptr<RandomRWFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
auto status_and_enc_path = EncodePathWithNewBasename(fname); auto status_and_enc_path = EncodePathWithNewBasename(fname);
@ -99,7 +99,7 @@ class ChrootEnv : public EnvWrapper {
options); options);
} }
virtual Status NewDirectory(const std::string& dir, Status NewDirectory(const std::string& dir,
std::unique_ptr<Directory>* result) override { std::unique_ptr<Directory>* result) override {
auto status_and_enc_path = EncodePathWithNewBasename(dir); auto status_and_enc_path = EncodePathWithNewBasename(dir);
if (!status_and_enc_path.first.ok()) { if (!status_and_enc_path.first.ok()) {
@ -108,7 +108,7 @@ class ChrootEnv : public EnvWrapper {
return EnvWrapper::NewDirectory(status_and_enc_path.second, result); return EnvWrapper::NewDirectory(status_and_enc_path.second, result);
} }
virtual Status FileExists(const std::string& fname) override { Status FileExists(const std::string& fname) override {
auto status_and_enc_path = EncodePathWithNewBasename(fname); auto status_and_enc_path = EncodePathWithNewBasename(fname);
if (!status_and_enc_path.first.ok()) { if (!status_and_enc_path.first.ok()) {
return status_and_enc_path.first; return status_and_enc_path.first;
@ -116,7 +116,7 @@ class ChrootEnv : public EnvWrapper {
return EnvWrapper::FileExists(status_and_enc_path.second); return EnvWrapper::FileExists(status_and_enc_path.second);
} }
virtual Status GetChildren(const std::string& dir, Status GetChildren(const std::string& dir,
std::vector<std::string>* result) override { std::vector<std::string>* result) override {
auto status_and_enc_path = EncodePath(dir); auto status_and_enc_path = EncodePath(dir);
if (!status_and_enc_path.first.ok()) { if (!status_and_enc_path.first.ok()) {
@ -125,7 +125,7 @@ class ChrootEnv : public EnvWrapper {
return EnvWrapper::GetChildren(status_and_enc_path.second, result); return EnvWrapper::GetChildren(status_and_enc_path.second, result);
} }
virtual Status GetChildrenFileAttributes( Status GetChildrenFileAttributes(
const std::string& dir, std::vector<FileAttributes>* result) override { const std::string& dir, std::vector<FileAttributes>* result) override {
auto status_and_enc_path = EncodePath(dir); auto status_and_enc_path = EncodePath(dir);
if (!status_and_enc_path.first.ok()) { if (!status_and_enc_path.first.ok()) {
@ -135,7 +135,7 @@ class ChrootEnv : public EnvWrapper {
result); result);
} }
virtual Status DeleteFile(const std::string& fname) override { Status DeleteFile(const std::string& fname) override {
auto status_and_enc_path = EncodePath(fname); auto status_and_enc_path = EncodePath(fname);
if (!status_and_enc_path.first.ok()) { if (!status_and_enc_path.first.ok()) {
return status_and_enc_path.first; return status_and_enc_path.first;
@ -143,7 +143,7 @@ class ChrootEnv : public EnvWrapper {
return EnvWrapper::DeleteFile(status_and_enc_path.second); return EnvWrapper::DeleteFile(status_and_enc_path.second);
} }
virtual Status CreateDir(const std::string& dirname) override { Status CreateDir(const std::string& dirname) override {
auto status_and_enc_path = EncodePathWithNewBasename(dirname); auto status_and_enc_path = EncodePathWithNewBasename(dirname);
if (!status_and_enc_path.first.ok()) { if (!status_and_enc_path.first.ok()) {
return status_and_enc_path.first; return status_and_enc_path.first;
@ -151,7 +151,7 @@ class ChrootEnv : public EnvWrapper {
return EnvWrapper::CreateDir(status_and_enc_path.second); return EnvWrapper::CreateDir(status_and_enc_path.second);
} }
virtual Status CreateDirIfMissing(const std::string& dirname) override { Status CreateDirIfMissing(const std::string& dirname) override {
auto status_and_enc_path = EncodePathWithNewBasename(dirname); auto status_and_enc_path = EncodePathWithNewBasename(dirname);
if (!status_and_enc_path.first.ok()) { if (!status_and_enc_path.first.ok()) {
return status_and_enc_path.first; return status_and_enc_path.first;
@ -159,7 +159,7 @@ class ChrootEnv : public EnvWrapper {
return EnvWrapper::CreateDirIfMissing(status_and_enc_path.second); return EnvWrapper::CreateDirIfMissing(status_and_enc_path.second);
} }
virtual Status DeleteDir(const std::string& dirname) override { Status DeleteDir(const std::string& dirname) override {
auto status_and_enc_path = EncodePath(dirname); auto status_and_enc_path = EncodePath(dirname);
if (!status_and_enc_path.first.ok()) { if (!status_and_enc_path.first.ok()) {
return status_and_enc_path.first; return status_and_enc_path.first;
@ -167,8 +167,7 @@ class ChrootEnv : public EnvWrapper {
return EnvWrapper::DeleteDir(status_and_enc_path.second); return EnvWrapper::DeleteDir(status_and_enc_path.second);
} }
virtual Status GetFileSize(const std::string& fname, Status GetFileSize(const std::string& fname, uint64_t* file_size) override {
uint64_t* file_size) override {
auto status_and_enc_path = EncodePath(fname); auto status_and_enc_path = EncodePath(fname);
if (!status_and_enc_path.first.ok()) { if (!status_and_enc_path.first.ok()) {
return status_and_enc_path.first; return status_and_enc_path.first;
@ -176,7 +175,7 @@ class ChrootEnv : public EnvWrapper {
return EnvWrapper::GetFileSize(status_and_enc_path.second, file_size); return EnvWrapper::GetFileSize(status_and_enc_path.second, file_size);
} }
virtual Status GetFileModificationTime(const std::string& fname, Status GetFileModificationTime(const std::string& fname,
uint64_t* file_mtime) override { uint64_t* file_mtime) override {
auto status_and_enc_path = EncodePath(fname); auto status_and_enc_path = EncodePath(fname);
if (!status_and_enc_path.first.ok()) { if (!status_and_enc_path.first.ok()) {
@ -186,8 +185,7 @@ class ChrootEnv : public EnvWrapper {
file_mtime); file_mtime);
} }
virtual Status RenameFile(const std::string& src, Status RenameFile(const std::string& src, const std::string& dest) override {
const std::string& dest) override {
auto status_and_src_enc_path = EncodePath(src); auto status_and_src_enc_path = EncodePath(src);
if (!status_and_src_enc_path.first.ok()) { if (!status_and_src_enc_path.first.ok()) {
return status_and_src_enc_path.first; return status_and_src_enc_path.first;
@ -200,8 +198,7 @@ class ChrootEnv : public EnvWrapper {
status_and_dest_enc_path.second); status_and_dest_enc_path.second);
} }
virtual Status LinkFile(const std::string& src, Status LinkFile(const std::string& src, const std::string& dest) override {
const std::string& dest) override {
auto status_and_src_enc_path = EncodePath(src); auto status_and_src_enc_path = EncodePath(src);
if (!status_and_src_enc_path.first.ok()) { if (!status_and_src_enc_path.first.ok()) {
return status_and_src_enc_path.first; return status_and_src_enc_path.first;
@ -214,7 +211,7 @@ class ChrootEnv : public EnvWrapper {
status_and_dest_enc_path.second); status_and_dest_enc_path.second);
} }
virtual Status LockFile(const std::string& fname, FileLock** lock) override { Status LockFile(const std::string& fname, FileLock** lock) override {
auto status_and_enc_path = EncodePathWithNewBasename(fname); auto status_and_enc_path = EncodePathWithNewBasename(fname);
if (!status_and_enc_path.first.ok()) { if (!status_and_enc_path.first.ok()) {
return status_and_enc_path.first; return status_and_enc_path.first;
@ -225,7 +222,7 @@ class ChrootEnv : public EnvWrapper {
return EnvWrapper::LockFile(status_and_enc_path.second, lock); return EnvWrapper::LockFile(status_and_enc_path.second, lock);
} }
virtual Status GetTestDirectory(std::string* path) override { Status GetTestDirectory(std::string* path) override {
// Adapted from PosixEnv's implementation since it doesn't provide a way to // Adapted from PosixEnv's implementation since it doesn't provide a way to
// create directory in the chroot. // create directory in the chroot.
char buf[256]; char buf[256];
@ -237,7 +234,7 @@ class ChrootEnv : public EnvWrapper {
return Status::OK(); return Status::OK();
} }
virtual Status NewLogger(const std::string& fname, Status NewLogger(const std::string& fname,
std::shared_ptr<Logger>* result) override { std::shared_ptr<Logger>* result) override {
auto status_and_enc_path = EncodePathWithNewBasename(fname); auto status_and_enc_path = EncodePathWithNewBasename(fname);
if (!status_and_enc_path.first.ok()) { if (!status_and_enc_path.first.ok()) {
@ -246,7 +243,7 @@ class ChrootEnv : public EnvWrapper {
return EnvWrapper::NewLogger(status_and_enc_path.second, result); return EnvWrapper::NewLogger(status_and_enc_path.second, result);
} }
virtual Status GetAbsolutePath(const std::string& db_path, Status GetAbsolutePath(const std::string& db_path,
std::string* output_path) override { std::string* output_path) override {
auto status_and_enc_path = EncodePath(db_path); auto status_and_enc_path = EncodePath(db_path);
if (!status_and_enc_path.first.ok()) { if (!status_and_enc_path.first.ok()) {

@ -42,7 +42,7 @@ class EncryptedSequentialFile : public SequentialFile {
// If an error was encountered, returns a non-OK status. // If an error was encountered, returns a non-OK status.
// //
// REQUIRES: External synchronization // REQUIRES: External synchronization
virtual Status Read(size_t n, Slice* result, char* scratch) override { Status Read(size_t n, Slice* result, char* scratch) override {
assert(scratch); assert(scratch);
Status status = file_->Read(n, result, scratch); Status status = file_->Read(n, result, scratch);
if (!status.ok()) { if (!status.ok()) {
@ -60,7 +60,7 @@ class EncryptedSequentialFile : public SequentialFile {
// file, and Skip will return OK. // file, and Skip will return OK.
// //
// REQUIRES: External synchronization // REQUIRES: External synchronization
virtual Status Skip(uint64_t n) override { Status Skip(uint64_t n) override {
auto status = file_->Skip(n); auto status = file_->Skip(n);
if (!status.ok()) { if (!status.ok()) {
return status; return status;
@ -71,26 +71,25 @@ class EncryptedSequentialFile : public SequentialFile {
// Indicates the upper layers if the current SequentialFile implementation // Indicates the upper layers if the current SequentialFile implementation
// uses direct IO. // uses direct IO.
virtual bool use_direct_io() const override { bool use_direct_io() const override { return file_->use_direct_io(); }
return file_->use_direct_io();
}
// Use the returned alignment value to allocate // Use the returned alignment value to allocate
// aligned buffer for Direct I/O // aligned buffer for Direct I/O
virtual size_t GetRequiredBufferAlignment() const override { size_t GetRequiredBufferAlignment() const override {
return file_->GetRequiredBufferAlignment(); return file_->GetRequiredBufferAlignment();
} }
// Remove any kind of caching of data from the offset to offset+length // Remove any kind of caching of data from the offset to offset+length
// of this file. If the length is 0, then it refers to the end of file. // of this file. If the length is 0, then it refers to the end of file.
// If the system is not caching the file contents, then this is a noop. // If the system is not caching the file contents, then this is a noop.
virtual Status InvalidateCache(size_t offset, size_t length) override { Status InvalidateCache(size_t offset, size_t length) override {
return file_->InvalidateCache(offset + prefixLength_, length); return file_->InvalidateCache(offset + prefixLength_, length);
} }
// Positioned Read for direct I/O // Positioned Read for direct I/O
// If Direct I/O enabled, offset, n, and scratch should be properly aligned // If Direct I/O enabled, offset, n, and scratch should be properly aligned
virtual Status PositionedRead(uint64_t offset, size_t n, Slice* result, char* scratch) override { Status PositionedRead(uint64_t offset, size_t n, Slice* result,
char* scratch) override {
assert(scratch); assert(scratch);
offset += prefixLength_; // Skip prefix offset += prefixLength_; // Skip prefix
auto status = file_->PositionedRead(offset, n, result, scratch); auto status = file_->PositionedRead(offset, n, result, scratch);
@ -101,7 +100,6 @@ class EncryptedSequentialFile : public SequentialFile {
status = stream_->Decrypt(offset, (char*)result->data(), result->size()); status = stream_->Decrypt(offset, (char*)result->data(), result->size());
return status; return status;
} }
}; };
// A file abstraction for randomly reading the contents of a file. // A file abstraction for randomly reading the contents of a file.
@ -125,7 +123,8 @@ class EncryptedRandomAccessFile : public RandomAccessFile {
// //
// Safe for concurrent use by multiple threads. // Safe for concurrent use by multiple threads.
// If Direct I/O enabled, offset, n, and scratch should be aligned properly. // If Direct I/O enabled, offset, n, and scratch should be aligned properly.
virtual Status Read(uint64_t offset, size_t n, Slice* result, char* scratch) const override { Status Read(uint64_t offset, size_t n, Slice* result,
char* scratch) const override {
assert(scratch); assert(scratch);
offset += prefixLength_; offset += prefixLength_;
auto status = file_->Read(offset, n, result, scratch); auto status = file_->Read(offset, n, result, scratch);
@ -137,7 +136,7 @@ class EncryptedRandomAccessFile : public RandomAccessFile {
} }
// Readahead the file starting from offset by n bytes for caching. // Readahead the file starting from offset by n bytes for caching.
virtual Status Prefetch(uint64_t offset, size_t n) override { Status Prefetch(uint64_t offset, size_t n) override {
//return Status::OK(); //return Status::OK();
return file_->Prefetch(offset + prefixLength_, n); return file_->Prefetch(offset + prefixLength_, n);
} }
@ -157,30 +156,26 @@ class EncryptedRandomAccessFile : public RandomAccessFile {
// a single varint. // a single varint.
// //
// Note: these IDs are only valid for the duration of the process. // Note: these IDs are only valid for the duration of the process.
virtual size_t GetUniqueId(char* id, size_t max_size) const override { size_t GetUniqueId(char* id, size_t max_size) const override {
return file_->GetUniqueId(id, max_size); return file_->GetUniqueId(id, max_size);
}; };
virtual void Hint(AccessPattern pattern) override { void Hint(AccessPattern pattern) override { file_->Hint(pattern); }
file_->Hint(pattern);
}
// Indicates the upper layers if the current RandomAccessFile implementation // Indicates the upper layers if the current RandomAccessFile implementation
// uses direct IO. // uses direct IO.
virtual bool use_direct_io() const override { bool use_direct_io() const override { return file_->use_direct_io(); }
return file_->use_direct_io();
}
// Use the returned alignment value to allocate // Use the returned alignment value to allocate
// aligned buffer for Direct I/O // aligned buffer for Direct I/O
virtual size_t GetRequiredBufferAlignment() const override { size_t GetRequiredBufferAlignment() const override {
return file_->GetRequiredBufferAlignment(); return file_->GetRequiredBufferAlignment();
} }
// Remove any kind of caching of data from the offset to offset+length // Remove any kind of caching of data from the offset to offset+length
// of this file. If the length is 0, then it refers to the end of file. // of this file. If the length is 0, then it refers to the end of file.
// If the system is not caching the file contents, then this is a noop. // If the system is not caching the file contents, then this is a noop.
virtual Status InvalidateCache(size_t offset, size_t length) override { Status InvalidateCache(size_t offset, size_t length) override {
return file_->InvalidateCache(offset + prefixLength_, length); return file_->InvalidateCache(offset + prefixLength_, length);
} }
}; };
@ -247,16 +242,18 @@ class EncryptedWritableFile : public WritableFileWrapper {
// Indicates the upper layers if the current WritableFile implementation // Indicates the upper layers if the current WritableFile implementation
// uses direct IO. // uses direct IO.
virtual bool use_direct_io() const override { return file_->use_direct_io(); } bool use_direct_io() const override { return file_->use_direct_io(); }
// Use the returned alignment value to allocate // Use the returned alignment value to allocate
// aligned buffer for Direct I/O // aligned buffer for Direct I/O
virtual size_t GetRequiredBufferAlignment() const override { return file_->GetRequiredBufferAlignment(); } size_t GetRequiredBufferAlignment() const override {
return file_->GetRequiredBufferAlignment();
}
/* /*
* Get the size of valid data in the file. * Get the size of valid data in the file.
*/ */
virtual uint64_t GetFileSize() override { uint64_t GetFileSize() override {
return file_->GetFileSize() - prefixLength_; return file_->GetFileSize() - prefixLength_;
} }
@ -264,7 +261,7 @@ class EncryptedWritableFile : public WritableFileWrapper {
// before closing. It is not always possible to keep track of the file // before closing. It is not always possible to keep track of the file
// size due to whole pages writes. The behavior is undefined if called // size due to whole pages writes. The behavior is undefined if called
// with other writes to follow. // with other writes to follow.
virtual Status Truncate(uint64_t size) override { Status Truncate(uint64_t size) override {
return file_->Truncate(size + prefixLength_); return file_->Truncate(size + prefixLength_);
} }
@ -272,7 +269,7 @@ class EncryptedWritableFile : public WritableFileWrapper {
// of this file. If the length is 0, then it refers to the end of file. // of this file. If the length is 0, then it refers to the end of file.
// If the system is not caching the file contents, then this is a noop. // If the system is not caching the file contents, then this is a noop.
// This call has no effect on dirty pages in the cache. // This call has no effect on dirty pages in the cache.
virtual Status InvalidateCache(size_t offset, size_t length) override { Status InvalidateCache(size_t offset, size_t length) override {
return file_->InvalidateCache(offset + prefixLength_, length); return file_->InvalidateCache(offset + prefixLength_, length);
} }
@ -282,7 +279,7 @@ class EncryptedWritableFile : public WritableFileWrapper {
// This asks the OS to initiate flushing the cached data to disk, // This asks the OS to initiate flushing the cached data to disk,
// without waiting for completion. // without waiting for completion.
// Default implementation does nothing. // Default implementation does nothing.
virtual Status RangeSync(uint64_t offset, uint64_t nbytes) override { Status RangeSync(uint64_t offset, uint64_t nbytes) override {
return file_->RangeSync(offset + prefixLength_, nbytes); return file_->RangeSync(offset + prefixLength_, nbytes);
} }
@ -291,12 +288,12 @@ class EncryptedWritableFile : public WritableFileWrapper {
// of space on devices where it can result in less file // of space on devices where it can result in less file
// fragmentation and/or less waste from over-zealous filesystem // fragmentation and/or less waste from over-zealous filesystem
// pre-allocation. // pre-allocation.
virtual void PrepareWrite(size_t offset, size_t len) override { void PrepareWrite(size_t offset, size_t len) override {
file_->PrepareWrite(offset + prefixLength_, len); file_->PrepareWrite(offset + prefixLength_, len);
} }
// Pre-allocates space for a file. // Pre-allocates space for a file.
virtual Status Allocate(uint64_t offset, uint64_t len) override { Status Allocate(uint64_t offset, uint64_t len) override {
return file_->Allocate(offset + prefixLength_, len); return file_->Allocate(offset + prefixLength_, len);
} }
}; };
@ -314,17 +311,17 @@ class EncryptedRandomRWFile : public RandomRWFile {
// Indicates if the class makes use of direct I/O // Indicates if the class makes use of direct I/O
// If false you must pass aligned buffer to Write() // If false you must pass aligned buffer to Write()
virtual bool use_direct_io() const override { return file_->use_direct_io(); } bool use_direct_io() const override { return file_->use_direct_io(); }
// Use the returned alignment value to allocate // Use the returned alignment value to allocate
// aligned buffer for Direct I/O // aligned buffer for Direct I/O
virtual size_t GetRequiredBufferAlignment() const override { size_t GetRequiredBufferAlignment() const override {
return file_->GetRequiredBufferAlignment(); return file_->GetRequiredBufferAlignment();
} }
// Write bytes in `data` at offset `offset`, Returns Status::OK() on success. // Write bytes in `data` at offset `offset`, Returns Status::OK() on success.
// Pass aligned buffer when use_direct_io() returns true. // Pass aligned buffer when use_direct_io() returns true.
virtual Status Write(uint64_t offset, const Slice& data) override { Status Write(uint64_t offset, const Slice& data) override {
AlignedBuffer buf; AlignedBuffer buf;
Status status; Status status;
Slice dataToWrite(data); Slice dataToWrite(data);
@ -347,7 +344,8 @@ class EncryptedRandomRWFile : public RandomRWFile {
// Read up to `n` bytes starting from offset `offset` and store them in // Read up to `n` bytes starting from offset `offset` and store them in
// result, provided `scratch` size should be at least `n`. // result, provided `scratch` size should be at least `n`.
// Returns Status::OK() on success. // Returns Status::OK() on success.
virtual Status Read(uint64_t offset, size_t n, Slice* result, char* scratch) const override { Status Read(uint64_t offset, size_t n, Slice* result,
char* scratch) const override {
assert(scratch); assert(scratch);
offset += prefixLength_; offset += prefixLength_;
auto status = file_->Read(offset, n, result, scratch); auto status = file_->Read(offset, n, result, scratch);
@ -358,21 +356,13 @@ class EncryptedRandomRWFile : public RandomRWFile {
return status; return status;
} }
virtual Status Flush() override { Status Flush() override { return file_->Flush(); }
return file_->Flush();
}
virtual Status Sync() override { Status Sync() override { return file_->Sync(); }
return file_->Sync();
}
virtual Status Fsync() override { Status Fsync() override { return file_->Fsync(); }
return file_->Fsync();
}
virtual Status Close() override { Status Close() override { return file_->Close(); }
return file_->Close();
}
}; };
// EncryptedEnv implements an Env wrapper that adds encryption to files stored on disk. // EncryptedEnv implements an Env wrapper that adds encryption to files stored on disk.
@ -384,7 +374,7 @@ class EncryptedEnv : public EnvWrapper {
} }
// NewSequentialFile opens a file for sequential reading. // NewSequentialFile opens a file for sequential reading.
virtual Status NewSequentialFile(const std::string& fname, Status NewSequentialFile(const std::string& fname,
std::unique_ptr<SequentialFile>* result, std::unique_ptr<SequentialFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
result->reset(); result->reset();
@ -421,7 +411,7 @@ class EncryptedEnv : public EnvWrapper {
} }
// NewRandomAccessFile opens a file for random read access. // NewRandomAccessFile opens a file for random read access.
virtual Status NewRandomAccessFile(const std::string& fname, Status NewRandomAccessFile(const std::string& fname,
std::unique_ptr<RandomAccessFile>* result, std::unique_ptr<RandomAccessFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
result->reset(); result->reset();
@ -458,7 +448,7 @@ class EncryptedEnv : public EnvWrapper {
} }
// NewWritableFile opens a file for sequential writing. // NewWritableFile opens a file for sequential writing.
virtual Status NewWritableFile(const std::string& fname, Status NewWritableFile(const std::string& fname,
std::unique_ptr<WritableFile>* result, std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
result->reset(); result->reset();
@ -504,7 +494,7 @@ class EncryptedEnv : public EnvWrapper {
// returns non-OK. // returns non-OK.
// //
// The returned file will only be accessed by one thread at a time. // The returned file will only be accessed by one thread at a time.
virtual Status ReopenWritableFile(const std::string& fname, Status ReopenWritableFile(const std::string& fname,
std::unique_ptr<WritableFile>* result, std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
result->reset(); result->reset();
@ -544,7 +534,7 @@ class EncryptedEnv : public EnvWrapper {
} }
// Reuse an existing file by renaming it and opening it as writable. // Reuse an existing file by renaming it and opening it as writable.
virtual Status ReuseWritableFile(const std::string& fname, Status ReuseWritableFile(const std::string& fname,
const std::string& old_fname, const std::string& old_fname,
std::unique_ptr<WritableFile>* result, std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
@ -589,7 +579,7 @@ class EncryptedEnv : public EnvWrapper {
// *result and returns OK. On failure returns non-OK. // *result and returns OK. On failure returns non-OK.
// //
// The returned file will only be accessed by one thread at a time. // The returned file will only be accessed by one thread at a time.
virtual Status NewRandomRWFile(const std::string& fname, Status NewRandomRWFile(const std::string& fname,
std::unique_ptr<RandomRWFile>* result, std::unique_ptr<RandomRWFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
result->reset(); result->reset();
@ -649,7 +639,8 @@ class EncryptedEnv : public EnvWrapper {
// NotFound if "dir" does not exist, the calling process does not have // NotFound if "dir" does not exist, the calling process does not have
// permission to access "dir", or if "dir" is invalid. // permission to access "dir", or if "dir" is invalid.
// IOError if an IO Error was encountered // IOError if an IO Error was encountered
virtual Status GetChildrenFileAttributes(const std::string& dir, std::vector<FileAttributes>* result) override { Status GetChildrenFileAttributes(
const std::string& dir, std::vector<FileAttributes>* result) override {
auto status = EnvWrapper::GetChildrenFileAttributes(dir, result); auto status = EnvWrapper::GetChildrenFileAttributes(dir, result);
if (!status.ok()) { if (!status.ok()) {
return status; return status;
@ -663,7 +654,7 @@ class EncryptedEnv : public EnvWrapper {
} }
// Store the size of fname in *file_size. // Store the size of fname in *file_size.
virtual Status GetFileSize(const std::string& fname, uint64_t* file_size) override { Status GetFileSize(const std::string& fname, uint64_t* file_size) override {
auto status = EnvWrapper::GetFileSize(fname, file_size); auto status = EnvWrapper::GetFileSize(fname, file_size);
if (!status.ok()) { if (!status.ok()) {
return status; return status;

102
env/env_posix.cc vendored

@ -119,7 +119,7 @@ class PosixEnv : public Env {
public: public:
PosixEnv(); PosixEnv();
virtual ~PosixEnv() { ~PosixEnv() override {
for (const auto tid : threads_to_join_) { for (const auto tid : threads_to_join_) {
pthread_join(tid, nullptr); pthread_join(tid, nullptr);
} }
@ -141,7 +141,7 @@ class PosixEnv : public Env {
} }
} }
virtual Status NewSequentialFile(const std::string& fname, Status NewSequentialFile(const std::string& fname,
std::unique_ptr<SequentialFile>* result, std::unique_ptr<SequentialFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
result->reset(); result->reset();
@ -191,7 +191,7 @@ class PosixEnv : public Env {
return Status::OK(); return Status::OK();
} }
virtual Status NewRandomAccessFile(const std::string& fname, Status NewRandomAccessFile(const std::string& fname,
std::unique_ptr<RandomAccessFile>* result, std::unique_ptr<RandomAccessFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
result->reset(); result->reset();
@ -332,19 +332,19 @@ class PosixEnv : public Env {
return s; return s;
} }
virtual Status NewWritableFile(const std::string& fname, Status NewWritableFile(const std::string& fname,
std::unique_ptr<WritableFile>* result, std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
return OpenWritableFile(fname, result, options, false); return OpenWritableFile(fname, result, options, false);
} }
virtual Status ReopenWritableFile(const std::string& fname, Status ReopenWritableFile(const std::string& fname,
std::unique_ptr<WritableFile>* result, std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
return OpenWritableFile(fname, result, options, true); return OpenWritableFile(fname, result, options, true);
} }
virtual Status ReuseWritableFile(const std::string& fname, Status ReuseWritableFile(const std::string& fname,
const std::string& old_fname, const std::string& old_fname,
std::unique_ptr<WritableFile>* result, std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
@ -429,7 +429,7 @@ class PosixEnv : public Env {
return s; return s;
} }
virtual Status NewRandomRWFile(const std::string& fname, Status NewRandomRWFile(const std::string& fname,
std::unique_ptr<RandomRWFile>* result, std::unique_ptr<RandomRWFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
int fd = -1; int fd = -1;
@ -453,7 +453,7 @@ class PosixEnv : public Env {
return Status::OK(); return Status::OK();
} }
virtual Status NewMemoryMappedFileBuffer( Status NewMemoryMappedFileBuffer(
const std::string& fname, const std::string& fname,
std::unique_ptr<MemoryMappedFileBuffer>* result) override { std::unique_ptr<MemoryMappedFileBuffer>* result) override {
int fd = -1; int fd = -1;
@ -496,7 +496,7 @@ class PosixEnv : public Env {
return status; return status;
} }
virtual Status NewDirectory(const std::string& name, Status NewDirectory(const std::string& name,
std::unique_ptr<Directory>* result) override { std::unique_ptr<Directory>* result) override {
result->reset(); result->reset();
int fd; int fd;
@ -513,7 +513,7 @@ class PosixEnv : public Env {
return Status::OK(); return Status::OK();
} }
virtual Status FileExists(const std::string& fname) override { Status FileExists(const std::string& fname) override {
int result = access(fname.c_str(), F_OK); int result = access(fname.c_str(), F_OK);
if (result == 0) { if (result == 0) {
@ -535,7 +535,7 @@ class PosixEnv : public Env {
} }
} }
virtual Status GetChildren(const std::string& dir, Status GetChildren(const std::string& dir,
std::vector<std::string>* result) override { std::vector<std::string>* result) override {
result->clear(); result->clear();
DIR* d = opendir(dir.c_str()); DIR* d = opendir(dir.c_str());
@ -557,7 +557,7 @@ class PosixEnv : public Env {
return Status::OK(); return Status::OK();
} }
virtual Status DeleteFile(const std::string& fname) override { Status DeleteFile(const std::string& fname) override {
Status result; Status result;
if (unlink(fname.c_str()) != 0) { if (unlink(fname.c_str()) != 0) {
result = IOError("while unlink() file", fname, errno); result = IOError("while unlink() file", fname, errno);
@ -565,7 +565,7 @@ class PosixEnv : public Env {
return result; return result;
}; };
virtual Status CreateDir(const std::string& name) override { Status CreateDir(const std::string& name) override {
Status result; Status result;
if (mkdir(name.c_str(), 0755) != 0) { if (mkdir(name.c_str(), 0755) != 0) {
result = IOError("While mkdir", name, errno); result = IOError("While mkdir", name, errno);
@ -573,7 +573,7 @@ class PosixEnv : public Env {
return result; return result;
}; };
virtual Status CreateDirIfMissing(const std::string& name) override { Status CreateDirIfMissing(const std::string& name) override {
Status result; Status result;
if (mkdir(name.c_str(), 0755) != 0) { if (mkdir(name.c_str(), 0755) != 0) {
if (errno != EEXIST) { if (errno != EEXIST) {
@ -587,7 +587,7 @@ class PosixEnv : public Env {
return result; return result;
}; };
virtual Status DeleteDir(const std::string& name) override { Status DeleteDir(const std::string& name) override {
Status result; Status result;
if (rmdir(name.c_str()) != 0) { if (rmdir(name.c_str()) != 0) {
result = IOError("file rmdir", name, errno); result = IOError("file rmdir", name, errno);
@ -595,8 +595,7 @@ class PosixEnv : public Env {
return result; return result;
}; };
virtual Status GetFileSize(const std::string& fname, Status GetFileSize(const std::string& fname, uint64_t* size) override {
uint64_t* size) override {
Status s; Status s;
struct stat sbuf; struct stat sbuf;
if (stat(fname.c_str(), &sbuf) != 0) { if (stat(fname.c_str(), &sbuf) != 0) {
@ -608,7 +607,7 @@ class PosixEnv : public Env {
return s; return s;
} }
virtual Status GetFileModificationTime(const std::string& fname, Status GetFileModificationTime(const std::string& fname,
uint64_t* file_mtime) override { uint64_t* file_mtime) override {
struct stat s; struct stat s;
if (stat(fname.c_str(), &s) !=0) { if (stat(fname.c_str(), &s) !=0) {
@ -617,7 +616,7 @@ class PosixEnv : public Env {
*file_mtime = static_cast<uint64_t>(s.st_mtime); *file_mtime = static_cast<uint64_t>(s.st_mtime);
return Status::OK(); return Status::OK();
} }
virtual Status RenameFile(const std::string& src, Status RenameFile(const std::string& src,
const std::string& target) override { const std::string& target) override {
Status result; Status result;
if (rename(src.c_str(), target.c_str()) != 0) { if (rename(src.c_str(), target.c_str()) != 0) {
@ -626,8 +625,7 @@ class PosixEnv : public Env {
return result; return result;
} }
virtual Status LinkFile(const std::string& src, Status LinkFile(const std::string& src, const std::string& target) override {
const std::string& target) override {
Status result; Status result;
if (link(src.c_str(), target.c_str()) != 0) { if (link(src.c_str(), target.c_str()) != 0) {
if (errno == EXDEV) { if (errno == EXDEV) {
@ -647,8 +645,8 @@ class PosixEnv : public Env {
return Status::OK(); return Status::OK();
} }
virtual Status AreFilesSame(const std::string& first, Status AreFilesSame(const std::string& first, const std::string& second,
const std::string& second, bool* res) override { bool* res) override {
struct stat statbuf[2]; struct stat statbuf[2];
if (stat(first.c_str(), &statbuf[0]) != 0) { if (stat(first.c_str(), &statbuf[0]) != 0) {
return IOError("stat file", first, errno); return IOError("stat file", first, errno);
@ -667,7 +665,7 @@ class PosixEnv : public Env {
return Status::OK(); return Status::OK();
} }
virtual Status LockFile(const std::string& fname, FileLock** lock) override { Status LockFile(const std::string& fname, FileLock** lock) override {
*lock = nullptr; *lock = nullptr;
Status result; Status result;
@ -713,7 +711,7 @@ class PosixEnv : public Env {
return result; return result;
} }
virtual Status UnlockFile(FileLock* lock) override { Status UnlockFile(FileLock* lock) override {
PosixFileLock* my_lock = reinterpret_cast<PosixFileLock*>(lock); PosixFileLock* my_lock = reinterpret_cast<PosixFileLock*>(lock);
Status result; Status result;
mutex_lockedFiles.Lock(); mutex_lockedFiles.Lock();
@ -731,19 +729,19 @@ class PosixEnv : public Env {
return result; return result;
} }
virtual void Schedule(void (*function)(void* arg1), void* arg, void Schedule(void (*function)(void* arg1), void* arg, Priority pri = LOW,
Priority pri = LOW, void* tag = nullptr, void* tag = nullptr,
void (*unschedFunction)(void* arg) = nullptr) override; void (*unschedFunction)(void* arg) = nullptr) override;
virtual int UnSchedule(void* arg, Priority pri) override; int UnSchedule(void* arg, Priority pri) override;
virtual void StartThread(void (*function)(void* arg), void* arg) override; void StartThread(void (*function)(void* arg), void* arg) override;
virtual void WaitForJoin() override; void WaitForJoin() override;
virtual unsigned int GetThreadPoolQueueLen(Priority pri = LOW) const override; unsigned int GetThreadPoolQueueLen(Priority pri = LOW) const override;
virtual Status GetTestDirectory(std::string* result) override { Status GetTestDirectory(std::string* result) override {
const char* env = getenv("TEST_TMPDIR"); const char* env = getenv("TEST_TMPDIR");
if (env && env[0] != '\0') { if (env && env[0] != '\0') {
*result = env; *result = env;
@ -757,8 +755,7 @@ class PosixEnv : public Env {
return Status::OK(); return Status::OK();
} }
virtual Status GetThreadList( Status GetThreadList(std::vector<ThreadStatus>* thread_list) override {
std::vector<ThreadStatus>* thread_list) override {
assert(thread_status_updater_); assert(thread_status_updater_);
return thread_status_updater_->GetThreadList(thread_list); return thread_status_updater_->GetThreadList(thread_list);
} }
@ -774,12 +771,9 @@ class PosixEnv : public Env {
return gettid(tid); return gettid(tid);
} }
virtual uint64_t GetThreadID() const override { uint64_t GetThreadID() const override { return gettid(pthread_self()); }
return gettid(pthread_self());
}
virtual Status GetFreeSpace(const std::string& fname, Status GetFreeSpace(const std::string& fname, uint64_t* free_space) override {
uint64_t* free_space) override {
struct statvfs sbuf; struct statvfs sbuf;
if (statvfs(fname.c_str(), &sbuf) < 0) { if (statvfs(fname.c_str(), &sbuf) < 0) {
@ -790,7 +784,7 @@ class PosixEnv : public Env {
return Status::OK(); return Status::OK();
} }
virtual Status NewLogger(const std::string& fname, Status NewLogger(const std::string& fname,
std::shared_ptr<Logger>* result) override { std::shared_ptr<Logger>* result) override {
FILE* f; FILE* f;
{ {
@ -817,13 +811,13 @@ class PosixEnv : public Env {
} }
} }
virtual uint64_t NowMicros() override { uint64_t NowMicros() override {
struct timeval tv; struct timeval tv;
gettimeofday(&tv, nullptr); gettimeofday(&tv, nullptr);
return static_cast<uint64_t>(tv.tv_sec) * 1000000 + tv.tv_usec; return static_cast<uint64_t>(tv.tv_sec) * 1000000 + tv.tv_usec;
} }
virtual uint64_t NowNanos() override { uint64_t NowNanos() override {
#if defined(OS_LINUX) || defined(OS_FREEBSD) || defined(OS_AIX) #if defined(OS_LINUX) || defined(OS_FREEBSD) || defined(OS_AIX)
struct timespec ts; struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts); clock_gettime(CLOCK_MONOTONIC, &ts);
@ -843,7 +837,7 @@ class PosixEnv : public Env {
#endif #endif
} }
virtual uint64_t NowCPUNanos() override { uint64_t NowCPUNanos() override {
#if defined(OS_LINUX) || defined(OS_FREEBSD) || defined(OS_AIX) || \ #if defined(OS_LINUX) || defined(OS_FREEBSD) || defined(OS_AIX) || \
defined(__MACH__) defined(__MACH__)
struct timespec ts; struct timespec ts;
@ -853,9 +847,9 @@ class PosixEnv : public Env {
return 0; return 0;
} }
virtual void SleepForMicroseconds(int micros) override { usleep(micros); } void SleepForMicroseconds(int micros) override { usleep(micros); }
virtual Status GetHostName(char* name, uint64_t len) override { Status GetHostName(char* name, uint64_t len) override {
int ret = gethostname(name, static_cast<size_t>(len)); int ret = gethostname(name, static_cast<size_t>(len));
if (ret < 0) { if (ret < 0) {
if (errno == EFAULT || errno == EINVAL) if (errno == EFAULT || errno == EINVAL)
@ -866,7 +860,7 @@ class PosixEnv : public Env {
return Status::OK(); return Status::OK();
} }
virtual Status GetCurrentTime(int64_t* unix_time) override { Status GetCurrentTime(int64_t* unix_time) override {
time_t ret = time(nullptr); time_t ret = time(nullptr);
if (ret == (time_t) -1) { if (ret == (time_t) -1) {
return IOError("GetCurrentTime", "", errno); return IOError("GetCurrentTime", "", errno);
@ -875,7 +869,7 @@ class PosixEnv : public Env {
return Status::OK(); return Status::OK();
} }
virtual Status GetAbsolutePath(const std::string& db_path, Status GetAbsolutePath(const std::string& db_path,
std::string* output_path) override { std::string* output_path) override {
if (!db_path.empty() && db_path[0] == '/') { if (!db_path.empty() && db_path[0] == '/') {
*output_path = db_path; *output_path = db_path;
@ -893,28 +887,28 @@ class PosixEnv : public Env {
} }
// Allow increasing the number of worker threads. // Allow increasing the number of worker threads.
virtual void SetBackgroundThreads(int num, Priority pri) override { void SetBackgroundThreads(int num, Priority pri) override {
assert(pri >= Priority::BOTTOM && pri <= Priority::HIGH); assert(pri >= Priority::BOTTOM && pri <= Priority::HIGH);
thread_pools_[pri].SetBackgroundThreads(num); thread_pools_[pri].SetBackgroundThreads(num);
} }
virtual int GetBackgroundThreads(Priority pri) override { int GetBackgroundThreads(Priority pri) override {
assert(pri >= Priority::BOTTOM && pri <= Priority::HIGH); assert(pri >= Priority::BOTTOM && pri <= Priority::HIGH);
return thread_pools_[pri].GetBackgroundThreads(); return thread_pools_[pri].GetBackgroundThreads();
} }
virtual Status SetAllowNonOwnerAccess(bool allow_non_owner_access) override { Status SetAllowNonOwnerAccess(bool allow_non_owner_access) override {
allow_non_owner_access_ = allow_non_owner_access; allow_non_owner_access_ = allow_non_owner_access;
return Status::OK(); return Status::OK();
} }
// Allow increasing the number of worker threads. // Allow increasing the number of worker threads.
virtual void IncBackgroundThreadsIfNeeded(int num, Priority pri) override { void IncBackgroundThreadsIfNeeded(int num, Priority pri) override {
assert(pri >= Priority::BOTTOM && pri <= Priority::HIGH); assert(pri >= Priority::BOTTOM && pri <= Priority::HIGH);
thread_pools_[pri].IncBackgroundThreadsIfNeeded(num); thread_pools_[pri].IncBackgroundThreadsIfNeeded(num);
} }
virtual void LowerThreadPoolIOPriority(Priority pool = LOW) override { void LowerThreadPoolIOPriority(Priority pool = LOW) override {
assert(pool >= Priority::BOTTOM && pool <= Priority::HIGH); assert(pool >= Priority::BOTTOM && pool <= Priority::HIGH);
#ifdef OS_LINUX #ifdef OS_LINUX
thread_pools_[pool].LowerIOPriority(); thread_pools_[pool].LowerIOPriority();
@ -923,7 +917,7 @@ class PosixEnv : public Env {
#endif #endif
} }
virtual void LowerThreadPoolCPUPriority(Priority pool = LOW) override { void LowerThreadPoolCPUPriority(Priority pool = LOW) override {
assert(pool >= Priority::BOTTOM && pool <= Priority::HIGH); assert(pool >= Priority::BOTTOM && pool <= Priority::HIGH);
#ifdef OS_LINUX #ifdef OS_LINUX
thread_pools_[pool].LowerCPUPriority(); thread_pools_[pool].LowerCPUPriority();
@ -932,7 +926,7 @@ class PosixEnv : public Env {
#endif #endif
} }
virtual std::string TimeToString(uint64_t secondsSince1970) override { std::string TimeToString(uint64_t secondsSince1970) override {
const time_t seconds = (time_t)secondsSince1970; const time_t seconds = (time_t)secondsSince1970;
struct tm t; struct tm t;
int maxsize = 64; int maxsize = 64;

18
env/env_test.cc vendored

@ -118,7 +118,7 @@ class EnvPosixTestWithParam
} }
} }
~EnvPosixTestWithParam() { WaitThreadPoolsEmpty(); } ~EnvPosixTestWithParam() override { WaitThreadPoolsEmpty(); }
}; };
static void SetBool(void* ptr) { static void SetBool(void* ptr) {
@ -1135,7 +1135,7 @@ TEST_P(EnvPosixTestWithParam, InvalidateCache) {
class TestLogger : public Logger { class TestLogger : public Logger {
public: public:
using Logger::Logv; using Logger::Logv;
virtual void Logv(const char* format, va_list ap) override { void Logv(const char* format, va_list ap) override {
log_count++; log_count++;
char new_format[550]; char new_format[550];
@ -1217,7 +1217,7 @@ class TestLogger2 : public Logger {
public: public:
explicit TestLogger2(size_t max_log_size) : max_log_size_(max_log_size) {} explicit TestLogger2(size_t max_log_size) : max_log_size_(max_log_size) {}
using Logger::Logv; using Logger::Logv;
virtual void Logv(const char* format, va_list ap) override { void Logv(const char* format, va_list ap) override {
char new_format[2000]; char new_format[2000];
std::fill_n(new_format, sizeof(new_format), '2'); std::fill_n(new_format, sizeof(new_format), '2');
{ {
@ -1466,7 +1466,7 @@ TEST_P(EnvPosixTestWithParam, WritableFileWrapper) {
} }
public: public:
~Base() { inc(23); } ~Base() override { inc(23); }
}; };
class Wrapper : public WritableFileWrapper { class Wrapper : public WritableFileWrapper {
@ -1689,15 +1689,15 @@ class TestEnv : public EnvWrapper {
public: public:
using Logger::Logv; using Logger::Logv;
TestLogger(TestEnv* env_ptr) : Logger() { env = env_ptr; } TestLogger(TestEnv* env_ptr) : Logger() { env = env_ptr; }
~TestLogger() { ~TestLogger() override {
if (!closed_) { if (!closed_) {
CloseHelper(); CloseHelper();
} }
} }
virtual void Logv(const char* /*format*/, va_list /*ap*/) override{}; void Logv(const char* /*format*/, va_list /*ap*/) override{};
protected: protected:
virtual Status CloseImpl() override { return CloseHelper(); } Status CloseImpl() override { return CloseHelper(); }
private: private:
Status CloseHelper() { Status CloseHelper() {
@ -1711,8 +1711,8 @@ class TestEnv : public EnvWrapper {
int GetCloseCount() { return close_count; } int GetCloseCount() { return close_count; }
virtual Status NewLogger(const std::string& /*fname*/, Status NewLogger(const std::string& /*fname*/,
std::shared_ptr<Logger>* result) { std::shared_ptr<Logger>* result) override {
result->reset(new TestLogger(this)); result->reset(new TestLogger(this));
return Status::OK(); return Status::OK();
} }

44
env/mock_env.cc vendored

@ -183,9 +183,9 @@ class MockSequentialFile : public SequentialFile {
file_->Ref(); file_->Ref();
} }
~MockSequentialFile() { file_->Unref(); } ~MockSequentialFile() override { file_->Unref(); }
virtual Status Read(size_t n, Slice* result, char* scratch) override { Status Read(size_t n, Slice* result, char* scratch) override {
Status s = file_->Read(pos_, n, result, scratch); Status s = file_->Read(pos_, n, result, scratch);
if (s.ok()) { if (s.ok()) {
pos_ += result->size(); pos_ += result->size();
@ -193,7 +193,7 @@ class MockSequentialFile : public SequentialFile {
return s; return s;
} }
virtual Status Skip(uint64_t n) override { Status Skip(uint64_t n) override {
if (pos_ > file_->Size()) { if (pos_ > file_->Size()) {
return Status::IOError("pos_ > file_->Size()"); return Status::IOError("pos_ > file_->Size()");
} }
@ -214,9 +214,9 @@ class MockRandomAccessFile : public RandomAccessFile {
public: public:
explicit MockRandomAccessFile(MemFile* file) : file_(file) { file_->Ref(); } explicit MockRandomAccessFile(MemFile* file) : file_(file) { file_->Ref(); }
~MockRandomAccessFile() { file_->Unref(); } ~MockRandomAccessFile() override { file_->Unref(); }
virtual Status Read(uint64_t offset, size_t n, Slice* result, Status Read(uint64_t offset, size_t n, Slice* result,
char* scratch) const override { char* scratch) const override {
return file_->Read(offset, n, result, scratch); return file_->Read(offset, n, result, scratch);
} }
@ -229,22 +229,22 @@ class MockRandomRWFile : public RandomRWFile {
public: public:
explicit MockRandomRWFile(MemFile* file) : file_(file) { file_->Ref(); } explicit MockRandomRWFile(MemFile* file) : file_(file) { file_->Ref(); }
~MockRandomRWFile() { file_->Unref(); } ~MockRandomRWFile() override { file_->Unref(); }
virtual Status Write(uint64_t offset, const Slice& data) override { Status Write(uint64_t offset, const Slice& data) override {
return file_->Write(offset, data); return file_->Write(offset, data);
} }
virtual Status Read(uint64_t offset, size_t n, Slice* result, Status Read(uint64_t offset, size_t n, Slice* result,
char* scratch) const override { char* scratch) const override {
return file_->Read(offset, n, result, scratch); return file_->Read(offset, n, result, scratch);
} }
virtual Status Close() override { return file_->Fsync(); } Status Close() override { return file_->Fsync(); }
virtual Status Flush() override { return Status::OK(); } Status Flush() override { return Status::OK(); }
virtual Status Sync() override { return file_->Fsync(); } Status Sync() override { return file_->Fsync(); }
private: private:
MemFile* file_; MemFile* file_;
@ -257,9 +257,9 @@ class MockWritableFile : public WritableFile {
file_->Ref(); file_->Ref();
} }
~MockWritableFile() { file_->Unref(); } ~MockWritableFile() override { file_->Unref(); }
virtual Status Append(const Slice& data) override { Status Append(const Slice& data) override {
size_t bytes_written = 0; size_t bytes_written = 0;
while (bytes_written < data.size()) { while (bytes_written < data.size()) {
auto bytes = RequestToken(data.size() - bytes_written); auto bytes = RequestToken(data.size() - bytes_written);
@ -271,17 +271,17 @@ class MockWritableFile : public WritableFile {
} }
return Status::OK(); return Status::OK();
} }
virtual Status Truncate(uint64_t size) override { Status Truncate(uint64_t size) override {
file_->Truncate(static_cast<size_t>(size)); file_->Truncate(static_cast<size_t>(size));
return Status::OK(); return Status::OK();
} }
virtual Status Close() override { return file_->Fsync(); } Status Close() override { return file_->Fsync(); }
virtual Status Flush() override { return Status::OK(); } Status Flush() override { return Status::OK(); }
virtual Status Sync() override { return file_->Fsync(); } Status Sync() override { return file_->Fsync(); }
virtual uint64_t GetFileSize() override { return file_->Size(); } uint64_t GetFileSize() override { return file_->Size(); }
private: private:
inline size_t RequestToken(size_t bytes) { inline size_t RequestToken(size_t bytes) {
@ -299,7 +299,7 @@ class MockWritableFile : public WritableFile {
class MockEnvDirectory : public Directory { class MockEnvDirectory : public Directory {
public: public:
virtual Status Fsync() override { return Status::OK(); } Status Fsync() override { return Status::OK(); }
}; };
class MockEnvFileLock : public FileLock { class MockEnvFileLock : public FileLock {
@ -330,9 +330,9 @@ class TestMemLogger : public Logger {
last_flush_micros_(0), last_flush_micros_(0),
env_(env), env_(env),
flush_pending_(false) {} flush_pending_(false) {}
virtual ~TestMemLogger() {} ~TestMemLogger() override {}
virtual void Flush() override { void Flush() override {
if (flush_pending_) { if (flush_pending_) {
flush_pending_ = false; flush_pending_ = false;
} }
@ -340,7 +340,7 @@ class TestMemLogger : public Logger {
} }
using Logger::Logv; using Logger::Logv;
virtual void Logv(const char* format, va_list ap) override { void Logv(const char* format, va_list ap) override {
// We try twice: the first time with a fixed-size stack allocated buffer, // We try twice: the first time with a fixed-size stack allocated buffer,
// and the second time with a much larger dynamically allocated buffer. // and the second time with a much larger dynamically allocated buffer.
char buffer[500]; char buffer[500];

@ -20,9 +20,7 @@ class MockEnvTest : public testing::Test {
MockEnvTest() MockEnvTest()
: env_(new MockEnv(Env::Default())) { : env_(new MockEnv(Env::Default())) {
} }
~MockEnvTest() { ~MockEnvTest() override { delete env_; }
delete env_;
}
}; };
TEST_F(MockEnvTest, Corrupt) { TEST_F(MockEnvTest, Corrupt) {

Loading…
Cancel
Save