jayzhan211 opened a new pull request, #71110: URL: https://github.com/apache/doris/pull/71110
### Background When a load into an auto-partition table meets a row with no partition, the BE asks the master FE to create one through the `createPartition` thrift RPC, then routes the buffered rows to it. `INSERT OVERWRITE` with auto-detected partitions calls `replacePartition` the same way. Right after a master switch, the BE can still call an FE that is now a follower. `status` is optional in both results. ### What problem does this PR solve? Issue Number: close #70258 Related PR: #24412 (introduced the bug in createPartition), #32156 (copied it into replacePartition) PR Type: Bugfix Problem Summary: A follower FE answers either RPC without `status`. The BE reads the unset field as a default `TStatus`, whose code is `OK`, and goes on as if the partitions were made. For `createPartition`, the rows that needed them are then counted as filtered, so a load that tolerates filtered rows succeeds without them. This PR sets the `NOT_MASTER` status that the handler already builds, so the load fails with `FE is not master`. `createPartition` on a live follower FE, read by a client built from the BE's thrift code: | | Before the fix | With the fix | |---|---|---| | `result.__isset.status` | `false` | `true` | | `result.status.status_code` | `OK` | `NOT_MASTER` | | `result.status.error_msgs` | `[]` | `["FE is not master"]` | | Branch taken in `VRowDistribution` | success, 0 partitions | returns the error | ### Details - **Frequency:** Not observed; found by code review in #70258. Triggers when a BE calls an FE that is no longer the master, such as an old master restarted as a follower. - **Root cause:** The non-master branch of `FrontendServiceImpl.createPartition` and `replacePartition` returns before `result.setStatus(errorStatus)`. The generated C++ `TStatus` starts with code 0, `OK`, and `VRowDistribution` does not check `__isset.status`. - **Why existing tests missed it:** Unit tests: the createPartition and replacePartition cases in `FrontendServiceImplTest` all run on the master FE, and `vrow_distribution_test.cpp` injects results that always set a status. Regression: the auto partition suites run on one FE, where the BE always reaches the master. - **Fix:** Set the status, as the other error branches of both handlers do. The BE already fails on `NOT_MASTER`. - **Other paths and branches:** Every other non-master branch in `FrontendServiceImpl` sets its status. Making the BE reject an unset `status` is left out. `branch-3.1`, `branch-4.0`, `branch-4.1`, and `branch-4.2` have both bugs. ### Testing - New `FrontendServiceImplTest#testPartitionRpcsOnFollowerReturnNotMaster`: fails on master `3933c9d672` with `the result must carry a status`, fails at the `replacePartition` call when only the `createPartition` line is fixed, and passes with the fix, as do the other 40 tests in the class. Run locally. - A master FE and a follower FE built with `build.sh --fe`, run in Docker: the table above, before and after (output below). Not run: a load through a BE during a master switch; the filtering is traced in the BE code. <details> <summary>Output of the real FE pair, before and after</summary> Before (baseline `doris-fe.jar`, follower fe2): ```text createPartition on 127.0.0.1:19120 result.__isset.status = false result.status.status_code = OK (OK) result.status.error_msgs = [] result.partitions.size() = 0 BE takes the success branch with 0 partition(s) and returns OK replacePartition on 127.0.0.1:19120 result.__isset.status = false result.status.status_code = OK (OK) result.status.error_msgs = [] result.partitions.size() = 0 BE takes the success branch with 0 partition(s) and returns OK ``` The follower logged `failed to createPartition: FE is not master` and `failed to replace Partition: FE is not master` for these calls. After (fixed `doris-fe.jar`; after a restart fe2 won the election, so the follower is fe1, the old master): ```text createPartition on 127.0.0.1:19020 result.__isset.status = true result.status.status_code = NOT_MASTER (NOT_MASTER) result.status.error_msgs = ["FE is not master"] result.partitions.size() = 0 BE returns the error status, so the load fails replacePartition on 127.0.0.1:19020 result.__isset.status = true result.status.status_code = NOT_MASTER (NOT_MASTER) result.status.error_msgs = ["FE is not master"] result.partitions.size() = 0 BE returns the error status, so the load fails ``` For contrast, the master's own error branches already set the status: a request with an unknown db id gets `RUNTIME_ERROR` with `dbId=999999999 is not exists`, before and after. The client is generated from `gensrc/thrift` with the BE's flags (`--gen cpp:moveable_types,no_skeleton`) and uses `TBufferedTransport` with `TBinaryProtocol`. After the call, it applies the BE's check: `result.status.status_code == TStatusCode::OK`. A row with no partition is filtered on replay because `VTabletWriter::_send_new_partition_batch` writes the buffered block with `_deal_batched = true`, which routes through `OlapTabletFinder::find_tablets` without a missing-rows list. </details> ### Release note Auto partition loads and auto-detect INSERT OVERWRITE no longer treat a follower FE's refusal to create or replace partitions as success; they fail with `FE is not master`. ### Check List (For Author) - Behavior changed: No - Does this need documentation: No - Pre-submission status: Partially verified: no load ran through a BE during a master switch. ### AI Disclosure - Tool: Claude Code (Claude Opus 5.5) - Generated: the fix, the test, and this description - Human review: not stated - Prompts: Asked for a draft PR with as much evidence as practical, first for #70529 (already fixed on master), then for another open issue; the agent chose #70258. -- 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]
