airborne12 commented on code in PR #71137:
URL: https://github.com/apache/doris/pull/71137#discussion_r4746882000


##########
fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java:
##########
@@ -3914,6 +3962,278 @@ private String getCloudClusterName() throws 
UserException {
         return clusterName;
     }
 
+    // How one ADD INDEX runs: LIGHT only changes metadata, so only data 
written afterwards gets the index;
+    // LIGHT_AND_BUILD also builds the existing data of every partition 
through index change jobs;
+    // HEAVY rewrites the existing data in a schema change job.
+    private enum AddIndexPath { LIGHT, LIGHT_AND_BUILD, HEAVY }
+
+    // Resolves the path of every ADD INDEX in alterOps. An index added with 
BUILD DEFERRED keeps the existing
+    // data unindexed, so it can not share a statement with a clause that 
rewrites or changes that data.
+    private static Map<CreateIndexOp, AddIndexPath> 
resolveAddIndexPaths(List<AlterOp> alterOps,
+            OlapTable olapTable, boolean enableAddIndexForNewData) throws 
DdlException {
+        boolean onlyAddIndex = alterOps.stream().allMatch(alterOp -> alterOp 
instanceof CreateIndexOp);
+        boolean sniiTable = olapTable.getInvertedIndexFileStorageFormat() == 
TInvertedIndexFileStorageFormat.SNII;
+        boolean tableHasValuesIndex = 
olapTable.getIndexes().stream().anyMatch(Index::isVariantValuesIndex);
+        // A partition with a storage policy may hold rowsets that have cooled 
to remote storage.
+        boolean mayHaveCooledData = 
olapTable.getPartitionIds().stream().anyMatch(partitionId ->

Review Comment:
   Confirmed and fixed: f7abd3baf27 and 9b0a0144509 on #71130, merged here, 
plus 0b6ae9a465f here.
   
   Setting a non-empty storage policy, on the table or on partitions, now fails 
while the table has a BUILD INDEX job that has not finished or, after a 
failover, pending BUILD IMMEDIATE builds the master has not submitted yet; the 
message says to wait for the jobs or cancel them. This also covers a manual 
BUILD INDEX, which had the same gap. Removing a policy is still allowed.
   
   The check is serialized with BUILD IMMEDIATE, which picks its path and 
submits its jobs under the table write lock: ALTER TABLE ... SET checks and 
sets the table policy under that lock, and MODIFY PARTITION ... SET reserves 
the change under it before sending the policy to BE, releasing it after the 
partition metadata changes. BUILD IMMEDIATE treats a table policy or a reserved 
change like a partition policy and runs the heavy schema change. So either the 
policy is rejected because build jobs exist, or BUILD IMMEDIATE sees it.
   
   `SchemaChangeHandlerTest#testStoragePolicyRejectedWhileBuildIndexJobsRun`, 
`#testStoragePolicyRejectedWhilePendingIndexBuildsRemain` and 
`#testAddIndexBuildImmediateRunsHeavyWhileStoragePolicyIsSet` each failed 
before their change and pass now; `ModifyPartitionStoragePolicyTest` still 
passes.
   



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