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


##########
fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java:
##########
@@ -2670,9 +2670,19 @@ public int getAsInt() {
                         }
                         Set<String> specifiedPartitions = new 
HashSet<>(dropIndexOp.getPartitionNames());
                         for (String partName : specifiedPartitions) {
-                            if (olapTable.getPartition(partName) == null) {
+                            Partition partition = 
olapTable.getPartition(partName);
+                            if (partition == null) {
                                 throw new DdlException("partition " + partName 
+ " does not exist");
                             }
+                            // The BE drops the index only from local rowsets. 
A partition with a storage policy
+                            // can move rowsets to remote storage at any time, 
and one whose policy was cancelled
+                            // can still hold remote rowsets, so the index of 
those rowsets would stay.
+                            String storagePolicy = 
olapTable.getPartitionInfo().getDataProperty(partition.getId())
+                                    .getStoragePolicy();
+                            if (!Strings.isNullOrEmpty(storagePolicy) || 
partition.getRemoteDataSize() > 0) {

Review Comment:
   Confirmed and fixed in 6e6246dca00.
   
   The window was real. A partition drop job can wait in WAITING_TXN for 
earlier loads while the table stays NORMAL, so another session could run 
`MODIFY PARTITION ... SET ("storage_policy" = ...)` or the table-level `SET 
("storage_policy" = ...)`, and rowsets could cool before the index task ran.
   
   The fix follows how a schema change already refuses to start while an index 
change job on the table is unfinished (`createJob` / 
`hasIndexChangeJobOnTable`):
   
   - Both ALTER paths now fail with `partition <p> of table <t> has an 
unfinished DROP INDEX ... PARTITION job, please set the storage policy after it 
finishes.` when a named partition (every partition, for the table property) has 
an unfinished partition drop job. The check runs before the tablet meta update 
goes to the BE. An empty policy is still allowed.
   - For the in-flight window, the job checks the partition again under the 
table lock right before it sends its tasks. This covers a MODIFY PARTITION that 
sent the policy to the BE before it updated the DataProperty, and remote data 
reported after the statement. If the partition can now hold remote data, the 
job is cancelled with the statement's error. A table-wide DROP INDEX job is not 
affected, because it removes the index from the schema; the job tells the two 
apart by whether the dropped index is still in the table schema.
   
   One gap remains, and the PR description lists it: the policy reaches the BE, 
a drop on that partition is accepted, and its job sends its tasks, all before 
the MODIFY PARTITION statement writes the DataProperty, which it does right 
after the BE acknowledges. Closing that needs the FE meta written before the BE 
update, or a check on the BE. I kept this change FE-only.
   
   Tests:
   - 
`SchemaChangeHandlerTest#testStoragePolicyRejectedWhileDropIndexOnPartitionIsUnfinished`
 keeps the drop job in WAITING_TXN behind an open load. It checks that `MODIFY 
PARTITION (p1)`, `MODIFY PARTITION (*)` and the table-level SET are rejected, 
that p2 can still get the policy, and that p1 can once its job is done.
   - 
`#testDropIndexOnPartitionJobCancelledIfPartitionMayHoldRemoteDataWhenItStarts` 
gives the partitions a policy or remote data while their jobs wait, then lets 
the jobs start. The affected jobs are CANCELLED; the job on the untouched 
partition and the table-wide drop jobs run.
   
   Both tests fail on the previous head.
   



##########
fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java:
##########
@@ -2670,9 +2670,19 @@ public int getAsInt() {
                         }
                         Set<String> specifiedPartitions = new 
HashSet<>(dropIndexOp.getPartitionNames());
                         for (String partName : specifiedPartitions) {
-                            if (olapTable.getPartition(partName) == null) {
+                            Partition partition = 
olapTable.getPartition(partName);
+                            if (partition == null) {
                                 throw new DdlException("partition " + partName 
+ " does not exist");
                             }
+                            // The BE drops the index only from local rowsets. 
A partition with a storage policy
+                            // can move rowsets to remote storage at any time, 
and one whose policy was cancelled
+                            // can still hold remote rowsets, so the index of 
those rowsets would stay.
+                            String storagePolicy = 
olapTable.getPartitionInfo().getDataProperty(partition.getId())

Review Comment:
   Confirmed and fixed in 6e6246dca00.
   
   I reproduced it in an FE unit test. On a table with a `storage_policy`, 
`ALTER TABLE t ADD PARTITION p2 VALUES LESS THAN ("20") DISTRIBUTED BY HASH(k1) 
BUCKETS 1 PROPERTIES ('storage_policy' = '')` leaves p2's DataProperty policy 
empty, and the partition drop on p2 was accepted.
   
   The check now counts the table's storage policy as well as the partition's. 
This is the same fallback `InternalCatalog.addPartition` uses for the tablets. 
A heavy schema change (`SchemaChangeJobV2`) and replica re-creation from tablet 
reports (`ReportHandler`) also create tablets with the table's policy. So a 
partition of a table with a storage policy can get that policy on the BE even 
when its own is empty.
   
   As a result, some partitions whose tablets have no policy right now are 
rejected too, such as a partition whose policy was cancelled with MODIFY 
PARTITION while its table keeps one. I took that as the safe side. The job's 
start-time check uses the same condition.
   
   Test: 
`SchemaChangeHandlerTest#testDropIndexOnPartitionRejectsPartitionGettingTablePolicy`.
 It fails on the previous head.
   



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