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_r385437194
##########
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);
}
- throw new SolrException(ErrorCode.SERVER_ERROR, "Could not find
coreNodeName");
+ return coreNodeName.get();
}
- ClusterState waitForNewShard(String collectionName, String sliceName) throws
KeeperException, InterruptedException {
+ ClusterState waitForNewShard(String collectionName, String sliceName) {
log.debug("Waiting for slice {} of collection {} to be available",
sliceName, collectionName);
- RTimer timer = new RTimer();
- int retryCount = 320;
- while (retryCount-- > 0) {
- ClusterState clusterState = zkStateReader.getClusterState();
- DocCollection collection = clusterState.getCollection(collectionName);
-
- if (collection == null) {
- throw new SolrException(ErrorCode.SERVER_ERROR,
- "Unable to find collection: " + collectionName + " in
clusterstate");
- }
- Slice slice = collection.getSlice(sliceName);
- if (slice != null) {
- log.debug("Waited for {}ms for slice {} of collection {} to be
available",
- timer.getTime(), sliceName, collectionName);
- return clusterState;
- }
- Thread.sleep(1000);
+ try {
+ zkStateReader.waitForState(collectionName, 320, TimeUnit.SECONDS, c -> c
!= null && c.getSlice(sliceName) != null);
+ } catch (TimeoutException | InterruptedException e) {
+ throw new SolrException(ErrorCode.SERVER_ERROR, "Timeout waiting for new
slice", e);
Review comment:
interruption?
----------------------------------------------------------------
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]