Search in sources :

Example 1 with CloudConfig

use of org.apache.solr.core.CloudConfig in project lucene-solr by apache.

the class ZkControllerTest method testGetHostName.

public void testGetHostName() throws Exception {
    String zkDir = createTempDir("zkData").toFile().getAbsolutePath();
    CoreContainer cc = null;
    ZkTestServer server = new ZkTestServer(zkDir);
    try {
        server.run();
        AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
        AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
        cc = getCoreContainer();
        ZkController zkController = null;
        try {
            CloudConfig cloudConfig = new CloudConfig.CloudConfigBuilder("127.0.0.1", 8983, "solr").build();
            zkController = new ZkController(cc, server.getZkAddress(), TIMEOUT, cloudConfig, new CurrentCoreDescriptorProvider() {

                @Override
                public List<CoreDescriptor> getCurrentDescriptors() {
                    // do nothing
                    return null;
                }
            });
        } catch (IllegalArgumentException e) {
            fail("ZkController did not normalize host name correctly");
        } finally {
            if (zkController != null)
                zkController.close();
        }
    } finally {
        if (cc != null) {
            cc.shutdown();
        }
        server.shutdown();
    }
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) CoreDescriptor(org.apache.solr.core.CoreDescriptor) CloudConfig(org.apache.solr.core.CloudConfig)

Example 2 with CloudConfig

use of org.apache.solr.core.CloudConfig in project lucene-solr by apache.

the class TestHarness method buildTestNodeConfig.

public static NodeConfig buildTestNodeConfig(SolrResourceLoader loader) {
    CloudConfig cloudConfig = new CloudConfig.CloudConfigBuilder(System.getProperty("host"), Integer.getInteger("hostPort", 8983), System.getProperty("hostContext", "")).setZkClientTimeout(Integer.getInteger("zkClientTimeout", 30000)).build();
    if (System.getProperty("zkHost") == null)
        cloudConfig = null;
    UpdateShardHandlerConfig updateShardHandlerConfig = new UpdateShardHandlerConfig(UpdateShardHandlerConfig.DEFAULT_MAXUPDATECONNECTIONS, UpdateShardHandlerConfig.DEFAULT_MAXUPDATECONNECTIONSPERHOST, 30000, 30000, UpdateShardHandlerConfig.DEFAULT_METRICNAMESTRATEGY, UpdateShardHandlerConfig.DEFAULT_MAXRECOVERYTHREADS);
    // universal default metric reporter
    Map<String, Object> attributes = new HashMap<>();
    attributes.put("name", "default");
    attributes.put("class", SolrJmxReporter.class.getName());
    PluginInfo defaultPlugin = new PluginInfo("reporter", attributes);
    MetricsConfig metricsConfig = new MetricsConfig.MetricsConfigBuilder().setMetricReporterPlugins(new PluginInfo[] { defaultPlugin }).build();
    return new NodeConfig.NodeConfigBuilder("testNode", loader).setUseSchemaCache(Boolean.getBoolean("shareSchema")).setCloudConfig(cloudConfig).setUpdateShardHandlerConfig(updateShardHandlerConfig).setMetricsConfig(metricsConfig).build();
}
Also used : HashMap(java.util.HashMap) CloudConfig(org.apache.solr.core.CloudConfig) MetricsConfig(org.apache.solr.core.MetricsConfig) UpdateShardHandlerConfig(org.apache.solr.update.UpdateShardHandlerConfig) PluginInfo(org.apache.solr.core.PluginInfo) SolrJmxReporter(org.apache.solr.metrics.reporters.SolrJmxReporter) NodeConfig(org.apache.solr.core.NodeConfig)

Example 3 with CloudConfig

use of org.apache.solr.core.CloudConfig in project lucene-solr by apache.

the class TestLeaderElectionZkExpiry method testLeaderElectionWithZkExpiry.

