You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celeborn.apache.org by ni...@apache.org on 2026/03/19 03:12:23 UTC
(celeborn) branch main updated: [CELEBORN-2276] Fix race condition in MemoryManager.releaseSortMemory
This is an automated email from the ASF dual-hosted git repository.
nicholasjiang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/celeborn.git
The following commit(s) were added to refs/heads/main by this push:
new 28a0733bb [CELEBORN-2276] Fix race condition in MemoryManager.releaseSortMemory
28a0733bb is described below
commit 28a0733bb2441f98531f531b26800c0d3ea06e99
Author: sychen <sy...@ctrip.com>
AuthorDate: Thu Mar 19 11:12:12 2026 +0800
[CELEBORN-2276] Fix race condition in MemoryManager.releaseSortMemory
### What changes were proposed in this pull request?
Use `updateAndGet`
### Why are the changes needed?
`reserveSortMemory` calls `sortMemoryCounter.addAndGet` without any synchronized, so the lock in `releaseSortMemory` doesn't actually protect against races with `reserveSortMemory` anyway.
### Does this PR resolve a correctness bug?
No
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
GHA
Closes #3620 from cxzl25/CELEBORN-2276.
Authored-by: sychen <sy...@ctrip.com>
Signed-off-by: SteNicholas <pr...@163.com>
---
.../celeborn/service/deploy/worker/memory/MemoryManager.java | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/worker/src/main/java/org/apache/celeborn/service/deploy/worker/memory/MemoryManager.java b/worker/src/main/java/org/apache/celeborn/service/deploy/worker/memory/MemoryManager.java
index 1e3540e08..f62951cbd 100644
--- a/worker/src/main/java/org/apache/celeborn/service/deploy/worker/memory/MemoryManager.java
+++ b/worker/src/main/java/org/apache/celeborn/service/deploy/worker/memory/MemoryManager.java
@@ -435,13 +435,7 @@ public class MemoryManager {
}
public void releaseSortMemory(long size) {
- synchronized (this) {
- if (sortMemoryCounter.get() - size < 0) {
- sortMemoryCounter.set(0);
- } else {
- sortMemoryCounter.addAndGet(-1L * size);
- }
- }
+ sortMemoryCounter.updateAndGet(current -> Math.max(0, current - size));
}
public void incrementDiskBuffer(int size) {