ding-young opened a new pull request, #16535:
URL: https://github.com/apache/datafusion/pull/16535

   ## Which issue does this PR close?
   Related to #16367 
   
   ## Rationale for this change
   Previously, the `spilled_bytes` metric reported the estimated in-memory size 
of spilled `RecordBatches`, based on their array sizes. However, with the 
introduction of spill file compression in the `SpillManager`, the in-memory 
size no longer reflects the actual bytes written to disk.
   
   This PR updates the `spilled_bytes` metric to instead report the total 
number of bytes physically **written to disk** during spilling.
   <!--
    Why are you proposing this change? If this is already explained clearly in 
the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your 
changes and offer better suggestions for fixes.  
   -->
   
   ## What changes are included in this PR?
   Whenever `in_progress_file.finish()` is called, it updates the spill file 
metric based on `current_disk_usage` for this spill file. Since spill files are 
append-only, we only update this value once. 
   
   <!--
   There is no need to duplicate the description in the issue here but it is 
sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   ## Are these changes tested?
   Yes. We manually compare the spill file size and reported metric.
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are 
they covered by existing tests)?
   -->
   
   ## Are there any user-facing changes?
   After this PR, running certain spilling aggregate queries may show 
significantly lower `spilled_bytes` values compared to previous runs—even when 
using the uncompressed spill option.
   
   This is because the previous metric was based on an inaccurate estimate of 
in-memory size. In particular, when a large `RecordBatch` was sliced into 
smaller batches during `spill_record_batch_by_size`, the underlying buffers 
were not resized due to zero-copy semantics, resulting in inflated memory 
accounting.
   
   The updated `spilled_bytes` metric now reflects the actual number of bytes 
written to disk, and therefore provides a more accurate representation of spill 
size.
   <!--
   If there are user-facing changes then we may require documentation to be 
updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api 
change` label.
   -->
   


-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to