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

   ## Proposed changes
   
   Fixes two related bugs on the event-driven warm-up path that together
   stall BE's heavy work pool whenever a warm-up job is cancelled or
   expired while BE still has its id in `_tablet_replica_cache`.
   
   ### 1. BE — `CANCELED` vs `CANCELLED` typo
   
   `be/src/cloud/cloud_warm_up_manager.cpp` used:
   
   ```cpp
   if (st.is<CANCELED>()) {   // one L
       cancelled_jobs.push_back(job_id);
   }
   ```
   
   `CANCELED` (one L) is **not** defined in `ErrorCode`. Since this file
   is in `namespace doris`, ADL resolved the bare name to
   `PCacheStatus::CANCELED = 9` (a proto-generated unscoped enum in
   `gensrc/build/gen_cpp/internal_service.pb.h`). `Status::is<int>()` is a
   simple `code == _code` check, so the check compared `1` (the real
   `TStatusCode::CANCELLED`) against `9` and was **always false**.
   
   Consequence: whenever FE responded to `getTabletReplicaInfos` with
   `TStatusCode.CANCELLED` (e.g. after `CANCEL WARM UP JOB`, or when
   `job.isDone()`), BE logged a WARNING and went straight back to the
   loop without pushing the `job_id` into `cancelled_jobs` — so
   `_tablet_replica_cache.erase(job_id)` at the end of the loop never
   ran, leaving the job as a zombie entry that every subsequent
   `commit_rowset` continued to query FE for.
   
   Fix: use the correctly-spelled, namespace-qualified constant (same
   form already used on line 610 of the same file):
   
   ```cpp
   if (st.is<ErrorCode::CANCELLED>()) {
   ```
   
   ### 2. FE — `getTabletReplicaInfos` NPE on removed job
   
   `fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java`:
   
   ```java
   CloudWarmUpJob job = ((CloudEnv) Env.getCurrentEnv())
           .getCacheHotspotMgr()
           .getCloudWarmUpJob(request.getWarmUpJobId());
   if (job == null || job.isDone()) {
       LOG.info("warmup job {} is not running, notify caller BE {} to cancel 
job",
               job.getJobId(), clientAddr);   // <-- NPE when job == null
       result.setStatus(new TStatus(TStatusCode.CANCELLED));
       return result;
   }
   ```
   
   Once a cancelled job had been removed from `cloudWarmUpJobs` (after
   `history_cloud_warm_up_job_keep_max_second`, default 7d, via the
   `JobDaemon.clearFinishedOrCancelCloudWarmUpJob` cycle), this NPE
   propagated out as `Internal error processing getTabletReplicaInfos`.
   Combined with bug #1 above, BE kept calling this RPC for a stale
   `job_id` forever, and every such call triggered the
   `apache::thrift::TException` catch branch in `thrift_rpc_helper.cpp`,
   which sleeps `thrift_client_retry_interval_ms * 2 = 2000 ms` inside
   `CloudWarmUpManager::_mtx`. With one global mutex and a 2s synchronous
   sleep per call, `bthread_fork_join(commit_rowset, concurrency=10)`
   serialised, heavy-pool threads blocked in `CloudTabletsChannel::close`
   waiting for the fork-join, the heavy-pool queue backed up, load tasks
   timed out, and query `Fragment RPC Phase1` latency spiked into the
   10-second range.
   
   Fix: log `request.getWarmUpJobId()`, which is safe inside
   `request.isSetWarmUpJobId()` guard.
   
   ## Symptoms observed in the field
   
   Real incident on a cloud-4.1.1 cluster (CIR-20058): one BE's heavy
   work pool saturated, all routine-load tasks aborted with
   `[E1008]Reached timeout` and `[TIMEOUT]FragmentMgr cancel worker`,
   query profile showed `Fragment RPC Phase1 Time: 10sec925ms`. FE log
   had ~30 NPEs/minute:
   
   ```
   ERROR ... Internal error processing getTabletReplicaInfos
   java.lang.NullPointerException:
     Cannot invoke "org.apache.doris.cloud.CloudWarmUpJob.getJobId()" because 
"job" is null
       at 
FrontendServiceImpl.getTabletReplicaInfos(FrontendServiceImpl.java:2817)
   ```
   
   BE log had matching ~90 lines/minute (3 warnings per 1 RPC failure)
   across `thrift_rpc_helper.cpp`, `status.h`,
   `cloud_warm_up_manager.cpp`. The 7-day timing matched when a prior
   warm-up job's `finishedTimeMs` crossed
   `history_cloud_warm_up_job_keep_max_second`.
   
   ## Tests
   
   - 
`fe/fe-core/src/test/java/org/apache/doris/service/GetTabletReplicaInfosTest.java`
     — pure-Mockito unit test. Mocks `Env.getCurrentEnv()` to return a
     `CloudEnv` whose `CacheHotspotManager.getCloudWarmUpJob(jobId)`
     returns `null`, then asserts `getTabletReplicaInfos` does not throw
     and returns `TStatusCode.CANCELLED`.
   
   - 
`regression-test/suites/cloud_p0/cache/multi_cluster/warm_up/cluster/test_warm_up_cluster_event_cancel_expired.groovy`
     — docker cloud regression. Shortens
     `history_cloud_warm_up_job_keep_max_second=30`, creates an
     event-driven LOAD warm-up job, drives loads, cancels the job, waits
     for FE to remove it, then asserts (a) a follow-up batch of 20
     inserts completes in <30s (buggy path would take ≥40s due to 2s
     per-commit sleeps) and (b) the BE
     `file_cache_event_driven_warm_up_skipped_rowset_num` metric grows
     (indicating `_tablet_replica_cache` was cleared and subsequent
     `warm_up_rowset` calls take the empty-replicas fast path).
   
   ## Checklist
   
   - [x] Bug fix
   - [x] Unit test
   - [x] Regression test


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