tflobbe commented on a change in pull request #1297: SOLR-14253 Replace various sleep calls with ZK waits URL: https://github.com/apache/lucene-solr/pull/1297#discussion_r385434556
########## File path: solr/core/src/java/org/apache/solr/cloud/ZkController.java ########## @@ -1684,58 +1685,37 @@ private void doGetShardIdAndNodeNameProcess(CoreDescriptor cd) { } private void waitForCoreNodeName(CoreDescriptor descriptor) { - int retryCount = 320; - log.debug("look for our core node name"); - while (retryCount-- > 0) { - final DocCollection docCollection = zkStateReader.getClusterState() - .getCollectionOrNull(descriptor.getCloudDescriptor().getCollectionName()); - if (docCollection != null && docCollection.getSlicesMap() != null) { - final Map<String, Slice> slicesMap = docCollection.getSlicesMap(); - for (Slice slice : slicesMap.values()) { - for (Replica replica : slice.getReplicas()) { - // TODO: for really large clusters, we could 'index' on this - - String nodeName = replica.getStr(ZkStateReader.NODE_NAME_PROP); - String core = replica.getStr(ZkStateReader.CORE_NAME_PROP); - - String msgNodeName = getNodeName(); - String msgCore = descriptor.getName(); - - if (msgNodeName.equals(nodeName) && core.equals(msgCore)) { - descriptor.getCloudDescriptor() - .setCoreNodeName(replica.getName()); - getCoreContainer().getCoresLocator().persist(getCoreContainer(), descriptor); - return; - } - } + log.debug("waitForCoreNodeName >>> look for our core node name"); + try { + zkStateReader.waitForState(descriptor.getCollectionName(), 320, TimeUnit.SECONDS, c -> { + String name = ClusterStateMutator.getAssignedCoreNodeName(c, getNodeName(), descriptor.getName()); + if (name == null) { + return false; } - } - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } + descriptor.getCloudDescriptor().setCoreNodeName(name); Review comment: Do we need any synchronization, since this will now be running on a different thread? ---------------------------------------------------------------- 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 With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org