[ 
https://issues.apache.org/jira/browse/GEODE-8553?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17205184#comment-17205184
 ] 

ASF GitHub Bot commented on GEODE-8553:
---------------------------------------

gaussianrecurrence commented on a change in pull request #660:
URL: https://github.com/apache/geode-native/pull/660#discussion_r497908712



##########
File path: cppcache/src/ThinClientLocatorHelper.cpp
##########
@@ -174,30 +176,25 @@ GfErrType 
ThinClientLocatorHelper::getEndpointForNewCallBackConn(
     ClientProxyMembershipID& memId, std::list<ServerLocation>& outEndpoint,
     std::string&, int redundancy, const std::set<ServerLocation>& exclEndPts,
     const std::string& serverGrp) {
-  std::lock_guard<decltype(m_locatorLock)> guard(m_locatorLock);
   auto& sysProps = m_poolDM->getConnectionManager()
                        .getCacheImpl()
                        ->getDistributedSystem()
                        .getSystemProperties();
-  int locatorsRetry = 3;
-  if (m_poolDM) {
-    int poolRetry = m_poolDM->getRetryAttempts();
-    locatorsRetry = poolRetry <= 0 ? locatorsRetry : poolRetry;
-  }
+
+  auto poolRetry = m_poolDM->getRetryAttempts();
+  auto locatorsRetry = poolRetry <= 0 ? 3 : poolRetry;
+
   LOGFINER(
       "ThinClientLocatorHelper::getEndpointForNewCallBackConn locatorsRetry = "
       "%d ",
       locatorsRetry);
-  for (unsigned attempts = 0;
-       attempts <
-       (m_locHostPort.size() == 1 ? locatorsRetry : m_locHostPort.size());
-       attempts++) {
-    ServerLocation loc;
-    if (m_locHostPort.size() == 1) {
-      loc = m_locHostPort[0];
-    } else {
-      loc = m_locHostPort[attempts];
-    }
+
+  auto locators = getLocators();
+  auto locatorsSize = locators.size();
+  auto maxAttempts = locatorsSize == 1 ? locatorsRetry : locatorsSize;
+
+  for (auto attempts = 0ULL; attempts < maxAttempts; ++attempts) {
+    const auto& loc = locatorsSize == 1 ? locators[0] : locators[attempts];

Review comment:
       I don't like either the way code is written for connections attemps. 
Problem with your approach is that it would change the business logic, meaning 
it might have some impact in terms of robustness.
   
   The way I see it, connections attemps towards locators should work as 
follows:
   
   - Call getLocators (considering vector is shuffled each call), returning the 
list of locators.
   - Treat the list of locators as a circular buffer and make locatorsRetry 
connections attempts meaning, the i-th connection attempt will be made to the 
(i mod locators.size()) locator.
   
   How about this? :)




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Reduce ThinClientLocatorHelper lock time
> ----------------------------------------
>
>                 Key: GEODE-8553
>                 URL: https://issues.apache.org/jira/browse/GEODE-8553
>             Project: Geode
>          Issue Type: Improvement
>          Components: native client
>    Affects Versions: 1.12.0, 1.13.0
>            Reporter: Mario Salazar de Torres
>            Assignee: Mario Salazar de Torres
>            Priority: Major
>              Labels: pull-request-available
>
> During my troublshootings, I've seen that locking m_locatorLock for the whole 
> scope of the class function members might cause some inter-locks.
> Problem here and in many other places of the NC is that networking operations 
> are performed while a mutex is locked. Therefore if *thread A* takes longer 
> than expected in performing its network operation, it might block another one 
> which does not requires any resource of the first *thread A*. Hence, the 
> inter-lock.
> This improvement is the first one of a series regarding to lock scope 
> reduction when it comes with code regarding networking in NC.
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to