You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by st...@apache.org on 2023/11/08 18:08:56 UTC
(solr) branch branch_9x updated: SOLR-17041 Make CommitTracker currentTlogSize lazy (#2027)
This is an automated email from the ASF dual-hosted git repository.
stillalex 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 713d41e91af SOLR-17041 Make CommitTracker currentTlogSize lazy (#2027)
713d41e91af is described below
commit 713d41e91afbc1086d48ad9dd9bbfaf390f0f262
Author: Alex D <st...@apache.org>
AuthorDate: Wed Nov 8 09:41:53 2023 -0800
SOLR-17041 Make CommitTracker currentTlogSize lazy (#2027)
---
solr/CHANGES.txt | 2 ++
solr/core/src/java/org/apache/solr/update/CommitTracker.java | 11 ++++++-----
.../src/java/org/apache/solr/update/DirectUpdateHandler2.java | 8 +++-----
3 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 9e85323ad58..dcd141fab54 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -29,6 +29,8 @@ Improvements
* SOLR-17011: Add tracing spans to internal collection commands (Alex Deparvu)
+* SOLR-17041: Make CommitTracker currentTlogSize lazy (Alex Deparvu)
+
Optimizations
---------------------
(No changes)
diff --git a/solr/core/src/java/org/apache/solr/update/CommitTracker.java b/solr/core/src/java/org/apache/solr/update/CommitTracker.java
index 54516430040..fd02cd51006 100644
--- a/solr/core/src/java/org/apache/solr/update/CommitTracker.java
+++ b/solr/core/src/java/org/apache/solr/update/CommitTracker.java
@@ -24,6 +24,7 @@ import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.LongSupplier;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.SolrNamedThreadFactory;
import org.apache.solr.core.SolrCore;
@@ -171,7 +172,7 @@ public final class CommitTracker implements Runnable {
* @param commitWithin amount of time (in ms) within which a commit should be scheduled
*/
public void addedDocument(int commitWithin) {
- addedDocument(commitWithin, -1);
+ addedDocument(commitWithin, () -> -1);
}
/**
@@ -181,7 +182,7 @@ public final class CommitTracker implements Runnable {
* @param currentTlogSize current tlog size (in bytes). Use -1 if we don't want to check for a max
* size triggered commit
*/
- public void addedDocument(int commitWithin, long currentTlogSize) {
+ public void addedDocument(int commitWithin, LongSupplier currentTlogSize) {
// maxDocs-triggered autoCommit
_scheduleMaxDocsTriggeredCommitIfNeeded();
@@ -219,7 +220,7 @@ public final class CommitTracker implements Runnable {
*
* @param currentTlogSize current tlog size (in bytes)
*/
- public void scheduleMaxSizeTriggeredCommitIfNeeded(long currentTlogSize) {
+ public void scheduleMaxSizeTriggeredCommitIfNeeded(LongSupplier currentTlogSize) {
_scheduleMaxSizeTriggeredCommitIfNeeded(currentTlogSize);
}
@@ -229,8 +230,8 @@ public final class CommitTracker implements Runnable {
*
* @param currentTlogSize current tlog size (in bytes)
*/
- private void _scheduleMaxSizeTriggeredCommitIfNeeded(long currentTlogSize) {
- if (tLogFileSizeUpperBound > 0 && currentTlogSize > tLogFileSizeUpperBound) {
+ private void _scheduleMaxSizeTriggeredCommitIfNeeded(LongSupplier currentTlogSize) {
+ if (tLogFileSizeUpperBound > 0 && currentTlogSize.getAsLong() > tLogFileSizeUpperBound) {
docsSinceCommit.set(0);
_scheduleCommitWithin(SIZE_COMMIT_DELAY_MS);
}
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 36ecf31a9c6..c50709d13a2 100644
--- a/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java
+++ b/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java
@@ -379,13 +379,12 @@ public class DirectUpdateHandler2 extends UpdateHandler
}
if ((cmd.getFlags() & UpdateCommand.IGNORE_AUTOCOMMIT) == 0) {
- long currentTlogSize = getCurrentTLogSize();
if (commitWithinSoftCommit) {
- commitTracker.addedDocument(-1, currentTlogSize);
+ commitTracker.addedDocument(-1, this::getCurrentTLogSize);
softCommitTracker.addedDocument(cmd.commitWithin);
} else {
softCommitTracker.addedDocument(-1);
- commitTracker.addedDocument(cmd.commitWithin, currentTlogSize);
+ commitTracker.addedDocument(cmd.commitWithin, this::getCurrentTLogSize);
}
}
@@ -484,8 +483,7 @@ public class DirectUpdateHandler2 extends UpdateHandler
commitTracker.scheduleCommitWithin(commitTracker.getTimeUpperBound());
}
- long currentTlogSize = getCurrentTLogSize();
- commitTracker.scheduleMaxSizeTriggeredCommitIfNeeded(currentTlogSize);
+ commitTracker.scheduleMaxSizeTriggeredCommitIfNeeded(this::getCurrentTLogSize);
if (softCommitTracker.getTimeUpperBound() > 0) {
softCommitTracker.scheduleCommitWithin(softCommitTracker.getTimeUpperBound());