hello-stephen commented on code in PR #71158:
URL: https://github.com/apache/doris/pull/71158#discussion_r4798891400


##########
be/src/exec/sink/vrow_distribution.cpp:
##########
@@ -47,6 +49,13 @@
 
 namespace doris {
 
+bool VRowDistribution::_use_utc_partition_boundaries() const {
+    // A query may be planned by an upgraded Follower while the Master is 
still old.
+    // Local heartbeats also cannot establish a remote Doris Master's 
capabilities.
+    return _vpartition->get_master_address() == nullptr &&

Review Comment:
   [P2] Negotiate automatic RANGE mode with the destination Master
   
   Even when both Doris clusters are upgraded, RemoteOlapTableSink.toThrift 
sets master_address, so this condition always selects local truncation. For a 
remote daily TIMESTAMPTZ auto-range table with no range covering the requested 
day, a New York insert of `2024-11-03 23:30:00-05:00` is Nov 4 04:30Z. The 
local floor is Nov 3 04:00Z (EDT), but PartitionExprUtil adds one UTC day and 
creates a range ending at Nov 4 04:00Z. The batch retry has _deal_batched=true 
and uses the original instant, so OlapTabletFinder filters this valid row as 
having no partition (or the load fails on filtered rows). This leaves the 
DST/local-boundary problem in the fully upgraded remote path. Carry the 
destination Master's capability, rather than the source cluster's heartbeat, 
through the remote sink and cover a remote DST-day insert.



##########
fe/fe-core/src/main/java/org/apache/doris/analysis/PartitionExprUtil.java:
##########
@@ -202,50 +250,158 @@ public static Map<String, AddPartitionOp> 
getAddPartitionClauseFromPartitionValu
                             + "_" + 
Integer.toHexString(partitionName.hashCode());
                     }
                 }
