Search in sources :

Example 46 with DocCollection

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

the class TestClusterStateMutator method testCreateCollection.

public void testCreateCollection() throws Exception {
    ClusterState state = new ClusterState(-1, Collections.<String>emptySet(), Collections.<String, DocCollection>emptyMap());
    MockZkStateReader zkStateReader = new MockZkStateReader(state, Collections.<String>emptySet());
    ClusterState clusterState = zkStateReader.getClusterState();
    ClusterStateMutator mutator = new ClusterStateMutator(zkStateReader);
    ZkNodeProps message = new ZkNodeProps(Utils.makeMap("name", "xyz", "numShards", "1"));
    ZkWriteCommand cmd = mutator.createCollection(clusterState, message);
    DocCollection collection = cmd.collection;
    assertEquals("xyz", collection.getName());
    assertEquals(1, collection.getSlicesMap().size());
    assertEquals(1, collection.getMaxShardsPerNode());
    state = new ClusterState(-1, Collections.<String>emptySet(), Collections.singletonMap("xyz", collection));
    message = new ZkNodeProps(Utils.makeMap("name", "abc", "numShards", "2", "router.name", "implicit", "shards", "x,y", "replicationFactor", "3", "maxShardsPerNode", "4"));
    cmd = mutator.createCollection(state, message);
    collection = cmd.collection;
    assertEquals("abc", collection.getName());
    assertEquals(2, collection.getSlicesMap().size());
    assertNotNull(collection.getSlicesMap().get("x"));
    assertNotNull(collection.getSlicesMap().get("y"));
    assertNull(collection.getSlicesMap().get("x").getRange());
    assertNull(collection.getSlicesMap().get("y").getRange());
    assertSame(Slice.State.ACTIVE, collection.getSlicesMap().get("x").getState());
    assertSame(Slice.State.ACTIVE, collection.getSlicesMap().get("y").getState());
    assertEquals(4, collection.getMaxShardsPerNode());
    assertEquals(ImplicitDocRouter.class, collection.getRouter().getClass());
    // we still have the old collection
    assertNotNull(state.getCollectionOrNull("xyz"));
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) DocCollection(org.apache.solr.common.cloud.DocCollection) MockZkStateReader(org.apache.solr.cloud.MockZkStateReader)

Example 47 with DocCollection

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

the class ZkStateReaderTest method testWatchedCollectionCreation.

public void testWatchedCollectionCreation() throws Exception {
    String zkDir = createTempDir("testWatchedCollectionCreation").toFile().getAbsolutePath();
    ZkTestServer server = new ZkTestServer(zkDir);
    SolrZkClient zkClient = null;
    ZkStateReader reader = null;
    try {
        server.run();
        AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
        AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
        zkClient = new SolrZkClient(server.getZkAddress(), OverseerTest.DEFAULT_CONNECTION_TIMEOUT);
        ZkController.createClusterZkNodes(zkClient);
        reader = new ZkStateReader(zkClient);
        reader.createClusterStateWatchersAndUpdate();
        reader.registerCore("c1");
        // Initially there should be no c1 collection.
        assertNull(reader.getClusterState().getCollectionRef("c1"));
        zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1", true);
        reader.forceUpdateCollection("c1");
        // Still no c1 collection, despite a collection path.
        assertNull(reader.getClusterState().getCollectionRef("c1"));
        ZkStateWriter writer = new ZkStateWriter(reader, new Overseer.Stats());
        // create new collection with stateFormat = 2
        DocCollection state = new DocCollection("c1", new HashMap<>(), new HashMap<>(), DocRouter.DEFAULT, 0, ZkStateReader.CLUSTER_STATE + "/c1/state.json");
        ZkWriteCommand wc = new ZkWriteCommand("c1", state);
        writer.enqueueUpdate(reader.getClusterState(), wc, null);
        writer.writePendingUpdates();
        assertTrue(zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", true));
        //reader.forceUpdateCollection("c1");
        reader.waitForState("c1", TIMEOUT, TimeUnit.SECONDS, (n, c) -> c != null);
        ClusterState.CollectionRef ref = reader.getClusterState().getCollectionRef("c1");
        assertNotNull(ref);
        assertFalse(ref.isLazilyLoaded());
        assertEquals(2, ref.get().getStateFormat());
    } finally {
        IOUtils.close(reader, zkClient);
        server.shutdown();
    }
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) ClusterState(org.apache.solr.common.cloud.ClusterState) ZkTestServer(org.apache.solr.cloud.ZkTestServer) Overseer(org.apache.solr.cloud.Overseer) DocCollection(org.apache.solr.common.cloud.DocCollection) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient)

Example 48 with DocCollection

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

the class ZkStateReaderTest method testExternalCollectionWatchedNotWatched.

