Apache Solr open-source search software
SOLR-16255: Introduce DirectUpdateHandler2#shouldCommit.
Bruno Roustant49ae2f0acfdd
diff --git a/solr/core/src/java/org/apache/solr/update/CommitUpdateCommand.java b/solr/core/src/java/org/apache/solr/update/CommitUpdateCommand.javaindex 8dcb5ff6cb6..0d47cbc6392 100644--- a/solr/core/src/java/org/apache/solr/update/CommitUpdateCommand.java+++ b/solr/core/src/java/org/apache/solr/update/CommitUpdateCommand.java@@ -27,7 +27,11 @@ public class CommitUpdateCommand extends UpdateCommand {public boolean expungeDeletes = false;public boolean softCommit = false;public boolean prepareCommit = false;- /** User provided commit data. Can be let to null if there is none. */+ /**+ * User provided commit data. Can be let to null if there is none. It is possible to commit this+ * user data, even if there is no uncommitted change in the index writer, provided this user data+ * is not empty.+ */public Map<String, String> commitData;/**diff --git a/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java b/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.javaindex 0c9d9fc6ddc..b9eeb90f526 100644--- a/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java+++ b/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java@@ -744,7 +744,7 @@ public class DirectUpdateHandler2 extends UpdateHandler// SolrCore.verbose("writer.commit() start writer=",writer);- if (writer.hasUncommittedChanges()) {+ if (shouldCommit(cmd, writer)) {SolrIndexWriter.setCommitData(writer, cmd.getVersion(), cmd.commitData);writer.commit();} else {@@ -824,6 +824,15 @@ public class DirectUpdateHandler2 extends UpdateHandler}}+ /**+ * Determines whether the commit command should effectively trigger a commit on the index writer.+ * This method is called with the commit lock and is the last step before effectively calling+ * {@link IndexWriter#commit()}.+ */+ protected boolean shouldCommit(CommitUpdateCommand cmd, IndexWriter writer) throws IOException {+ return writer.hasUncommittedChanges() || (cmd.commitData != null && !cmd.commitData.isEmpty());+ }+@Overridepublic void newIndexWriter(boolean rollback) throws IOException {solrCoreState.newIndexWriter(core, rollback);