+                if (partitionColumn.stream().anyMatch(column -> 
column.getType().isTimeStampTz())) {
+                    partitionName = 
existingTimestampTzListPartitionName(olapTable, partitionInfo,
+                            PartitionKey.createListPartitionKey(inValues, 
partitionColumn), partitionName);
+                }
             } else {
                 throw new AnalysisException("now only support range and list 
partition");
             }
 
-            Map<String, String> partitionProperties = Maps.newHashMap();
-            DistributionInfo defaultDistributionInfo = 
olapTable.getDefaultDistributionInfo();
-            DistributionDesc distributionDesc = 
defaultDistributionInfo.toDistributionDesc();
-            if (olapTable.isAutoBucket() && partitionType == 
PartitionType.RANGE) {
-                // Use unified auto bucket calculator
-                AutoBucketCalculator.AutoBucketContext context = new 
AutoBucketCalculator.AutoBucketContext(
-                        olapTable, partitionName, partitionName, false,
-                        defaultDistributionInfo.getBucketNum());
-
-                int bucketsNum = 
AutoBucketCalculator.calculateAutoBucketsWithBoundsCheck(context);
-
-                // Only update distribution if calculation was successful 
(bucketsNum != default)
-                if (bucketsNum != defaultDistributionInfo.getBucketNum()) {
-                    if (defaultDistributionInfo.getType() == 
DistributionInfo.DistributionInfoType.HASH) {
-                        HashDistributionInfo hashDistributionInfo = 
(HashDistributionInfo) defaultDistributionInfo;
-                        List<String> distColumnNames = new ArrayList<>();
-                        for (Column distributionColumn : 
hashDistributionInfo.getDistributionColumns()) {
-                            distColumnNames.add(distributionColumn.getName());
-                        }
-                        distributionDesc = new 
HashDistributionDesc(bucketsNum, distColumnNames);
-                    } else {
-                        distributionDesc = new 
RandomDistributionDesc(bucketsNum);
+            Map<String, PartitionKeyDesc> descriptions = Maps.newHashMap();
+            if (partitionType == PartitionType.RANGE && 
partitionColumn.get(0).getType().isTimeStampTz()
+                    && "date_trunc".equalsIgnoreCase(intervalInfo.fnName)) {
+                descriptions = timestampTzRangePartitions(olapTable, 
partitionInfo, partitionName, partitionKeyDesc,
+                        result);
+            } else {
+                descriptions.put(partitionName, partitionKeyDesc);
+            }
+            for (Map.Entry<String, PartitionKeyDesc> entry : 
descriptions.entrySet()) {
+                if (!result.addPartitionOps.containsKey(entry.getKey())) {
+                    result.addPartitionOps.put(entry.getKey(), 
buildAddPartitionOp(
+                            olapTable, partitionType, entry.getKey(), 
entry.getValue()));
+                }
+            }
+        }
+        return result;
+    }
+
+    private static AddPartitionOp buildAddPartitionOp(OlapTable olapTable, 
PartitionType partitionType,
+            String partitionName, PartitionKeyDesc partitionKeyDesc) throws 
AnalysisException {
+        Map<String, String> partitionProperties = Maps.newHashMap();
+        DistributionInfo defaultDistributionInfo = 
olapTable.getDefaultDistributionInfo();
+        DistributionDesc distributionDesc = 
defaultDistributionInfo.toDistributionDesc();
+        if (olapTable.isAutoBucket() && partitionType == PartitionType.RANGE) {
+            // Use unified auto bucket calculator
+            AutoBucketCalculator.AutoBucketContext context = new 
AutoBucketCalculator.AutoBucketContext(
+                    olapTable, partitionName, partitionName, false,
+                    defaultDistributionInfo.getBucketNum());
+
+            int bucketsNum = 
AutoBucketCalculator.calculateAutoBucketsWithBoundsCheck(context);
+
+            // Only update distribution if calculation was successful 
(bucketsNum != default)
+            if (bucketsNum != defaultDistributionInfo.getBucketNum()) {
+                if (defaultDistributionInfo.getType() == 
DistributionInfo.DistributionInfoType.HASH) {
+                    HashDistributionInfo hashDistributionInfo = 
(HashDistributionInfo) defaultDistributionInfo;
+                    List<String> distColumnNames = new ArrayList<>();
+                    for (Column distributionColumn : 
hashDistributionInfo.getDistributionColumns()) {
+                        distColumnNames.add(distributionColumn.getName());
                     }
+                    distributionDesc = new HashDistributionDesc(bucketsNum, 
distColumnNames);
+                } else {
+                    distributionDesc = new RandomDistributionDesc(bucketsNum);
                 }
             }
+        }
 
-            SinglePartitionDesc singleRangePartitionDesc = new 
SinglePartitionDesc(true, partitionName,
-                    partitionKeyDesc, partitionProperties);
-            // iff table's storage medium is not equal default storage medium,
-            // should add storage medium in partition properties
-            if 
(!DataProperty.DEFAULT_STORAGE_MEDIUM.equals(olapTable.getStorageMedium())) {
-                
partitionProperties.put(PropertyAnalyzer.PROPERTIES_STORAGE_MEDIUM,
-                        olapTable.getStorageMedium().name());
+        SinglePartitionDesc singleRangePartitionDesc = new 
SinglePartitionDesc(true, partitionName,
+                partitionKeyDesc, partitionProperties);
+        // iff table's storage medium is not equal default storage medium,
+        // should add storage medium in partition properties
+        if 
(!DataProperty.DEFAULT_STORAGE_MEDIUM.equals(olapTable.getStorageMedium())) {
+            partitionProperties.put(PropertyAnalyzer.PROPERTIES_STORAGE_MEDIUM,
+                    olapTable.getStorageMedium().name());
+        }
+        AddPartitionOp addPartitionClause = new AddPartitionOp(
+                singleRangePartitionDesc.translateToPartitionDefinition(),
+                distributionDesc.toDistributionDescriptor(), 
partitionProperties, false);
+        return addPartitionClause;
+    }
+
+    private static String existingTimestampTzListPartitionName(OlapTable 
table, PartitionInfo partitionInfo,
+            PartitionKey key, String canonicalName) {
+        table.readLock();
+        try {
+            if (table.checkPartitionNameExist(canonicalName)) {
+                return canonicalName;
             }
-            AddPartitionOp addPartitionClause = new AddPartitionOp(
-                    singleRangePartitionDesc.translateToPartitionDefinition(),
-                    distributionDesc.toDistributionDescriptor(), 
partitionProperties, false);
-            result.put(partitionName, addPartitionClause);
+            // Older writers named partitions with their local offset. Reuse 
the same key even
+            // when that persisted partition's name differs from today's UTC 
spelling.
+            for (Map.Entry<Long, PartitionItem> entry : 
partitionInfo.getIdToItem(false).entrySet()) {

Review Comment:
   [P3] Look up existing LIST keys once per automatic-partition request
   
   For every distinct missing TIMESTAMPTZ key with no canonical-name match, 
this loop scans all formal LIST items while holding the table read lock. A 
table at the default limit of 20,000 single-key partitions and a batch of 8,192 
new keys can perform about 164 million key comparisons before 
FrontendServiceImpl even reaches its max_auto_partition_num rejection. 
Previously, LIST planning on this rejected request needed only names and 
descriptors, with no DDL/key-history validation. Please build a request-local 
key-to-formal-partition lookup (or reuse an existing index) once, while 
retaining the catalog's final uniqueness checks. This is separate from the 
now-fixed repeated auto-bucket sizing for reused RANGE partitions.



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