Skip to content

Commit 31a9b12

Browse files
committed
More changes for AWS on Windows
1 parent faa1278 commit 31a9b12

File tree

5 files changed

+36
-12
lines changed

5 files changed

+36
-12
lines changed

cloud/aws/aws_env.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ void AwsCloudAccessCredentials::InitializeConfig(
102102
Status AwsCloudAccessCredentials::HasValid() const {
103103
AwsAccessType aws_type = GetAccessType();
104104
Status status = CheckCredentials(aws_type);
105-
printf("MJR: Credentials HasValid=%d status=%s\n", (int) aws_type, status.ToString().c_str());
106105
return status;
107106
}
108107

@@ -117,7 +116,6 @@ Status AwsCloudAccessCredentials::GetCredentialsProvider(
117116

118117
AwsAccessType aws_type = GetAccessType();
119118
Status status = CheckCredentials(aws_type);
120-
printf("MJR: Credentials=%d status=%s\n", (int) aws_type, status.ToString().c_str());
121119
if (status.ok()) {
122120
#ifdef USE_AWS
123121
switch (aws_type) {
@@ -166,6 +164,7 @@ Status AwsCloudAccessCredentials::GetCredentialsProvider(
166164
}
167165

168166
#ifdef USE_AWS
167+
static Aws::SDKOptions sdkOptions;
169168

170169
//
171170
// The AWS credentials are specified to the constructor via
@@ -174,7 +173,8 @@ Status AwsCloudAccessCredentials::GetCredentialsProvider(
174173
AwsEnv::AwsEnv(Env* underlying_env, const CloudEnvOptions& _cloud_env_options,
175174
const std::shared_ptr<Logger>& info_log)
176175
: CloudEnvImpl(_cloud_env_options, underlying_env, info_log) {
177-
Aws::InitAPI(Aws::SDKOptions());
176+
Aws::InitAPI(sdkOptions); //**TODO: Move this into PrepareOptions and do it
177+
// conditionally (first time)
178178
if (cloud_env_options.src_bucket.GetRegion().empty() ||
179179
cloud_env_options.dest_bucket.GetRegion().empty()) {
180180
std::string region;
@@ -192,7 +192,11 @@ AwsEnv::AwsEnv(Env* underlying_env, const CloudEnvOptions& _cloud_env_options,
192192
base_env_ = underlying_env;
193193
}
194194

195-
void AwsEnv::Shutdown() { Aws::ShutdownAPI(Aws::SDKOptions()); }
195+
AwsEnv::~AwsEnv() {
196+
//**TODO: Conditionally call shutdown (or make shutdown conditional on last...
197+
}
198+
199+
void AwsEnv::Shutdown() { Aws::ShutdownAPI(sdkOptions); }
196200

197201
//
198202
// All db in a bucket are stored in path /.rockset/dbid/<dbid>

cloud/aws/aws_env.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class AwsEnv : public CloudEnvImpl {
5151
const std::shared_ptr<Logger>& info_log,
5252
CloudEnv** cenv);
5353

54-
virtual ~AwsEnv() {}
54+
virtual ~AwsEnv();
5555

5656
const char* Name() const override { return "aws"; }
5757

cloud/cloud_env.cc

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "cloud/cloud_env_wrapper.h"
1313
#include "cloud/db_cloud_impl.h"
1414
#include "cloud/filename.h"
15+
#include "file/filename.h"
1516
#include "port/likely.h"
1617
#include "rocksdb/cloud/cloud_log_controller.h"
1718
#include "rocksdb/db.h"
@@ -59,6 +60,23 @@ void BucketOptions::SetBucketName(const std::string& bucket,
5960
}
6061
}
6162

63+
void BucketOptions::SetObjectPath(const std::string& object) {
64+
// Remove the drive if there is one...
65+
auto colon = object.find(':');
66+
if (colon != std::string::npos) {
67+
object_ = object.substr(colon + 1);
68+
} else {
69+
object_ = object;
70+
}
71+
// Replace any "\" with "/"
72+
for (auto pos = object_.find('\\'); pos != std::string::npos;
73+
pos = object_.find('\\', pos)) {
74+
object_[pos] = '/';
75+
}
76+
// Remove any duplicate markers
77+
object_ = NormalizePath(object_);
78+
}
79+
6280
// Initializes the bucket properties
6381

6482
void BucketOptions::TEST_Initialize(const std::string& bucket,
@@ -70,15 +88,13 @@ void BucketOptions::TEST_Initialize(const std::string& bucket,
7088
if (!CloudEnvOptions::GetNameFromEnvironment("ROCKSDB_CLOUD_TEST_BUCKET_NAME",
7189
"ROCKSDB_CLOUD_BUCKET_NAME",
7290
&bucket_)) {
73-
#ifdef _WIN32_WINNT
91+
#ifdef _WIN32
7492
char user_name[257]; // UNLEN + 1
7593
DWORD dwsize = sizeof(user_name);
7694
if (!::GetUserName(user_name, &dwsize)) {
7795
bucket_ = bucket_ + "unknown";
7896
} else {
79-
bucket_ =
80-
bucket_ +
81-
std::string(user_name, static_cast<std::string::size_type>(dwsize));
97+
bucket_ = bucket_ + user_name;
8298
}
8399
#else
84100
bucket_ = bucket + std::to_string(geteuid());

cloud/db_cloud_test.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,14 @@ class CloudTest : public testing::Test {
6464

6565
CloudEnv* aenv;
6666
// create a dummy aws env
67+
6768
ASSERT_OK(CloudEnv::NewAwsEnv(base_env_, cloud_env_options_,
6869
options_.info_log, &aenv));
6970
ASSERT_NE(aenv, nullptr);
7071
aenv_.reset(aenv);
7172
// delete all pre-existing contents from the bucket
7273
Status st = aenv_->GetCloudEnvOptions().storage_provider->EmptyBucket(
73-
aenv_->GetSrcBucketName(), dbname_);
74+
aenv_->GetSrcBucketName(), aenv_->GetSrcObjectPath());
7475
ASSERT_TRUE(st.ok() || st.IsNotFound());
7576
aenv_.reset();
7677

@@ -109,7 +110,7 @@ class CloudTest : public testing::Test {
109110
options_.info_log, &aenv);
110111
if (st.ok()) {
111112
aenv->GetCloudEnvOptions().storage_provider->EmptyBucket(
112-
aenv->GetSrcBucketName(), dbname_);
113+
aenv->GetSrcBucketName(), aenv->GetSrcObjectPath());
113114
delete aenv;
114115
}
115116
}
@@ -1539,8 +1540,11 @@ TEST_F(CloudTest, SharedBlockCache) {
15391540

15401541
} // namespace ROCKSDB_NAMESPACE
15411542

1543+
#include "port/stack_trace.h"
1544+
15421545
// A black-box test for the cloud wrapper around rocksdb
15431546
int main(int argc, char** argv) {
1547+
ROCKSDB_NAMESPACE::port::InstallStackTraceHandler();
15441548
::testing::InitGoogleTest(&argc, argv);
15451549
return RUN_ALL_TESTS();
15461550
}

include/rocksdb/cloud/cloud_env_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class BucketOptions {
125125
void SetBucketName(const std::string& bucket, const std::string& prefix = "");
126126
const std::string& GetBucketName() const { return name_; }
127127
const std::string& GetObjectPath() const { return object_; }
128-
void SetObjectPath(const std::string& object) { object_ = object; }
128+
void SetObjectPath(const std::string& object);
129129
const std::string& GetRegion() const { return region_; }
130130
void SetRegion(const std::string& region) { region_ = region; }
131131

0 commit comments

Comments
 (0)