Search in sources :

Example 71 with Slice

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

the class TestMiniSolrCloudCluster method testCollectionCreateSearchDelete.

@Test
public void testCollectionCreateSearchDelete() throws Exception {
    final String collectionName = "testcollection";
    MiniSolrCloudCluster miniCluster = createMiniSolrCloudCluster();
    final CloudSolrClient cloudSolrClient = miniCluster.getSolrClient();
    try {
        assertNotNull(miniCluster.getZkServer());
        List<JettySolrRunner> jettys = miniCluster.getJettySolrRunners();
        assertEquals(NUM_SERVERS, jettys.size());
        for (JettySolrRunner jetty : jettys) {
            assertTrue(jetty.isRunning());
        }
        // shut down a server
        log.info("#### Stopping a server");
        JettySolrRunner stoppedServer = miniCluster.stopJettySolrRunner(0);
        assertTrue(stoppedServer.isStopped());
        assertEquals(NUM_SERVERS - 1, miniCluster.getJettySolrRunners().size());
        // create a server
        log.info("#### Starting a server");
        JettySolrRunner startedServer = miniCluster.startJettySolrRunner();
        assertTrue(startedServer.isRunning());
        assertEquals(NUM_SERVERS, miniCluster.getJettySolrRunners().size());
        // create collection
        log.info("#### Creating a collection");
        final String asyncId = (random().nextBoolean() ? null : "asyncId(" + collectionName + ".create)=" + random().nextInt());
        createCollection(miniCluster, collectionName, null, asyncId, null, null);
        ZkStateReader zkStateReader = miniCluster.getSolrClient().getZkStateReader();
        AbstractDistribZkTestBase.waitForRecoveriesToFinish(collectionName, zkStateReader, true, true, 330);
        // modify/query collection
        log.info("#### updating a querying collection");
        cloudSolrClient.setDefaultCollection(collectionName);
        SolrInputDocument doc = new SolrInputDocument();
        doc.setField("id", "1");
        cloudSolrClient.add(doc);
        cloudSolrClient.commit();
        SolrQuery query = new SolrQuery();
        query.setQuery("*:*");
        QueryResponse rsp = cloudSolrClient.query(query);
        assertEquals(1, rsp.getResults().getNumFound());
        // remove a server not hosting any replicas
        zkStateReader.forceUpdateCollection(collectionName);
        ClusterState clusterState = zkStateReader.getClusterState();
        HashMap<String, JettySolrRunner> jettyMap = new HashMap<String, JettySolrRunner>();
        for (JettySolrRunner jetty : miniCluster.getJettySolrRunners()) {
            String key = jetty.getBaseUrl().toString().substring((jetty.getBaseUrl().getProtocol() + "://").length());
            jettyMap.put(key, jetty);
        }
        Collection<Slice> slices = clusterState.getSlices(collectionName);
        // track the servers not host repliacs
        for (Slice slice : slices) {
            jettyMap.remove(slice.getLeader().getNodeName().replace("_solr", "/solr"));
            for (Replica replica : slice.getReplicas()) {
                jettyMap.remove(replica.getNodeName().replace("_solr", "/solr"));
            }
        }
        assertTrue("Expected to find a node without a replica", jettyMap.size() > 0);
        log.info("#### Stopping a server");
        JettySolrRunner jettyToStop = jettyMap.entrySet().iterator().next().getValue();
        jettys = miniCluster.getJettySolrRunners();
        for (int i = 0; i < jettys.size(); ++i) {
            if (jettys.get(i).equals(jettyToStop)) {
                miniCluster.stopJettySolrRunner(i);
                assertEquals(NUM_SERVERS - 1, miniCluster.getJettySolrRunners().size());
            }
        }
        // re-create a server (to restore original NUM_SERVERS count)
        log.info("#### Starting a server");
        startedServer = miniCluster.startJettySolrRunner(jettyToStop);
        assertTrue(startedServer.isRunning());
        assertEquals(NUM_SERVERS, miniCluster.getJettySolrRunners().size());
        CollectionAdminRequest.deleteCollection(collectionName).process(miniCluster.getSolrClient());
        // create it again
        String asyncId2 = (random().nextBoolean() ? null : "asyncId(" + collectionName + ".create)=" + random().nextInt());
        createCollection(miniCluster, collectionName, null, asyncId2, null, null);
        AbstractDistribZkTestBase.waitForRecoveriesToFinish(collectionName, zkStateReader, true, true, 330);
        // check that there's no left-over state
        assertEquals(0, cloudSolrClient.query(new SolrQuery("*:*")).getResults().getNumFound());
        cloudSolrClient.add(doc);
        cloudSolrClient.commit();
        assertEquals(1, cloudSolrClient.query(new SolrQuery("*:*")).getResults().getNumFound());
    } finally {
        miniCluster.shutdown();
    }
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) HashMap(java.util.HashMap) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) Replica(org.apache.solr.common.cloud.Replica) SolrQuery(org.apache.solr.client.solrj.SolrQuery) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) SolrInputDocument(org.apache.solr.common.SolrInputDocument) Slice(org.apache.solr.common.cloud.Slice) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) Test(org.junit.Test)

