Search in sources :

Example 76 with ClusterState

use of org.apache.solr.common.cloud.ClusterState in project lucene-solr by apache.

the class PeerSyncReplicationTest method waitTillNodesActive.

private void waitTillNodesActive() throws Exception {
    for (int i = 0; i < 60; i++) {
        Thread.sleep(3000);
        ZkStateReader zkStateReader = cloudClient.getZkStateReader();
        ClusterState clusterState = zkStateReader.getClusterState();
        DocCollection collection1 = clusterState.getCollection("collection1");
        Slice slice = collection1.getSlice("shard1");
        Collection<Replica> replicas = slice.getReplicas();
        boolean allActive = true;
        Collection<String> nodesDownNames = nodesDown.stream().map(n -> n.coreNodeName).collect(Collectors.toList());
        Collection<Replica> replicasToCheck = replicas.stream().filter(r -> !nodesDownNames.contains(r.getName())).collect(Collectors.toList());
        for (Replica replica : replicasToCheck) {
            if (!clusterState.liveNodesContain(replica.getNodeName()) || replica.getState() != Replica.State.ACTIVE) {
                allActive = false;
                break;
            }
        }
        if (allActive) {
            return;
        }
    }
    printLayout();
    fail("timeout waiting to see all nodes active");
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) Arrays(java.util.Arrays) Slow(org.apache.lucene.util.LuceneTestCase.Slow) DocCollection(org.apache.solr.common.cloud.DocCollection) ClusterState(org.apache.solr.common.cloud.ClusterState) LoggerFactory(org.slf4j.LoggerFactory) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) HashSet(java.util.HashSet) SolrServerException(org.apache.solr.client.solrj.SolrServerException) Map(java.util.Map) Counter(com.codahale.metrics.Counter) RandomStringUtils(org.apache.commons.lang.RandomStringUtils) ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) MetricRegistry(com.codahale.metrics.MetricRegistry) Slice(org.apache.solr.common.cloud.Slice) Logger(org.slf4j.Logger) Files(java.nio.file.Files) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) Set(java.util.Set) Metric(com.codahale.metrics.Metric) IOException(java.io.IOException) Test(org.junit.Test) TimeOut(org.apache.solr.util.TimeOut) Collectors(java.util.stream.Collectors) Replica(org.apache.solr.common.cloud.Replica) BadApple(org.apache.lucene.util.LuceneTestCase.BadApple) List(java.util.List) Paths(java.nio.file.Paths) SolrQuery(org.apache.solr.client.solrj.SolrQuery) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) LimitViolationAction(org.apache.solr.cloud.ZkTestServer.LimitViolationAction) Timer(com.codahale.metrics.Timer) SECONDS(java.util.concurrent.TimeUnit.SECONDS) SolrInputDocument(org.apache.solr.common.SolrInputDocument) ClusterState(org.apache.solr.common.cloud.ClusterState) Slice(org.apache.solr.common.cloud.Slice) DocCollection(org.apache.solr.common.cloud.DocCollection) Replica(org.apache.solr.common.cloud.Replica)

Example 77 with ClusterState

use of org.apache.solr.common.cloud.ClusterState in project lucene-solr by apache.

the class ShardSplitTest method incompleteOrOverlappingCustomRangeTest.

