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 17:41:58 UTC

(solr) branch main 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 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 11141c0c6a7 SOLR-17041 Make CommitTracker currentTlogSize lazy (#2027)
11141c0c6a7 is described below

commit 11141c0c6a788213e15a9eff1b5fe7e2ea4870ad
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                                              |  6 ++++--
 solr/core/src/java/org/apache/solr/update/CommitTracker.java  | 11 ++++++-----
 .../src/java/org/apache/solr/update/DirectUpdateHandler2.java |  8 +++-----
 3 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 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.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());