Search in sources :

Example 11 with UpdateHandler

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

the class TestRecovery method testBufferingFlags.

@Test
public void testBufferingFlags() throws Exception {
    DirectUpdateHandler2.commitOnClose = false;
    final Semaphore logReplayFinish = new Semaphore(0);
    UpdateLog.testing_logReplayFinishHook = () -> logReplayFinish.release();
    SolrQueryRequest req = req();
    UpdateHandler uhandler = req.getCore().getUpdateHandler();
    UpdateLog ulog = uhandler.getUpdateLog();
    try {
        String v101 = getNextVersion();
        String v102 = getNextVersion();
        String v103 = getNextVersion();
        String v114 = getNextVersion();
        String v115 = getNextVersion();
        String v116 = getNextVersion();
        String v117 = getNextVersion();
        clearIndex();
        assertU(commit());
        assertEquals(UpdateLog.State.ACTIVE, ulog.getState());
        ulog.bufferUpdates();
        // simulate updates from a leader
        updateJ(jsonAdd(sdoc("id", "Q1", "_version_", v101)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
        updateJ(jsonAdd(sdoc("id", "Q2", "_version_", v102)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
        updateJ(jsonAdd(sdoc("id", "Q3", "_version_", v103)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
        assertEquals(UpdateLog.State.BUFFERING, ulog.getState());
        req.close();
        h.close();
        createCore();
        req = req();
        uhandler = req.getCore().getUpdateHandler();
        ulog = uhandler.getUpdateLog();
        // wait for replay to finish
        logReplayFinish.acquire();
        // since we died while buffering, we should see this last
        assertTrue((ulog.getStartingOperation() & UpdateLog.FLAG_GAP) != 0);
        //
        // Try again to ensure that the previous log replay didn't wipe out our flags
        //
        req.close();
        h.close();
        createCore();
        req = req();
        uhandler = req.getCore().getUpdateHandler();
        ulog = uhandler.getUpdateLog();
        assertTrue((ulog.getStartingOperation() & UpdateLog.FLAG_GAP) != 0);
        // now do some normal non-buffered adds
        updateJ(jsonAdd(sdoc("id", "Q4", "_version_", v114)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
        updateJ(jsonAdd(sdoc("id", "Q5", "_version_", v115)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
        updateJ(jsonAdd(sdoc("id", "Q6", "_version_", v116)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
        assertU(commit());
        req.close();
        h.close();
        createCore();
        req = req();
        uhandler = req.getCore().getUpdateHandler();
        ulog = uhandler.getUpdateLog();
        assertTrue((ulog.getStartingOperation() & UpdateLog.FLAG_GAP) == 0);
        ulog.bufferUpdates();
        // simulate receiving no updates
        ulog.applyBufferedUpdates();
        // do another add to make sure flags are back to normal
        updateJ(jsonAdd(sdoc("id", "Q7", "_version_", v117)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
        req.close();
        h.close();
        createCore();
        req = req();
        uhandler = req.getCore().getUpdateHandler();
        ulog = uhandler.getUpdateLog();
        // check flags on Q7
        assertTrue((ulog.getStartingOperation() & UpdateLog.FLAG_GAP) == 0);
        logReplayFinish.acquire();
        // leave each test method in a good state
        assertEquals(UpdateLog.State.ACTIVE, ulog.getState());
    } finally {
        DirectUpdateHandler2.commitOnClose = true;
        UpdateLog.testing_logReplayHook = null;
        UpdateLog.testing_logReplayFinishHook = null;
        req().close();
    }
}
Also used : UpdateHandler(org.apache.solr.update.UpdateHandler) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) UpdateLog(org.apache.solr.update.UpdateLog) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.Test)

Example 12 with UpdateHandler

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

the class TestRecoveryHdfs method testCleanShutdown.

// make sure that log isn't needlessly replayed after a clean close
@Test
public void testCleanShutdown() throws Exception {
    DirectUpdateHandler2.commitOnClose = true;
    final Semaphore logReplay = new Semaphore(0);
    final Semaphore logReplayFinish = new Semaphore(0);
    UpdateLog.testing_logReplayHook = () -> {
        try {
            assertTrue(logReplay.tryAcquire(timeout, TimeUnit.SECONDS));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    };
    UpdateLog.testing_logReplayFinishHook = () -> logReplayFinish.release();
    SolrQueryRequest req = req();
    UpdateHandler uhandler = req.getCore().getUpdateHandler();
    UpdateLog ulog = uhandler.getUpdateLog();
    try {
        clearIndex();
        assertU(commit());
        assertU(adoc("id", "E1", "val_i", "1"));
        assertU(adoc("id", "E2", "val_i", "1"));
        // set to a high enough number so this test won't hang on a bug
        logReplay.release(10);
        h.close();
        createCore();
        // make sure the docs got committed
        assertJQ(req("q", "*:*"), "/response/numFound==2");
        // make sure no replay happened
        assertEquals(10, logReplay.availablePermits());
    } finally {
        DirectUpdateHandler2.commitOnClose = true;
        UpdateLog.testing_logReplayHook = null;
        UpdateLog.testing_logReplayFinishHook = null;
        req().close();
    }
}
Also used : UpdateHandler(org.apache.solr.update.UpdateHandler) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) HdfsUpdateLog(org.apache.solr.update.HdfsUpdateLog) UpdateLog(org.apache.solr.update.UpdateLog) Semaphore(java.util.concurrent.Semaphore) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Test(org.junit.Test)

Example 13 with UpdateHandler

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

the class TestSchemalessBufferedUpdates method test.

@Test
public void test() throws Exception {
    DirectUpdateHandler2.commitOnClose = false;
    final Semaphore logReplay = new Semaphore(0);
    final Semaphore logReplayFinish = new Semaphore(0);
    UpdateLog.testing_logReplayHook = () -> {
        try {
            assertTrue(logReplay.tryAcquire(TIMEOUT, TimeUnit.SECONDS));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    };
    UpdateLog.testing_logReplayFinishHook = logReplayFinish::release;
    SolrQueryRequest req = req();
    UpdateHandler uhandler = req.getCore().getUpdateHandler();
    UpdateLog ulog = uhandler.getUpdateLog();
    try {
        assertEquals(UpdateLog.State.ACTIVE, ulog.getState());
        // Invalid date will be normalized by ParseDateField URP
        updateJ(jsonAdd(processAdd(sdoc("id", "1", "f_dt", "2017-01-04"))), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
        assertU(commit());
        assertJQ(req("q", "*:*"), "/response/numFound==1");
        ulog.bufferUpdates();
        assertEquals(UpdateLog.State.BUFFERING, ulog.getState());
        // If the ParseDateField URP isn't ahead of the DUP, then the date won't be normalized in the buffered tlog entry,
        // and the doc won't be indexed on the replaying replica - a warning is logged as follows:
        // WARN [...] o.a.s.u.UpdateLog REYPLAY_ERR: IOException reading log
        //            org.apache.solr.common.SolrException: Invalid Date String:'2017-01-05'
        //              at org.apache.solr.util.DateMathParser.parseMath(DateMathParser.java:234)
        //              at org.apache.solr.schema.TrieField.createField(TrieField.java:725) [...]
        updateJ(jsonAdd(processAdd(sdoc("id", "2", "f_dt", "2017-01-05"))), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
        Future<UpdateLog.RecoveryInfo> rinfoFuture = ulog.applyBufferedUpdates();
        assertTrue(rinfoFuture != null);
        assertEquals(UpdateLog.State.APPLYING_BUFFERED, ulog.getState());
        logReplay.release(1000);
        UpdateLog.RecoveryInfo rinfo = rinfoFuture.get();
        assertEquals(UpdateLog.State.ACTIVE, ulog.getState());
        assertU(commit());
        assertJQ(req("q", "*:*"), "/response/numFound==2");
    } finally {
        DirectUpdateHandler2.commitOnClose = true;
        UpdateLog.testing_logReplayHook = null;
        UpdateLog.testing_logReplayFinishHook = null;
        req().close();
    }
}
Also used : UpdateHandler(org.apache.solr.update.UpdateHandler) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) UpdateLog(org.apache.solr.update.UpdateLog) Semaphore(java.util.concurrent.Semaphore) IOException(java.io.IOException) Test(org.junit.Test)

Example 14 with UpdateHandler

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

the class TestLazyCores method addLazy.

private void addLazy(SolrCore core, String... fieldValues) throws IOException {
    UpdateHandler updater = core.getUpdateHandler();
    AddUpdateCommand cmd = new AddUpdateCommand(makeReq(core));
    cmd.solrDoc = sdoc((Object[]) fieldValues);
    updater.addDoc(cmd);
}
Also used : UpdateHandler(org.apache.solr.update.UpdateHandler) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand)

Example 15 with UpdateHandler

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

the class ChangedSchemaMergeTest method addDoc.

private void addDoc(SolrCore core, String... fieldValues) throws IOException {
    UpdateHandler updater = core.getUpdateHandler();
    AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(core, new NamedList<>()));
    cmd.solrDoc = sdoc((Object[]) fieldValues);
    updater.addDoc(cmd);
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) UpdateHandler(org.apache.solr.update.UpdateHandler) NamedList(org.apache.solr.common.util.NamedList) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand)

Aggregations

UpdateHandler (org.apache.solr.update.UpdateHandler)16 UpdateLog (org.apache.solr.update.UpdateLog)12 Semaphore (java.util.concurrent.Semaphore)11 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)11 Test (org.junit.Test)11 IOException (java.io.IOException)5 HdfsUpdateLog (org.apache.solr.update.HdfsUpdateLog)4 URISyntaxException (java.net.URISyntaxException)3 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)2 Gauge (com.codahale.metrics.Gauge)1 Meter (com.codahale.metrics.Meter)1 Metric (com.codahale.metrics.Metric)1 FileNotFoundException (java.io.FileNotFoundException)1 Constructor (java.lang.reflect.Constructor)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)1