-
Notifications
You must be signed in to change notification settings - Fork 81
PIP-121: Introduce ServiceInfoProvider to update service info dynamically #541
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
Open
BewareMyPower
wants to merge
29
commits into
apache:main
Choose a base branch
from
BewareMyPower:bewaremypower/service-url-provider
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+787
−255
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
7862234
Initial commit
BewareMyPower a1746a9
implemented
BewareMyPower 15908f9
fix auth not cleared if it's not set and improve tests
BewareMyPower 8b0899f
refactor and add a getServiceInfo method
BewareMyPower 7ca8136
fix format
BewareMyPower e70a0a4
use read-write lock instead
BewareMyPower 342505e
pass by value + std::move for better performance
BewareMyPower 477fb94
fix thread safety due to read lock for write operation
BewareMyPower 9114edf
fix stale lookup service might be refered
BewareMyPower c6de067
fix the reader cannot consume after switching to a new cluster
BewareMyPower a209112
address comments from copilot
BewareMyPower fc04394
fix libstdc++ header include error
BewareMyPower f7e35ea
Use ServiceInfo as the single source of truth for ClientConnection
BewareMyPower a01842d
revert changes on ClientConfiguration
BewareMyPower 38a6111
simplify implementations
BewareMyPower 792fede
Pass ServiceInfo to lookup service and fix AuthPluginTest.testInvalid…
BewareMyPower 529fa96
remove ambiguous methods from ClientConfiguration
BewareMyPower 4adb04a
replace the updateServiceInfo method with the ServiceInfoProvider int…
BewareMyPower a238057
revert unnecessary change
BewareMyPower d8c5b27
fix perf build
BewareMyPower e5f9cca
fix clang-tidy checks and remove Client from the ServiceInfoProvider …
BewareMyPower cdb2128
fix LookupServiceTest.testAfterClientShutdown
BewareMyPower b2bc7d7
fix other tests
BewareMyPower b91860a
revert unnecessary changes
BewareMyPower 1144c27
clean up implementation
BewareMyPower 5285efd
address comments
BewareMyPower f5666d8
Merge branch 'main' into bewaremypower/service-url-provider
BewareMyPower b9c2d54
fix tests
BewareMyPower 696d616
reset redirectedClusterURI
BewareMyPower File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| #ifndef PULSAR_SERVICE_INFO_H_ | ||
| #define PULSAR_SERVICE_INFO_H_ | ||
|
|
||
| #include <pulsar/Authentication.h> | ||
|
|
||
| #include <optional> | ||
| #include <string> | ||
|
|
||
| namespace pulsar { | ||
|
|
||
| /** | ||
| * ServiceInfo encapsulates the information of a Pulsar service, which is used by the client to connect to the | ||
| * service. It includes the service URL, authentication information, and TLS configuration. | ||
| */ | ||
| class PULSAR_PUBLIC ServiceInfo final { | ||
| public: | ||
| ServiceInfo(std::string serviceUrl, AuthenticationPtr authentication = AuthFactory::Disabled(), | ||
| std::optional<std::string> tlsTrustCertsFilePath = std::nullopt); | ||
|
|
||
| auto& serviceUrl() const noexcept { return serviceUrl_; } | ||
| auto useTls() const noexcept { return useTls_; } | ||
| auto& authentication() const noexcept { return authentication_; } | ||
| auto& tlsTrustCertsFilePath() const noexcept { return tlsTrustCertsFilePath_; } | ||
|
|
||
| bool operator==(const ServiceInfo& other) const noexcept { | ||
| return serviceUrl_ == other.serviceUrl_ && useTls_ == other.useTls_ && | ||
| authentication_ == other.authentication_ && | ||
| tlsTrustCertsFilePath_ == other.tlsTrustCertsFilePath_; | ||
| } | ||
|
|
||
| private: | ||
| std::string serviceUrl_; | ||
| bool useTls_; | ||
| AuthenticationPtr authentication_; | ||
| std::optional<std::string> tlsTrustCertsFilePath_; | ||
| }; | ||
|
|
||
| } // namespace pulsar | ||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| #ifndef PULSAR_SERVICE_INFO_PROVIDER_H_ | ||
| #define PULSAR_SERVICE_INFO_PROVIDER_H_ | ||
|
|
||
| #include <pulsar/ServiceInfo.h> | ||
|
|
||
| #include <functional> | ||
|
|
||
| namespace pulsar { | ||
|
|
||
| class PULSAR_PUBLIC ServiceInfoProvider { | ||
| public: | ||
| /** | ||
| * The destructor will be called when `Client::close()` is invoked, and the provider should stop any | ||
| * ongoing work and release the resources in the destructor. | ||
| */ | ||
| virtual ~ServiceInfoProvider() = default; | ||
|
|
||
| /** | ||
| * Get the initial `ServiceInfo` connection for the client. | ||
| * This method is called **only once** internally in `Client::create()` to get the initial `ServiceInfo` | ||
| * for the client to connect to the Pulsar service, typically before {@link initialize} is invoked. | ||
| * Since it's only called once, it's legal to return a moved `ServiceInfo` object to avoid unnecessary | ||
| * copying. | ||
| */ | ||
| virtual ServiceInfo initialServiceInfo() = 0; | ||
|
|
||
| /** | ||
| * Initialize the ServiceInfoProvider. | ||
| * | ||
| * After the client has obtained the initial `ServiceInfo` via {@link initialServiceInfo}, this method is | ||
| * called to allow the provider to start any background work (for example, service discovery or watching | ||
| * configuration changes) and to report subsequent updates to the service information. | ||
| * | ||
| * @param onServiceInfoUpdate the callback to deliver updated `ServiceInfo` values to the client after | ||
| * the initial connection has been established | ||
| * | ||
| * Implementations may choose not to invoke `onServiceInfoUpdate` if the `ServiceInfo` never changes. | ||
| */ | ||
| virtual void initialize(std::function<void(ServiceInfo)> onServiceInfoUpdate) = 0; | ||
| }; | ||
|
|
||
| }; // namespace pulsar | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| #pragma once | ||
|
|
||
| #include <memory> | ||
| namespace pulsar { | ||
|
|
||
| // C++17 does not have std::atomic<std::shared_ptr<T>>, so we have to manually implement it. | ||
| template <typename T> | ||
| class AtomicSharedPtr { | ||
| public: | ||
| using Pointer = std::shared_ptr<const T>; | ||
|
|
||
| AtomicSharedPtr() = default; | ||
| explicit AtomicSharedPtr(T value) : ptr_(std::make_shared<const T>(std::move(value))) {} | ||
|
|
||
| auto load() const { return std::atomic_load(&ptr_); } | ||
|
|
||
| void store(Pointer&& newPtr) { std::atomic_store(&ptr_, std::move(newPtr)); } | ||
|
|
||
| private: | ||
| std::shared_ptr<const T> ptr_; | ||
| }; | ||
|
|
||
| } // namespace pulsar |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.