Search in sources :

Example 16 with Replica

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

the class TestPullReplica method testRealTimeGet.

public void testRealTimeGet() throws SolrServerException, IOException, KeeperException, InterruptedException {
    // should be redirected to Replica.Type.NRT
    int numReplicas = random().nextBoolean() ? 1 : 2;
    CollectionAdminRequest.createCollection(collectionName, "conf", 1, numReplicas, 0, numReplicas).setMaxShardsPerNode(100).process(cluster.getSolrClient());
    waitForState("Unexpected replica count", collectionName, activeReplicaCount(numReplicas, 0, numReplicas));
    DocCollection docCollection = assertNumberOfReplicas(numReplicas, 0, numReplicas, false, true);
    HttpClient httpClient = cluster.getSolrClient().getHttpClient();
    int id = 0;
    Slice slice = docCollection.getSlice("shard1");
    List<String> ids = new ArrayList<>(slice.getReplicas().size());
    for (Replica rAdd : slice.getReplicas()) {
        try (HttpSolrClient client = getHttpSolrClient(rAdd.getCoreUrl(), httpClient)) {
            client.add(new SolrInputDocument("id", String.valueOf(id), "foo_s", "bar"));
        }
        SolrDocument docCloudClient = cluster.getSolrClient().getById(collectionName, String.valueOf(id));
        assertEquals("bar", docCloudClient.getFieldValue("foo_s"));
        for (Replica rGet : slice.getReplicas()) {
            try (HttpSolrClient client = getHttpSolrClient(rGet.getCoreUrl(), httpClient)) {
                SolrDocument doc = client.getById(String.valueOf(id));
                assertEquals("bar", doc.getFieldValue("foo_s"));
            }
        }
        ids.add(String.valueOf(id));
        id++;
    }
    SolrDocumentList previousAllIdsResult = null;
    for (Replica rAdd : slice.getReplicas()) {
        try (HttpSolrClient client = getHttpSolrClient(rAdd.getCoreUrl(), httpClient)) {
            SolrDocumentList allIdsResult = client.getById(ids);
            if (previousAllIdsResult != null) {
                assertTrue(compareSolrDocumentList(previousAllIdsResult, allIdsResult));
            } else {
                // set the first response here
                previousAllIdsResult = allIdsResult;
                assertEquals("Unexpected number of documents", ids.size(), allIdsResult.getNumFound());
            }
        }
        id++;
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrDocument(org.apache.solr.common.SolrDocument) Slice(org.apache.solr.common.cloud.Slice) HttpClient(org.apache.http.client.HttpClient) ArrayList(java.util.ArrayList) DocCollection(org.apache.solr.common.cloud.DocCollection) SolrDocumentList(org.apache.solr.common.SolrDocumentList) Replica(org.apache.solr.common.cloud.Replica)

Example 17 with Replica

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

the class TestPullReplica method assertUlogPresence.

/**
   * Asserts that Update logs don't exist for replicas of type {@link org.apache.solr.common.cloud.Replica.Type#PULL}
   */
private void assertUlogPresence(DocCollection collection) {
    for (Slice s : collection.getSlices()) {
        for (Replica r : s.getReplicas()) {
            if (r.getType() == Replica.Type.NRT) {
                continue;
            }
            SolrCore core = null;
            try {
                core = cluster.getReplicaJetty(r).getCoreContainer().getCore(r.getCoreName());
                assertNotNull(core);
                assertFalse("Update log should not exist for replicas of type Passive but file is present: " + core.getUlogDir(), new java.io.File(core.getUlogDir()).exists());
            } finally {
                core.close();
            }
        }
    }
}
Also used : Slice(org.apache.solr.common.cloud.Slice) SolrCore(org.apache.solr.core.SolrCore) Replica(org.apache.solr.common.cloud.Replica)

Example 18 with Replica

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

the class TestSolrConfigHandlerCloud method getRandomServer.

public static String getRandomServer(CloudSolrClient cloudClient, String collName) {
    DocCollection coll = cloudClient.getZkStateReader().getClusterState().getCollection(collName);
    List<String> urls = new ArrayList<>();
    for (Slice slice : coll.getSlices()) {
        for (Replica replica : slice.getReplicas()) urls.add("" + replica.get(ZkStateReader.BASE_URL_PROP) + "/" + replica.get(ZkStateReader.CORE_NAME_PROP));
    }
    return urls.get(random().nextInt(urls.size()));
}
Also used : Slice(org.apache.solr.common.cloud.Slice) ArrayList(java.util.ArrayList) DocCollection(org.apache.solr.common.cloud.DocCollection) TestBlobHandler.getAsString(org.apache.solr.handler.TestBlobHandler.getAsString) Replica(org.apache.solr.common.cloud.Replica)

Example 19 with Replica

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

the class BasicAuthIntegrationTest method getRandomReplica.

public static Replica getRandomReplica(DocCollection coll, Random random) {
    ArrayList<Replica> l = new ArrayList<>();
    for (Slice slice : coll.getSlices()) {
        for (Replica replica : slice.getReplicas()) {
            l.add(replica);
        }
    }
    Collections.shuffle(l, random);
    return l.isEmpty() ? null : l.get(0);
}
Also used : Slice(org.apache.solr.common.cloud.Slice) ArrayList(java.util.ArrayList) Replica(org.apache.solr.common.cloud.Replica)

Example 20 with Replica

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

the class FeaturesSelectionStream method getShardUrls.

private List<String> getShardUrls() throws IOException {
    try {
        ZkStateReader zkStateReader = cloudSolrClient.getZkStateReader();
        Collection<Slice> slices = CloudSolrStream.getSlices(this.collection, zkStateReader, false);
        ClusterState clusterState = zkStateReader.getClusterState();
        Set<String> liveNodes = clusterState.getLiveNodes();
        List<String> baseUrls = new ArrayList<>();
        for (Slice slice : slices) {
            Collection<Replica> replicas = slice.getReplicas();
            List<Replica> shuffler = new ArrayList<>();
            for (Replica replica : replicas) {
                if (replica.getState() == Replica.State.ACTIVE && liveNodes.contains(replica.getNodeName())) {
                    shuffler.add(replica);
                }
            }
            Collections.shuffle(shuffler, new Random());
            Replica rep = shuffler.get(0);
            ZkCoreNodeProps zkProps = new ZkCoreNodeProps(rep);
            String url = zkProps.getCoreUrl();
            baseUrls.add(url);
        }
        return baseUrls;
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) ZkCoreNodeProps(org.apache.solr.common.cloud.ZkCoreNodeProps) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Replica(org.apache.solr.common.cloud.Replica) IOException(java.io.IOException) ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) Random(java.util.Random) Slice(org.apache.solr.common.cloud.Slice)

Aggregations

Replica (org.apache.solr.common.cloud.Replica)231 Slice (org.apache.solr.common.cloud.Slice)139 DocCollection (org.apache.solr.common.cloud.DocCollection)86 ArrayList (java.util.ArrayList)81 ClusterState (org.apache.solr.common.cloud.ClusterState)66 HashMap (java.util.HashMap)59 SolrException (org.apache.solr.common.SolrException)53 Test (org.junit.Test)50 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)49 Map (java.util.Map)44 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)37 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)35 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)29 NamedList (org.apache.solr.common.util.NamedList)28 SolrQuery (org.apache.solr.client.solrj.SolrQuery)26 IOException (java.io.IOException)25 SolrInputDocument (org.apache.solr.common.SolrInputDocument)25 ZkCoreNodeProps (org.apache.solr.common.cloud.ZkCoreNodeProps)25 HashSet (java.util.HashSet)24 List (java.util.List)20