You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by yo...@apache.org on 2012/03/03 23:01:37 UTC
svn commit: r1296712 - in
/lucene/dev/trunk/solr/core/src/java/org/apache/solr/update:
DirectUpdateHandler2.java UpdateLog.java
Author: yonik
Date: Sat Mar 3 22:01:36 2012
New Revision: 1296712
URL: http://svn.apache.org/viewvc?rev=1296712&view=rev
Log:
SOLR-3180: do an explicit commit and not just close when shutting down
Modified:
lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/UpdateLog.java
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java?rev=1296712&r1=1296711&r2=1296712&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java Sat Mar 3 22:01:36 2012
@@ -42,12 +42,19 @@ import org.apache.lucene.search.BooleanQ
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
+import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.core.SolrConfig.UpdateHandlerInfo;
import org.apache.solr.core.SolrCore;
+import org.apache.solr.request.LocalSolrQueryRequest;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.request.SolrRequestInfo;
+import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.search.FunctionRangeQuery;
import org.apache.solr.search.QParser;
@@ -524,49 +531,73 @@ public class DirectUpdateHandler2 extend
// IndexWriterCloser interface method - called from solrCoreState.decref(this)
@Override
public void closeWriter(IndexWriter writer) throws IOException {
+ boolean clearRequestInfo = false;
commitLock.lock();
try {
+ SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams());
+ SolrQueryResponse rsp = new SolrQueryResponse();
+ if (SolrRequestInfo.getRequestInfo() == null) {
+ clearRequestInfo = true;
+ SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp)); // important for debugging
+ }
+
+
if (!commitOnClose) {
if (writer != null) {
writer.rollback();
}
// we shouldn't close the transaction logs either, but leaving them open
- // means we can't delete them on windows.
+ // means we can't delete them on windows (needed for tests)
if (ulog != null) ulog.close(false);
return;
}
- // if we are later going to mark everything in the tlog as committed, then we
- // need to block all updates from coming in so we can be sure that the close
- // will contain all of the updates.
-
- VersionInfo vinfo = ulog == null ? null : ulog.getVersionInfo();
- if (vinfo != null) {
- // TODO: move the RW update lock somewhere else?
- vinfo.blockUpdates();
- }
+ // do a commit before we quit?
+ boolean tryToCommit = writer != null && ulog != null && ulog.hasUncommittedChanges() && ulog.getState() == UpdateLog.State.ACTIVE;
+
try {
+ if (tryToCommit) {
+
+ CommitUpdateCommand cmd = new CommitUpdateCommand(req, false);
+ cmd.openSearcher = false;
+ cmd.waitSearcher = false;
+ cmd.softCommit = false;
- boolean succeeded = false;
- try {
- if (writer != null) {
- writer.close();
+ // TODO: keep other commit callbacks from being called?
+ // this.commit(cmd); // too many test failures using this method... is it because of callbacks?
+
+ synchronized (this) {
+ ulog.preCommit(cmd);
}
- succeeded = true;
- } finally {
- if (ulog != null) ulog.close(succeeded);
- }
- } finally {
- if (vinfo != null) {
- vinfo.unblockUpdates();
+ // todo: refactor this shared code (or figure out why a real CommitUpdateCommand can't be used)
+ final Map<String,String> commitData = new HashMap<String,String>();
+ commitData.put(SolrIndexWriter.COMMIT_TIME_MSEC_KEY, String.valueOf(System.currentTimeMillis()));
+ writer.commit(commitData);
+
+ synchronized (this) {
+ ulog.postCommit(cmd);
+ }
}
+ } catch (Throwable th) {
+ log.error("Error in final commit", th);
}
+ // we went through the normal process to commit, so we don't have to artificially
+ // cap any ulog files.
+ try {
+ if (ulog != null) ulog.close(false);
+ } catch (Throwable th) {
+ log.error("Error closing log files", th);
+ }
+
+ if (writer != null) writer.close();
+
} finally {
commitLock.unlock();
+ if (clearRequestInfo) SolrRequestInfo.clearRequestInfo();
}
}
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/UpdateLog.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/UpdateLog.java?rev=1296712&r1=1296711&r2=1296712&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/UpdateLog.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/UpdateLog.java Sat Mar 3 22:01:36 2012
@@ -375,6 +375,10 @@ public class UpdateLog implements Plugin
prevMap2 = null;
}
+ public boolean hasUncommittedChanges() {
+ return tlog != null;
+ }
+
public void preCommit(CommitUpdateCommand cmd) {
synchronized (this) {
if (debug) {