FrankChen021 commented on code in PR #19179:
URL: https://github.com/apache/druid/pull/19179#discussion_r3894413607
##########
indexing-service/src/main/java/org/apache/druid/indexing/compact/OverlordCompactionScheduler.java:
##########
@@ -503,6 +519,22 @@ public CompactionSimulateResult
simulateRunWithConfigUpdate(ClusterCompactionCon
}
}
+ @Override
+ public CompactionStatusDetailedStats
dryRunWithConfig(ClusterCompactionConfig config)
+ {
+ CompactionStatusDetailedStats detailedStats = new
CompactionStatusDetailedStats();
+ if (isRunning() && isEnabled()) {
+ try {
+ scheduleOnExecutor(() -> resetCompactionJobQueue(true, config,
detailedStats), 0L).get();
Review Comment:
[P2] Dry run replaces the live compaction queue
This invokes the same resetCompactionJobQueue path used by the live
scheduler, which clears latestJobQueue and then installs a dry-run queue. After
this future completes, task-finish callbacks and later queue updates operate on
that dry-run queue, so real pending compaction jobs can stop launching and
snapshots can remain stale until the next scheduled reset. Build the dry-run
state independently, or save and restore the live queue and tracker state in a
finally block.
##########
indexing-service/src/main/java/org/apache/druid/indexing/compact/OverlordCompactionScheduler.java:
##########
@@ -539,9 +571,9 @@ private DataSourcesSnapshot getDatasourceSnapshot()
return segmentManager.getRecentDataSourcesSnapshot();
}
- private void scheduleOnExecutor(Runnable runnable, long delayMillis)
+ private ScheduledFuture<?> scheduleOnExecutor(Runnable runnable, long
delayMillis)
{
- executor.schedule(
+ return executor.schedule(
Review Comment:
[P2] Dry-run executor failures are swallowed
The newly returned future is not enough to propagate failures because the
scheduled runnable still catches every Throwable and only logs it.
Consequently, dryRunWithConfig(...).get() completes normally even when
resetCompactionJobQueue fails, and the endpoint can return HTTP 200 with empty
or partial statistics instead of the intended error response. Use a propagation
path for this synchronous dry-run call, or rethrow the task failure through the
future while preserving the existing logging behavior for asynchronous
scheduling.
##########
server/src/main/java/org/apache/druid/server/compaction/CompactionStatusDetailedStats.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.druid.server.compaction;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import org.apache.druid.common.guava.GuavaUtils;
+import org.apache.druid.error.DruidException;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Collects detailed compaction statistics in table format during dry run mode
in overlord.
+ */
+public class CompactionStatusDetailedStats
+{
+ private final Map<CompactionStatus.State, Table> stateToTable;
+ private final String[] COLUMNS = new String[]{
+ "dataSource",
+ "interval",
+ "numSegments",
+ "bytes",
+ "rows",
+ "uncompactedSegments",
+ "uncompactedBytes",
+ "uncompactedRows",
+ "reasonToCompactOrSkip",
+ "mode"
+ };
+
+ public CompactionStatusDetailedStats()
+ {
+ this.stateToTable = new HashMap<>();
+ stateToTable.put(CompactionStatus.State.COMPLETE,
Table.withColumnNames(COLUMNS));
+ stateToTable.put(CompactionStatus.State.RUNNING,
Table.withColumnNames(COLUMNS));
+ stateToTable.put(CompactionStatus.State.PENDING,
Table.withColumnNames(COLUMNS));
+ stateToTable.put(CompactionStatus.State.SKIPPED,
Table.withColumnNames(COLUMNS));
+ }
+
+ @JsonCreator
+ public CompactionStatusDetailedStats(
+ @JsonProperty("compactionStates") Map<CompactionStatus.State, Table>
compactionStates
+ )
+ {
+ this.stateToTable = compactionStates != null ? new
HashMap<>(compactionStates) : new HashMap<>();
+ }
+
+ public void recordCompactionStatus(CompactionCandidate candidate)
+ {
+ final CompactionStatus status = candidate.getCurrentStatus();
+ CompactionStatistics stats = GuavaUtils.firstNonNull(candidate.getStats(),
new CompactionStatistics());
+ CompactionStatistics uncompactedStats = GuavaUtils.firstNonNull(
+ candidate.getUncompactedStats(),
+ new CompactionStatistics()
+ );
+
+ final Object[] baseRow = new Object[]{
+ candidate.getDataSource(),
+ candidate.getCompactionInterval(),
+ candidate.numSegments(),
+ stats.getTotalBytes(),
+ stats.getTotalRows(),
+ uncompactedStats.getNumSegments(),
+ uncompactedStats.getTotalBytes(),
+ uncompactedStats.getTotalRows(),
+ status.getReason(),
+ null,
+ };
+
+ final Table table = stateToTable.get(status.getState());
+
+ switch (status.getState()) {
+ case COMPLETE:
+ case SKIPPED:
+ case PENDING:
+ table.addRow(baseRow);
+ break;
+ case RUNNING:
+ default:
+ throw DruidException.defensive("unexpected compaction status[%s]",
status.getState());
+ }
+ }
+
+ public void recordSubmittedTask(CompactionCandidate candidate,
CompactionMode compactionMode)
+ {
+ Preconditions.checkNotNull(candidate.getStats(), "compaction stats");
+ Preconditions.checkNotNull(candidate.getUncompactedStats(), "uncompacted
stats");
+ stateToTable.get(CompactionStatus.State.RUNNING).addRow(
+ candidate.getDataSource(),
+ candidate.getCompactionInterval(),
+ candidate.numSegments(),
+ candidate.getStats().getTotalBytes(),
+ candidate.getStats().getTotalRows(),
+ candidate.getUncompactedStats().getNumSegments(),
+ candidate.getUncompactedStats().getTotalRows(),
Review Comment:
[P2] Running-stat rows omit uncompacted bytes
The table declares ten columns in the order uncompactedSegments,
uncompactedBytes, uncompactedRows, reasonToCompactOrSkip, and mode, but this
row supplies only nine values and omits getUncompactedStats().getTotalBytes().
The remaining values shift into the wrong columns and mode is missing from the
row, so the new running-task response is malformed. Add uncompacted bytes
between the segment count and row count.
--
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]