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

   Problem Summary:
   There are two critical bugs in the spill-disk feature implementation:
   1. **Data Race in SpillDataDir**: In 
`SpillStreamManager::_get_stores_for_spill`, reading `_disk_capacity_bytes` 
without a lock concurrently with the GC thread updating it can lead to 
undefined behavior or torn reads.
   2. **Memory Tracking Under-report in SpillWriter**: In 
`SpillWriter::_write_internal`, the memory counter increment and its paired 
`Defer` deduction were placed inside a nested inner scope. This caused the 
memory to be prematurely deducted before the synchronous, time-consuming disk 
I/O `_file_writer->append(buff)` occurred, leading to significant 
under-reporting of memory usage.
   
   Solution:
   1. Added a thread-safe `get_disk_usage` method guarded by `_mutex` in 
`SpillDataDir` for the pipeline worker threads to fetch capacity safely.
   2. Optimized the memory tracking in `SpillWriter::_write_internal` by moving 
the `COUNTER_UPDATE` after the disk capacity check, and unified the memory 
deduction and disk metric updates into a single `Defer` block at the outer 
scope. This guarantees that memory is accurately tracked during I/O and 
simplifies the error-handling paths.
   3. Added corresponding BE unit tests `SpillDataDirThreadSafety` and 
`SpillWriterMemoryTracking` to prevent regression.


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