Core: Fix InMemoryLockManager shared scheduler shutdown#15894
Open
fightBoxing wants to merge 3 commits intoapache:mainfrom
Open
Core: Fix InMemoryLockManager shared scheduler shutdown#15894fightBoxing wants to merge 3 commits intoapache:mainfrom
fightBoxing wants to merge 3 commits intoapache:mainfrom
Conversation
…and junit test code.
Add reference counting to BaseLockManager's shared ScheduledExecutorService to prevent one manager instance from shutting down the scheduler while other active instances still need it for heartbeats. Previously, any single close() call would shutdownNow() the JVM-wide shared scheduler, causing RejectedExecutionException in other live managers trying to schedule heartbeats. The fix tracks per-instance initialization state and uses an AtomicInteger reference counter. The scheduler is only shut down when the last active manager closes.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #15861
Problem
BaseLockManageruses a JVM-wide shared staticScheduledExecutorServicefor heartbeats, but eachInMemoryLockManagerinstance callsclose()independently. When multiple managers exist (e.g., in tests or multi-catalog JVM usage), one manager'sclose()shuts down the shared scheduler viashutdownNow(), causingRejectedExecutionExceptionin 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
AtomicIntegerreference counter (schedulerRefCount) toBaseLockManagerschedulerInitializedflag to track whether this instance has incremented the ref countscheduler(): increment ref count on first access per instanceclose(): onlyshutdownNow()the scheduler when the ref count reaches zero (last active manager)Testing
testClosingOneManagerDoesNotAffectAnother: creates two managers, closes one, verifies the other can still acquire lockstestClosingAllManagersShutsDownScheduler: closes all managers, then verifies a new manager can create a fresh schedulerNotes
synchronizedblocks andvolatilefieldsAtomicIntegercounter ensures correct behavior even under concurrent close operations