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. 31
      db/write_batch.cc
  6. 91
      db/write_batch_test.cc
  7. 4
      db/write_callback_test.cc
  8. 2
      db/write_controller_test.cc
  9. 12
      env/env_basic_test.cc
  10. 77
      env/env_chroot.cc
  11. 131
      env/env_encryption.cc
  12. 142
      env/env_posix.cc
  13. 18
      env/env_test.cc
  14. 48
      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);
}
~VersionBuilderTest() {
~VersionBuilderTest() override {
for (int i = 0; i < vstorage_.num_levels(); i++) {
for (auto* f : vstorage_.LevelFiles(i)) {
if (--f->refs == 0) {

@ -492,39 +492,38 @@ class LevelIterator final : public InternalIterator {
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;
virtual void SeekForPrev(const Slice& target) override;
virtual void SeekToFirst() override;
virtual void SeekToLast() override;
virtual void Next() override;
virtual void Prev() override;
void Seek(const Slice& target) override;
void SeekForPrev(const Slice& target) override;
void SeekToFirst() override;
void SeekToLast() override;
void Next() override;
void Prev() override;
virtual bool Valid() const override { return file_iter_.Valid(); }
virtual Slice key() const override {
bool Valid() const override { return file_iter_.Valid(); }
Slice key() const override {
assert(Valid());
return file_iter_.key();
}
virtual Slice value() const override {
Slice value() const override {
assert(Valid());
return file_iter_.value();
}
virtual Status status() const override {
Status status() const override {
return file_iter_.iter() ? file_iter_.status() : Status::OK();
}
virtual void SetPinnedItersMgr(
PinnedIteratorsManager* pinned_iters_mgr) override {
void SetPinnedItersMgr(PinnedIteratorsManager* pinned_iters_mgr) override {
pinned_iters_mgr_ = pinned_iters_mgr;
if (file_iter_.iter()) {
file_iter_.SetPinnedItersMgr(pinned_iters_mgr);
}
}
virtual bool IsKeyPinned() const override {
bool IsKeyPinned() const override {
return pinned_iters_mgr_ && pinned_iters_mgr_->PinningEnabled() &&
file_iter_.iter() && file_iter_.IsKeyPinned();
}
virtual bool IsValuePinned() const override {
bool IsValuePinned() const override {
return pinned_iters_mgr_ && pinned_iters_mgr_->PinningEnabled() &&
file_iter_.iter() && file_iter_.IsValuePinned();
}

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

@ -429,7 +429,7 @@ Status WalManager::ReadFirstLine(const std::string& fname,
Status* status;
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",
(this->ignore_error ? "(ignoring error) " : ""), fname,
static_cast<int>(bytes), s.ToString().c_str());

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

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

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

@ -18,7 +18,7 @@ class TimeSetEnv : public EnvWrapper {
public:
explicit TimeSetEnv() : EnvWrapper(nullptr) {}
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) {

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

77
env/env_chroot.cc vendored

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

@ -42,7 +42,7 @@ class EncryptedSequentialFile : public SequentialFile {
// If an error was encountered, returns a non-OK status.
//
// 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);
Status status = file_->Read(n, result, scratch);
if (!status.ok()) {
@ -60,7 +60,7 @@ class EncryptedSequentialFile : public SequentialFile {
// file, and Skip will return OK.
//
// REQUIRES: External synchronization
virtual Status Skip(uint64_t n) override {
Status Skip(uint64_t n) override {
auto status = file_->Skip(n);
if (!status.ok()) {
return status;
@ -71,26 +71,25 @@ class EncryptedSequentialFile : public SequentialFile {
// Indicates the upper layers if the current SequentialFile implementation
// 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
// aligned buffer for Direct I/O
virtual size_t GetRequiredBufferAlignment() const override {
return file_->GetRequiredBufferAlignment();
size_t GetRequiredBufferAlignment() const override {
return file_->GetRequiredBufferAlignment();
}
// 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.
// 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);
}
// Positioned Read for direct I/O
// 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);
offset += prefixLength_; // Skip prefix
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());
return status;
}
};
// 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.
// 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);
offset += prefixLength_;
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.
virtual Status Prefetch(uint64_t offset, size_t n) override {
Status Prefetch(uint64_t offset, size_t n) override {
//return Status::OK();
return file_->Prefetch(offset + prefixLength_, n);
}
@ -157,30 +156,26 @@ class EncryptedRandomAccessFile : public RandomAccessFile {
// a single varint.
//
// 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);
};
virtual void Hint(AccessPattern pattern) override {
file_->Hint(pattern);
}
void Hint(AccessPattern pattern) override { file_->Hint(pattern); }
// Indicates the upper layers if the current RandomAccessFile implementation
// 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
// aligned buffer for Direct I/O
virtual size_t GetRequiredBufferAlignment() const override {
return file_->GetRequiredBufferAlignment();
size_t GetRequiredBufferAlignment() const override {
return file_->GetRequiredBufferAlignment();
}
// 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.
// 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);
}
};
@ -247,16 +242,18 @@ class EncryptedWritableFile : public WritableFileWrapper {
// Indicates the upper layers if the current WritableFile implementation
// 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
// 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.
*/
virtual uint64_t GetFileSize() override {
uint64_t GetFileSize() override {
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
// size due to whole pages writes. The behavior is undefined if called
// with other writes to follow.
virtual Status Truncate(uint64_t size) override {
Status Truncate(uint64_t size) override {
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.
// 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.
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);
}
@ -282,7 +279,7 @@ class EncryptedWritableFile : public WritableFileWrapper {
// This asks the OS to initiate flushing the cached data to disk,
// without waiting for completion.
// 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);
}
@ -291,12 +288,12 @@ class EncryptedWritableFile : public WritableFileWrapper {
// of space on devices where it can result in less file
// fragmentation and/or less waste from over-zealous filesystem
// 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);
}
// 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);
}
};
@ -314,17 +311,17 @@ class EncryptedRandomRWFile : public RandomRWFile {
// Indicates if the class makes use of direct I/O
// 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
// aligned buffer for Direct I/O
virtual size_t GetRequiredBufferAlignment() const override {
return file_->GetRequiredBufferAlignment();
size_t GetRequiredBufferAlignment() const override {
return file_->GetRequiredBufferAlignment();
}
// Write bytes in `data` at offset `offset`, Returns Status::OK() on success.
// 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;
Status status;
Slice dataToWrite(data);
@ -347,7 +344,8 @@ class EncryptedRandomRWFile : public RandomRWFile {
// Read up to `n` bytes starting from offset `offset` and store them in
// result, provided `scratch` size should be at least `n`.
// 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);
offset += prefixLength_;
auto status = file_->Read(offset, n, result, scratch);
@ -358,21 +356,13 @@ class EncryptedRandomRWFile : public RandomRWFile {
return status;
}
virtual Status Flush() override {
return file_->Flush();
}
Status Flush() override { return file_->Flush(); }
virtual Status Sync() override {
return file_->Sync();
}
Status Sync() override { return file_->Sync(); }
virtual Status Fsync() override {
return file_->Fsync();
}
Status Fsync() override { return file_->Fsync(); }
virtual Status Close() override {
return file_->Close();
}
Status Close() override { return file_->Close(); }
};
// EncryptedEnv implements an Env wrapper that adds encryption to files stored on disk.
@ -384,9 +374,9 @@ class EncryptedEnv : public EnvWrapper {
}
// NewSequentialFile opens a file for sequential reading.
virtual Status NewSequentialFile(const std::string& fname,
std::unique_ptr<SequentialFile>* result,
const EnvOptions& options) override {
Status NewSequentialFile(const std::string& fname,
std::unique_ptr<SequentialFile>* result,
const EnvOptions& options) override {
result->reset();
if (options.use_mmap_reads) {
return Status::InvalidArgument();
@ -421,9 +411,9 @@ class EncryptedEnv : public EnvWrapper {
}
// NewRandomAccessFile opens a file for random read access.
virtual Status NewRandomAccessFile(const std::string& fname,
std::unique_ptr<RandomAccessFile>* result,
const EnvOptions& options) override {
Status NewRandomAccessFile(const std::string& fname,
std::unique_ptr<RandomAccessFile>* result,
const EnvOptions& options) override {
result->reset();
if (options.use_mmap_reads) {
return Status::InvalidArgument();
@ -458,9 +448,9 @@ class EncryptedEnv : public EnvWrapper {
}
// NewWritableFile opens a file for sequential writing.
virtual Status NewWritableFile(const std::string& fname,
std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override {
Status NewWritableFile(const std::string& fname,
std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override {
result->reset();
if (options.use_mmap_writes) {
return Status::InvalidArgument();
@ -504,9 +494,9 @@ class EncryptedEnv : public EnvWrapper {
// returns non-OK.
//
// The returned file will only be accessed by one thread at a time.
virtual Status ReopenWritableFile(const std::string& fname,
std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override {
Status ReopenWritableFile(const std::string& fname,
std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override {
result->reset();
if (options.use_mmap_writes) {
return Status::InvalidArgument();
@ -544,10 +534,10 @@ class EncryptedEnv : public EnvWrapper {
}
// Reuse an existing file by renaming it and opening it as writable.
virtual Status ReuseWritableFile(const std::string& fname,
const std::string& old_fname,
std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override {
Status ReuseWritableFile(const std::string& fname,
const std::string& old_fname,
std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override {
result->reset();
if (options.use_mmap_writes) {
return Status::InvalidArgument();
@ -589,9 +579,9 @@ class EncryptedEnv : public EnvWrapper {
// *result and returns OK. On failure returns non-OK.
//
// The returned file will only be accessed by one thread at a time.
virtual Status NewRandomRWFile(const std::string& fname,
std::unique_ptr<RandomRWFile>* result,
const EnvOptions& options) override {
Status NewRandomRWFile(const std::string& fname,
std::unique_ptr<RandomRWFile>* result,
const EnvOptions& options) override {
result->reset();
if (options.use_mmap_reads || options.use_mmap_writes) {
return Status::InvalidArgument();
@ -649,7 +639,8 @@ class EncryptedEnv : public EnvWrapper {
// NotFound if "dir" does not exist, the calling process does not have
// permission to access "dir", or if "dir" is invalid.
// 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);
if (!status.ok()) {
return status;
@ -660,10 +651,10 @@ class EncryptedEnv : public EnvWrapper {
it->size_bytes -= prefixLength;
}
return Status::OK();
}
}
// 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);
if (!status.ok()) {
return status;
@ -671,7 +662,7 @@ class EncryptedEnv : public EnvWrapper {
size_t prefixLength = provider_->GetPrefixLength();
assert(*file_size >= prefixLength);
*file_size -= prefixLength;
return Status::OK();
return Status::OK();
}
private:

142
env/env_posix.cc vendored

@ -119,7 +119,7 @@ class PosixEnv : public Env {
public:
PosixEnv();
virtual ~PosixEnv() {
~PosixEnv() override {
for (const auto tid : threads_to_join_) {
pthread_join(tid, nullptr);
}
@ -141,9 +141,9 @@ class PosixEnv : public Env {
}
}
virtual Status NewSequentialFile(const std::string& fname,
std::unique_ptr<SequentialFile>* result,
const EnvOptions& options) override {
Status NewSequentialFile(const std::string& fname,
std::unique_ptr<SequentialFile>* result,
const EnvOptions& options) override {
result->reset();
int fd = -1;
int flags = cloexec_flags(O_RDONLY, &options);
@ -191,9 +191,9 @@ class PosixEnv : public Env {
return Status::OK();
}
virtual Status NewRandomAccessFile(const std::string& fname,
std::unique_ptr<RandomAccessFile>* result,
const EnvOptions& options) override {
Status NewRandomAccessFile(const std::string& fname,
std::unique_ptr<RandomAccessFile>* result,
const EnvOptions& options) override {
result->reset();
Status s;
int fd;
@ -332,22 +332,22 @@ class PosixEnv : public Env {
return s;
}
virtual Status NewWritableFile(const std::string& fname,
std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override {
Status NewWritableFile(const std::string& fname,
std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override {
return OpenWritableFile(fname, result, options, false);
}
virtual Status ReopenWritableFile(const std::string& fname,
std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override {
Status ReopenWritableFile(const std::string& fname,
std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override {
return OpenWritableFile(fname, result, options, true);
}
virtual Status ReuseWritableFile(const std::string& fname,
const std::string& old_fname,
std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override {
Status ReuseWritableFile(const std::string& fname,
const std::string& old_fname,
std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override {
result->reset();
Status s;
int fd = -1;
@ -429,9 +429,9 @@ class PosixEnv : public Env {
return s;
}
virtual Status NewRandomRWFile(const std::string& fname,
std::unique_ptr<RandomRWFile>* result,
const EnvOptions& options) override {
Status NewRandomRWFile(const std::string& fname,
std::unique_ptr<RandomRWFile>* result,
const EnvOptions& options) override {
int fd = -1;
int flags = cloexec_flags(O_RDWR, &options);
@ -453,7 +453,7 @@ class PosixEnv : public Env {
return Status::OK();
}
virtual Status NewMemoryMappedFileBuffer(
Status NewMemoryMappedFileBuffer(
const std::string& fname,
std::unique_ptr<MemoryMappedFileBuffer>* result) override {
int fd = -1;
@ -496,8 +496,8 @@ class PosixEnv : public Env {
return status;
}
virtual Status NewDirectory(const std::string& name,
std::unique_ptr<Directory>* result) override {
Status NewDirectory(const std::string& name,
std::unique_ptr<Directory>* result) override {
result->reset();
int fd;
int flags = cloexec_flags(0, nullptr);
@ -513,7 +513,7 @@ class PosixEnv : public Env {
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);
if (result == 0) {
@ -535,8 +535,8 @@ class PosixEnv : public Env {
}
}
virtual Status GetChildren(const std::string& dir,
std::vector<std::string>* result) override {
Status GetChildren(const std::string& dir,
std::vector<std::string>* result) override {
result->clear();
DIR* d = opendir(dir.c_str());
if (d == nullptr) {
@ -557,7 +557,7 @@ class PosixEnv : public Env {
return Status::OK();
}
virtual Status DeleteFile(const std::string& fname) override {
Status DeleteFile(const std::string& fname) override {
Status result;
if (unlink(fname.c_str()) != 0) {
result = IOError("while unlink() file", fname, errno);
@ -565,7 +565,7 @@ class PosixEnv : public Env {
return result;
};
virtual Status CreateDir(const std::string& name) override {
Status CreateDir(const std::string& name) override {
Status result;
if (mkdir(name.c_str(), 0755) != 0) {
result = IOError("While mkdir", name, errno);
@ -573,7 +573,7 @@ class PosixEnv : public Env {
return result;
};
virtual Status CreateDirIfMissing(const std::string& name) override {
Status CreateDirIfMissing(const std::string& name) override {
Status result;
if (mkdir(name.c_str(), 0755) != 0) {
if (errno != EEXIST) {
@ -587,7 +587,7 @@ class PosixEnv : public Env {
return result;
};
virtual Status DeleteDir(const std::string& name) override {
Status DeleteDir(const std::string& name) override {
Status result;
if (rmdir(name.c_str()) != 0) {
result = IOError("file rmdir", name, errno);
@ -595,8 +595,7 @@ class PosixEnv : public Env {
return result;
};
virtual Status GetFileSize(const std::string& fname,
uint64_t* size) override {
Status GetFileSize(const std::string& fname, uint64_t* size) override {
Status s;
struct stat sbuf;
if (stat(fname.c_str(), &sbuf) != 0) {
@ -608,8 +607,8 @@ class PosixEnv : public Env {
return s;
}
virtual Status GetFileModificationTime(const std::string& fname,
uint64_t* file_mtime) override {
Status GetFileModificationTime(const std::string& fname,
uint64_t* file_mtime) override {
struct stat s;
if (stat(fname.c_str(), &s) !=0) {
return IOError("while stat a file for modification time", fname, errno);
@ -617,8 +616,8 @@ class PosixEnv : public Env {
*file_mtime = static_cast<uint64_t>(s.st_mtime);
return Status::OK();
}
virtual Status RenameFile(const std::string& src,
const std::string& target) override {
Status RenameFile(const std::string& src,
const std::string& target) override {
Status result;
if (rename(src.c_str(), target.c_str()) != 0) {
result = IOError("While renaming a file to " + target, src, errno);
@ -626,8 +625,7 @@ class PosixEnv : public Env {
return result;
}
virtual Status LinkFile(const std::string& src,
const std::string& target) override {
Status LinkFile(const std::string& src, const std::string& target) override {
Status result;
if (link(src.c_str(), target.c_str()) != 0) {
if (errno == EXDEV) {
@ -647,8 +645,8 @@ class PosixEnv : public Env {
return Status::OK();
}
virtual Status AreFilesSame(const std::string& first,
const std::string& second, bool* res) override {
Status AreFilesSame(const std::string& first, const std::string& second,
bool* res) override {
struct stat statbuf[2];
if (stat(first.c_str(), &statbuf[0]) != 0) {
return IOError("stat file", first, errno);
@ -667,7 +665,7 @@ class PosixEnv : public Env {
return Status::OK();
}
virtual Status LockFile(const std::string& fname, FileLock** lock) override {
Status LockFile(const std::string& fname, FileLock** lock) override {
*lock = nullptr;
Status result;
@ -713,7 +711,7 @@ class PosixEnv : public Env {
return result;
}
virtual Status UnlockFile(FileLock* lock) override {
Status UnlockFile(FileLock* lock) override {
PosixFileLock* my_lock = reinterpret_cast<PosixFileLock*>(lock);
Status result;
mutex_lockedFiles.Lock();
@ -731,19 +729,19 @@ class PosixEnv : public Env {
return result;
}
virtual void Schedule(void (*function)(void* arg1), void* arg,
Priority pri = LOW, void* tag = nullptr,
void (*unschedFunction)(void* arg) = nullptr) override;
void Schedule(void (*function)(void* arg1), void* arg, Priority pri = LOW,
void* tag = nullptr,
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");
if (env && env[0] != '\0') {
*result = env;
@ -757,8 +755,7 @@ class PosixEnv : public Env {
return Status::OK();
}
virtual Status GetThreadList(
std::vector<ThreadStatus>* thread_list) override {
Status GetThreadList(std::vector<ThreadStatus>* thread_list) override {
assert(thread_status_updater_);
return thread_status_updater_->GetThreadList(thread_list);
}
@ -774,12 +771,9 @@ class PosixEnv : public Env {
return gettid(tid);
}
virtual uint64_t GetThreadID() const override {
return gettid(pthread_self());
}
uint64_t GetThreadID() const override { return gettid(pthread_self()); }
virtual Status GetFreeSpace(const std::string& fname,
uint64_t* free_space) override {
Status GetFreeSpace(const std::string& fname, uint64_t* free_space) override {
struct statvfs sbuf;
if (statvfs(fname.c_str(), &sbuf) < 0) {
@ -790,8 +784,8 @@ class PosixEnv : public Env {
return Status::OK();
}
virtual Status NewLogger(const std::string& fname,
std::shared_ptr<Logger>* result) override {
Status NewLogger(const std::string& fname,
std::shared_ptr<Logger>* result) override {
FILE* f;
{
IOSTATS_TIMER_GUARD(open_nanos);
@ -817,13 +811,13 @@ class PosixEnv : public Env {
}
}
virtual uint64_t NowMicros() override {
uint64_t NowMicros() override {
struct timeval tv;
gettimeofday(&tv, nullptr);
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)
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
@ -843,7 +837,7 @@ class PosixEnv : public Env {
#endif
}
virtual uint64_t NowCPUNanos() override {
uint64_t NowCPUNanos() override {
#if defined(OS_LINUX) || defined(OS_FREEBSD) || defined(OS_AIX) || \
defined(__MACH__)
struct timespec ts;
@ -853,9 +847,9 @@ class PosixEnv : public Env {
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));
if (ret < 0) {
if (errno == EFAULT || errno == EINVAL)
@ -866,7 +860,7 @@ class PosixEnv : public Env {
return Status::OK();
}
virtual Status GetCurrentTime(int64_t* unix_time) override {
Status GetCurrentTime(int64_t* unix_time) override {
time_t ret = time(nullptr);
if (ret == (time_t) -1) {
return IOError("GetCurrentTime", "", errno);
@ -875,8 +869,8 @@ class PosixEnv : public Env {
return Status::OK();
}
virtual Status GetAbsolutePath(const std::string& db_path,
std::string* output_path) override {
Status GetAbsolutePath(const std::string& db_path,
std::string* output_path) override {
if (!db_path.empty() && db_path[0] == '/') {
*output_path = db_path;
return Status::OK();
@ -893,28 +887,28 @@ class PosixEnv : public Env {
}
// 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);
thread_pools_[pri].SetBackgroundThreads(num);
}
virtual int GetBackgroundThreads(Priority pri) override {
int GetBackgroundThreads(Priority pri) override {
assert(pri >= Priority::BOTTOM && pri <= Priority::HIGH);
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;
return Status::OK();
}
// 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);
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);
#ifdef OS_LINUX
thread_pools_[pool].LowerIOPriority();
@ -923,7 +917,7 @@ class PosixEnv : public Env {
#endif
}
virtual void LowerThreadPoolCPUPriority(Priority pool = LOW) override {
void LowerThreadPoolCPUPriority(Priority pool = LOW) override {
assert(pool >= Priority::BOTTOM && pool <= Priority::HIGH);
#ifdef OS_LINUX
thread_pools_[pool].LowerCPUPriority();
@ -932,7 +926,7 @@ class PosixEnv : public Env {
#endif
}
virtual std::string TimeToString(uint64_t secondsSince1970) override {
std::string TimeToString(uint64_t secondsSince1970) override {
const time_t seconds = (time_t)secondsSince1970;
struct tm t;
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) {
@ -1135,7 +1135,7 @@ TEST_P(EnvPosixTestWithParam, InvalidateCache) {
class TestLogger : public Logger {
public:
using Logger::Logv;
virtual void Logv(const char* format, va_list ap) override {
void Logv(const char* format, va_list ap) override {
log_count++;
char new_format[550];
@ -1217,7 +1217,7 @@ class TestLogger2 : public Logger {
public:
explicit TestLogger2(size_t max_log_size) : max_log_size_(max_log_size) {}
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];
std::fill_n(new_format, sizeof(new_format), '2');
{
@ -1466,7 +1466,7 @@ TEST_P(EnvPosixTestWithParam, WritableFileWrapper) {
}
public:
~Base() { inc(23); }
~Base() override { inc(23); }
};
class Wrapper : public WritableFileWrapper {
@ -1689,15 +1689,15 @@ class TestEnv : public EnvWrapper {
public:
using Logger::Logv;
TestLogger(TestEnv* env_ptr) : Logger() { env = env_ptr; }
~TestLogger() {
~TestLogger() override {
if (!closed_) {
CloseHelper();
}
}
virtual void Logv(const char* /*format*/, va_list /*ap*/) override{};
void Logv(const char* /*format*/, va_list /*ap*/) override{};
protected:
virtual Status CloseImpl() override { return CloseHelper(); }
Status CloseImpl() override { return CloseHelper(); }
private:
Status CloseHelper() {
@ -1711,8 +1711,8 @@ class TestEnv : public EnvWrapper {
int GetCloseCount() { return close_count; }
virtual Status NewLogger(const std::string& /*fname*/,
std::shared_ptr<Logger>* result) {
Status NewLogger(const std::string& /*fname*/,
std::shared_ptr<Logger>* result) override {
result->reset(new TestLogger(this));
return Status::OK();
}

48
env/mock_env.cc vendored

@ -183,9 +183,9 @@ class MockSequentialFile : public SequentialFile {
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);
if (s.ok()) {
pos_ += result->size();
@ -193,7 +193,7 @@ class MockSequentialFile : public SequentialFile {
return s;
}
virtual Status Skip(uint64_t n) override {
Status Skip(uint64_t n) override {
if (pos_ > file_->Size()) {
return Status::IOError("pos_ > file_->Size()");
}
@ -214,10 +214,10 @@ class MockRandomAccessFile : public RandomAccessFile {
public:
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,
char* scratch) const override {
Status Read(uint64_t offset, size_t n, Slice* result,
char* scratch) const override {
return file_->Read(offset, n, result, scratch);
}
@ -229,22 +229,22 @@ class MockRandomRWFile : public RandomRWFile {
public:
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);
}
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 {
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:
MemFile* file_;
@ -257,9 +257,9 @@ class MockWritableFile : public WritableFile {
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;
while (bytes_written < data.size()) {
auto bytes = RequestToken(data.size() - bytes_written);
@ -271,17 +271,17 @@ class MockWritableFile : public WritableFile {
}
return Status::OK();
}
virtual Status Truncate(uint64_t size) override {
Status Truncate(uint64_t size) override {
file_->Truncate(static_cast<size_t>(size));
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:
inline size_t RequestToken(size_t bytes) {
@ -299,7 +299,7 @@ class MockWritableFile : public WritableFile {
class MockEnvDirectory : public Directory {
public:
virtual Status Fsync() override { return Status::OK(); }
Status Fsync() override { return Status::OK(); }
};
class MockEnvFileLock : public FileLock {
@ -330,9 +330,9 @@ class TestMemLogger : public Logger {
last_flush_micros_(0),
env_(env),
flush_pending_(false) {}
virtual ~TestMemLogger() {}
~TestMemLogger() override {}
virtual void Flush() override {
void Flush() override {
if (flush_pending_) {
flush_pending_ = false;
}
@ -340,7 +340,7 @@ class TestMemLogger : public Logger {
}
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,
// and the second time with a much larger dynamically allocated buffer.
char buffer[500];

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

Loading…
Cancel
Save