diff --git a/env/mock_env.cc b/env/mock_env.cc index 719e9ebdda1..9b019260dd9 100644 --- a/env/mock_env.cc +++ b/env/mock_env.cc @@ -575,6 +575,17 @@ Status MockEnv::DeleteFile(const std::string& fname) { return Status::OK(); } +Status MockEnv::Truncate(const std::string& fname, size_t size) { + auto fn = NormalizePath(fname); + MutexLock lock(&mutex_); + auto iter = file_map_.find(fn); + if (iter == file_map_.end()) { + return Status::IOError(fn, "File not found"); + } + iter->second->Truncate(size); + return Status::OK(); +} + Status MockEnv::CreateDir(const std::string& dirname) { auto dn = NormalizePath(dirname); if (file_map_.find(dn) == file_map_.end()) { @@ -725,18 +736,6 @@ uint64_t MockEnv::NowNanos() { return EnvWrapper::NowNanos() + fake_sleep_micros_.load() * 1000; } -// Non-virtual functions, specific to MockEnv -Status MockEnv::Truncate(const std::string& fname, size_t size) { - auto fn = NormalizePath(fname); - MutexLock lock(&mutex_); - auto iter = file_map_.find(fn); - if (iter == file_map_.end()) { - return Status::IOError(fn, "File not found"); - } - iter->second->Truncate(size); - return Status::OK(); -} - Status MockEnv::CorruptBuffer(const std::string& fname) { auto fn = NormalizePath(fname); MutexLock lock(&mutex_); diff --git a/env/mock_env.h b/env/mock_env.h index ba1e5fa31e7..816256ab08c 100644 --- a/env/mock_env.h +++ b/env/mock_env.h @@ -60,6 +60,8 @@ class MockEnv : public EnvWrapper { virtual Status DeleteFile(const std::string& fname) override; + virtual Status Truncate(const std::string& fname, size_t size) override; + virtual Status CreateDir(const std::string& dirname) override; virtual Status CreateDirIfMissing(const std::string& dirname) override; @@ -92,9 +94,6 @@ class MockEnv : public EnvWrapper { virtual uint64_t NowMicros() override; virtual uint64_t NowNanos() override; - // Non-virtual functions, specific to MockEnv - Status Truncate(const std::string& fname, size_t size); - Status CorruptBuffer(const std::string& fname); // Doesn't really sleep, just affects output of GetCurrentTime(), NowMicros() diff --git a/include/rocksdb/env.h b/include/rocksdb/env.h index 212b1770a99..1f1f0601030 100644 --- a/include/rocksdb/env.h +++ b/include/rocksdb/env.h @@ -258,6 +258,11 @@ class Env { // Delete the named file. virtual Status DeleteFile(const std::string& fname) = 0; + // Truncate the named file to the specified size. + virtual Status Truncate(const std::string& /*fname*/, size_t /*size*/) { + return Status::NotSupported("Truncate is not supported for this Env"); + } + // Create the specified directory. Returns error if directory exists. virtual Status CreateDir(const std::string& dirname) = 0;