dataroaring opened a new pull request, #62117:
URL: https://github.com/apache/doris/pull/62117

   ## Summary
   - **forEach deadlock**: Changed `forEach` in both 
`ConcurrentLong2ObjectHashMap` and `ConcurrentLong2LongHashMap` from inline 
iteration under read-lock to snapshot-based iteration. Entries are copied into 
arrays under the read lock, then callbacks are invoked outside the lock. This 
eliminates the read-to-write upgrade deadlock (e.g., `forEach((k, v) -> 
map.put(k, v + 1))`).
   - **Reentrant callback guard**: Added a `ThreadLocal<Boolean>` per map 
instance that is set during compute/merge callback execution. All write 
operations (`put`, `remove`, `putIfAbsent`, `replace`, `clear`, `addTo`, and 
all compute/merge variants) check this flag and throw `IllegalStateException` 
on reentrant access, turning a silent deadlock into a fail-fast error.
   - **Documentation**: Added Javadoc on both classes documenting the callback 
restriction (matching `ConcurrentHashMap`'s contract).
   
   ## Test plan
   - [x] `testForEachWithMutatingCallbackDoesNotDeadlock` — verifies forEach + 
put no longer deadlocks (uses 5s timeout)
   - [x] `testReentrantComputeThrowsIllegalStateException` — verifies compute 
callback calling put throws ISE
   - [x] `testReentrantComputeIfAbsentThrowsIllegalStateException` — verifies 
computeIfAbsent callback calling put throws ISE
   - [x] `testReentrantMergeThrowsIllegalStateException` / 
`testReentrantMergeLongThrowsIllegalStateException` — verifies merge callback 
calling remove throws ISE
   - [x] All 64 existing tests pass (33 Long2Long + 31 Long2Object)
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


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