dsmiley commented on code in PR #4216:
URL: https://github.com/apache/solr/pull/4216#discussion_r2938049900
##########
solr/core/src/java/org/apache/solr/update/UpdateLog.java:
##########
@@ -107,6 +112,8 @@ public class UpdateLog implements PluginInfoInitialized,
SolrMetricProducer {
public static String LOG_FILENAME_PATTERN = "%s.%019d";
public static String TLOG_NAME = "tlog";
public static String BUFFER_TLOG_NAME = "buffer.tlog";
+ private static final String UPDATELOG_REPLAY_SPAN_NAME = "updatelog.replay";
Review Comment:
honestly just inline these. The constants serve no purpose. I know this is
a matter of taste. The practice of constants spreads readability around thus
reducing readability.
##########
solr/core/src/java/org/apache/solr/update/UpdateLog.java:
##########
@@ -2129,36 +2136,69 @@ public void run() {
// setting request info will help logging
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
- try {
- for (; ; ) {
- TransactionLog translog = translogs.pollFirst();
- if (translog == null) break;
- doReplay(translog);
- }
- } catch (SolrException e) {
- if (e.code() == ErrorCode.SERVICE_UNAVAILABLE.code) {
- log.error("Replay failed service unavailable", e);
- recoveryInfo.failed = true;
- } else {
+ final int initialLogCount = translogs.size();
+ int logsReplayed = 0;
+ long replayedOps = 0;
+ final int replayErrorsStart = recoveryInfo.errors.get();
+ final Span replaySpan =
+
TraceUtils.getGlobalTracer().spanBuilder(UPDATELOG_REPLAY_SPAN_NAME).startSpan();
+ TraceUtils.ifNotNoop(
+ replaySpan,
+ span -> {
+ span.setAttribute("updatelog.replay.state", state.toString());
+ span.setAttribute("updatelog.replay.active_log", activeLog);
+ span.setAttribute("updatelog.replay.in_sorted_order",
inSortedOrder);
+ span.setAttribute("updatelog.replay.logs_total", initialLogCount);
+ span.setAttribute("updatelog.replay.core",
req.getCore().getName());
Review Comment:
Probably remove, assuming redundant with the line below
##########
solr/core/src/test/org/apache/solr/update/UpdateLogReplayTracingTest.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.update;
+
+import io.opentelemetry.api.GlobalOpenTelemetry;
+import io.opentelemetry.api.common.AttributeKey;
+import io.opentelemetry.api.trace.Span;
+import io.opentelemetry.sdk.OpenTelemetrySdk;
+import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter;
+import io.opentelemetry.sdk.trace.SdkTracerProvider;
+import io.opentelemetry.sdk.trace.data.SpanData;
+import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.update.processor.DistributedUpdateProcessor;
+import org.apache.solr.update.processor.DistributingUpdateProcessorFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class UpdateLogReplayTracingTest extends SolrTestCaseJ4 {
Review Comment:
Thanks.... I would've been sufficiently happy to see a pic of it working in
your tracing viewer of choice. We mostly don't test logs; traces are a
glorified log in the end, and thus I think testing traces is questionable value
trade-off.
##########
solr/core/src/java/org/apache/solr/update/UpdateLog.java:
##########
@@ -2129,36 +2136,69 @@ public void run() {
// setting request info will help logging
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
- try {
- for (; ; ) {
- TransactionLog translog = translogs.pollFirst();
- if (translog == null) break;
- doReplay(translog);
- }
- } catch (SolrException e) {
- if (e.code() == ErrorCode.SERVICE_UNAVAILABLE.code) {
- log.error("Replay failed service unavailable", e);
- recoveryInfo.failed = true;
- } else {
+ final int initialLogCount = translogs.size();
+ int logsReplayed = 0;
+ long replayedOps = 0;
+ final int replayErrorsStart = recoveryInfo.errors.get();
+ final Span replaySpan =
+
TraceUtils.getGlobalTracer().spanBuilder(UPDATELOG_REPLAY_SPAN_NAME).startSpan();
+ TraceUtils.ifNotNoop(
+ replaySpan,
+ span -> {
+ span.setAttribute("updatelog.replay.state", state.toString());
+ span.setAttribute("updatelog.replay.active_log", activeLog);
+ span.setAttribute("updatelog.replay.in_sorted_order",
inSortedOrder);
+ span.setAttribute("updatelog.replay.logs_total", initialLogCount);
+ span.setAttribute("updatelog.replay.core",
req.getCore().getName());
+ TraceUtils.setDbInstance(span, req.getCore().getName());
+ });
+
+ try (Scope scope = replaySpan.makeCurrent()) {
Review Comment:
can we avoid adding a try-finally when I see one here already?
##########
solr/core/src/java/org/apache/solr/update/UpdateLog.java:
##########
@@ -2389,11 +2455,38 @@ public void doReplay(TransactionLog translog) {
IOUtils.closeQuietly(proc);
}
}
+ replayLogSucceeded = true;
} finally {
if (tlogReader != null) tlogReader.close();
translog.decref();
+ final int replayErrors = recoveryInfo.errors.get() - replayErrorsStart;
+ if (replayLogSpan.isRecording()) {
+ replayLogSpan.setAttribute("updatelog.replay.log_ops", replayedOps);
+ replayLogSpan.setAttribute("updatelog.replay.log_errors",
replayErrors);
+ replayLogSpan.setAttribute("updatelog.replay.log_success",
replayLogSucceeded);
+ }
+ if (!replayLogSucceeded || replayErrors > 0) {
+ replayLogSpan.setStatus(StatusCode.ERROR);
+ }
+ replayLogSpan.end();
+ }
+ return replayedOps;
+ }
+
+ private String summarizeProcessorChain(UpdateRequestProcessorChain
processorChain) {
Review Comment:
lets put this on UpdateRequestProcessorChain.toString().
BTW processorChain won't be null
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]