Skip to content

Commit ce32a72

Browse files
committed
Introduce DBCloud::CheckpointToCloud()
This is a useful utility to copy snapshot of the RocksDB-Cloud database to a destination in the cloud. Another RocksDB-Cloud instance can then be started from the specified location in the cloud.
1 parent b4e59f5 commit ce32a72

File tree

10 files changed

+232
-72
lines changed

10 files changed

+232
-72
lines changed

cloud/aws/aws_env.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ Aws::S3::Model::HeadObjectOutcome AwsS3ClientWrapper::HeadObject(
253253
t.SetSuccess(outcome.IsSuccess());
254254
return outcome;
255255
}
256-
256+
257257
//
258258
// The AWS credentials are specified to the constructor via
259259
// access_key_id and secret_key.
@@ -1459,7 +1459,7 @@ Status AwsEnv::SaveIdentitytoS3(const std::string& localfile,
14591459

14601460
// Save mapping from ID to cloud pathname
14611461
if (st.ok() && !GetDestObjectPath().empty()) {
1462-
st = SaveDbid(dbid, GetDestObjectPath());
1462+
st = SaveDbid(GetDestBucketName(), dbid, GetDestObjectPath());
14631463
}
14641464
return st;
14651465
}
@@ -1468,14 +1468,14 @@ Status AwsEnv::SaveIdentitytoS3(const std::string& localfile,
14681468
// All db in a bucket are stored in path /.rockset/dbid/<dbid>
14691469
// The value of the object is the pathname where the db resides.
14701470
//
1471-
Status AwsEnv::SaveDbid(const std::string& dbid, const std::string& dirname) {
1471+
Status AwsEnv::SaveDbid(const std::string& bucket_name, const std::string& dbid,
1472+
const std::string& dirname) {
14721473
assert(status().ok());
14731474
Log(InfoLogLevel::DEBUG_LEVEL, info_log_, "[s3] SaveDbid dbid %s dir '%s'",
14741475
dbid.c_str(), dirname.c_str());
14751476

14761477
std::string dbidkey = dbid_registry_ + dbid;
1477-
std::string bucket = GetDestBucketName();
1478-
Aws::String s3_bucket = ToAwsString(bucket);
1478+
Aws::String s3_bucket = ToAwsString(bucket_name);
14791479
Aws::String key = ToAwsString(dbidkey);
14801480

14811481
Aws::Map<Aws::String, Aws::String> metadata;
@@ -1497,11 +1497,11 @@ Status AwsEnv::SaveDbid(const std::string& dbid, const std::string& dirname) {
14971497
std::string errmsg(error.GetMessage().c_str(), error.GetMessage().size());
14981498
Log(InfoLogLevel::ERROR_LEVEL, info_log_,
14991499
"[s3] Bucket %s SaveDbid error in saving dbid %s dirname %s %s",
1500-
bucket.c_str(), dbid.c_str(), dirname.c_str(), errmsg.c_str());
1500+
bucket_name.c_str(), dbid.c_str(), dirname.c_str(), errmsg.c_str());
15011501
return Status::IOError(dirname, errmsg.c_str());
15021502
}
15031503
Log(InfoLogLevel::INFO_LEVEL, info_log_,
1504-
"[s3] Bucket %s SaveDbid dbid %s dirname %s %s", bucket.c_str(),
1504+
"[s3] Bucket %s SaveDbid dbid %s dirname %s %s", bucket_name.c_str(),
15051505
dbid.c_str(), dirname.c_str(), "ok");
15061506
return Status::OK();
15071507
};
@@ -1880,7 +1880,7 @@ Status AwsEnv::NewLogger(const std::string& fname, shared_ptr<Logger>* result) {
18801880
}
18811881

18821882
// The factory method for creating an S3 Env
1883-
Status AwsEnv::NewAwsEnv(Env* base_env,
1883+
Status AwsEnv::NewAwsEnv(Env* base_env,
18841884
const CloudEnvOptions& cloud_options,
18851885
const std::shared_ptr<Logger> & info_log, CloudEnv** cenv) {
18861886
Status status;

cloud/aws/aws_env.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ struct JobHandle;
9797
class AwsEnv : public CloudEnvImpl {
9898
public:
9999
// A factory method for creating S3 envs
100-
static Status NewAwsEnv(Env* env,
100+
static Status NewAwsEnv(Env* env,
101101
const CloudEnvOptions& env_options,
102102
const std::shared_ptr<Logger> & info_log, CloudEnv** cenv);
103103

@@ -241,8 +241,8 @@ class AwsEnv : public CloudEnvImpl {
241241

242242
bool IsRunning() const { return running_; }
243243

244-
245-
244+
245+
246246
std::string GetWALCacheDir();
247247

248248
std::shared_ptr<Logger> info_log_; // informational messages
@@ -263,7 +263,8 @@ class AwsEnv : public CloudEnvImpl {
263263
Status StartTailingStream();
264264

265265
// Saves and retrieves the dbid->dirname mapping in S3
266-
Status SaveDbid(const std::string& dbid, const std::string& dirname) override;
266+
Status SaveDbid(const std::string& bucket_name, const std::string& dbid,
267+
const std::string& dirname) override;
267268
Status GetPathForDbid(const std::string& bucket,
268269
const std::string& dbid, std::string* dirname) override;
269270
Status GetDbidList(const std::string& bucket,

cloud/cloud_env.cc

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
namespace rocksdb {
2020

2121
bool CloudEnvOptions::GetNameFromEnvironment(const char *name, const char *alt, std::string * result) {
22-
22+
2323
char *value = getenv(name); // See if name is set in the environment
2424
if (value == nullptr && alt != nullptr) { // Not set. Do we have an alt name?
2525
value = getenv(alt); // See if alt is in the environment
@@ -41,21 +41,21 @@ void CloudEnvOptions::TEST_Initialize(const std::string & bucket,
4141
BucketOptions::BucketOptions() {
4242
prefix_ = "rockset.";
4343
}
44-
44+
4545
void BucketOptions::SetBucketName(const std::string & bucket,
4646
const std::string & prefix) {
4747
if (!prefix.empty()) {
4848
prefix_ = prefix;
4949
}
50-
50+
5151
bucket_ = bucket;
5252
if (bucket_.empty()) {
5353
name_.clear();
5454
} else {
5555
name_ = prefix_ + bucket_;
5656
}
5757
}
58-
58+
5959

6060
// Initializes the bucket properties
6161

@@ -77,13 +77,13 @@ void BucketOptions::TEST_Initialize(const std::string & bucket,
7777
if (! CloudEnvOptions::GetNameFromEnvironment("ROCKSDB_CLOUD_TEST_OBECT_PATH",
7878
"ROCKSDB_CLOUD_OBJECT_PATH", &object_)) {
7979
object_ = object;
80-
}
80+
}
8181
if (! CloudEnvOptions::GetNameFromEnvironment("ROCKSDB_CLOUD_TEST_REGION",
8282
"ROCKSDB_CLOUD_REGION", &region_)) {
8383
region_ = region;
8484
}
8585
}
86-
86+
8787
CloudEnv::~CloudEnv() {}
8888

8989
CloudEnvWrapper::~CloudEnvWrapper() {}
@@ -228,8 +228,8 @@ Status CloudEnv::NewAwsEnv(Env* base_env,
228228
if (!dest_cloud_region.empty()) options.dest_bucket.SetRegion(dest_cloud_region);
229229
return NewAwsEnv(base_env, options, logger, cenv);
230230
}
231-
232-
Status CloudEnv::NewAwsEnv(Env* base_env,
231+
232+
Status CloudEnv::NewAwsEnv(Env* base_env,
233233
const CloudEnvOptions& options,
234234
const std::shared_ptr<Logger> & logger, CloudEnv** cenv) {
235235
#ifndef USE_AWS
@@ -238,13 +238,6 @@ Status CloudEnv::NewAwsEnv(Env* base_env,
238238
// Dump out cloud env options
239239
options.Dump(logger.get());
240240

241-
// If the src bucket is not specified, then this is a pass-through cloud env.
242-
if (! options.dest_bucket.IsValid() &&
243-
! options.src_bucket.IsValid()) {
244-
*cenv = new CloudEnvWrapper(options, base_env);
245-
return Status::OK();
246-
}
247-
248241
Status st = AwsEnv::NewAwsEnv(base_env, options, logger, cenv);
249242
if (st.ok()) {
250243
// store a copy of the logger

cloud/cloud_env_options.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ void CloudEnvOptions::Dump(Logger* log) const {
2929
ephemeral_resync_on_open ? "true" : "false");
3030
Header(log, " COptions.skip_dbid_verification: %s",
3131
skip_dbid_verification ? "true" : "false");
32+
Header(log, " COptions.use_aws_transfer_manager: %s",
33+
use_aws_transfer_manager ? "true" : "false");
3234
}
3335

3436
} // namespace rocksdb

cloud/cloud_env_wrapper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class CloudEnvWrapper : public CloudEnvImpl {
3737
const EnvOptions& options) override {
3838
return notsup_;
3939
}
40-
virtual Status SaveDbid(const std::string& dbid,
40+
virtual Status SaveDbid(const std::string& bucket_name,
41+
const std::string& dbid,
4142
const std::string& dirname) override {
4243
return notsup_;
4344
}

0 commit comments

Comments
 (0)