This is an automated email from the ASF dual-hosted git repository.

uros-b pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new a2f49fa82fb9 [SPARK-58975][CORE] Add failure messages to MemoryPool 
require checks
a2f49fa82fb9 is described below

commit a2f49fa82fb9d6b78028ff13ebab0d2274d90844
Author: Uros <[email protected]>
AuthorDate: Mon Nov 9 16:37:39 2026 +0000

    [SPARK-58975][CORE] Add failure messages to MemoryPool require checks
    
    ### What changes were proposed in this pull request?
    
    `MemoryPool.incrementPoolSize` and `decrementPoolSize` guard their 
pool-size accounting invariants with four `require(...)` checks that carry no 
failure message. When one fails, the thrown `IllegalArgumentException` reads 
only `requirement failed`, with no indication of which invariant was violated 
or the values involved.
    
    This adds descriptive messages to those four checks, interpolating the 
offending values, for example:
    
    ```scala
    require(delta >= 0, s"cannot increment the pool size by a negative amount: 
$delta")
    ```
    
    The sibling `MemoryManager` already attaches messages to all of its 
`require` calls; this brings `MemoryPool` in line.
    
    ### Why are the changes needed?
    
    These checks guard internal memory-bookkeeping invariants. A bare 
`requirement failed` is hard to act on when one trips; including the invariant 
and the actual `delta` / pool size / used-memory values makes such failures 
diagnosable.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No. `MemoryPool` is `private[memory]`; this only changes the message of an 
`IllegalArgumentException` thrown on an internal invariant violation.
    
    ### How was this patch tested?
    
    Existing tests. The change only adds messages to existing `require` checks; 
the conditions themselves are unchanged.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Generated-by: Claude Code (Opus 4.8)
    
    Closes #58251 from uros-b/memorypool-require-messages.
    
    Authored-by: Uros <[email protected]>
    Signed-off-by: Uros Bojanic <[email protected]>
    
    
    skip-checks: true
---
 core/src/main/scala/org/apache/spark/memory/MemoryPool.scala | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/core/src/main/scala/org/apache/spark/memory/MemoryPool.scala 
b/core/src/main/scala/org/apache/spark/memory/MemoryPool.scala
index 1b9edf9c43bd..604298c87299 100644
--- a/core/src/main/scala/org/apache/spark/memory/MemoryPool.scala
+++ b/core/src/main/scala/org/apache/spark/memory/MemoryPool.scala
@@ -50,7 +50,7 @@ private[memory] abstract class MemoryPool(lock: Object) {
    * Expands the pool by `delta` bytes.
    */
   final def incrementPoolSize(delta: Long): Unit = lock.synchronized {
-    require(delta >= 0)
+    require(delta >= 0, s"cannot increment the pool size by a negative amount: 
$delta")
     _poolSize += delta
   }
 
@@ -58,9 +58,12 @@ private[memory] abstract class MemoryPool(lock: Object) {
    * Shrinks the pool by `delta` bytes.
    */
   final def decrementPoolSize(delta: Long): Unit = lock.synchronized {
-    require(delta >= 0)
-    require(delta <= _poolSize)
-    require(_poolSize - delta >= memoryUsed)
+    require(delta >= 0, s"cannot decrement the pool size by a negative amount: 
$delta")
+    require(delta <= _poolSize,
+      s"cannot decrement the pool size ${_poolSize} by a larger amount: 
$delta")
+    require(_poolSize - delta >= memoryUsed,
+      s"cannot decrement the pool size ${_poolSize} by $delta because the used 
memory " +
+        s"$memoryUsed would exceed the remaining pool size")
     _poolSize -= delta
   }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to