Route GetTestDirectory to FileSystem in CompositeEnvWrappers (#6896)

Summary:
GetTestDirectory implies a file system operation (it creates the
default test directory if missing), so it should be routed to
the FileSystem rather than the Env.

Also remove the GetTestDirectory implementation in the PosixEnv,
since it overrides GetTestDirectory in CompositeEnv making it
impossible to override with a custom FileSystem.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6896

Reviewed By: cheng-chang

Differential Revision: D21868984

Pulled By: ajkr

fbshipit-source-id: e79bfef758d06dacef727c54b96abe62e78726fd
main
Hans Holmberg 4 years ago committed by Facebook GitHub Bot
parent f005dac2d9
commit 0f85d163e6
  1. 4
      env/composite_env_wrapper.h
  2. 14
      env/env_posix.cc

@ -523,7 +523,9 @@ class CompositeEnvWrapper : public Env {
return env_target_->GetThreadPoolQueueLen(pri); return env_target_->GetThreadPoolQueueLen(pri);
} }
Status GetTestDirectory(std::string* path) override { Status GetTestDirectory(std::string* path) override {
return env_target_->GetTestDirectory(path); IOOptions io_opts;
IODebugContext dbg;
return file_system_->GetTestDirectory(io_opts, path, &dbg);
} }
uint64_t NowMicros() override { return env_target_->NowMicros(); } uint64_t NowMicros() override { return env_target_->NowMicros(); }
uint64_t NowNanos() override { return env_target_->NowNanos(); } uint64_t NowNanos() override { return env_target_->NowNanos(); }

14
env/env_posix.cc vendored

@ -224,20 +224,6 @@ class PosixEnv : public CompositeEnvWrapper {
unsigned int GetThreadPoolQueueLen(Priority pri = LOW) const override; unsigned int GetThreadPoolQueueLen(Priority pri = LOW) const override;
Status GetTestDirectory(std::string* result) override {
const char* env = getenv("TEST_TMPDIR");
if (env && env[0] != '\0') {
*result = env;
} else {
char buf[100];
snprintf(buf, sizeof(buf), "/tmp/rocksdbtest-%d", int(geteuid()));
*result = buf;
}
// Directory may already exist
CreateDir(*result);
return Status::OK();
}
Status GetThreadList(std::vector<ThreadStatus>* thread_list) override { Status GetThreadList(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);

Loading…
Cancel
Save