This is an automated email from the ASF dual-hosted git repository.

broustant pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new a8e72f71650 SOLR-16255: Introduce DirectUpdateHandler2#shouldCommit.
a8e72f71650 is described below

commit a8e72f71650e867463ff249f7ea13145a6723136
Author: Bruno Roustant <[email protected]>
AuthorDate: Wed Jul 13 16:26:07 2022 +0200

    SOLR-16255: Introduce DirectUpdateHandler2#shouldCommit.
---
 .../src/java/org/apache/solr/update/CommitUpdateCommand.java  |  6 +++++-
 .../src/java/org/apache/solr/update/DirectUpdateHandler2.java | 11 ++++++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/update/CommitUpdateCommand.java 
b/solr/core/src/java/org/apache/solr/update/CommitUpdateCommand.java
index 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.java
index bc94e1227bf..1d5339f26d7 100644
--- a/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java
+++ b/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java
@@ -737,7 +737,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 {
@@ -817,6 +817,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());
+  }
+
   @Override
   public void newIndexWriter(boolean rollback) throws IOException {
     solrCoreState.newIndexWriter(core, rollback);

Reply via email to