Repository navigation
[#2663] Add lockAcquireRetryInterval to LeaseDatabaseLocker - #2664
Open
colinwerner wants to merge 3 commits into
Open
colinwerner wants to merge 3 commits into
colinwerner wants to merge 3 commits into
Conversation
The class was ignored during the jakarta migration (AMQ-9239) with a note about Mockito/byte-buddy module opens. The Derby-based tests pass as-is. The three time-offset tests failed because the mocked Statements returned null for getCurrentDateTime(), and anyString() does not match null, so prepareStatement() returned null. Stub the statement text so the mock matches. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
LeaseDatabaseLocker used lockAcquireSleepInterval both as the lease duration and as the wait between acquire attempts. The lease has to outlive the slowest renewal the master can make, so a safe lease also makes a waiting broker poll slowly: failover after a clean stop could take up to lockAcquireSleepInterval even though the lease was released immediately, and up to twice that after a crash. Add an optional lockAcquireRetryInterval that sets only the wait between acquire attempts. lockAcquireSleepInterval stays the lease duration. The default (unset) uses lockAcquireSleepInterval, so existing configurations behave as before. Warn if the retry interval is longer than the lease. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ocker.toString() toString() printed lockAcquireSleepInterval for both duration and renew. The lease is renewed every lockKeepAlivePeriod of the lockable service, so report that instead. Along with the new retry value this gives the three timings that decide failover behaviour. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
colinwerner
commented
Oct 14, 2026
| @Override | ||
| public String toString() { | ||
| return "LeaseDatabaseLocker owner:" + leaseHolderId + ",duration:" + lockAcquireSleepInterval + ",renew:" + lockAcquireSleepInterval; | ||
| return "LeaseDatabaseLocker owner:" + leaseHolderId + ",duration:" + lockAcquireSleepInterval + ",renew:" + (lockable != null ? lockable.getLockKeepAlivePeriod() : -1) |
Contributor
Author
There was a problem hiding this comment.
This toString() change isn't required for lockAcquireRetryInterval. It's included because renew previously printed lockAcquireSleepInterval (the same value as duration), while the lease is actually renewed every lockKeepAlivePeriod of the lockable service. Since this PR separates the locker's timings, it seemed worth making the one place that reports them accurate: duration, renew and retry are the three values that determine failover time. lockable is null until the locker is configured, so renew prints -1 in that case. It's a separate commit, so I'm happy to drop it or move it to its own PR.
Contributor
Author
|
@jbonofre do you know who might be best to review this PR? |
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.
Closes #2663
LeaseDatabaseLockeruseslockAcquireSleepIntervalboth as the lease duration and as the wait between acquire attempts. A lease that is long enough to be safe also makes a waiting broker poll slowly, so a lease that has expired or been released is picked up up to a full lease duration late.This adds an optional
lockAcquireRetryInterval(<lease-database-locker lockAcquireRetryInterval="..."/>):doStart();lockAcquireSleepIntervalremains the lease duration indoStart()andkeepAlive();<= 0(the default) useslockAcquireSleepInterval, so existing configurations are unchanged;The attribute appears in the generated
activemq.xsdunderlease-database-locker.Commits:
LeaseDatabaseLockerTest. The class was@Ignored during the jakarta migration (AMQ-9239), so new tests there would not run. The Derby tests passed as-is. The three time-offset tests failed only because the mockedStatements.getCurrentDateTime()returned null, which Mockito'sanyString()does not match. Stubbing it fixes them.lockAcquireRetryInterval.renewintoString().toString()printedlockAcquireSleepIntervalfor bothdurationandrenew, but the lease is renewed everylockKeepAlivePeriod. It's included here because this PR is about separating the locker's timings, andtoString()is where they are read when tuning failover. With this change it reports all three correctly (duration,renew,retry). It's a separate commit so it can be dropped if preferred.Tests (
LeaseDatabaseLockerTest, embedded Derby):testReleasedLeaseAcquiredWithinLockAcquireRetryInterval: with a 10 s lease and a 250 ms retry interval, a waiting locker acquires a released lease in well under 2.5 s (about 50 ms locally; about 9.8 s before this change), and the acquired lease still runs for the full lease duration.testDefaultLockAcquireRetryIntervalIsLockAcquireSleepInterval: with the property unset, a released lease is picked up on the nextlockAcquireSleepIntervalpoll, as before.testToStringReportsLeaseTimings:toString()reports the lease duration, the keep-alive period and the retry interval.Note: on current
main,activemq-brokertest-compile fails inManagementContextSslTest(SslContextis abstract), which is unrelated to this change. I ran the tests above against the other modules built with-DskipTests.Docs: the JDBC master/slave / pluggable storage lockers page in
activemq-websiteshould list the new attribute; I can open a follow-up PR there.Generated with Claude Code.