airborne12 opened a new pull request, #71216:
URL: https://github.com/apache/doris/pull/71216

   ### Background
   
   `DROP INDEX idx ON t PARTITION (p)` and `ALTER TABLE t DROP INDEX idx 
PARTITION (p)` (#62181) delete the inverted index files of the named partitions 
and keep the index in the table schema. In shared-nothing mode the FE submits 
one index change job per partition, and each BE task rewrites the tablet's 
rowsets without the index. A partition with a `storage_policy` moves its 
rowsets to remote storage once they reach the policy's cooldown time; the BE 
keeps their meta locally and reads their data and index files from the remote 
storage.
   
   ### What problem does this PR solve?
   
   Issue Number: None
   Related PR: #62181 (introduced DROP INDEX ON PARTITION), #70357 (same 
feature on branch-4.1, has the bug), #70352 (same feature for branch-4.2, open, 
has the bug; its review found this), #71041 (rejects the statement in cloud 
mode), #71043, #71122, #71128, #71130 (open, edit the same block of 
SchemaChangeHandler)
   PR Type: Bugfix
   
   Problem Summary:
   
   When a named partition has rowsets on remote storage, a partition drop 
reports success and its job reaches FINISHED, but the BE task skips the remote 
rowsets: they keep their index files and the index in their rowset schema, and 
since the table schema keeps the index too, queries on the partition keep using 
it. This PR rejects the statement before any job is created when a named 
partition has a storage policy or reports remote data. Partitions with neither 
still work.
   
   On a shared-nothing table whose partition `p1` has a storage policy:
   
   ```sql
   ALTER TABLE t DROP INDEX idx_v1 PARTITION (p1);
   ```
   
   | | Result |
   |---|---|
   | Before | Accepted; an index change job for `p1` is created |
   | After | Fails with `DROP INDEX ON PARTITION is not supported for partition 
p1 because it has a storage policy or data in remote storage`; no job is 
created |
   
   ### Details
   
   - **Frequency:** Always, in shared-nothing mode, for a partition drop on a 
partition with rowsets on remote storage. Not observed in a cluster; found by 
code review of #70352.
   - **Root cause:** `SchemaChangeHandler` accepts a partition drop without 
looking at where the partition's data is. On the BE, 
`Tablet::pick_candidate_rowsets_to_build_inverted_index` picks only local 
rowsets (`rs->is_local()`), and `IndexBuilder::do_build_inverted_index` returns 
OK when it picked none, so the task finishes without touching the remote 
rowsets.
   - **Why existing tests missed it:** Unit tests: the partition-drop cases in 
`SchemaChangeHandlerTest` and `IndexChangeJobTest` use tables without a storage 
policy. Regression: 
`inverted_index_p0/index_change/test_drop_index_on_partition` has no storage 
policy and checks job states, the index metadata, and query results; no suite 
combines a partition drop with cold data.
   - **Fix:** Reject the statement when a named partition has a storage policy 
in its data property or reports remote data. The policy is the main check: the 
BE cools rowsets only for tablets with a storage policy 
(`Tablet::_get_newest_cooldown_time` returns 0 without one), at any moment, 
also while the job runs, whereas the reported remote size and cooldown meta lag 
by a report interval. The remote size covers a partition whose policy was 
cancelled after some data cooled, which the cancel check, working from the same 
reports, can let through. Dropping the index from remote rowsets is not 
implemented.
   - **Other paths and branches:** Cloud mode already rejects partition drops 
(#71041). A full-table `DROP INDEX` removes the index from the table schema, so 
it is not affected. `BUILD INDEX ... PARTITION` also skips remote rowsets and 
is not changed here. Master has the bug since #62181, branch-4.1 through 
#70357, and branch-4.2 will with #70352; branch-4.0 and branch-3.1 lack the 
statement.
   - **Behavior change:** In shared-nothing mode, a partition drop on a 
partition with a storage policy now fails even when none of its data has cooled 
yet, since it can cool while the job runs.
   
   ### Testing
   
   All runs were local FE unit tests on master 5d3b20272b8 plus this change.
   
   - New 
`SchemaChangeHandlerTest#testDropIndexOnPartitionRejectsPartitionThatMayHoldRemoteData`:
 `p1` has a storage policy, `p2` has none but reports remote data, `p3` has 
neither. Drops on `p1`, `p2`, and `p3, p1` fail with the new error and create 
no job; a drop on `p3` creates its job and keeps the index. On the unfixed code 
it fails at the first drop (`Expected java.lang.Exception to be thrown, but 
nothing was thrown`); with only the policy check, at the `p2` drop.
   - `SchemaChangeHandlerTest` (47 tests) and `IndexChangeJobTest` (23 tests) 
pass; `build.sh --fe` reports 0 checkstyle violations.
   
   ### Notes for Reviewers
   
   - #71043, #71122, #71128, and #71130 also edit the partition-drop block of 
`SchemaChangeHandler`; whichever merges later needs a rebase there.
   
   ### Release note
   
   In shared-nothing mode, `DROP INDEX ... ON PARTITION` and `ALTER TABLE ... 
DROP INDEX ... PARTITION` now fail with `DROP INDEX ON PARTITION is not 
supported for partition <p> because it has a storage policy or data in remote 
storage` for a partition that has a storage policy or data on remote storage, 
instead of finishing without dropping the index from the remote data.
   
   ### Check List (For Author)
   
   - Behavior changed: Yes (see Details)
   - Does this need documentation: Yes, the DROP INDEX page of 
apache/doris-website should note that a partition drop is rejected for 
partitions with a storage policy or remote data; not written yet
   - Pre-submission status: Partially verified: no cluster run with data on 
remote storage; the BE side of the problem comes from reading the code
   
   ### AI Disclosure
   
   - Tool: Claude Code (Claude Opus 5.5)
   - Generated: code, tests, this description
   - Human review: not stated
   - Prompts: Fix two FE findings from the review of the branch-4.2 backport 
#70352 on master, one PR each; for this one, reject the partition drop when a 
chosen partition has cooled data, using the check that is true exactly when 
remote rowsets can exist, without implementing remote index removal, and add an 
FE unit test that fails without the fix.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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