Apache Solr open-source search software
SOLR-17041 Make CommitTracker currentTlogSize lazy (#2027)
Alex D11141c0c6a78
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 15f70ad21c7..7c703fb434f 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -20,8 +20,6 @@ Improvements* SOLR-16536: Replace OpenTracing instrumentation with OpenTelemetry (Alex Deparvu, janhoy)-* SOLR-17011: Add tracing spans to internal collection commands (Alex Deparvu)-Optimizations---------------------(No changes)@@ -92,6 +90,10 @@ Improvements* SOLR-16397: Swap core v2 endpoints have been updated to be more REST-ful.SWAP is now available at `POST /api/cores/coreName/swap` (Sanjay Dutt via Jason Gerlowski)+* 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.javaindex 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.javaindex 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 UpdateHandlercommitTracker.scheduleCommitWithin(commitTracker.getTimeUpperBound());}- long currentTlogSize = getCurrentTLogSize();- commitTracker.scheduleMaxSizeTriggeredCommitIfNeeded(currentTlogSize);+ commitTracker.scheduleMaxSizeTriggeredCommitIfNeeded(this::getCurrentTLogSize);if (softCommitTracker.getTimeUpperBound() > 0) {softCommitTracker.scheduleCommitWithin(softCommitTracker.getTimeUpperBound());