private void incompleteOrOverlappingCustomRangeTest() throws Exception {
    ClusterState clusterState = cloudClient.getZkStateReader().getClusterState();
    final DocRouter router = clusterState.getCollection(AbstractDistribZkTestBase.DEFAULT_COLLECTION).getRouter();
    Slice shard1 = clusterState.getSlice(AbstractDistribZkTestBase.DEFAULT_COLLECTION, SHARD1);
    DocRouter.Range shard1Range = shard1.getRange() != null ? shard1.getRange() : router.fullRange();
    List<DocRouter.Range> subRanges = new ArrayList<>();
    List<DocRouter.Range> ranges = router.partitionRange(4, shard1Range);
    // test with only one range
    subRanges.add(ranges.get(0));
    try {
        splitShard(AbstractDistribZkTestBase.DEFAULT_COLLECTION, SHARD1, subRanges, null);
        fail("Shard splitting with just one custom hash range should not succeed");
    } catch (HttpSolrClient.RemoteSolrException e) {
        log.info("Expected exception:", e);
    }
    subRanges.clear();
    // test with ranges with a hole in between them
    // order shouldn't matter
    subRanges.add(ranges.get(3));
    subRanges.add(ranges.get(0));
    try {
        splitShard(AbstractDistribZkTestBase.DEFAULT_COLLECTION, SHARD1, subRanges, null);
        fail("Shard splitting with missing hashes in between given ranges should not succeed");
    } catch (HttpSolrClient.RemoteSolrException e) {
        log.info("Expected exception:", e);
    }
    subRanges.clear();
    // test with overlapping ranges
    subRanges.add(ranges.get(0));
    subRanges.add(ranges.get(1));
    subRanges.add(ranges.get(2));
    subRanges.add(new DocRouter.Range(ranges.get(3).min - 15, ranges.get(3).max));
    try {
        splitShard(AbstractDistribZkTestBase.DEFAULT_COLLECTION, SHARD1, subRanges, null);
        fail("Shard splitting with overlapping ranges should not succeed");
    } catch (HttpSolrClient.RemoteSolrException e) {
        log.info("Expected exception:", e);
    }
    subRanges.clear();
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) ClusterState(org.apache.solr.common.cloud.ClusterState) Slice(org.apache.solr.common.cloud.Slice) DocRouter(org.apache.solr.common.cloud.DocRouter) ArrayList(java.util.ArrayList)

Example 78 with ClusterState

use of org.apache.solr.common.cloud.ClusterState in project lucene-solr by apache.

the class ReplicaPropertiesBase method verifyPropertyVal.

// The params are triplets,
// collection
// shard
// replica
public static void verifyPropertyVal(CloudSolrClient client, String collectionName, String replicaName, String property, String val) throws InterruptedException, KeeperException {
    Replica replica = null;
    ClusterState clusterState = null;
    for (int idx = 0; idx < 300; ++idx) {
        // Keep trying while Overseer writes the ZK state for up to 30 seconds.
        clusterState = client.getZkStateReader().getClusterState();
        replica = clusterState.getReplica(collectionName, replicaName);
        if (replica == null) {
            fail("Could not find collection/replica pair! " + collectionName + "/" + replicaName);
        }
        if (StringUtils.equals(val, replica.getStr(property)))
            return;
        Thread.sleep(100);
    }
    fail("Property '" + property + "' with value " + replica.getStr(property) + " not set correctly for collection/replica pair: " + collectionName + "/" + replicaName + " property map is " + replica.getProperties().toString() + ".");
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) Replica(org.apache.solr.common.cloud.Replica)

Example 79 with ClusterState

use of org.apache.solr.common.cloud.ClusterState in project lucene-solr by apache.

the class ReplicaPropertiesBase method verifyUnique.

