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

   ### Background
   
   The BE metrics hook and memory overview profiler both refresh the JVM gauges 
through `JvmMetrics::update()`. A shared counter limits repeated collection 
attempts after failures.
   
   ### What problem does this PR solve?
   
   Issue Number: None
   Related PR: None
   PR Type: Bugfix
   
   Problem Summary:
   
   ThreadSanitizer reported concurrent accesses to the JVM metrics failure 
counter during a P0 run. Make the counter atomic so both refresh callers can 
read, increment, and reset it safely.
   
   ### Details
   
   - **Frequency:** Intermittent when the metrics hook and memory-maintenance 
thread refresh JVM statistics concurrently.
   - **Root cause:** Both callers access the same function-local `static long`, 
including resetting it after a successful refresh.
   - **Why existing tests missed it:** The reports came from overlapping 
background refreshes during P0. Functional checks can pass while the counter 
races.
   - **Fix:** Use relaxed atomic operations on the failure counter. Keep the 
threshold at 30 and allow in-flight refreshes to overlap.
   - **Other paths and branches:** Both refresh callers use the same counter. 
This patch targets master.
   
   ### Testing
   
   - ASAN BE build with `./build.sh --be -j48` on the candidate based on 
`7d457d52b82`.
   - The race was observed on the pre-fix TSan build `a371bd1428f`. Post-fix 
TSan and unit tests have not been run.
   
   ### Notes for Reviewers
   
   Representative pre-fix TSan report, with framework frames omitted.
   
   ```text
   SUMMARY: ThreadSanitizer: data race 
be/src/common/metrics/jvm_metrics.cpp:187:9 in doris::JvmMetrics::update()
   
   Read of size 8
     #0 doris::JvmMetrics::update() be/src/common/metrics/jvm_metrics.cpp:187:9
     #1 doris::MemoryProfile::refresh_memory_overview_profile() 
be/src/runtime/memory/memory_profile.cpp:272:50
     #2 doris::refresh_memory_state_after_memory_change() 
be/src/common/daemon.cpp:230:62
     #3 doris::Daemon::memory_maintenance_thread() 
be/src/common/daemon.cpp:342:9
   
   Previous write of size 8
     #0 doris::JvmMetrics::update() be/src/common/metrics/jvm_metrics.cpp:197:24
     #1 __invoke_impl<void, void (doris::JvmMetrics::*&)(), doris::JvmMetrics 
*&> libstdc++/bits/invoke.h:76:14
   
   Location is global 'doris::JvmMetrics::update()::fail_count' of size 8
   ```
   
   ### Release note
   
   Fix a data race in the BE JVM metrics failure counter.
   
   ### Check List (For Author)
   
   - Behavior changed: No
   - Does this need documentation: No
   - Pre-submission status: Partially verified: Post-fix TSan and unit tests 
have not been run.
   
   ### AI Disclosure
   
   - Tool: Codex (GPT-6)
   - Generated: Code change and PR description
   - Human review: The author reviewed the approach and approved the relaxed 
threshold semantics.
   


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