smengcl opened a new pull request, #10351:
URL: https://github.com/apache/ozone/pull/10351

   ## What changes were proposed in this pull request?
   
   `MappedBufferManager` caches mapped buffers as `WeakReference<ByteBuffer>` 
and tracks in-flight quota via a `Semaphore`. Two races on master:
   
   1. `computeIfAbsent` GC race: The cache-hit branch reads `refer.get()` once 
for a null check and a second time at the return. Between the two reads, the 
`WeakReference` is the only handle to the buffer. GC may clear it, the second 
read returns `null`, and `ChunkUtils.readData` then dereferences a null 
`IOException` (`throw null`).
   
   2. Cleanup-loop races in `getQuota`: The async loop walks 
`mappedBuffers.keySet()` and re-looks up each key. A concurrent `remove()` 
makes the lookup return `null` and the chained `.get()` NPEs. A concurrent 
`put()` that replaces the `WeakReference` makes the unconditional 
`mappedBuffers.remove(key)` drop someone else's fresh entry. `p` is incremented 
for it, and `releaseQuota(p)` over-releases the semaphore.
   
   ### Fix
   
   * `computeIfAbsent` resolves `refer.get()` once into a local `final 
ByteBuffer cached` and returns that. The stack-local strong reference keeps the 
buffer reachable until the method returns.
   * The cleanup loop iterates entries directly (no key-then-get re-lookup, no 
NPE) and uses `ConcurrentHashMap.remove(key, value)` so a concurrent `put()` 
that replaced the `WeakReference` returns `false` from the conditional remove 
and is not counted as freed quota.
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/HDDS-15357
   
   ## How was this patch tested?
   
   - Existing tests


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