mirror of https://github.com/apache/lucene.git
SOLR-6224: Post soft-commit callbacks are called before soft commit actually happens
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1633676 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4ed9b12033
commit
7fa2cea91c
|
@ -256,6 +256,9 @@ Bug Fixes
|
|||
* SOLR-6524: Collections left in recovery state after node restart because recovery sleep time
|
||||
increases exponentially between retries. (Mark Miller, shalin)
|
||||
|
||||
* SOLR-6224: Post soft-commit callbacks are called before soft commit actually happens.
|
||||
(shalin)
|
||||
|
||||
Optimizations
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -587,8 +587,6 @@ public class DirectUpdateHandler2 extends UpdateHandler implements SolrCoreState
|
|||
// SolrCore.verbose("writer.commit() end");
|
||||
numDocsPending.set(0);
|
||||
callPostCommitCallbacks();
|
||||
} else {
|
||||
callPostSoftCommitCallbacks();
|
||||
}
|
||||
} finally {
|
||||
iw.decref();
|
||||
|
@ -607,7 +605,7 @@ public class DirectUpdateHandler2 extends UpdateHandler implements SolrCoreState
|
|||
core.getSearcher(true, false, waitSearcher, true);
|
||||
if (ulog != null) ulog.postSoftCommit(cmd);
|
||||
}
|
||||
// ulog.postSoftCommit();
|
||||
callPostSoftCommitCallbacks();
|
||||
} else {
|
||||
synchronized (solrCoreState.getUpdateLock()) {
|
||||
if (ulog != null) ulog.preSoftCommit(cmd);
|
||||
|
|
|
@ -20,6 +20,8 @@ package org.apache.solr.update;
|
|||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.apache.lucene.index.TieredMergePolicy;
|
||||
import org.apache.lucene.index.DirectoryReader;
|
||||
|
@ -27,9 +29,12 @@ import org.apache.lucene.store.Directory;
|
|||
import org.apache.solr.SolrTestCaseJ4;
|
||||
import org.apache.solr.common.params.CommonParams;
|
||||
import org.apache.solr.common.params.MapSolrParams;
|
||||
import org.apache.solr.common.util.NamedList;
|
||||
import org.apache.solr.core.SolrCore;
|
||||
import org.apache.solr.core.SolrEventListener;
|
||||
import org.apache.solr.request.LocalSolrQueryRequest;
|
||||
import org.apache.solr.request.SolrQueryRequest;
|
||||
import org.apache.solr.search.SolrIndexSearcher;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
|
@ -339,7 +344,45 @@ public class DirectUpdateHandlerTest extends SolrTestCaseJ4 {
|
|||
|
||||
sr.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPostSoftCommitEvents() throws Exception {
|
||||
SolrCore core = h.getCore();
|
||||
assert core != null;
|
||||
DirectUpdateHandler2 updater = (DirectUpdateHandler2) core.getUpdateHandler();
|
||||
MySolrEventListener listener = new MySolrEventListener();
|
||||
core.registerNewSearcherListener(listener);
|
||||
updater.registerSoftCommitCallback(listener);
|
||||
assertU(adoc("id", "999"));
|
||||
assertU(commit("softCommit", "true"));
|
||||
assertEquals("newSearcher was called more than once", 1, listener.newSearcherCount.get());
|
||||
assertFalse("postSoftCommit was not called", listener.postSoftCommitAt.get() == Long.MAX_VALUE);
|
||||
assertTrue("newSearcher was called after postSoftCommitCallback", listener.postSoftCommitAt.get() >= listener.newSearcherOpenedAt.get());
|
||||
}
|
||||
|
||||
static class MySolrEventListener implements SolrEventListener {
|
||||
AtomicInteger newSearcherCount = new AtomicInteger(0);
|
||||
AtomicLong newSearcherOpenedAt = new AtomicLong(Long.MAX_VALUE);
|
||||
AtomicLong postSoftCommitAt = new AtomicLong(Long.MAX_VALUE);
|
||||
|
||||
@Override
|
||||
public void postCommit() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postSoftCommit() {
|
||||
postSoftCommitAt.set(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void newSearcher(SolrIndexSearcher newSearcher, SolrIndexSearcher currentSearcher) {
|
||||
newSearcherCount.incrementAndGet();
|
||||
newSearcherOpenedAt.set(newSearcher.getOpenTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(NamedList args) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue