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


##########
fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java:
##########
@@ -4094,6 +4096,40 @@ private static boolean 
isConflictingIndexChangeJob(IndexChangeJob indexChangeJob
                 && !indexChangeJob.isDone();
     }
 
+    // Throws if the BE can keep rowsets of the partition in remote storage, 
where it does not drop an index.
+    // New tablets of a partition without its own storage policy get the 
table's policy, so that one counts too.
+    static void checkPartitionHoldsOnlyLocalData(OlapTable olapTable, 
Partition partition) throws DdlException {
+        String storagePolicy = 
olapTable.getPartitionInfo().getDataProperty(partition.getId()).getStoragePolicy();
+        if (!Strings.isNullOrEmpty(storagePolicy) || 
!Strings.isNullOrEmpty(olapTable.getStoragePolicy())
+                || partition.getRemoteDataSize() > 0) {
+            throw new DdlException("DROP INDEX ON PARTITION is not supported 
for partition " + partition.getName()
+                    + " because it has a storage policy or data in remote 
storage");
+        }
+    }
+
+    // Throws if a storage policy is set on a partition with an unfinished 
DROP INDEX ... PARTITION job, since
+    // rowsets that cool before the job runs would keep the index.
+    public void checkCanSetStoragePolicy(Database db, OlapTable olapTable, 
Collection<String> partitionNames,
+            String storagePolicy) throws DdlException {
+        if (Strings.isNullOrEmpty(storagePolicy)) {
+            return;
+        }
+        olapTable.readLock();
+        try {
+            for (IndexChangeJob indexChangeJob : 
ImmutableList.copyOf(indexChangeJobs.values())) {
+                if (indexChangeJob.getDbId() == db.getId() && 
indexChangeJob.getTableId() == olapTable.getId()
+                        && !indexChangeJob.isDone() && 
partitionNames.contains(indexChangeJob.getPartitionName())

Review Comment:
   Confirmed and fixed in df66c2715ab.
   
   `IndexChangeJob` now exposes `getPartitionId()`, and 
`SchemaChangeHandler.checkCanSetStoragePolicy` resolves target partition names 
(or reads `olapTable.getPartitionIds()` directly via a new table-level 
overload) under `olapTable.readLock()`, matches 
`indexChangeJob.getPartitionId()`, and formats the error with the partition's 
current name 
(`olapTable.getPartition(indexChangeJob.getPartitionId()).getName()`).
   
   Test: 
`SchemaChangeHandlerTest#testStoragePolicyRejectedAfterRenamingPartitionWithRunningDropIndexJob`
 moves a `DROP INDEX ... PARTITION (p1)` job to `RUNNING`, renames `p1` to 
`p_new`, and checks that `MODIFY PARTITION (p_new)`, `MODIFY PARTITION (*)`, 
and table-level `SET ("storage_policy" = ...)` are rejected naming `p_new`, 
while `p2` can still get a policy and `p_new` can once the job finishes. Fails 
before the fix and passes after.



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