re20052 commented on code in PR #66187:
URL: https://github.com/apache/doris/pull/66187#discussion_r4611477047


##########
fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java:
##########
@@ -1539,6 +1539,67 @@ public Partition dropPartitionForTruncate(long dbId, 
boolean isForceDrop,
      *
      */
 
+    @Override
+    public Partition getMaxVisiblePartition() {
+        PartitionInfo partitionInfo = getPartitionInfo();
+        PartitionType type = partitionInfo.getType();
+        // Cloud mode: prefetch all visible versions in one batch RPC so the 
loop below hits
+        // cache instead of firing N sequential meta-service RPCs under 
metadata locks.
+        if (Config.isCloudMode()) {
+            try {
+                getVersionInBatchForCloudMode(nameToPartition.values().stream()
+                        .map(Partition::getId).collect(Collectors.toList()));
+            } catch (RpcException e) {
+                LOG.warn("batch prefetch visible version failed, fallback to 
per-partition lookup", e);
+            }
+        }
+        if (type == PartitionType.UNPARTITIONED) {
+            for (Partition partition : nameToPartition.values()) {
+                if (partition.getVisibleVersion() > 
Partition.PARTITION_INIT_VERSION) {
+                    return partition;
+                }
+            }
+            return null;
+        }
+        // RANGE/LIST: pick the visible partition with the greatest key (RANGE 
by upper bound,
+        // LIST by max discrete key). A LIST default partition is only a 
last-resort fallback.
+        Partition result = null;
+        PartitionKey maxKey = null;
+        Partition defaultFallback = null;
+        for (Partition partition : nameToPartition.values()) {
+            if (partition.getVisibleVersion() <= 
Partition.PARTITION_INIT_VERSION) {

Review Comment:
   Fixed in 58b82a6a74a.
   
   getVersionInBatchForCloudMode() now returns the partition ID to 
visible-version mapping from the batch lookup. getMaxVisiblePartition() 
consumes that mapping directly for both unpartitioned and RANGE/LIST partition 
selection, instead of rereading each partition through getVisibleVersion().
   
   This avoids relying on cache side effects and eliminates the batch lookup 
followed by N sequential version RPCs.



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