This is an automated email from the ASF dual-hosted git repository.

xyz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pulsar-client-cpp.git


The following commit(s) were added to refs/heads/main by this push:
     new c8b98c6  [fix] Use authoritative argument correctly in 
BinaryProtoLookupService::findBroker (#146)
c8b98c6 is described below

commit c8b98c6a6f6c1b19631b2248f43909a6e9c1dfaf
Author: erobot <[email protected]>
AuthorDate: Fri Dec 16 13:57:45 2022 +0800

    [fix] Use authoritative argument correctly in 
BinaryProtoLookupService::findBroker (#146)
    
    ### Motivation
    
    Use authoritative argument correctly in 
BinaryProtoLookupService::findBroker.
    
    In the current code, authoritative field of lookup request is always false. 
When a bundle is not loaded by any broker, a lookup request with authoritative 
as false will not trigger broker to load the bundle, and lookup requests will 
loop between leader broker and the chosen broker. In this case, the lookup will 
not succeed and result in a large number of lookup requests to the broker as 
current c++ client do not have lookup redirect limit. If broker return failure 
after a large number [...]
     of future will result in a large depth of function calls and may cause the 
stack to overflow.
    
    
https://github.com/apache/pulsar-client-cpp/blob/44f3b5240732a035395ec34b977301435dd0ec71/lib/BinaryProtoLookupService.cc#L55
    
    ### Modifications
    
    Use authoritative argument.
---
 lib/BinaryProtoLookupService.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/BinaryProtoLookupService.cc b/lib/BinaryProtoLookupService.cc
index b863d52..b925db4 100644
--- a/lib/BinaryProtoLookupService.cc
+++ b/lib/BinaryProtoLookupService.cc
@@ -38,7 +38,7 @@ auto BinaryProtoLookupService::findBroker(const std::string& 
address, bool autho
     LOG_DEBUG("find broker from " << address << ", authoritative: " << 
authoritative << ", topic: " << topic);
     auto promise = std::make_shared<Promise<Result, LookupResult>>();
     // NOTE: we can use move capture for topic since C++14
-    cnxPool_.getConnectionAsync(address).addListener([this, promise, topic, 
address](
+    cnxPool_.getConnectionAsync(address).addListener([this, promise, topic, 
address, authoritative](
                                                          Result result,
                                                          const 
ClientConnectionWeakPtr& weakCnx) {
         if (result != ResultOk) {
@@ -52,7 +52,7 @@ auto BinaryProtoLookupService::findBroker(const std::string& 
address, bool autho
             return;
         }
         auto lookupPromise = std::make_shared<LookupDataResultPromise>();
-        cnx->newTopicLookup(topic, false, listenerName_, newRequestId(), 
lookupPromise);
+        cnx->newTopicLookup(topic, authoritative, listenerName_, 
newRequestId(), lookupPromise);
         lookupPromise->getFuture().addListener([this, cnx, promise, topic, 
address](
                                                    Result result, const 
LookupDataResultPtr& data) {
             if (result != ResultOk || !data) {

Reply via email to