biley06 opened a new issue, #71164:
URL: https://github.com/apache/doris/issues/71164

   ### Search before asking
   
   - [x] I had searched in the 
[issues](https://github.com/apache/doris/issues?q=is%3Aissue) and found no 
similar issues.
   
   
   ### Version
   
   master (dc5517d7afb) and 4.1.5-release. Compute-storage decoupled (cloud) 
mode.
   
      
fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudTabletRebalancer.java
      - master: checkInflightWarmUpCacheAsync(), L893-907
      - 4.1.5-release: L863-877
   
   ### What's Wrong?
   
   
   When the destination backend of inflight rebalance warm-up tasks no longer 
exists (or has been dead longer than `rehash_tablet_after_be_dead_seconds`), 
`checkInflightWarmUpCacheAsync()` removes its tasks like this:
   
   ```java
   List<InfightTablet> toRemove = new LinkedList<>();
   for (InfightTask task : entry.getValue()) {                    // T = 
inflight tasks of that backend
       for (InfightTablet key : tabletToInfightTask.keySet()) {   // N = all 
inflight tasks, all compute groups
           toRemove.add(new InfightTablet(task.pickedTabletId, key.clusterId));
       }
   }
   for (InfightTablet key : toRemove) {
       tabletToInfightTask.remove(key);
   }
   ```
   
   `InfightTask` does not store its cluster id, so the key of each task is 
guessed by pairing its tablet id with the cluster id of every key in the map. 
This has three problems:
   
   1. **Memory.** It allocates T x N `InfightTablet` objects plus `LinkedList` 
nodes. All of them stay reachable from `toRemove` until the loop ends, so GC 
cannot reclaim them. With thousands of inflight tasks the old generation fills 
up and full GCs run back to back without freeing memory.
   
   2. **No recovery.** The method runs every 10 s on the `cloud-warmup-checker` 
thread, which catches `Throwable`. If the loop fails (e.g. `OutOfMemoryError`), 
the tasks are not removed and the next run repeats the same allocation, until 
the FE is restarted. While those tasks remain, `statRouteInfo()` keeps counting 
their tablets on the missing backend in the future route maps, which also skews 
rebalance decisions.
   
   3. **Wrong removals in other compute groups.** Tablet ids are shared by all 
compute groups, and a backend belongs to exactly one compute group (tasks are 
created only by `preheatAndUpdateTablet`, with the destination picked from that 
group's backends). When tablet `t` is inflight in group A towards the dropped 
backend and also inflight in group B towards a healthy backend, the loop also 
removes `(t, B)`. Group B's warm-up still completes, but 
`handleWarmupCompletion` then logs `cannot find inflight task` and never 
switches the mapping, so the warm-up is wasted and B's rebalance is repeated.
   
   We observed this in a cloud-mode cluster: after a backend with many inflight 
warm-up tasks was removed, the master FE showed long old-generation GC pauses 
that did not reclaim heap.
   
   A standalone replica of the loop (JDK 8, `-Xmx1g`, same key class, same 
loop) shows the scaling:
   
   | tasks of dropped BE / total inflight | current loop | single pass over the 
map |
   |---|---|---|
   | 2,000 / 4,001 | 3.4 s, 8,002,000 keys allocated; also removed the other 
group's task | 5 ms |
   | 10,000 / 20,001 | not finished after 120 s | 25 ms |
   | 20,000 / 40,001 | 67 full GCs in 180 s, ~2.6 s each, old gen 699385K -> 
699385K (nothing freed) | - |
   | 200,000 / 400,001 | - | 31 ms |
   
   
   ### What You Expected?
   
    Removing the inflight tasks of a dropped (or long-dead) destination backend 
should be a single pass over the inflight map, without per-(task, entry) 
allocation, and should remove only the tasks whose destination is that backend.
   Inflight tasks of the same tablet in other compute groups should not be 
affected.
   
   ### How to Reproduce?
   
   
   This is **not reproducible every time**. The cleanup loop itself always runs 
with T x N cost when its branch is taken, but it only becomes a visible problem 
when all of the following hold:
   
   - The balance type creates inflight tasks: 
`cloud_warm_up_for_rebalance_type` is `async_warmup` (default) or `sync_warmup` 
(`without_warmup` / `peer_read_async_warmup` switch the mapping directly and 
create no tasks).
   - Many warm-up tasks are inflight towards one backend, e.g. right after a BE 
is added to a compute group with many tablets.
   - That backend disappears before the tasks finish: it is dropped without 
being decommissioned first, or it stays dead longer than 
`rehash_tablet_after_be_dead_seconds`. With `async_warmup`, tasks finish or are 
forced after `cloud_pre_heating_time_limit_sec` (default 300 s), so the drop 
has to happen within that window. A graceful decommission avoids it, because a 
decommissioning backend is not chosen as a destination and its tasks complete 
before it is dropped.
   - The warm-up RPCs were already sent (batches still queued at that moment 
fail and are reverted, which removes them).
   - T x N is large relative to the FE heap. Small clusters only see a short 
CPU/GC spike.
   
   ### Steps to Reproduce
   
   1. Cloud mode, a compute group with many tablets, 
`cloud_warm_up_for_rebalance_type=async_warmup`.
   2. Add a BE so the rebalancer starts warm-up tasks towards it; the master FE 
log shows `before pre cache check dest be <id> inflight task num <n>` with a 
large `n`.
   3. Drop that BE (without decommissioning it first) before the warm-ups 
finish.
   4. On the following runs of the `cloud-warmup-checker` thread (every 10 s), 
the master FE GC log shows repeated full GCs that free almost nothing.
   
   
   ### Anything Else?
   
   Investigation and validation were assisted by Claude Code.
   
   ### Are you willing to submit PR?
   
   - [x] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


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