This is an automated email from the ASF dual-hosted git repository.
github-bot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new 2347306943 [Minor] Fix error messages for `shrink` and `try_shrink`
(#20422)
2347306943 is described below
commit 234730694392553bb5fa244e7b3782b9ccf3ebd3
Author: Haresh Khanna <[email protected]>
AuthorDate: Wed Feb 25 01:47:39 2026 +0000
[Minor] Fix error messages for `shrink` and `try_shrink` (#20422)
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes #123` indicates that this PR will close issue #123.
-->
- Closes #.
## Rationale for this change
<!--
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.
-->
In the following code, when we fetch `prev` again to construct the error
message, the value we get may be different from the value that failed
`checked_sub` in the first place which would get us out of the
fetch_update CAS loop. Instead we should use the prev value that
`fetch_update` returned in the error message.
```rust
pub fn try_shrink(&self, capacity: usize) -> Result<usize> {
let prev = self
.size
.fetch_update(
atomic::Ordering::Relaxed,
atomic::Ordering::Relaxed,
|prev| prev.checked_sub(capacity),
)
.map_err(|_| {
let prev = self.size.load(atomic::Ordering::Relaxed);
internal_datafusion_err!(
"Cannot free the capacity {capacity} out of allocated size
{prev}"
)
})?;
self.registration.pool.shrink(self, capacity);
Ok(prev - capacity)
}
```
## What changes are included in this PR?
<!--
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?
<!--
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)?
-->
Yes, with existing tests.
## Are there any user-facing changes?
<!--
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.
-->
No
---
datafusion/execution/src/memory_pool/mod.rs | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/datafusion/execution/src/memory_pool/mod.rs
b/datafusion/execution/src/memory_pool/mod.rs
index 6dee87fee0..0b4eb3786f 100644
--- a/datafusion/execution/src/memory_pool/mod.rs
+++ b/datafusion/execution/src/memory_pool/mod.rs
@@ -391,7 +391,9 @@ impl MemoryReservation {
atomic::Ordering::Relaxed,
|prev| prev.checked_sub(capacity),
)
- .expect("capacity exceeds reservation size");
+ .unwrap_or_else(|prev| {
+ panic!("Cannot free the capacity {capacity} out of allocated
size {prev}")
+ });
self.registration.pool.shrink(self, capacity);
}
@@ -407,8 +409,7 @@ impl MemoryReservation {
atomic::Ordering::Relaxed,
|prev| prev.checked_sub(capacity),
)
- .map_err(|_| {
- let prev = self.size.load(atomic::Ordering::Relaxed);
+ .map_err(|prev| {
internal_datafusion_err!(
"Cannot free the capacity {capacity} out of allocated size
{prev}"
)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]