@Test
public void testLeaderElectionWithZkExpiry() throws Exception {
    String zkDir = createTempDir("zkData").toFile().getAbsolutePath();
    Path ccDir = createTempDir("testLeaderElectionWithZkExpiry-solr");
    CoreContainer cc = createCoreContainer(ccDir, SOLRXML);
    final ZkTestServer server = new ZkTestServer(zkDir);
    server.setTheTickTime(1000);
    SolrZkClient zc = null;
    try {
        server.run();
        AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
        AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
        CloudConfig cloudConfig = new CloudConfig.CloudConfigBuilder("dummy.host.com", 8984, "solr").setLeaderConflictResolveWait(180000).setLeaderVoteWait(180000).build();
        final ZkController zkController = new ZkController(cc, server.getZkAddress(), 15000, cloudConfig, new CurrentCoreDescriptorProvider() {

            @Override
            public List<CoreDescriptor> getCurrentDescriptors() {
                return Collections.EMPTY_LIST;
            }
        });
        try {
            Thread killer = new Thread() {

                @Override
                public void run() {
                    long timeout = System.nanoTime() + TimeUnit.NANOSECONDS.convert(10, TimeUnit.SECONDS);
                    while (System.nanoTime() < timeout) {
                        long sessionId = zkController.getZkClient().getSolrZooKeeper().getSessionId();
                        server.expire(sessionId);
                        try {
                            Thread.sleep(10);
                        } catch (InterruptedException e) {
                        }
                    }
                }
            };
            killer.start();
            killer.join();
            long timeout = System.nanoTime() + TimeUnit.NANOSECONDS.convert(60, TimeUnit.SECONDS);
            zc = new SolrZkClient(server.getZkAddress(), LeaderElectionTest.TIMEOUT);
            boolean found = false;
            while (System.nanoTime() < timeout) {
                try {
                    String leaderNode = OverseerCollectionConfigSetProcessor.getLeaderNode(zc);
                    if (leaderNode != null && !leaderNode.trim().isEmpty()) {
                        log.info("Time={} Overseer leader is = {}", System.nanoTime(), leaderNode);
                        found = true;
                        break;
                    }
                } catch (KeeperException.NoNodeException nne) {
                // ignore
                }
            }
            assertTrue(found);
        } finally {
            zkController.close();
        }
    } finally {
        if (zc != null)
            zc.close();
        cc.shutdown();
        server.shutdown();
    }
}
Also used : Path(java.nio.file.Path) CloudConfig(org.apache.solr.core.CloudConfig) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) CoreContainer(org.apache.solr.core.CoreContainer) List(java.util.List) KeeperException(org.apache.zookeeper.KeeperException) Test(org.junit.Test)

Example 4 with CloudConfig

use of org.apache.solr.core.CloudConfig in project lucene-solr by apache.

the class CollectionsHandler method waitForActiveCollection.

private static void waitForActiveCollection(String collectionName, ZkNodeProps message, CoreContainer cc, SolrResponse response) throws KeeperException, InterruptedException {
    if (response.getResponse().get("exception") != null) {
        // the main called failed, don't wait
        log.info("Not waiting for active collection due to exception: " + response.getResponse().get("exception"));
        return;
    }
    if (response.getResponse().get("failure") != null) {
    // TODO: we should not wait for Replicas we know failed
    }
    String replicaNotAlive = null;
    String replicaState = null;
    String nodeNotLive = null;
    CloudConfig ccfg = cc.getConfig().getCloudConfig();
    Integer numRetries = ccfg.getCreateCollectionWaitTimeTillActive();
    Boolean checkLeaderOnly = ccfg.isCreateCollectionCheckLeaderActive();
    log.info("Wait for new collection to be active for at most " + numRetries + " seconds. Check all shard " + (checkLeaderOnly ? "leaders" : "replicas"));
    ZkStateReader zkStateReader = cc.getZkController().getZkStateReader();
    for (int i = 0; i < numRetries; i++) {
        ClusterState clusterState = zkStateReader.getClusterState();
        Collection<Slice> shards = clusterState.getSlices(collectionName);
        if (shards != null) {
            replicaNotAlive = null;
            for (Slice shard : shards) {
                Collection<Replica> replicas;
                if (!checkLeaderOnly)
                    replicas = shard.getReplicas();
                else {
                    replicas = new ArrayList<Replica>();
                    replicas.add(shard.getLeader());
                }
                for (Replica replica : replicas) {
                    String state = replica.getStr(ZkStateReader.STATE_PROP);
                    log.debug("Checking replica status, collection={} replica={} state={}", collectionName, replica.getCoreUrl(), state);
                    if (!clusterState.liveNodesContain(replica.getNodeName()) || !state.equals(Replica.State.ACTIVE.toString())) {
                        replicaNotAlive = replica.getCoreUrl();
                        nodeNotLive = replica.getNodeName();
                        replicaState = state;
                        break;
                    }
                }
                if (replicaNotAlive != null)
                    break;
            }
            if (replicaNotAlive == null)
                return;
        }
        Thread.sleep(1000);
    }
    if (nodeNotLive != null && replicaState != null) {
        log.error("Timed out waiting for new collection's replicas to become ACTIVE " + (replicaState.equals(Replica.State.ACTIVE.toString()) ? "node " + nodeNotLive + " is not live" : "replica " + replicaNotAlive + " is in state of " + replicaState.toString()) + " with timeout=" + numRetries);
    } else {
        log.error("Timed out waiting for new collection's replicas to become ACTIVE with timeout=" + numRetries);
    }
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) ClusterState(org.apache.solr.common.cloud.ClusterState) Slice(org.apache.solr.common.cloud.Slice) CloudConfig(org.apache.solr.core.CloudConfig) StrUtils.formatString(org.apache.solr.common.util.StrUtils.formatString) Replica(org.apache.solr.common.cloud.Replica)

