Search in sources :

Example 1 with DirectUpdateHandler2

use of org.apache.solr.update.DirectUpdateHandler2 in project lucene-solr by apache.

the class TestCloudRecovery method leaderRecoverFromLogOnStartupTest.

@Test
public void leaderRecoverFromLogOnStartupTest() throws Exception {
    AtomicInteger countReplayLog = new AtomicInteger(0);
    DirectUpdateHandler2.commitOnClose = false;
    UpdateLog.testing_logReplayFinishHook = countReplayLog::incrementAndGet;
    CloudSolrClient cloudClient = cluster.getSolrClient();
    cloudClient.add(COLLECTION, sdoc("id", "1"));
    cloudClient.add(COLLECTION, sdoc("id", "2"));
    cloudClient.add(COLLECTION, sdoc("id", "3"));
    cloudClient.add(COLLECTION, sdoc("id", "4"));
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("q", "*:*");
    QueryResponse resp = cloudClient.query(COLLECTION, params);
    assertEquals(0, resp.getResults().getNumFound());
    ChaosMonkey.stop(cluster.getJettySolrRunners());
    assertTrue("Timeout waiting for all not live", ClusterStateUtil.waitForAllReplicasNotLive(cloudClient.getZkStateReader(), 45000));
    ChaosMonkey.start(cluster.getJettySolrRunners());
    assertTrue("Timeout waiting for all live and active", ClusterStateUtil.waitForAllActiveAndLiveReplicas(cloudClient.getZkStateReader(), COLLECTION, 120000));
    resp = cloudClient.query(COLLECTION, params);
    assertEquals(4, resp.getResults().getNumFound());
    // Make sure all nodes is recover from tlog
    if (onlyLeaderIndexes) {
        // Leader election can be kicked off, so 2 tlog replicas will replay its tlog before becoming new leader
        assertTrue(countReplayLog.get() >= 2);
    } else {
        assertEquals(4, countReplayLog.get());
    }
    // check metrics
    int replicationCount = 0;
    int errorsCount = 0;
    int skippedCount = 0;
    for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {
        SolrMetricManager manager = jetty.getCoreContainer().getMetricManager();
        List<String> registryNames = manager.registryNames().stream().filter(s -> s.startsWith("solr.core.")).collect(Collectors.toList());
        for (String registry : registryNames) {
            Map<String, Metric> metrics = manager.registry(registry).getMetrics();
            Timer timer = (Timer) metrics.get("REPLICATION.peerSync.time");
            Counter counter = (Counter) metrics.get("REPLICATION.peerSync.errors");
            Counter skipped = (Counter) metrics.get("REPLICATION.peerSync.skipped");
            replicationCount += timer.getCount();
            errorsCount += counter.getCount();
            skippedCount += skipped.getCount();
        }
    }
    if (onlyLeaderIndexes) {
        assertTrue(replicationCount >= 2);
    } else {
        assertEquals(2, replicationCount);
    }
}
Also used : Arrays(java.util.Arrays) BeforeClass(org.junit.BeforeClass) HashMap(java.util.HashMap) DirectUpdateHandler2(org.apache.solr.update.DirectUpdateHandler2) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ClusterStateUtil(org.apache.solr.common.cloud.ClusterStateUtil) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Counter(com.codahale.metrics.Counter) UpdateLog(org.apache.solr.update.UpdateLog) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) Before(org.junit.Before) AfterClass(org.junit.AfterClass) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrCore(org.apache.solr.core.SolrCore) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) FileOutputStream(java.io.FileOutputStream) Metric(com.codahale.metrics.Metric) IOException(java.io.IOException) Test(org.junit.Test) FileInputStream(java.io.FileInputStream) Collectors(java.util.stream.Collectors) File(java.io.File) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Timer(com.codahale.metrics.Timer) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) TestInjection(org.apache.solr.util.TestInjection) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) Metric(com.codahale.metrics.Metric) Test(org.junit.Test)

Example 2 with DirectUpdateHandler2

use of org.apache.solr.update.DirectUpdateHandler2 in project lucene-solr by apache.

the class SolrCore method initUpdateHandler.

private UpdateHandler initUpdateHandler(UpdateHandler updateHandler) {
    String updateHandlerClass = solrConfig.getUpdateHandlerInfo().className;
    if (updateHandlerClass == null) {
        updateHandlerClass = DirectUpdateHandler2.class.getName();
    }
    final UpdateHandler newUpdateHandler;
    if (updateHandler == null) {
        newUpdateHandler = createUpdateHandler(updateHandlerClass);
    } else {
        newUpdateHandler = createUpdateHandler(updateHandlerClass, updateHandler);
    }
    if (newUpdateHandler instanceof SolrMetricProducer) {
        coreMetricManager.registerMetricProducer("updateHandler", (SolrMetricProducer) newUpdateHandler);
    }
    infoRegistry.put("updateHandler", newUpdateHandler);
    return newUpdateHandler;
}
Also used : UpdateHandler(org.apache.solr.update.UpdateHandler) SolrMetricProducer(org.apache.solr.metrics.SolrMetricProducer) DirectUpdateHandler2(org.apache.solr.update.DirectUpdateHandler2)

Aggregations

DirectUpdateHandler2 (org.apache.solr.update.DirectUpdateHandler2)2 Counter (com.codahale.metrics.Counter)1 Metric (com.codahale.metrics.Metric)1 Timer (com.codahale.metrics.Timer)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors (java.util.stream.Collectors)1 IOUtils (org.apache.commons.io.IOUtils)1 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)1 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)1 CollectionAdminRequest (org.apache.solr.client.solrj.request.CollectionAdminRequest)1 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)1