public void testExternalCollectionWatchedNotWatched() throws Exception {
    String zkDir = createTempDir("testExternalCollectionWatchedNotWatched").toFile().getAbsolutePath();
    ZkTestServer server = new ZkTestServer(zkDir);
    SolrZkClient zkClient = null;
    ZkStateReader reader = null;
    try {
        server.run();
        AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
        AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
        zkClient = new SolrZkClient(server.getZkAddress(), OverseerTest.DEFAULT_CONNECTION_TIMEOUT);
        ZkController.createClusterZkNodes(zkClient);
        reader = new ZkStateReader(zkClient);
        reader.createClusterStateWatchersAndUpdate();
        ZkStateWriter writer = new ZkStateWriter(reader, new Overseer.Stats());
        zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1", true);
        // create new collection with stateFormat = 2
        ZkWriteCommand c1 = new ZkWriteCommand("c1", new DocCollection("c1", new HashMap<>(), new HashMap<>(), DocRouter.DEFAULT, 0, ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json"));
        writer.enqueueUpdate(reader.getClusterState(), c1, null);
        writer.writePendingUpdates();
        reader.forceUpdateCollection("c1");
        assertTrue(reader.getClusterState().getCollectionRef("c1").isLazilyLoaded());
        reader.registerCore("c1");
        assertFalse(reader.getClusterState().getCollectionRef("c1").isLazilyLoaded());
        reader.unregisterCore("c1");
        assertTrue(reader.getClusterState().getCollectionRef("c1").isLazilyLoaded());
    } finally {
        IOUtils.close(reader, zkClient);
        server.shutdown();
    }
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) ZkTestServer(org.apache.solr.cloud.ZkTestServer) Overseer(org.apache.solr.cloud.Overseer) HashMap(java.util.HashMap) DocCollection(org.apache.solr.common.cloud.DocCollection) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient)

Example 49 with DocCollection

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

the class RulesTest method testModifyColl.

@Test
public void testModifyColl() throws Exception {
    final long minGB1 = (random().nextBoolean() ? 1 : 0);
    final long minGB2 = 5;
    assumeTrue("testModifyColl needs minGB1=" + minGB1 + " usable disk space", ImplicitSnitch.getUsableSpaceInGB(Paths.get("/")) > minGB1);
    assumeTrue("testModifyColl needs minGB2=" + minGB2 + " usable disk space", ImplicitSnitch.getUsableSpaceInGB(Paths.get("/")) > minGB2);
    String rulesColl = "modifyColl";
    CollectionAdminRequest.createCollection(rulesColl, "conf", 1, 2).setRule("cores:<4", "node:*,replica:1", "freedisk:>" + minGB1).setSnitch("class:ImplicitSnitch").process(cluster.getSolrClient());
    // TODO: Make a MODIFYCOLLECTION SolrJ class
    ModifiableSolrParams p = new ModifiableSolrParams();
    p.add("collection", rulesColl);
    p.add("action", "MODIFYCOLLECTION");
    p.add("rule", "cores:<5");
    p.add("rule", "node:*,replica:1");
    p.add("rule", "freedisk:>" + minGB2);
    p.add("autoAddReplicas", "true");
    cluster.getSolrClient().request(new GenericSolrRequest(POST, COLLECTIONS_HANDLER_PATH, p));
    DocCollection rulesCollection = getCollectionState(rulesColl);
    log.info("version_of_coll {}  ", rulesCollection.getZNodeVersion());
    List list = (List) rulesCollection.get("rule");
    assertEquals(3, list.size());
    assertEquals("<5", ((Map) list.get(0)).get("cores"));
    assertEquals("1", ((Map) list.get(1)).get("replica"));
    assertEquals(">" + minGB2, ((Map) list.get(2)).get("freedisk"));
    assertEquals("true", String.valueOf(rulesCollection.getProperties().get("autoAddReplicas")));
    list = (List) rulesCollection.get("snitch");
    assertEquals(1, list.size());
    assertEquals("ImplicitSnitch", ((Map) list.get(0)).get("class"));
}
Also used : GenericSolrRequest(org.apache.solr.client.solrj.request.GenericSolrRequest) List(java.util.List) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) DocCollection(org.apache.solr.common.cloud.DocCollection) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Test(org.junit.Test)

Example 50 with DocCollection

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

the class RulesTest method doIntegrationTest.

@Test
public void doIntegrationTest() throws Exception {
    final long minGB = (random().nextBoolean() ? 1 : 0);
    assumeTrue("doIntegrationTest needs minGB=" + minGB + " usable disk space", ImplicitSnitch.getUsableSpaceInGB(Paths.get("/")) > minGB);
    String rulesColl = "rulesColl";
    CollectionAdminRequest.createCollectionWithImplicitRouter(rulesColl, "conf", "shard1", 2).setRule("cores:<4", "node:*,replica:<2", "freedisk:>" + minGB).setSnitch("class:ImplicitSnitch").process(cluster.getSolrClient());
    DocCollection rulesCollection = getCollectionState(rulesColl);
    List list = (List) rulesCollection.get("rule");
    assertEquals(3, list.size());
    assertEquals("<4", ((Map) list.get(0)).get("cores"));
    assertEquals("<2", ((Map) list.get(1)).get("replica"));
    assertEquals(">" + minGB, ((Map) list.get(2)).get("freedisk"));
    list = (List) rulesCollection.get("snitch");
    assertEquals(1, list.size());
    assertEquals("ImplicitSnitch", ((Map) list.get(0)).get("class"));
    CollectionAdminRequest.createShard(rulesColl, "shard2").process(cluster.getSolrClient());
    CollectionAdminRequest.addReplicaToShard(rulesColl, "shard2").process(cluster.getSolrClient());
}
Also used : List(java.util.List) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) DocCollection(org.apache.solr.common.cloud.DocCollection) Test(org.junit.Test)

Aggregations

DocCollection (org.apache.solr.common.cloud.DocCollection)187 Slice (org.apache.solr.common.cloud.Slice)120 Replica (org.apache.solr.common.cloud.Replica)86 HashMap (java.util.HashMap)55 ClusterState (org.apache.solr.common.cloud.ClusterState)52 ArrayList (java.util.ArrayList)50 Map (java.util.Map)42 SolrException (org.apache.solr.common.SolrException)41 Test (org.junit.Test)39 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)32 List (java.util.List)23 NamedList (org.apache.solr.common.util.NamedList)23 HashSet (java.util.HashSet)21 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)19 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)19 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)19 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)17 SolrQuery (org.apache.solr.client.solrj.SolrQuery)16 SolrInputDocument (org.apache.solr.common.SolrInputDocument)16 ZkNodeProps (org.apache.solr.common.cloud.ZkNodeProps)15