You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by br...@apache.org on 2022/07/13 14:26:12 UTC
[solr] branch main updated: SOLR-16255: Introduce DirectUpdateHandler2#shouldCommit.
This is an automated email from the ASF dual-hosted git repository.
broustant pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new 49ae2f0acfd SOLR-16255: Introduce DirectUpdateHandler2#shouldCommit.
49ae2f0acfd is described below
commit 49ae2f0acfddfafe1fb9974d5da764a3e7756e0a
Author: Bruno Roustant <33...@users.noreply.github.com>
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 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());
+ }
+
@Override
public void newIndexWriter(boolean rollback) throws IOException {
solrCoreState.newIndexWriter(core, rollback);