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_r385436856
##########
File path:
solr/core/src/java/org/apache/solr/cloud/api/collections/OverseerCollectionMessageHandler.java
##########
@@ -526,57 +518,31 @@ static UpdateResponse softCommit(String url) throws
SolrServerException, IOExcep
}
String waitForCoreNodeName(String collectionName, String msgNodeName, String
msgCore) {
- int retryCount = 320;
- while (retryCount-- > 0) {
- final DocCollection docCollection =
zkStateReader.getClusterState().getCollectionOrNull(collectionName);
- if (docCollection != null && docCollection.getSlicesMap() != null) {
- 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);
-
- if (nodeName.equals(msgNodeName) && core.equals(msgCore)) {
- return replica.getName();
- }
- }
+ AtomicReference<String> coreNodeName = new AtomicReference<>();
+ try {
+ zkStateReader.waitForState(collectionName, 320, TimeUnit.SECONDS, c -> {
+ String name = ClusterStateMutator.getAssignedCoreNodeName(c,
msgNodeName, msgCore);
+ if (name == null) {
+ return false;
}
- }
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- }
+ coreNodeName.set(name);
+ return true;
+ });
+ } catch (TimeoutException | InterruptedException e) {
+ throw new SolrException(ErrorCode.SERVER_ERROR, "Timeout waiting for
collection state", e);
Review comment:
`Thread.currentThread().interrupt()`?
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]