|
27 | 27 | import java.util.Map;
|
28 | 28 | import java.util.Random;
|
29 | 29 | import java.util.Set;
|
| 30 | +import java.util.concurrent.ConcurrentHashMap; |
30 | 31 | import java.util.concurrent.ExecutorService;
|
31 | 32 | import java.util.concurrent.SynchronousQueue;
|
32 | 33 | import java.util.concurrent.TimeUnit;
|
33 | 34 | import java.util.concurrent.TimeoutException;
|
34 |
| -import java.util.concurrent.atomic.AtomicReference; |
35 | 35 |
|
36 | 36 | import com.google.common.collect.ImmutableMap;
|
37 | 37 | import org.apache.commons.lang3.StringUtils;
|
@@ -487,21 +487,15 @@ static UpdateResponse softCommit(String url) throws SolrServerException, IOExcep
|
487 | 487 | }
|
488 | 488 |
|
489 | 489 | String waitForCoreNodeName(String collectionName, String msgNodeName, String msgCore) {
|
490 |
| - AtomicReference<String> coreNodeName = new AtomicReference<>(); |
491 | 490 | try {
|
492 |
| - zkStateReader.waitForState(collectionName, 320, TimeUnit.SECONDS, c -> { |
493 |
| - String name = ClusterStateMutator.getAssignedCoreNodeName(c, msgNodeName, msgCore); |
494 |
| - if (name == null) { |
495 |
| - return false; |
496 |
| - } |
497 |
| - coreNodeName.set(name); |
498 |
| - return true; |
499 |
| - }); |
| 491 | + DocCollection collection = zkStateReader.waitForState(collectionName, 320, TimeUnit.SECONDS, c -> |
| 492 | + ClusterStateMutator.getAssignedCoreNodeName(c, msgNodeName, msgCore) != null |
| 493 | + ); |
| 494 | + return ClusterStateMutator.getAssignedCoreNodeName(collection, msgNodeName, msgCore); |
500 | 495 | } catch (TimeoutException | InterruptedException e) {
|
501 | 496 | SolrZkClient.checkInterrupted(e);
|
502 | 497 | throw new SolrException(ErrorCode.SERVER_ERROR, "Failed waiting for coreNodeName", e);
|
503 | 498 | }
|
504 |
| - return coreNodeName.get(); |
505 | 499 | }
|
506 | 500 |
|
507 | 501 | ClusterState waitForNewShard(String collectionName, String sliceName) throws KeeperException, InterruptedException {
|
@@ -609,26 +603,23 @@ void cleanupCollection(String collectionName, @SuppressWarnings({"rawtypes"})Nam
|
609 | 603 |
|
610 | 604 | Map<String, Replica> waitToSeeReplicasInState(String collectionName, Collection<String> coreNames) throws InterruptedException {
|
611 | 605 | assert coreNames.size() > 0;
|
612 |
| - Map<String, Replica> results = new HashMap<>(); |
613 |
| - AtomicReference<DocCollection> lastState = new AtomicReference<>(); |
| 606 | + Map<String, Replica> results = new ConcurrentHashMap<>(); |
614 | 607 |
|
615 | 608 | long maxWait = Long.getLong("solr.waitToSeeReplicasInStateTimeoutSeconds", 120); // could be a big cluster
|
616 | 609 | try {
|
617 | 610 | zkStateReader.waitForState(collectionName, maxWait, TimeUnit.SECONDS, c -> {
|
618 | 611 | if (c == null) return false;
|
619 | 612 |
|
| 613 | + // We write into a ConcurrentHashMap, which will be ok if called multiple times by multiple threads |
620 | 614 | c.getSlices().stream().flatMap(slice -> slice.getReplicas().stream())
|
621 |
| - .filter(r -> coreNames.contains(r.getCoreName())) // Only the elements that were asked for... |
622 |
| - .filter(r -> !results.containsKey(r.getCoreName())) // ...but not the ones we've seen already... |
623 |
| - .forEach(r -> results.put(r.getCoreName(), r)); // ...get added to the map |
| 615 | + .filter(r -> coreNames.contains(r.getCoreName())) // Only the elements that were asked for... |
| 616 | + .forEach(r -> results.putIfAbsent(r.getCoreName(), r)); // ...get added to the map |
624 | 617 |
|
625 |
| - lastState.set(c); |
626 | 618 | log.debug("Expecting {} cores, found {}", coreNames, results);
|
627 | 619 | return results.size() == coreNames.size();
|
628 | 620 | });
|
629 | 621 | } catch (TimeoutException e) {
|
630 |
| - String error = "Timed out waiting to see all replicas: " + coreNames + " in cluster state. Last state: " + lastState.get(); |
631 |
| - throw new SolrException(ErrorCode.SERVER_ERROR, error); |
| 622 | + throw new SolrException(ErrorCode.SERVER_ERROR, e.getMessage(), e); |
632 | 623 | }
|
633 | 624 |
|
634 | 625 | return results;
|
|
0 commit comments