Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add virtual Truncate method to Env #3779

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions env/mock_env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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_);
Expand Down
5 changes: 2 additions & 3 deletions env/mock_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions include/rocksdb/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down