public static void verifyUnique(CloudSolrClient client, String collectionName, String property, boolean balanced) throws KeeperException, InterruptedException {
    DocCollection col = null;
    for (int idx = 0; idx < 300; ++idx) {
        ClusterState clusterState = client.getZkStateReader().getClusterState();
        col = clusterState.getCollection(collectionName);
        if (col == null) {
            fail("Could not find collection " + collectionName);
        }
        Map<String, Integer> counts = new HashMap<>();
        Set<String> uniqueNodes = new HashSet<>();
        boolean allSlicesHaveProp = true;
        boolean badSlice = false;
        for (Slice slice : col.getSlices()) {
            boolean thisSliceHasProp = false;
            int propCount = 0;
            for (Replica replica : slice.getReplicas()) {
                uniqueNodes.add(replica.getNodeName());
                String propVal = replica.getStr(property);
                if (StringUtils.isNotBlank(propVal)) {
                    ++propCount;
                    if (counts.containsKey(replica.getNodeName()) == false) {
                        counts.put(replica.getNodeName(), 0);
                    }
                    int count = counts.get(replica.getNodeName());
                    thisSliceHasProp = true;
                    counts.put(replica.getNodeName(), count + 1);
                }
            }
            badSlice = (propCount > 1) ? true : badSlice;
            allSlicesHaveProp = allSlicesHaveProp ? thisSliceHasProp : allSlicesHaveProp;
        }
        if (balanced == false && badSlice == false) {
            return;
        }
        if (allSlicesHaveProp && balanced) {
            // Check that the properties are evenly distributed.
            int minProps = col.getSlices().size() / uniqueNodes.size();
            int maxProps = minProps;
            if (col.getSlices().size() % uniqueNodes.size() > 0) {
                ++maxProps;
            }
            boolean doSleep = false;
            for (Map.Entry<String, Integer> ent : counts.entrySet()) {
                if (ent.getValue() != minProps && ent.getValue() != maxProps) {
                    doSleep = true;
                }
            }
            if (doSleep == false) {
                assertTrue("We really shouldn't be calling this if there is no node with the property " + property, counts.size() > 0);
                return;
            }
        }
        Thread.sleep(100);
    }
    fail("Collection " + collectionName + " does not have roles evenly distributed. Collection is: " + col.toString());
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) HashMap(java.util.HashMap) Replica(org.apache.solr.common.cloud.Replica) Slice(org.apache.solr.common.cloud.Slice) DocCollection(org.apache.solr.common.cloud.DocCollection) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 80 with ClusterState

use of org.apache.solr.common.cloud.ClusterState in project lucene-solr by apache.

the class BackupManager method readCollectionState.

/**
   * This method reads the meta-data information for the backed-up collection.
   *
   * @param backupLoc The base path used to store the backup data.
   * @param backupId The unique name for the backup.
   * @param collectionName The name of the collection whose meta-data is to be returned.
   * @return the meta-data information for the backed-up collection.
   * @throws IOException in case of errors.
   */
public DocCollection readCollectionState(URI backupLoc, String backupId, String collectionName) throws IOException {
    Objects.requireNonNull(collectionName);
    URI zkStateDir = repository.resolve(backupLoc, backupId, ZK_STATE_DIR);
    try (IndexInput is = repository.openInput(zkStateDir, COLLECTION_PROPS_FILE, IOContext.DEFAULT)) {
        // probably ok since the json file should be small.
        byte[] arr = new byte[(int) is.length()];
        is.readBytes(arr, 0, (int) is.length());
        ClusterState c_state = ClusterState.load(-1, arr, Collections.emptySet());
        return c_state.getCollection(collectionName);
    }
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) IndexInput(org.apache.lucene.store.IndexInput) URI(java.net.URI)

Aggregations

ClusterState (org.apache.solr.common.cloud.ClusterState)122 Slice (org.apache.solr.common.cloud.Slice)78 Replica (org.apache.solr.common.cloud.Replica)65 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)56 DocCollection (org.apache.solr.common.cloud.DocCollection)49 HashMap (java.util.HashMap)42 ArrayList (java.util.ArrayList)36 Map (java.util.Map)25 IOException (java.io.IOException)20 Test (org.junit.Test)18 HashSet (java.util.HashSet)17 SolrException (org.apache.solr.common.SolrException)16 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)15 SolrQuery (org.apache.solr.client.solrj.SolrQuery)13 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)13 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)13 ZkCoreNodeProps (org.apache.solr.common.cloud.ZkCoreNodeProps)13 ZkNodeProps (org.apache.solr.common.cloud.ZkNodeProps)13 List (java.util.List)12 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)12