Example 5 with CloudConfig

use of org.apache.solr.core.CloudConfig in project lucene-solr by apache.

the class ZkControllerTest method testPublishAndWaitForDownStates.

@AwaitsFix(bugUrl = "https://issues.apache.org/jira/browse/SOLR-7736")
public void testPublishAndWaitForDownStates() throws Exception {
    String zkDir = createTempDir("testPublishAndWaitForDownStates").toFile().getAbsolutePath();
    CoreContainer cc = null;
    ZkTestServer server = new ZkTestServer(zkDir);
    try {
        server.run();
        AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
        AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
        cc = getCoreContainer();
        ZkController zkController = null;
        try {
            CloudConfig cloudConfig = new CloudConfig.CloudConfigBuilder("127.0.0.1", 8983, "solr").build();
            zkController = new ZkController(cc, server.getZkAddress(), TIMEOUT, cloudConfig, new CurrentCoreDescriptorProvider() {

                @Override
                public List<CoreDescriptor> getCurrentDescriptors() {
                    // do nothing
                    return null;
                }
            });
            HashMap<String, DocCollection> collectionStates = new HashMap<>();
            HashMap<String, Replica> replicas = new HashMap<>();
            // than this ZkController instance
            for (int i = 1; i <= 2; i++) {
                Replica r = new Replica("core_node" + i, map(ZkStateReader.STATE_PROP, i == 1 ? "active" : "down", ZkStateReader.NODE_NAME_PROP, i == 1 ? "127.0.0.1:8983_solr" : "non_existent_host", ZkStateReader.CORE_NAME_PROP, "collection1"));
                replicas.put("core_node" + i, r);
            }
            HashMap<String, Object> sliceProps = new HashMap<>();
            sliceProps.put("state", Slice.State.ACTIVE.toString());
            Slice slice = new Slice("shard1", replicas, sliceProps);
            DocCollection c = new DocCollection("testPublishAndWaitForDownStates", map("shard1", slice), Collections.emptyMap(), DocRouter.DEFAULT);
            ClusterState state = new ClusterState(0, Collections.emptySet(), map("testPublishAndWaitForDownStates", c));
            byte[] bytes = Utils.toJSON(state);
            zkController.getZkClient().makePath(ZkStateReader.getCollectionPath("testPublishAndWaitForDownStates"), bytes, CreateMode.PERSISTENT, true);
            zkController.getZkStateReader().forceUpdateCollection("testPublishAndWaitForDownStates");
            assertTrue(zkController.getZkStateReader().getClusterState().hasCollection("testPublishAndWaitForDownStates"));
            assertNotNull(zkController.getZkStateReader().getClusterState().getCollection("testPublishAndWaitForDownStates"));
            long now = System.nanoTime();
            long timeout = now + TimeUnit.NANOSECONDS.convert(ZkController.WAIT_DOWN_STATES_TIMEOUT_SECONDS, TimeUnit.SECONDS);
            zkController.publishAndWaitForDownStates();
            assertTrue("The ZkController.publishAndWaitForDownStates should have timed out but it didn't", System.nanoTime() >= timeout);
        } finally {
            if (zkController != null)
                zkController.close();
        }
    } finally {
        if (cc != null) {
            cc.shutdown();
        }
        server.shutdown();
    }
}
Also used : HashMap(java.util.HashMap) CoreDescriptor(org.apache.solr.core.CoreDescriptor) CloudConfig(org.apache.solr.core.CloudConfig) CoreContainer(org.apache.solr.core.CoreContainer)

Aggregations

CloudConfig (org.apache.solr.core.CloudConfig)6 CoreContainer (org.apache.solr.core.CoreContainer)4 HashMap (java.util.HashMap)3 List (java.util.List)2 CoreDescriptor (org.apache.solr.core.CoreDescriptor)2 Test (org.junit.Test)2 Path (java.nio.file.Path)1 ClusterState (org.apache.solr.common.cloud.ClusterState)1 Replica (org.apache.solr.common.cloud.Replica)1 Slice (org.apache.solr.common.cloud.Slice)1 SolrZkClient (org.apache.solr.common.cloud.SolrZkClient)1 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)1 StrUtils.formatString (org.apache.solr.common.util.StrUtils.formatString)1 MetricsConfig (org.apache.solr.core.MetricsConfig)1 NodeConfig (org.apache.solr.core.NodeConfig)1 PluginInfo (org.apache.solr.core.PluginInfo)1 SolrJmxReporter (org.apache.solr.metrics.reporters.SolrJmxReporter)1 UpdateShardHandlerConfig (org.apache.solr.update.UpdateShardHandlerConfig)1 KeeperException (org.apache.zookeeper.KeeperException)1