github-actions[bot] commented on code in PR #71005:
URL: https://github.com/apache/doris/pull/71005#discussion_r4691559500


##########
fe/fe-core/src/main/java/org/apache/doris/common/util/FetchRemoteTabletSchemaUtil.java:
##########
@@ -62,12 +68,73 @@
 public class FetchRemoteTabletSchemaUtil {
     private static final Logger LOG = 
LogManager.getLogger(FetchRemoteTabletSchemaUtil.class);
 
-    private final List<Tablet> remoteTablets;
-    private final List<Column> tableColumns;
+    private final int tabletCount;
+    private final Map<Long, List<Replica>> tabletReplicas = 
Maps.newLinkedHashMap();
 
+    /** Capture the candidate replica lists under the table lock and resolve 
Cloud routes during fetch. */
     public FetchRemoteTabletSchemaUtil(List<Tablet> tablets) {
-        this.remoteTablets = tablets;
-        this.tableColumns = Lists.newArrayList();
+        tabletCount = tablets.size();
+        for (Tablet tablet : tablets) {
+            tabletReplicas.put(tablet.getId(), 
Lists.newArrayList(tablet.getReplicas()));
+        }
+    }
+
+    public record PartitionTablets(Partition partition, List<Tablet> tablets) {
+    }
+
+    /** Capture tablet lists under the table lock. Cloud visibility can 
require a separate RPC. */
+    public static List<PartitionTablets> 
snapshotPartitions(Collection<Partition> partitions) {
+        boolean cloudMode = Config.isCloudMode();
+        List<PartitionTablets> snapshot = Lists.newArrayList();
+        for (Partition partition : partitions) {
+            if (cloudMode || partition.getVisibleVersion() > 
Partition.PARTITION_INIT_VERSION) {
+                snapshot.add(new PartitionTablets(partition, 
partition.getBaseIndex().getTablets()));
+            }
+        }
+        return snapshot;
+    }
+
+    public static List<Tablet> collectTablets(List<PartitionTablets> 
partitions) throws AnalysisException {
+        if (partitions.isEmpty()) {
+            return Collections.emptyList();
+        }
+        boolean cloudMode = Config.isCloudMode();
+        List<Long> cloudVersions = cloudMode ? 
getCloudVisibleVersions(partitions) : List.of();
+        int maxTablets = 
ConnectContext.get().getSessionVariable().maxFetchRemoteTabletCount;

Review Comment:
   [P2] Forward the session tablet limit for SHOW PROC
   
   This new hard-limit read also runs on the master for forwarded SHOW PROC, 
but `SessionVariable.maxFetchRemoteTabletCount` has no `needForward` or 
affect-result flag, so both session forwarding maps omit it. On a follower with 
the default `forward_to_master=true`, set `describe_extend_variant_column=true` 
and `max_fetch_remote_schema_tablet_count=2048`, then SHOW PROC the schema of a 
600-tablet table: the master receives the extended-DESC flag but constructs a 
fresh session with limit 512, and this path now throws despite the caller 
selecting 2048. Local DESC succeeds with the same setting; before this PR the 
remote default only changed sampling instead of causing this hard failure. 
Forward the tablet limit and add coverage for a follower session whose limit 
differs from the master default.



##########
fe/fe-core/src/main/java/org/apache/doris/common/proc/RemoteIndexSchemaProcNode.java:
##########
@@ -43,36 +36,27 @@ public class RemoteIndexSchemaProcNode implements 
ProcNodeInterface {
             .add("Default").add("Extra")
             .build();
 
-    private List<Partition> partitions;
-    private List<Column> schema;
-    private Set<String> bfColumns;
+    @FunctionalInterface
+    interface RemoteSchemaFetcher {
+        List<Column> fetch() throws AnalysisException;
+    }
+
+    private final ProcResult baseSchema;
+    private final Set<String> bfColumns;
+    private final RemoteSchemaFetcher remoteSchemaFetcher;
 
-    public RemoteIndexSchemaProcNode(List<Partition> partitions, List<Column> 
schema, Set<String> bfColumns) {
-        this.partitions = partitions;
-        this.schema = schema;
+    RemoteIndexSchemaProcNode(ProcResult baseSchema, Set<String> bfColumns, 
RemoteSchemaFetcher remoteSchemaFetcher) {
+        this.baseSchema = baseSchema;
         this.bfColumns = bfColumns;
+        this.remoteSchemaFetcher = remoteSchemaFetcher;
     }
 
     @Override
     public ProcResult fetchResult() throws AnalysisException {
-        Preconditions.checkNotNull(schema);
-        Preconditions.checkNotNull(partitions);
-        List<Tablet> tablets = Lists.newArrayList();
-        for (Partition partition : partitions) {
-            MaterializedIndex idx = partition.getBaseIndex();
-            for (Tablet tablet : idx.getTablets()) {
-                tablets.add(tablet);
-            }
-        }
-        // Get the maximum number of Remote Tablets that can be fetched
-        int maxFetchCount = 
ConnectContext.get().getSessionVariable().maxFetchRemoteTabletCount;
-        // If the number of tablets is greater than the maximum fetch count, 
randomly select maxFetchCount tablets
-        if (tablets.size() > maxFetchCount) {
-            Collections.shuffle(tablets);
-            tablets = tablets.subList(0, maxFetchCount);
-        }
-        List<Column> remoteSchema = new 
FetchRemoteTabletSchemaUtil(tablets).fetch();
-        this.schema.addAll(remoteSchema);
-        return IndexSchemaProcNode.createResult(this.schema, this.bfColumns, 
Lists.newArrayList());
+        List<Column> remoteSchema = remoteSchemaFetcher.fetch();
+        ProcResult remoteResult = 
IndexSchemaProcNode.createResult(remoteSchema, bfColumns, List.of());
+        BaseProcResult result = new 
BaseProcResult(baseSchema.getColumnNames(), new 
ArrayList<>(baseSchema.getRows()));
+        result.addRows(remoteResult.getRows());

Review Comment:
   [P2] Keep remote paths aligned with the captured catalog schema
   
   The saved base rows can belong to an older schema than the remote columns 
appended here. For a nonempty table with `id, v VARIANT`, let DESC capture its 
snapshot, then complete a light `ALTER TABLE t ADD COLUMN extra VARIANT DEFAULT 
NULL` and an INSERT containing `extra={"k":1}` before the worker reads those 
same tablets (e.g. while the Cloud version lookup is paused). The load updates 
the BE's current tablet schema; the coordinator returns `extra.k` after 
stripping root columns, while `baseSchema` still omits `extra`. DESC therefore 
succeeds with a schema matching neither catalog version. Its old outer read 
lock prevented this ALTER interleaving. Keep remote work outside the lock, but 
bind it to the captured schema or revalidate its version and retry/fail before 
combining the rows. Please cover a concurrent light ADD with nonempty remote 
columns; the new index-replacement unit test returns an empty remote schema.



-- 
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]

Reply via email to