Example 72 with Slice

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

the class TestCollectionAPI method replicaPropTest.

private void replicaPropTest() throws Exception {
    try (CloudSolrClient client = createCloudClient(null)) {
        client.connect();
        Map<String, Slice> slices = client.getZkStateReader().getClusterState().getCollection(COLLECTION_NAME).getSlicesMap();
        List<String> sliceList = new ArrayList<>(slices.keySet());
        String c1_s1 = sliceList.get(0);
        List<String> replicasList = new ArrayList<>(slices.get(c1_s1).getReplicasMap().keySet());
        String c1_s1_r1 = replicasList.get(0);
        String c1_s1_r2 = replicasList.get(1);
        String c1_s2 = sliceList.get(1);
        replicasList = new ArrayList<>(slices.get(c1_s2).getReplicasMap().keySet());
        String c1_s2_r1 = replicasList.get(0);
        String c1_s2_r2 = replicasList.get(1);
        slices = client.getZkStateReader().getClusterState().getCollection(COLLECTION_NAME1).getSlicesMap();
        sliceList = new ArrayList<>(slices.keySet());
        String c2_s1 = sliceList.get(0);
        replicasList = new ArrayList<>(slices.get(c2_s1).getReplicasMap().keySet());
        String c2_s1_r1 = replicasList.get(0);
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set("action", CollectionParams.CollectionAction.ADDREPLICAPROP.toString());
        // Insure we get error returns when omitting required parameters
        missingParamsError(client, params);
        params.set("collection", COLLECTION_NAME);
        missingParamsError(client, params);
        params.set("shard", c1_s1);
        missingParamsError(client, params);
        params.set("replica", c1_s1_r1);
        missingParamsError(client, params);
        params.set("property", "preferredLeader");
        missingParamsError(client, params);
        params.set("property.value", "true");
        SolrRequest request = new QueryRequest(params);
        request.setPath("/admin/collections");
        client.request(request);
        // The above should have set exactly one preferredleader...
        verifyPropertyVal(client, COLLECTION_NAME, c1_s1_r1, "property.preferredleader", "true");
        verifyUniquePropertyWithinCollection(client, COLLECTION_NAME, "property.preferredLeader");
        doPropertyAction(client, "action", CollectionParams.CollectionAction.ADDREPLICAPROP.toString(), "collection", COLLECTION_NAME, "shard", c1_s1, "replica", c1_s1_r2, "property", "preferredLeader", "property.value", "true");
        // The preferred leader property for shard1 should have switched to the other replica.
        verifyPropertyVal(client, COLLECTION_NAME, c1_s1_r2, "property.preferredleader", "true");
        verifyUniquePropertyWithinCollection(client, COLLECTION_NAME, "property.preferredLeader");
        doPropertyAction(client, "action", CollectionParams.CollectionAction.ADDREPLICAPROP.toString(), "collection", COLLECTION_NAME, "shard", c1_s2, "replica", c1_s2_r1, "property", "preferredLeader", "property.value", "true");
        // Now we should have a preferred leader in both shards...
        verifyPropertyVal(client, COLLECTION_NAME, c1_s1_r2, "property.preferredleader", "true");
        verifyPropertyVal(client, COLLECTION_NAME, c1_s2_r1, "property.preferredleader", "true");
        verifyUniquePropertyWithinCollection(client, COLLECTION_NAME, "property.preferredLeader");
        doPropertyAction(client, "action", CollectionParams.CollectionAction.ADDREPLICAPROP.toString(), "collection", COLLECTION_NAME1, "shard", c2_s1, "replica", c2_s1_r1, "property", "preferredLeader", "property.value", "true");
        // Now we should have three preferred leaders.
        verifyPropertyVal(client, COLLECTION_NAME, c1_s1_r2, "property.preferredleader", "true");
        verifyPropertyVal(client, COLLECTION_NAME, c1_s2_r1, "property.preferredleader", "true");
        verifyPropertyVal(client, COLLECTION_NAME1, c2_s1_r1, "property.preferredleader", "true");
        verifyUniquePropertyWithinCollection(client, COLLECTION_NAME, "property.preferredLeader");
        verifyUniquePropertyWithinCollection(client, COLLECTION_NAME1, "property.preferredLeader");
        doPropertyAction(client, "action", CollectionParams.CollectionAction.DELETEREPLICAPROP.toString(), "collection", COLLECTION_NAME1, "shard", c2_s1, "replica", c2_s1_r1, "property", "preferredLeader");
        // Now we should have two preferred leaders.
        // But first we have to wait for the overseer to finish the action
        verifyPropertyVal(client, COLLECTION_NAME, c1_s1_r2, "property.preferredleader", "true");
        verifyPropertyVal(client, COLLECTION_NAME, c1_s2_r1, "property.preferredleader", "true");
        verifyUniquePropertyWithinCollection(client, COLLECTION_NAME, "property.preferredLeader");
        verifyUniquePropertyWithinCollection(client, COLLECTION_NAME1, "property.preferredLeader");
        // Try adding an arbitrary property to one that has the leader property
        doPropertyAction(client, "action", CollectionParams.CollectionAction.ADDREPLICAPROP.toString(), "collection", COLLECTION_NAME, "shard", c1_s1, "replica", c1_s1_r1, "property", "testprop", "property.value", "true");
        verifyPropertyVal(client, COLLECTION_NAME, c1_s1_r2, "property.preferredleader", "true");
        verifyPropertyVal(client, COLLECTION_NAME, c1_s2_r1, "property.preferredleader", "true");
        verifyPropertyVal(client, COLLECTION_NAME, c1_s1_r1, "property.testprop", "true");
        verifyUniquePropertyWithinCollection(client, COLLECTION_NAME, "property.preferredLeader");
        verifyUniquePropertyWithinCollection(client, COLLECTION_NAME1, "property.preferredLeader");
        doPropertyAction(client, "action", CollectionParams.CollectionAction.ADDREPLICAPROP.toString(), "collection", COLLECTION_NAME, "shard", c1_s1, "replica", c1_s1_r2, "property", "prop", "property.value", "silly");
        verifyPropertyVal(client, COLLECTION_NAME, c1_s1_r2, "property.preferredleader", "true");
        verifyPropertyVal(client, COLLECTION_NAME, c1_s2_r1, "property.preferredleader", "true");
        verifyPropertyVal(client, COLLECTION_NAME, c1_s1_r1, "property.testprop", "true");
        verifyPropertyVal(client, COLLECTION_NAME, c1_s1_r2, "property.prop", "silly");
        verifyUniquePropertyWithinCollection(client, COLLECTION_NAME, "property.preferredLeader");
        verifyUniquePropertyWithinCollection(client, COLLECTION_NAME1, "property.preferredLeader");
        doPropertyAction(client, "action", CollectionParams.CollectionAction.ADDREPLICAPROP.toLower(), "collection", COLLECTION_NAME, "shard", c1_s1, "replica", c1_s1_r1, "property", "testprop", "property.value", "nonsense", SHARD_UNIQUE, "true");
        verifyPropertyVal(client, COLLECTION_NAME, c1_s1_r2, "property.preferredleader", "true");
        verifyPropertyVal(client, COLLECTION_NAME, c1_s2_r1, "property.preferredleader", "true");
        verifyPropertyVal(client, COLLECTION_NAME, c1_s1_r1, "property.testprop", "nonsense");
        verifyPropertyVal(client, COLLECTION_NAME, c1_s1_r2, "property.prop", "silly");
        verifyUniquePropertyWithinCollection(client, COLLECTION_NAME, "property.preferredLeader");
        verifyUniquePropertyWithinCollection(client, COLLECTION_NAME1, "property.preferredLeader");
        doPropertyAction(client, "action", CollectionParams.CollectionAction.ADDREPLICAPROP.toLower(), "collection", COLLECTION_NAME, "shard", c1_s1, "replica", c1_s1_r1, "property", "property.testprop", "property.value", "true", SHARD_UNIQUE, "false");
        verifyPropertyVal(client, COLLECTION_NAME, c1_s1_r2, "property.preferredleader", "true");
        verifyPropertyVal(client, COLLECTION_NAME, c1_s2_r1, "property.preferredleader", "true");
        verifyPropertyVal(client, COLLECTION_NAME, c1_s1_r1, "property.testprop", "true");
        verifyPropertyVal(client, COLLECTION_NAME, c1_s1_r2, "property.prop", "silly");
        verifyUniquePropertyWithinCollection(client, COLLECTION_NAME, "property.preferredLeader");
        verifyUniquePropertyWithinCollection(client, COLLECTION_NAME1, "property.preferredLeader");
        doPropertyAction(client, "action", CollectionParams.CollectionAction.DELETEREPLICAPROP.toLower(), "collection", COLLECTION_NAME, "shard", c1_s1, "replica", c1_s1_r1, "property", "property.testprop");
        verifyPropertyVal(client, COLLECTION_NAME, c1_s1_r2, "property.preferredleader", "true");
        verifyPropertyVal(client, COLLECTION_NAME, c1_s2_r1, "property.preferredleader", "true");
        verifyPropertyNotPresent(client, COLLECTION_NAME, c1_s1_r1, "property.testprop");
        verifyPropertyVal(client, COLLECTION_NAME, c1_s1_r2, "property.prop", "silly");
        verifyUniquePropertyWithinCollection(client, COLLECTION_NAME, "property.preferredLeader");
        verifyUniquePropertyWithinCollection(client, COLLECTION_NAME1, "property.preferredLeader");
        try {
            doPropertyAction(client, "action", CollectionParams.CollectionAction.ADDREPLICAPROP.toString(), "collection", COLLECTION_NAME, "shard", c1_s1, "replica", c1_s1_r1, "property", "preferredLeader", "property.value", "true", SHARD_UNIQUE, "false");
            fail("Should have thrown an exception, setting shardUnique=false is not allowed for 'preferredLeader'.");
        } catch (SolrException se) {
            assertTrue("Should have received a specific error message", se.getMessage().contains("with the shardUnique parameter set to something other than 'true'"));
        }
        verifyPropertyVal(client, COLLECTION_NAME, c1_s1_r2, "property.preferredleader", "true");
        verifyPropertyVal(client, COLLECTION_NAME, c1_s2_r1, "property.preferredleader", "true");
        verifyPropertyNotPresent(client, COLLECTION_NAME, c1_s1_r1, "property.testprop");
        verifyPropertyVal(client, COLLECTION_NAME, c1_s1_r2, "property.prop", "silly");
        verifyUniquePropertyWithinCollection(client, COLLECTION_NAME, "property.preferredLeader");
        verifyUniquePropertyWithinCollection(client, COLLECTION_NAME1, "property.preferredLeader");
        Map<String, String> origProps = getProps(client, COLLECTION_NAME, c1_s1_r1, "state", "core", "node_name", "base_url");
        doPropertyAction(client, "action", CollectionParams.CollectionAction.ADDREPLICAPROP.toLower(), "collection", COLLECTION_NAME, "shard", c1_s1, "replica", c1_s1_r1, "property", "state", "property.value", "state_bad");
        doPropertyAction(client, "action", CollectionParams.CollectionAction.ADDREPLICAPROP.toLower(), "collection", COLLECTION_NAME, "shard", c1_s1, "replica", c1_s1_r1, "property", "core", "property.value", "core_bad");
        doPropertyAction(client, "action", CollectionParams.CollectionAction.ADDREPLICAPROP.toLower(), "collection", COLLECTION_NAME, "shard", c1_s1, "replica", c1_s1_r1, "property", "node_name", "property.value", "node_name_bad");
        doPropertyAction(client, "action", CollectionParams.CollectionAction.ADDREPLICAPROP.toLower(), "collection", COLLECTION_NAME, "shard", c1_s1, "replica", c1_s1_r1, "property", "base_url", "property.value", "base_url_bad");
        // The above should be on new proeprties.
        verifyPropertyVal(client, COLLECTION_NAME, c1_s1_r1, "property.state", "state_bad");
        verifyPropertyVal(client, COLLECTION_NAME, c1_s1_r1, "property.core", "core_bad");
        verifyPropertyVal(client, COLLECTION_NAME, c1_s1_r1, "property.node_name", "node_name_bad");
        verifyPropertyVal(client, COLLECTION_NAME, c1_s1_r1, "property.base_url", "base_url_bad");
        doPropertyAction(client, "action", CollectionParams.CollectionAction.DELETEREPLICAPROP.toLower(), "collection", COLLECTION_NAME, "shard", c1_s1, "replica", c1_s1_r1, "property", "state");
        doPropertyAction(client, "action", CollectionParams.CollectionAction.DELETEREPLICAPROP.toLower(), "collection", COLLECTION_NAME, "shard", c1_s1, "replica", c1_s1_r1, "property", "core");
        doPropertyAction(client, "action", CollectionParams.CollectionAction.DELETEREPLICAPROP.toLower(), "collection", COLLECTION_NAME, "shard", c1_s1, "replica", c1_s1_r1, "property", "node_name");
        doPropertyAction(client, "action", CollectionParams.CollectionAction.DELETEREPLICAPROP.toLower(), "collection", COLLECTION_NAME, "shard", c1_s1, "replica", c1_s1_r1, "property", "base_url");
        // They better not have been changed!
        for (Map.Entry<String, String> ent : origProps.entrySet()) {
            verifyPropertyVal(client, COLLECTION_NAME, c1_s1_r1, ent.getKey(), ent.getValue());
        }
        verifyPropertyNotPresent(client, COLLECTION_NAME, c1_s1_r1, "property.state");
        verifyPropertyNotPresent(client, COLLECTION_NAME, c1_s1_r1, "property.core");
        verifyPropertyNotPresent(client, COLLECTION_NAME, c1_s1_r1, "property.node_name");
        verifyPropertyNotPresent(client, COLLECTION_NAME, c1_s1_r1, "property.base_url");
    }
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) SolrRequest(org.apache.solr.client.solrj.SolrRequest) ArrayList(java.util.ArrayList) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) Slice(org.apache.solr.common.cloud.Slice) HashMap(java.util.HashMap) Map(java.util.Map) SolrException(org.apache.solr.common.SolrException) RemoteSolrException(org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException)

