The lease database locker is designed to overcome the shortcomings of the default
database locker by forcing the lock holder to periodically renew the lock. When the
lock is first acquired the broker holds it for the period specified in the persistence
adapter's lockKeepAlivePeriod attribute. After the initial
period, the lock is renewed for the period specified by the locker's
lockAcquireSleepInterval attribute.
When all of broker's system clocks are properly synchronized, the master broker will always renew the lease before any of the slaves in the group can steal it. In the event of a master's failure, the lock will automatically expire within the configured amount of time and one of the slave's in the group will be able to acquire it.
As shown in Example 17, it is configured using the
lease-database-locker element.
Example 17. Configuring a Lease Database Locker
<persistenceAdapter> <jdbcPersistenceAdapter dataDirectory="${activemq.data}" dataSource="#mysql-ds" lockKeepAlivePeriod="10000"> <locker> <lease-database-locker lockAcquireSleepInterval="5000"/> </locker> </jdbcPersistenceAdapter> </persistenceAdapter>
The lease database locker supports the common configuration properties described in Table 6.1.
The lease database locker relies on each broker's system clock to enure the proper timing of lease expiration and lock requests. When all of the system clocks are synchronized, the timing works. Once the system clocks start drifting apart, the timing can be thrown off and a slave broker could possibly steal the lock from the group's master.
To avoid this problem the locker can make adjustments based on the database server's
current time setting. This feature is controlled by setting the locker's
maxAllowableDiffFromDBTime to specify the number of
milliseconds by which a broker's system clock can differ from the database's before the
locker automatically adds an adjustment. The default setting is zero which deactivates the
adjustments.
Example 18 shows configuration for making adjustments when a broker's clock differs from the database by one second.
Example 18. Configuring a Lease Database Locker to Adjust for Non-synchronized System Clocks
<persistenceAdapter> <jdbcPersistenceAdapter ... > <locker> <lease-database-locker maxAllowableDiffFromDBTime="1000"/> </locker> </jdbcPersistenceAdapter> </persistenceAdapter>








