You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "heesung-sn (via GitHub)" <gi...@apache.org> on 2024/02/12 20:14:41 UTC
[PR] [feat] PIP-188 Support blue-green migration [pulsar-client-cpp]
heesung-sn opened a new pull request, #402:
URL: https://github.com/apache/pulsar-client-cpp/pull/402
<!--
### Contribution Checklist
- PR title format should be *[type][component] summary*. For details, see *[Guideline - Pulsar PR Naming Convention](https://docs.google.com/document/d/1d8Pw6ZbWk-_pCKdOmdvx9rnhPiyuxwq60_TrD68d7BA/edit#heading=h.trs9rsex3xom)*.
- Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
- Each pull request should address only one issue, not mix up code from multiple issues.
- Each commit in the pull request has a meaningful commit message
- Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
-->
<!-- or this PR is one task of an issue -->
Master Issue: https://github.com/apache/pulsar/issues/16551
### Motivation
Support blue-green migration pip-188 for cpp client
### Modifications
- added blue-green client logic
- register the producer instance in the producers map before sending produce creation command. This is required since broker could send topic migration command in the middle of creating the producer.
### Verifying this change
- [x] Make sure that the change passes the CI checks.
Updated the exisiting extensibleLB test to cover the migration logic.
### Documentation
<!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
- [ ] `doc-required`
(Your PR needs to update docs and you will update later)
- [x] `doc-not-needed`
(Please explain why)
- [ ] `doc`
(Your PR contains doc changes)
- [ ] `doc-complete`
(Docs have been already added)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [feat] PIP-188 Support blue-green migration [pulsar-client-cpp]
Posted by "heesung-sn (via GitHub)" <gi...@apache.org>.
heesung-sn commented on PR #402:
URL: https://github.com/apache/pulsar-client-cpp/pull/402#issuecomment-1951391495
> I changed the IO threads to 8 for ExtensibleLoadManagerTest and found segmentation fault when closing the client.
Thanks for sharing this. I tried to reproduce this issue, but I couldn't. Updated the test config instead.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [feat] PIP-188 Support blue-green migration [pulsar-client-cpp]
Posted by "heesung-sn (via GitHub)" <gi...@apache.org>.
heesung-sn commented on code in PR #402:
URL: https://github.com/apache/pulsar-client-cpp/pull/402#discussion_r1493810369
##########
lib/ClientConnection.cc:
##########
@@ -1761,6 +1766,55 @@ void ClientConnection::handleError(const proto::CommandError& error) {
}
}
+std::string ClientConnection::getMigratedBrokerServiceUrl(
+ const proto::CommandTopicMigrated& commandTopicMigrated) {
+ if (tlsSocket_) {
+ if (commandTopicMigrated.has_brokerserviceurltls()) {
+ return commandTopicMigrated.brokerserviceurltls();
+ }
+ } else if (commandTopicMigrated.has_brokerserviceurl()) {
+ return commandTopicMigrated.brokerserviceurl();
+ }
+ return "";
+}
+
+void ClientConnection::handleTopicMigrated(const proto::CommandTopicMigrated& commandTopicMigrated) {
+ const long resourceId = commandTopicMigrated.resource_id();
+ const std::string migratedBrokerServiceUrl = getMigratedBrokerServiceUrl(commandTopicMigrated);
+
+ if (migratedBrokerServiceUrl.empty()) {
+ LOG_WARN("Failed to find the migrated broker url for resource:"
+ << resourceId
+ << (commandTopicMigrated.has_brokerserviceurl()
+ ? ", migratedBrokerUrl: " + commandTopicMigrated.brokerserviceurl()
+ : "")
+ << (commandTopicMigrated.has_brokerserviceurltls()
+ ? ", migratedBrokerUrlTls: " + commandTopicMigrated.brokerserviceurltls()
+ : ""));
+ return;
+ }
+
+ if (commandTopicMigrated.resource_type() == proto::CommandTopicMigrated_ResourceType_Producer) {
+ auto it = producers_.find(resourceId);
Review Comment:
nit: I see SynchronizedHashMap for the other producer and consumer maps in ClientImpl.h. Why are these not SynchronizedHashMap?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [feat] PIP-188 Support blue-green migration [pulsar-client-cpp]
Posted by "heesung-sn (via GitHub)" <gi...@apache.org>.
heesung-sn commented on code in PR #402:
URL: https://github.com/apache/pulsar-client-cpp/pull/402#discussion_r1493810369
##########
lib/ClientConnection.cc:
##########
@@ -1761,6 +1766,55 @@ void ClientConnection::handleError(const proto::CommandError& error) {
}
}
+std::string ClientConnection::getMigratedBrokerServiceUrl(
+ const proto::CommandTopicMigrated& commandTopicMigrated) {
+ if (tlsSocket_) {
+ if (commandTopicMigrated.has_brokerserviceurltls()) {
+ return commandTopicMigrated.brokerserviceurltls();
+ }
+ } else if (commandTopicMigrated.has_brokerserviceurl()) {
+ return commandTopicMigrated.brokerserviceurl();
+ }
+ return "";
+}
+
+void ClientConnection::handleTopicMigrated(const proto::CommandTopicMigrated& commandTopicMigrated) {
+ const long resourceId = commandTopicMigrated.resource_id();
+ const std::string migratedBrokerServiceUrl = getMigratedBrokerServiceUrl(commandTopicMigrated);
+
+ if (migratedBrokerServiceUrl.empty()) {
+ LOG_WARN("Failed to find the migrated broker url for resource:"
+ << resourceId
+ << (commandTopicMigrated.has_brokerserviceurl()
+ ? ", migratedBrokerUrl: " + commandTopicMigrated.brokerserviceurl()
+ : "")
+ << (commandTopicMigrated.has_brokerserviceurltls()
+ ? ", migratedBrokerUrlTls: " + commandTopicMigrated.brokerserviceurltls()
+ : ""));
+ return;
+ }
+
+ if (commandTopicMigrated.resource_type() == proto::CommandTopicMigrated_ResourceType_Producer) {
+ auto it = producers_.find(resourceId);
Review Comment:
nit: I see SynchronizedHashMap for the other producer and consumer maps in ClientImpl.h. Why are these not SynchronizedHashMap?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [feat] PIP-188 Support blue-green migration [pulsar-client-cpp]
Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower commented on PR #402:
URL: https://github.com/apache/pulsar-client-cpp/pull/402#issuecomment-1948061424
Added the 3.5.0 milestone according to https://lists.apache.org/thread/fr4pv2p8yxhxcg2wc9sqdfzm89y8cnox
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [feat] PIP-188 Support blue-green migration [pulsar-client-cpp]
Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower commented on code in PR #402:
URL: https://github.com/apache/pulsar-client-cpp/pull/402#discussion_r1493765400
##########
proto/PulsarApi.proto:
##########
@@ -620,6 +621,18 @@ message CommandReachedEndOfTopic {
required uint64 consumer_id = 1;
}
+message CommandTopicMigrated {
+ enum ResourceType {
Review Comment:
```suggestion
enum ResourceType {
```
Use 4 spaces instead of a TAB.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [feat] PIP-188 Support blue-green migration [pulsar-client-cpp]
Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower merged PR #402:
URL: https://github.com/apache/pulsar-client-cpp/pull/402
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [feat] PIP-188 Support blue-green migration [pulsar-client-cpp]
Posted by "heesung-sn (via GitHub)" <gi...@apache.org>.
heesung-sn commented on code in PR #402:
URL: https://github.com/apache/pulsar-client-cpp/pull/402#discussion_r1493804888
##########
proto/PulsarApi.proto:
##########
@@ -620,6 +621,18 @@ message CommandReachedEndOfTopic {
required uint64 consumer_id = 1;
}
+message CommandTopicMigrated {
+ enum ResourceType {
Review Comment:
updated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [feat] PIP-188 Support blue-green migration [pulsar-client-cpp]
Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower commented on PR #402:
URL: https://github.com/apache/pulsar-client-cpp/pull/402#issuecomment-1951580802
Okay. I will debug it locally and see if it's a serious problem.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [feat] PIP-188 Support blue-green migration [pulsar-client-cpp]
Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower commented on code in PR #402:
URL: https://github.com/apache/pulsar-client-cpp/pull/402#discussion_r1493773756
##########
lib/ClientConnection.cc:
##########
@@ -1761,6 +1766,55 @@ void ClientConnection::handleError(const proto::CommandError& error) {
}
}
+std::string ClientConnection::getMigratedBrokerServiceUrl(
+ const proto::CommandTopicMigrated& commandTopicMigrated) {
+ if (tlsSocket_) {
+ if (commandTopicMigrated.has_brokerserviceurltls()) {
+ return commandTopicMigrated.brokerserviceurltls();
+ }
+ } else if (commandTopicMigrated.has_brokerserviceurl()) {
+ return commandTopicMigrated.brokerserviceurl();
+ }
+ return "";
+}
+
+void ClientConnection::handleTopicMigrated(const proto::CommandTopicMigrated& commandTopicMigrated) {
+ const long resourceId = commandTopicMigrated.resource_id();
+ const std::string migratedBrokerServiceUrl = getMigratedBrokerServiceUrl(commandTopicMigrated);
+
+ if (migratedBrokerServiceUrl.empty()) {
+ LOG_WARN("Failed to find the migrated broker url for resource:"
+ << resourceId
+ << (commandTopicMigrated.has_brokerserviceurl()
+ ? ", migratedBrokerUrl: " + commandTopicMigrated.brokerserviceurl()
+ : "")
+ << (commandTopicMigrated.has_brokerserviceurltls()
+ ? ", migratedBrokerUrlTls: " + commandTopicMigrated.brokerserviceurltls()
+ : ""));
+ return;
+ }
+
+ if (commandTopicMigrated.resource_type() == proto::CommandTopicMigrated_ResourceType_Producer) {
+ auto it = producers_.find(resourceId);
Review Comment:
The access to `producers_` and `consumers_` should be protected by `mutex_`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [feat] PIP-188 Support blue-green migration [pulsar-client-cpp]
Posted by "heesung-sn (via GitHub)" <gi...@apache.org>.
heesung-sn commented on code in PR #402:
URL: https://github.com/apache/pulsar-client-cpp/pull/402#discussion_r1493804814
##########
lib/ClientConnection.cc:
##########
@@ -1761,6 +1766,55 @@ void ClientConnection::handleError(const proto::CommandError& error) {
}
}
+std::string ClientConnection::getMigratedBrokerServiceUrl(
+ const proto::CommandTopicMigrated& commandTopicMigrated) {
+ if (tlsSocket_) {
+ if (commandTopicMigrated.has_brokerserviceurltls()) {
+ return commandTopicMigrated.brokerserviceurltls();
+ }
+ } else if (commandTopicMigrated.has_brokerserviceurl()) {
+ return commandTopicMigrated.brokerserviceurl();
+ }
+ return "";
+}
+
+void ClientConnection::handleTopicMigrated(const proto::CommandTopicMigrated& commandTopicMigrated) {
+ const long resourceId = commandTopicMigrated.resource_id();
+ const std::string migratedBrokerServiceUrl = getMigratedBrokerServiceUrl(commandTopicMigrated);
+
+ if (migratedBrokerServiceUrl.empty()) {
+ LOG_WARN("Failed to find the migrated broker url for resource:"
+ << resourceId
+ << (commandTopicMigrated.has_brokerserviceurl()
+ ? ", migratedBrokerUrl: " + commandTopicMigrated.brokerserviceurl()
+ : "")
+ << (commandTopicMigrated.has_brokerserviceurltls()
+ ? ", migratedBrokerUrlTls: " + commandTopicMigrated.brokerserviceurltls()
+ : ""));
+ return;
+ }
+
+ if (commandTopicMigrated.resource_type() == proto::CommandTopicMigrated_ResourceType_Producer) {
+ auto it = producers_.find(resourceId);
Review Comment:
thanks. updated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [feat] PIP-188 Support blue-green migration [pulsar-client-cpp]
Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower commented on code in PR #402:
URL: https://github.com/apache/pulsar-client-cpp/pull/402#discussion_r1495363450
##########
lib/HandlerBase.h:
##########
@@ -52,6 +52,7 @@ class HandlerBase : public std::enable_shared_from_this<HandlerBase> {
ClientConnectionWeakPtr getCnx() const;
void setCnx(const ClientConnectionPtr& cnx);
void resetCnx() { setCnx(nullptr); }
+ void setRedirectedClusterURI(const std::string serviceUrl) { redirectedClusterURI_ = serviceUrl; }
Review Comment:
Use `const std::string&` as the parameter type.
##########
lib/HandlerBase.h:
##########
@@ -145,6 +146,8 @@ class HandlerBase : public std::enable_shared_from_this<HandlerBase> {
mutable std::mutex connectionMutex_;
std::atomic<bool> reconnectionPending_;
ClientConnectionWeakPtr connection_;
+ std::string redirectedClusterURI_;
Review Comment:
This field could be accessed in different threads. You should use a mutex to protect it.
##########
lib/ProducerImpl.cc:
##########
@@ -144,7 +144,11 @@ Future<Result, bool> ProducerImpl::connectionOpened(const ClientConnectionPtr& c
return promise.getFuture();
}
+ LOG_DEBUG("Creating producer for topic:" << topic() << ", producerName:" << producerName_ << " on "
Review Comment:
Maybe we can use `LOG_INFO` like Java client?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org