yujun777 commented on code in PR #71199:
URL: https://github.com/apache/doris/pull/71199#discussion_r4750765186
##########
be/src/information_schema/schema_table_stream_consumption_scanner.cpp:
##########
@@ -58,6 +61,12 @@ Status
SchemaTableStreamConsumptionScanner::start(RuntimeState* state) {
TFetchSchemaTableDataRequest
SchemaTableStreamConsumptionScanner::_build_fetch_request() const {
TSchemaTableRequestParams schema_table_request_params;
+ std::vector<std::string> columns;
+ columns.reserve(_s_table_stream_consumption_columns.size());
+ for (const auto& column : _s_table_stream_consumption_columns) {
+ columns.emplace_back(column.name);
+ }
+ schema_table_request_params.__set_columns_name(columns);
Review Comment:
Fixed in 16edb51b2d4. `SchemaTableStreamConsumptionScanner` now retries once
with the 7 legacy columns when Master FE rejects the 10-column request, decodes
both 10-column and 7-column responses (NULL-padding columns 7..9), and
`MetadataGenerator` skips FE monitoring computation unless at least one
monitoring column is requested in `columns_name`.
##########
fe/fe-core/src/main/java/org/apache/doris/catalog/stream/StreamResumabilityChecker.java:
##########
@@ -0,0 +1,171 @@
+// 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.doris.catalog.stream;
+
+import org.apache.doris.catalog.OlapTable;
+import org.apache.doris.changelog.ChangelogUtils;
+import org.apache.doris.tso.TSOTimestamp;
+
+/**
+ * Shared checkpoint resumability rules for OLAP table streams, used by both
the scan rewrite path
+ * and stream monitoring / consumption diagnostics.
+ */
+public final class StreamResumabilityChecker {
+ private StreamResumabilityChecker() {
+ }
+
+ public enum Status {
+ RESUMABLE(1),
+ CANNOT_RESUME(0),
+ UNKNOWN(-1);
+
+ private final int code;
+
+ Status(int code) {
+ this.code = code;
+ }
+
+ public int code() {
+ return code;
+ }
+ }
+
+ public enum Reason {
+ NONE(""),
+ BASE_TABLE_MISSING("BASE_TABLE_MISSING"),
+ STREAM_DISABLED("STREAM_DISABLED"),
+ STREAM_STALE("STREAM_STALE"),
+ CHANGELOG_DISABLED("CHANGELOG_DISABLED"),
+ TTL_EXPIRED("TTL_EXPIRED"),
+ NO_BASELINE_OFFSET("NO_BASELINE_OFFSET"),
+ TSO_UNINITIALIZED("TSO_UNINITIALIZED"),
+ STATE_UNAVAILABLE("STATE_UNAVAILABLE");
+
+ private final String code;
+
+ Reason(String code) {
+ this.code = code;
+ }
+
+ public String code() {
+ return code;
+ }
+ }
+
+ public record Result(Status status, Reason reason) {
+ public static Result resumable() {
+ return new Result(Status.RESUMABLE, Reason.NONE);
+ }
+
+ public static Result cannotResume(Reason reason) {
+ return new Result(Status.CANNOT_RESUME, reason);
+ }
+
+ public static Result unknown(Reason reason) {
+ return new Result(Status.UNKNOWN, reason);
+ }
+ }
+
+ /** Compute the inclusive TTL expiration cutoff TSO, or null if TTL is
disabled or referenceTso is unavailable. */
+ public static Long calculateCutoffTso(OlapTable baseTable, Long
referenceTso) {
+ if (baseTable == null || !baseTable.hasChangelogTtl()) {
+ return null;
+ }
+ if (referenceTso == null || referenceTso <= 0) {
+ return null;
+ }
+ return TSOTimestamp.calculateCutoff(referenceTso,
baseTable.getChangelogConfig().getTtlSeconds());
+ }
+
+ /** Check stream-wide prerequisites before inspecting individual
partitions. */
+ public static Result checkStreamLevel(OlapTableStream stream, OlapTable
baseTable) {
+ if (stream.isDisabled()) {
+ return Result.cannotResume(Reason.STREAM_DISABLED);
+ }
+ if (stream.isStale()) {
+ return Result.cannotResume(Reason.STREAM_STALE);
+ }
+ if (baseTable == null || baseTable.isDropped) {
+ return Result.cannotResume(Reason.BASE_TABLE_MISSING);
+ }
+ if (!baseTable.hasChangelog()) {
+ return Result.cannotResume(Reason.CHANGELOG_DISABLED);
+ }
+ return Result.resumable();
+ }
+
+ /**
+ * Evaluate whether one partition checkpoint can resume completely without
losing changes.
+ * Even for scan types that clip an expired start TSO instead of throwing,
clipping means
+ * incomplete resumption and reports {@link Status#CANNOT_RESUME}.
+ */
+ public static Result checkPartition(boolean hasChangelogTtl, Long
cutoffTso, boolean hasData,
+ Long offset, Long historicalTso, long endTso, long
streamCreateTimeMs, long oldestPendingTimeMs) {
+ // Initial-snapshot partitions read the base table directly and do not
depend on changelog retention.
+ if (historicalTso != null) {
+ return Result.resumable();
+ }
+ if (!hasData) {
+ return Result.resumable();
+ }
+ if (!hasChangelogTtl) {
+ return Result.resumable();
+ }
+ if (cutoffTso == null) {
+ return Result.unknown(Reason.TSO_UNINITIALIZED);
+ }
+ if (offset != null && offset >= 0) {
+ Long startTso = TSOTimestamp.toExclusiveBound(offset);
+ if (ChangelogUtils.isStartTsoExpired(startTso, cutoffTso)) {
+ return Result.cannotResume(Reason.TTL_EXPIRED);
+ }
+ return Result.resumable();
+ }
+ // Partition has data but no real consumption baseline (newly added or
empty at stream creation).
+ if (endTso >= 0 && endTso <= cutoffTso) {
+ return Result.cannotResume(Reason.TTL_EXPIRED);
+ }
+ long cutoffMs = TSOTimestamp.extractPhysicalTime(cutoffTso);
+ if (oldestPendingTimeMs > 0) {
+ return oldestPendingTimeMs <= cutoffMs
Review Comment:
Fixed in 16edb51b2d4. `StreamResumabilityChecker.checkPartition()` no longer
treats a fresh `oldestPendingTimeMs` anchor as proof of resumability when no
baseline offset exists — it only uses `oldestPendingTimeMs <= cutoffMs` to
detect `TTL_EXPIRED` and otherwise falls back to `NO_BASELINE_OFFSET` unless
the explicit `-1` empty-at-creation sentinel has `streamCreateTimeMs >
cutoffMs`. Also made caught-up partitions (`offset == endTso`) remain
`RESUMABLE`.
##########
fe/fe-core/src/main/java/org/apache/doris/catalog/stream/OlapStreamMonitorCollector.java:
##########
@@ -0,0 +1,411 @@
+// 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.doris.catalog.stream;
+
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.OlapTable;
+import org.apache.doris.catalog.Partition;
+import org.apache.doris.catalog.Table;
+import org.apache.doris.changelog.ChangelogMonitorSnapshot;
+import org.apache.doris.changelog.ChangelogMonitorSnapshot.PartitionHealth;
+import org.apache.doris.changelog.ChangelogMonitorSnapshot.StreamHealth;
+import org.apache.doris.cloud.proto.Cloud;
+import org.apache.doris.cloud.rpc.CloudTableStreamReadStateHelper;
+import org.apache.doris.common.Config;
+import org.apache.doris.common.UserException;
+import org.apache.doris.tso.TSOService;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
+/**
+ * Batch-samples registered OLAP table streams for {@link
org.apache.doris.changelog.ChangelogMonitor}.
+ *
+ * <p>In shared-nothing mode, partition states are copied under short read
locks. In cloud mode,
+ * partition identities are copied under short read locks and authoritative
states are fetched in one
+ * lock-free batch RPC, falling back to per-stream RPCs on batch failure so
one failing stream does
+ * not blind healthy streams.
+ */
+public final class OlapStreamMonitorCollector {
+ private static final Logger LOG =
LogManager.getLogger(OlapStreamMonitorCollector.class);
+
+ private OlapStreamMonitorCollector() {
+ }
+
+ @FunctionalInterface
+ public interface CloudStateFetcher {
+ Map<Cloud.TableStreamIdentityPB, Map<Long,
Cloud.TableStreamPartitionReadStatePB>> fetch(
+ Map<Cloud.TableStreamIdentityPB, Set<Long>>
requestedPartitions) throws UserException;
+ }
+
+ public static List<StreamHealth> collect(Env env, long sampleTimeMs,
StreamPendingAgeTracker tracker,
+ Map<Long, StreamHealth> previousByStreamId) {
+ return collect(env, sampleTimeMs, tracker, previousByStreamId,
CloudTableStreamReadStateHelper::getReadStates);
+ }
+
+ public static List<StreamHealth> collect(Env env, long sampleTimeMs,
StreamPendingAgeTracker tracker,
+ Map<Long, StreamHealth> previousByStreamId, CloudStateFetcher
cloudFetcher) {
+ TableStreamManager manager = env.getTableStreamManager();
+ if (manager == null) {
+ return List.of();
+ }
+ Map<Long, Set<Long>> dbStreamMap = manager.copyDbStreamMap();
+ if (dbStreamMap.isEmpty()) {
+ tracker.clear();
+ return List.of();
+ }
+ Long referenceTso = getReferenceTso(env);
+ StreamPendingAgeTracker.Round ageRound = tracker.beginRound();
+ List<StreamHealth> results = Config.isCloudMode()
+ ? collectCloud(env, dbStreamMap, referenceTso, sampleTimeMs,
ageRound, previousByStreamId, cloudFetcher)
+ : collectLocal(env, dbStreamMap, referenceTso, sampleTimeMs,
ageRound);
+ ageRound.commit();
+ return results;
+ }
+
+ public static Long getReferenceTso(Env env) {
+ TSOService tsoService = env.getTSOService();
+ if (tsoService == null) {
+ return null;
+ }
+ TSOService.TSOStatusSnapshot status = tsoService.getStatusSnapshot();
+ return status != null && status.isInitialized() ?
status.getCurrentTso() : null;
+ }
+
+ private static List<StreamHealth> collectLocal(Env env, Map<Long,
Set<Long>> dbStreamMap, Long referenceTso,
+ long sampleTimeMs, StreamPendingAgeTracker.Round ageRound) {
+ List<StreamHealth> results = new ArrayList<>();
+ for (Map.Entry<Long, Set<Long>> entry : dbStreamMap.entrySet()) {
+ Optional<Database> dbOpt =
env.getInternalCatalog().getDb(entry.getKey());
+ if (dbOpt.isEmpty()) {
+ continue;
+ }
+ Database db = dbOpt.get();
+ String dbName = db.getFullName();
+ for (Long tableId : entry.getValue()) {
+ Optional<Table> tableOpt = db.getTable(tableId);
+ if (tableOpt.isEmpty() || !(tableOpt.get() instanceof
OlapTableStream stream)) {
+ continue;
+ }
+ StreamHealth health = sampleLocalStream(dbName, stream,
referenceTso, sampleTimeMs, ageRound);
+ if (health != null) {
+ results.add(health);
+ }
+ }
+ }
+ return results;
+ }
+
+ private static StreamHealth sampleLocalStream(String dbName,
OlapTableStream stream, Long referenceTso,
+ long sampleTimeMs, StreamPendingAgeTracker.Round ageRound) {
+ if (!stream.readLockIfExist()) {
+ return null;
+ }
+ String streamName;
+ long streamId;
+ long streamCreateTimeMs;
+ StreamResumabilityChecker.Result streamLevelResult;
+ boolean hasChangelogTtl = false;
+ Long cutoffTso = null;
+ List<LocalPartitionInput> partitionInputs = Collections.emptyList();
+ try {
+ streamName = stream.getName();
+ streamId = stream.getId();
+ streamCreateTimeMs = stream.getCreateTime() > 0 ?
stream.getCreateTime() * 1000L : 0L;
+ OlapTable baseTable = stream.getBaseTableNullable();
+ if (baseTable == null || !baseTable.readLockIfExist()) {
Review Comment:
Fixed in 16edb51b2d4. Both local and cloud paths in
`OlapStreamMonitorCollector` now resolve the base table quietly before locking
and acquire read locks in ascending `Table::getId` order with a bounded 500ms
`MetaLockUtils.tryReadLockTables` timeout (falling back to preserving prior
state on contention). `OlapTableStream` and `TableStreamManager` now follow the
same ascending table-ID lock order as well.
--
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]