Skip to content

Commit 37eea74

Browse files
authored
chore: Add option to disable aws dependency (#3077)
Signed-off-by: Vladislav Oleshko <[email protected]>
1 parent ce2e127 commit 37eea74

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

src/server/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,12 @@ endif()
7777

7878
find_library(ZSTD_LIB NAMES libzstd.a libzstdstatic.a zstd NAMES_PER_DIR REQUIRED)
7979

80+
if (WITH_AWS)
81+
SET(AWS_LIB awsv2_lib)
82+
endif()
83+
8084
cxx_link(dfly_transaction dfly_core strings_lib TRDP::fast_float)
81-
cxx_link(dragonfly_lib dfly_transaction dfly_facade redis_lib awsv2_lib jsonpath
85+
cxx_link(dragonfly_lib dfly_transaction dfly_facade redis_lib ${AWS_LIB} jsonpath
8286
strings_lib html_lib
8387
http_client_lib absl::random_random TRDP::jsoncons ${ZSTD_LIB} TRDP::lz4
8488
TRDP::croncpp TRDP::flatbuffers)

src/server/detail/snapshot_storage.cc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,25 @@
55

66
#include <absl/strings/str_replace.h>
77
#include <absl/strings/strip.h>
8+
9+
#ifdef WITH_AWS
810
#include <aws/core/auth/AWSCredentialsProvider.h>
911
#include <aws/s3/S3Client.h>
1012
#include <aws/s3/model/ListObjectsV2Request.h>
1113
#include <aws/s3/model/PutObjectRequest.h>
1214

13-
#include <regex>
14-
15-
#include "base/logging.h"
16-
#include "io/file_util.h"
17-
#include "server/engine_shard_set.h"
1815
#include "util/aws/aws.h"
1916
#include "util/aws/credentials_provider_chain.h"
2017
#include "util/aws/s3_endpoint_provider.h"
2118
#include "util/aws/s3_read_file.h"
2219
#include "util/aws/s3_write_file.h"
20+
#endif
21+
22+
#include <regex>
23+
24+
#include "base/logging.h"
25+
#include "io/file_util.h"
26+
#include "server/engine_shard_set.h"
2327
#include "util/fibers/fiber_file.h"
2428

2529
namespace dfly {
@@ -173,6 +177,7 @@ io::Result<std::vector<std::string>, GenericError> FileSnapshotStorage::LoadPath
173177
return paths;
174178
}
175179

180+
#ifdef WITH_AWS
176181
AwsS3SnapshotStorage::AwsS3SnapshotStorage(const std::string& endpoint, bool https,
177182
bool ec2_metadata, bool sign_payload) {
178183
shard_set->pool()->GetNextProactor()->Await([&] {
@@ -375,6 +380,7 @@ AwsS3SnapshotStorage::ListObjects(std::string_view bucket_name, std::string_view
375380
} while (!continuation_token.empty());
376381
return keys;
377382
}
383+
#endif
378384

379385
#ifdef __linux__
380386
io::Result<size_t> LinuxWriteWrapper::WriteSome(const iovec* v, uint32_t len) {

src/server/detail/snapshot_storage.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
#pragma once
55

6+
#ifdef WITH_AWS
67
#include <aws/s3/S3Client.h>
8+
#endif
79

810
#include <filesystem>
911
#include <string>
@@ -70,6 +72,7 @@ class FileSnapshotStorage : public SnapshotStorage {
7072
util::fb2::FiberQueueThreadPool* fq_threadpool_;
7173
};
7274

75+
#ifdef WITH_AWS
7376
class AwsS3SnapshotStorage : public SnapshotStorage {
7477
public:
7578
AwsS3SnapshotStorage(const std::string& endpoint, bool https, bool ec2_metadata,
@@ -104,6 +107,7 @@ class AwsS3SnapshotStorage : public SnapshotStorage {
104107

105108
// Returns bucket_name, obj_path for an s3 path.
106109
std::optional<std::pair<std::string, std::string>> GetBucketPath(std::string_view path);
110+
#endif
107111

108112
#ifdef __linux__
109113
// takes ownership over the file.

src/server/server_family.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,10 +770,14 @@ void ServerFamily::Init(util::AcceptServer* acceptor, std::vector<facade::Listen
770770

771771
string flag_dir = GetFlag(FLAGS_dir);
772772
if (IsCloudPath(flag_dir)) {
773+
#ifdef WITH_AWS
773774
shard_set->pool()->GetNextProactor()->Await([&] { util::aws::Init(); });
774775
snapshot_storage_ = std::make_shared<detail::AwsS3SnapshotStorage>(
775776
absl::GetFlag(FLAGS_s3_endpoint), absl::GetFlag(FLAGS_s3_use_https),
776777
absl::GetFlag(FLAGS_s3_ec2_metadata), absl::GetFlag(FLAGS_s3_sign_payload));
778+
#else
779+
LOG(ERROR) << "Compiled without AWS support";
780+
#endif
777781
} else if (fq_threadpool_) {
778782
snapshot_storage_ = std::make_shared<detail::FileSnapshotStorage>(fq_threadpool_.get());
779783
} else {

0 commit comments

Comments
 (0)