Skip to content

LeaseDatabaseLocker: allow the lease acquire retry interval to be set separately from the lease duration #2663

Open

Description

@colinwerner

LeaseDatabaseLocker uses lockAcquireSleepInterval for two things:

  1. The lease duration. The lease row's expiry is set to now + lockAcquireSleepInterval when the lease is acquired and on every keepAlive() renewal.
  2. The wait between acquire attempts on a broker that does not hold the lease. doStart() sleeps lockAcquireSleepInterval after each failed attempt.

The lease has to outlive the slowest renewal the master can make (the keep-alive period plus connection and statement time). Otherwise a slow renewal lets the waiting broker take over while the master is still running. Choosing a lease long enough to be safe also makes the waiting broker poll that slowly:

  • after a clean stop, the old master releases the lease immediately, but the waiting broker can take up to lockAcquireSleepInterval to notice;
  • after a crash, failover can take up to 2 × lockAcquireSleepInterval (the lease runs out, then the next poll).

For example, on a JDBC master/slave pair on PostgreSQL where a renewal can take up to about 13 s, a safe lease is about 20 s. Failover then takes up to about 20 s after a clean stop and about 40 s after a crash. Polling every 2 s would bring these down to about 2 s and 22 s without changing the lease.

AMQ-4347 proposed renaming these properties and was closed as Won't Fix. This proposal leaves the existing properties and their meaning unchanged.

Proposal

Add an optional lockAcquireRetryInterval property to LeaseDatabaseLocker that sets only the wait between acquire attempts. When it is unset (the default), the locker uses lockAcquireSleepInterval as it does today, so existing configurations behave exactly as before.

<jdbcPersistenceAdapter dataSource="#ds" lockKeepAlivePeriod="5000">
  <locker>
    <lease-database-locker lockAcquireSleepInterval="20000" lockAcquireRetryInterval="2000"/>
  </locker>
</jdbcPersistenceAdapter>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions