You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ds...@apache.org on 2026/10/08 03:41:55 UTC
(solr) 08/12: SOLR-18124: Trace index replication with a span (#4963)
This is an automated email from the ASF dual-hosted git repository.
dsmiley pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/solr.git
commit b20293b157365b096e96e91ec85e313fb67b5b59
Author: David Smiley <ds...@apache.org>
AuthorDate: Wed Oct 7 14:38:41 2026 -0400
SOLR-18124: Trace index replication with a span (#4963)
Co-authored-by: Claude Opus 5.5 <no...@anthropic.com>
(cherry picked from commit 6d6504668e3cac77f74d6ad2b2b20754de1c3bec)
---
.../java/org/apache/solr/handler/IndexFetcher.java | 8 ++++++++
.../apache/solr/handler/ReplicationHandler.java | 24 +++++++++++++++++++++-
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java
index b6fa1146959..2652f2add4c 100644
--- a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java
+++ b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java
@@ -37,6 +37,7 @@ import static org.apache.solr.handler.admin.api.ReplicationAPIBase.FILE_STREAM;
import static org.apache.solr.handler.admin.api.ReplicationAPIBase.GENERATION;
import static org.apache.solr.handler.admin.api.ReplicationAPIBase.OFFSET;
+import io.opentelemetry.api.trace.Span;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -499,6 +500,9 @@ public class IndexFetcher {
log.info("Leader's generation: {}", latestGeneration);
log.info("Leader's version: {}", latestVersion);
+ Span.current()
+ .setAttribute("replication.leader", leaderCoreUrl)
+ .setAttribute("replication.leaderGeneration", latestGeneration);
// TODO: make sure that getLatestCommit only returns commit points for the main index (i.e. no
// side-car indexes)
@@ -576,6 +580,7 @@ public class IndexFetcher {
if (log.isInfoEnabled()) {
log.info("Number of files in latest index in leader: {}", filesToDownload.size());
}
+ Span.current().setAttribute("replication.leaderFiles", filesToDownload.size());
// Create the sync service
fsyncService =
@@ -687,6 +692,9 @@ public class IndexFetcher {
timeTakenSeconds,
bytesDownloadedPerSecond,
tmpIndexDir);
+ Span.current()
+ .setAttribute("replication.fullCopy", isFullCopyNeeded)
+ .setAttribute("replication.bytesDownloaded", bytesDownloaded);
Collection<Map<String, Object>> modifiedConfFiles =
getModifiedConfFiles(confFilesToDownload);
diff --git a/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java b/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
index ddd9793932b..6278a33fbfb 100644
--- a/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
@@ -33,6 +33,8 @@ import static org.apache.solr.handler.admin.api.ReplicationAPIBase.TLOG_FILE;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.metrics.ObservableDoubleMeasurement;
import io.opentelemetry.api.metrics.ObservableLongMeasurement;
+import io.opentelemetry.api.trace.Span;
+import io.opentelemetry.api.trace.StatusCode;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@@ -115,6 +117,7 @@ import org.apache.solr.util.NumberUtils;
import org.apache.solr.util.RefCounted;
import org.apache.solr.util.plugin.SolrCoreAware;
import org.apache.solr.util.stats.MetricUtils;
+import org.apache.solr.util.tracing.TraceUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
@@ -497,9 +500,28 @@ public class ReplicationHandler extends RequestHandlerBase
private volatile IndexFetcher currentIndexFetcher;
+ public IndexFetchResult doFetch(SolrParams solrParams, boolean forceReplication) {
+ final Span span = TraceUtils.getGlobalTracer().spanBuilder("replication").startSpan();
+ TraceUtils.setDbInstance(span, core.getName());
+ try (var scope = span.makeCurrent()) {
+ assert scope != null; // prevent javac warning about scope being unused
+ IndexFetchResult result = doFetchInternal(solrParams, forceReplication);
+ span.setAttribute("replication.result", result.getMessage());
+ if (!result.getSuccessful()) {
+ span.setStatus(StatusCode.ERROR);
+ }
+ if (result.getException() != null) {
+ span.recordException(result.getException());
+ }
+ return result;
+ } finally {
+ span.end();
+ }
+ }
+
@SuppressWarnings(
"ReferenceEquality") // detecting the shared pollingIndexFetcher vs. a one-off, by identity
- public IndexFetchResult doFetch(SolrParams solrParams, boolean forceReplication) {
+ private IndexFetchResult doFetchInternal(SolrParams solrParams, boolean forceReplication) {
String leaderUrl = solrParams.get(LEADER_URL, null);
if (!indexFetchLock.tryLock()) return IndexFetchResult.LOCK_OBTAIN_FAILED;
if (core.getCoreContainer().isShutDown()) {