-
Notifications
You must be signed in to change notification settings - Fork 436
Add C++ builder pattern #1018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add C++ builder pattern #1018
Changes from 4 commits
47add82
9c644f0
58650f8
4fbe66a
2fb2b7e
a9aa54c
58766bc
8010e07
a6a7dc3
ff674c5
9ebae76
1daeb48
1780a31
67d1268
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| #include <chrono> | ||
| #include <cstdint> | ||
| #include <cstdlib> | ||
| #include <string_view> | ||
| #include <optional> | ||
| #include <ranges> | ||
| #include <thread> | ||
|
|
@@ -406,6 +407,78 @@ std::optional<std::shared_ptr<Client>> Client::Create( | |
| return client; | ||
| } | ||
|
|
||
| MooncakeStoreBuilder& MooncakeStoreBuilder::WithLocalHostname( | ||
| std::string local_hostname) { | ||
| local_hostname_ = std::move(local_hostname); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
| return *this; | ||
| } | ||
|
|
||
| MooncakeStoreBuilder& MooncakeStoreBuilder::WithMetadataConnectionString( | ||
| std::string metadata_connstring) { | ||
| metadata_connstring_ = std::move(metadata_connstring); | ||
| return *this; | ||
| } | ||
|
|
||
| MooncakeStoreBuilder& MooncakeStoreBuilder::UsingProtocol( | ||
| std::string protocol) { | ||
| protocol_ = std::move(protocol); | ||
| return *this; | ||
| } | ||
|
|
||
| MooncakeStoreBuilder& MooncakeStoreBuilder::WithRdmaDeviceNames( | ||
| std::string device_names) { | ||
| if (device_names.empty()) { | ||
JasonZhang517 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| device_names_.reset(); | ||
| } else { | ||
| device_names_ = std::move(device_names); | ||
| } | ||
| return *this; | ||
| } | ||
|
|
||
| MooncakeStoreBuilder& MooncakeStoreBuilder::WithMasterServerEntry( | ||
| std::string master_server_entry) { | ||
| master_server_entry_ = std::move(master_server_entry); | ||
| return *this; | ||
| } | ||
|
|
||
| MooncakeStoreBuilder& MooncakeStoreBuilder::WithExistingTransferEngine( | ||
| std::shared_ptr<TransferEngine> transfer_engine) { | ||
| transfer_engine_ = std::move(transfer_engine); | ||
| return *this; | ||
| } | ||
|
|
||
| std::optional<std::shared_ptr<Client>> MooncakeStoreBuilder::Build() const { | ||
| std::vector<std::string_view> missing; | ||
| if (!local_hostname_) { | ||
| missing.emplace_back("local_hostname"); | ||
| } | ||
| if (!metadata_connstring_) { | ||
| missing.emplace_back("metadata_connstring"); | ||
| } | ||
|
|
||
| if (!missing.empty()) { | ||
| std::string joined; | ||
| joined.reserve(missing.size() * 16); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| for (size_t i = 0; i < missing.size(); ++i) { | ||
| if (i != 0) { | ||
| joined.append(", "); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
| joined.append(missing[0]); | ||
| for (size_t i = 1; i < missing.size(); ++i) { | ||
| joined.append(", "); | ||
| joined.append(missing[i]); | ||
| } | ||
| } | ||
| LOG(ERROR) << "MooncakeStoreBuilder missing required fields: " | ||
| << joined; | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| return Client::Create(*local_hostname_, *metadata_connstring_, protocol_, | ||
| device_names_, master_server_entry_, | ||
| transfer_engine_); | ||
| } | ||
|
|
||
| tl::expected<void, ErrorCode> Client::Get(const std::string& object_key, | ||
| std::vector<Slice>& slices) { | ||
| auto query_result = Query(object_key); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -178,9 +178,27 @@ tl::expected<void, ErrorCode> PyClient::setup_internal( | |
| (rdma_devices.empty() ? std::nullopt | ||
| : std::make_optional(rdma_devices)); | ||
|
|
||
| auto client_opt = mooncake::Client::Create( | ||
| this->local_hostname, metadata_server, protocol, device_name, | ||
| master_server_addr, transfer_engine); | ||
| MooncakeStoreBuilder builder; | ||
|
||
| builder.WithLocalHostname(this->local_hostname) | ||
| .WithMetadataConnectionString(metadata_server) | ||
| .UsingProtocol(protocol) | ||
| .WithMasterServerEntry(master_server_addr); | ||
|
|
||
| if (device_name) { | ||
| builder.WithRdmaDeviceNames(*device_name); | ||
| } | ||
| if (transfer_engine) { | ||
| builder.WithExistingTransferEngine(transfer_engine); | ||
| } | ||
|
|
||
| auto client_opt = MooncakeStoreBuilder() | ||
| .WithLocalHostname(this->local_hostname) | ||
| .WithMetadataConnectionString(metadata_server) | ||
| .UsingProtocol(protocol) | ||
| .WithMasterServerEntry(master_server_addr) | ||
| .WithRdmaDeviceNames(device_name.value_or("")) | ||
| .WithExistingTransferEngine(transfer_engine) | ||
| .Build(); | ||
| if (!client_opt) { | ||
| LOG(ERROR) << "Failed to create client"; | ||
| return tl::unexpected(ErrorCode::INVALID_PARAMS); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
ClientBuildershould be a better name in the context, as we are infact building aClient, not aMooncakeStore.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about MooncakeStoreClientBuilder? Don't be afraid of a long name.