Skip to content

Commit de4354b

Browse files
committed
Unify info_log env Posix/BaseEnv
1 parent c490198 commit de4354b

File tree

9 files changed

+31
-33
lines changed

9 files changed

+31
-33
lines changed

cloud/aws/aws_env.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,7 @@ Aws::S3::Model::HeadObjectOutcome AwsS3ClientWrapper::HeadObject(
391391
//
392392
AwsEnv::AwsEnv(Env* underlying_env, const CloudEnvOptions& _cloud_env_options,
393393
const std::shared_ptr<Logger>& info_log)
394-
: CloudEnvImpl(_cloud_env_options, underlying_env),
395-
info_log_(info_log),
394+
: CloudEnvImpl(_cloud_env_options, underlying_env, info_log),
396395
running_(true) {
397396
Aws::InitAPI(Aws::SDKOptions());
398397
if (cloud_env_options.src_bucket.GetRegion().empty() ||
@@ -887,7 +886,7 @@ class S3Directory : public Directory {
887886
public:
888887
explicit S3Directory(AwsEnv* env, const std::string name)
889888
: env_(env), name_(name) {
890-
status_ = env_->GetPosixEnv()->NewDirectory(name, &posixDir);
889+
status_ = env_->GetBaseEnv()->NewDirectory(name, &posixDir);
891890
}
892891

893892
~S3Directory() {}

cloud/aws/aws_env.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,10 @@ class AwsEnv : public CloudEnvImpl {
234234
virtual Status EmptyBucket(const std::string& bucket,
235235
const std::string& path) override;
236236

237-
// get the posix env
238-
Env* GetPosixEnv() const { return base_env_; }
239-
240237
bool IsRunning() const { return running_; }
241238

242239
std::string GetWALCacheDir();
243240

244-
std::shared_ptr<Logger> info_log_; // informational messages
245-
246241
// The S3 client
247242
std::shared_ptr<AwsS3ClientWrapper> s3client_;
248243

cloud/aws/aws_log.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ CloudLogController::CloudLogController(
3232
: env_(env), info_log_(info_log) {
3333

3434
// Create a random number for the cache directory.
35-
const std::string uid = trim(env_->GetPosixEnv()->GenerateUniqueId());
35+
const std::string uid = trim(env_->GetBaseEnv()->GenerateUniqueId());
3636

3737
// Temporary directory for cache.
3838
const std::string bucket_dir = kCacheDir + pathsep + env_->GetSrcBucketName();
3939
cache_dir_ = bucket_dir + pathsep + uid;
4040

4141
// Create temporary directories.
42-
status_ = env_->GetPosixEnv()->CreateDirIfMissing(kCacheDir);
42+
status_ = env_->GetBaseEnv()->CreateDirIfMissing(kCacheDir);
4343
if (status_.ok()) {
44-
status_ = env_->GetPosixEnv()->CreateDirIfMissing(bucket_dir);
44+
status_ = env_->GetBaseEnv()->CreateDirIfMissing(bucket_dir);
4545
}
4646
if (status_.ok()) {
47-
status_ = env_->GetPosixEnv()->CreateDirIfMissing(cache_dir_);
47+
status_ = env_->GetBaseEnv()->CreateDirIfMissing(cache_dir_);
4848
}
4949
}
5050

@@ -86,17 +86,17 @@ Status CloudLogController::Apply(const Slice& in) {
8686
// If this file is not yet open, open it and store it in cache.
8787
if (iter == cache_fds_.end()) {
8888
unique_ptr<RandomRWFile> result;
89-
st = env_->GetPosixEnv()->NewRandomRWFile(
89+
st = env_->GetBaseEnv()->NewRandomRWFile(
9090
pathname, &result, EnvOptions());
9191

9292
if (!st.ok()) {
9393
// create the file
9494
unique_ptr<WritableFile> tmp_writable_file;
95-
env_->GetPosixEnv()->NewWritableFile(pathname, &tmp_writable_file,
95+
env_->GetBaseEnv()->NewWritableFile(pathname, &tmp_writable_file,
9696
EnvOptions());
9797
tmp_writable_file.reset();
9898
// Try again.
99-
st = env_->GetPosixEnv()->NewRandomRWFile(
99+
st = env_->GetBaseEnv()->NewRandomRWFile(
100100
pathname, &result, EnvOptions());
101101
}
102102

@@ -129,7 +129,7 @@ Status CloudLogController::Apply(const Slice& in) {
129129
cache_fds_.erase(iter);
130130
}
131131

132-
st = env_->GetPosixEnv()->DeleteFile(pathname);
132+
st = env_->GetBaseEnv()->DeleteFile(pathname);
133133
Log(InfoLogLevel::DEBUG_LEVEL, env_->info_log_,
134134
"[%s] Tailer: Deleted file: %s %s",
135135
GetTypeName().c_str(), pathname.c_str(), st.ToString().c_str());

cloud/aws/aws_s3.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ Status S3WritableFile::Close() {
303303

304304
// delete local file
305305
if (!env_->GetCloudEnvOptions().keep_local_sst_files) {
306-
status_ = env_->GetPosixEnv()->DeleteFile(fname_);
306+
status_ = env_->GetBaseEnv()->DeleteFile(fname_);
307307
if (!status_.ok()) {
308308
Log(InfoLogLevel::ERROR_LEVEL, env_->info_log_,
309309
"[s3] S3WritableFile closing delete failed on local file %s",

cloud/cloud_env_impl.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
namespace rocksdb {
2121

22-
CloudEnvImpl::CloudEnvImpl(const CloudEnvOptions& opts, Env* base_env)
23-
: CloudEnv(opts), base_env_(base_env), purger_is_running_(true) {}
22+
CloudEnvImpl::CloudEnvImpl(const CloudEnvOptions& opts, Env* base, const std::shared_ptr<Logger>& l)
23+
: CloudEnv(opts, base, l), purger_is_running_(true) {}
2424

2525
CloudEnvImpl::~CloudEnvImpl() { StopPurger(); }
2626

cloud/cloud_env_impl.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,12 @@ class CloudEnvImpl : public CloudEnv {
2020

2121
public:
2222
// Constructor
23-
CloudEnvImpl(const CloudEnvOptions & options, Env* base_env);
23+
CloudEnvImpl(const CloudEnvOptions & options, Env* base_env, const std::shared_ptr<Logger>& logger);
2424

2525
virtual ~CloudEnvImpl();
2626

2727
const CloudType& GetCloudType() const { return cloud_env_options.cloud_type; }
2828

29-
// Returns the underlying env
30-
Env* GetBaseEnv() override { return base_env_; }
31-
3229
Status SanitizeDirectory(const DBOptions& options,
3330
const std::string& clone_name, bool read_only);
3431
Status LoadCloudManifest(const std::string& local_dbname, bool read_only);
@@ -122,11 +119,6 @@ class CloudEnvImpl : public CloudEnv {
122119
// The pathname of the source database that is cloned
123120
std::string src_dbdir_;
124121

125-
// The underlying env
126-
Env* base_env_;
127-
128-
std::shared_ptr<Logger> info_log_; // informational messages
129-
130122
// Protects purger_cv_
131123
std::mutex purger_lock_;
132124
std::condition_variable purger_cv_;

cloud/cloud_env_wrapper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ namespace rocksdb {
1919
class CloudEnvWrapper : public CloudEnvImpl {
2020
public:
2121
// Initialize an EnvWrapper that delegates all calls to *t
22-
explicit CloudEnvWrapper(const CloudEnvOptions& options, Env* t) : CloudEnvImpl(options, t) {
22+
explicit CloudEnvWrapper(const CloudEnvOptions& options, Env* t, const std::shared_ptr<Logger>& l) :
23+
CloudEnvImpl(options, t, l) {
2324
cloud_env_options.log_type = LogType::kLogNone;
2425
cloud_env_options.cloud_type = CloudType::kCloudNone;
2526
notsup_ = Status::NotSupported();

cloud/db_cloud_impl.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ Status DBCloud::Open(const Options& opt, const std::string& local_dbname,
7171
}
7272

7373
CloudEnvImpl* cenv = static_cast<CloudEnvImpl*>(options.env);
74+
if (!cenv->info_log_) {
75+
cenv->info_log_ = options.info_log;
76+
}
7477
Env* local_env = cenv->GetBaseEnv();
7578
if (!read_only) {
7679
local_env->CreateDirIfMissing(

include/rocksdb/cloud/cloud_env_options.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,19 @@ typedef std::map<std::string, std::string> DbidList;
307307
class CloudEnv : public Env {
308308
protected:
309309
CloudEnvOptions cloud_env_options;
310-
CloudEnv(const CloudEnvOptions& options) : cloud_env_options(options) { }
311-
public:
312-
// Returns the underlying env
313-
virtual Env* GetBaseEnv() = 0;
310+
Env* base_env_; // The underlying env
311+
CloudEnv(const CloudEnvOptions& options, Env *base, const std::shared_ptr<Logger>& logger)
312+
: cloud_env_options(options),
313+
base_env_(base),
314+
info_log_(logger) {
315+
}
316+
public:
317+
std::shared_ptr<Logger> info_log_; // informational messages
314318
virtual ~CloudEnv();
319+
// Returns the underlying env
320+
Env* GetBaseEnv() {
321+
return base_env_;
322+
}
315323
virtual Status PreloadCloudManifest(const std::string& local_dbname) = 0;
316324

317325
// Empties all contents of the associated cloud storage bucket.

0 commit comments

Comments
 (0)