fightBoxing opened a new pull request, #15894:
URL: https://github.com/apache/iceberg/pull/15894

   ## Description
   
   Fixes #15861
   
   ### Problem
   `BaseLockManager` uses a JVM-wide shared static `ScheduledExecutorService` 
for heartbeats, but each `InMemoryLockManager` instance calls `close()` 
independently. When multiple managers exist (e.g., in tests or multi-catalog 
JVM usage), one manager's `close()` shuts down the shared scheduler via 
`shutdownNow()`, causing `RejectedExecutionException` in other live managers 
that still need it for heartbeat scheduling.
   
   ### Root Cause
   No reference counting on the shared scheduler. Any single `close()` call 
destroys it for all instances.
   
   ### Fix
   - Added an `AtomicInteger` reference counter (`schedulerRefCount`) to 
`BaseLockManager`
   - Added a per-instance `schedulerInitialized` flag to track whether this 
instance has incremented the ref count
   - In `scheduler()`: increment ref count on first access per instance
   - In `close()`: only `shutdownNow()` the scheduler when the ref count 
reaches zero (last active manager)
   
   ### Testing
   - Added `testClosingOneManagerDoesNotAffectAnother`: creates two managers, 
closes one, verifies the other can still acquire locks
   - Added `testClosingAllManagersShutsDownScheduler`: closes all managers, 
then verifies a new manager can create a fresh scheduler
   - All existing tests pass
   
   ### Notes
   - The fix is backward compatible - no API changes
   - Thread safety is maintained via `synchronized` blocks and `volatile` fields
   - The `AtomicInteger` counter ensures correct behavior even under concurrent 
close operations


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