Example 73 with Slice

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

the class TestPullReplica method testCreateDelete.

// 2 times to make sure cleanup is complete and we can create the same collection
@Repeat(iterations = 2)
public void testCreateDelete() throws Exception {
    try {
        switch(random().nextInt(3)) {
            case 0:
                // Sometimes use SolrJ
                CollectionAdminRequest.createCollection(collectionName, "conf", 2, 1, 0, 3).setMaxShardsPerNode(100).process(cluster.getSolrClient());
                break;
            case 1:
                // Sometimes use v1 API
                String url = String.format(Locale.ROOT, "%s/admin/collections?action=CREATE&name=%s&numShards=%s&pullReplicas=%s&maxShardsPerNode=%s", cluster.getRandomJetty(random()).getBaseUrl(), collectionName, // numShards
                2, // pullReplicas
                3, // maxShardsPerNode
                100);
                // These options should all mean the same
                url = url + pickRandom("", "&nrtReplicas=1", "&replicationFactor=1");
                HttpGet createCollectionGet = new HttpGet(url);
                cluster.getSolrClient().getHttpClient().execute(createCollectionGet);
                break;
            case 2:
                // Sometimes use V2 API
                url = cluster.getRandomJetty(random()).getBaseUrl().toString() + "/____v2/c";
                String requestBody = String.format(Locale.ROOT, "{create:{name:%s, numShards:%s, pullReplicas:%s, maxShardsPerNode:%s %s}}", collectionName, // numShards
                2, // pullReplicas
                3, // maxShardsPerNode
                100, // These options should all mean the same
                pickRandom("", ", nrtReplicas:1", ", replicationFactor:1"));
                HttpPost createCollectionPost = new HttpPost(url);
                createCollectionPost.setHeader("Content-type", "application/json");
                createCollectionPost.setEntity(new StringEntity(requestBody));
                HttpResponse httpResponse = cluster.getSolrClient().getHttpClient().execute(createCollectionPost);
                assertEquals(200, httpResponse.getStatusLine().getStatusCode());
                break;
        }
        boolean reloaded = false;
        while (true) {
            DocCollection docCollection = getCollectionState(collectionName);
            assertNotNull(docCollection);
            assertEquals("Expecting 4 relpicas per shard", 8, docCollection.getReplicas().size());
            assertEquals("Expecting 6 pull replicas, 3 per shard", 6, docCollection.getReplicas(EnumSet.of(Replica.Type.PULL)).size());
            assertEquals("Expecting 2 writer replicas, one per shard", 2, docCollection.getReplicas(EnumSet.of(Replica.Type.NRT)).size());
            for (Slice s : docCollection.getSlices()) {
                // read-only replicas can never become leaders
                assertFalse(s.getLeader().getType() == Replica.Type.PULL);
                List<String> shardElectionNodes = cluster.getZkClient().getChildren(ZkStateReader.getShardLeadersElectPath(collectionName, s.getName()), null, true);
                assertEquals("Unexpected election nodes for Shard: " + s.getName() + ": " + Arrays.toString(shardElectionNodes.toArray()), 1, shardElectionNodes.size());
            }
            assertUlogPresence(docCollection);
            if (reloaded) {
                break;
            } else {
                // reload
                CollectionAdminResponse response = CollectionAdminRequest.reloadCollection(collectionName).process(cluster.getSolrClient());
                assertEquals(0, response.getStatus());
                reloaded = true;
            }
        }
    } finally {
        zkClient().printLayoutToStdOut();
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) Slice(org.apache.solr.common.cloud.Slice) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) DocCollection(org.apache.solr.common.cloud.DocCollection) Repeat(com.carrotsearch.randomizedtesting.annotations.Repeat)

Example 74 with Slice

use of org.apache.solr.common.cloud.Slice 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 75 with Slice

use of org.apache.solr.common.cloud.Slice 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)

Aggregations

Slice (org.apache.solr.common.cloud.Slice)220 Replica (org.apache.solr.common.cloud.Replica)142 DocCollection (org.apache.solr.common.cloud.DocCollection)121 ClusterState (org.apache.solr.common.cloud.ClusterState)81 ArrayList (java.util.ArrayList)79 HashMap (java.util.HashMap)67 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)50 SolrException (org.apache.solr.common.SolrException)49 Map (java.util.Map)46 Test (org.junit.Test)37 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)28 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)25 HashSet (java.util.HashSet)24 SolrQuery (org.apache.solr.client.solrj.SolrQuery)24 IOException (java.io.IOException)23 NamedList (org.apache.solr.common.util.NamedList)23 List (java.util.List)22 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)22 DocRouter (org.apache.solr.common.cloud.DocRouter)20 ZkCoreNodeProps (org.apache.solr.common.cloud.ZkCoreNodeProps)20