Interface DBLockProvider

All Superinterfaces:
Provider
All Known Implementing Classes:
LiquibaseDBLockProvider

public interface DBLockProvider extends Provider

Global database lock to ensure that some actions in DB can be done just be one cluster node at a time.

There are different namespaces that can be locked. The same DBLockProvider (same session in keycloack) can only be used to lock one namespace, a second attempt will throw a RuntimeException. The hasLock method returns the local namespace locked by this provider.

Different DBLockProvider instances can be used to lock in different threads. Note that the DBLockProvider is associated to the session (so in order to have different lock providers different sessions are needed).

Author:
Marek Posolda
  • Method Details

    • waitForLock

      void waitForLock(DBLockProvider.Namespace lock)
      Try to retrieve DB lock or wait if retrieve was unsuccessful. Throw exception if lock can't be retrieved within specified timeout (900 seconds by default) Throw exception if a different namespace has already been locked by this provider.
      Parameters:
      lock - The namespace to lock
    • releaseLock

      void releaseLock()
      Release previously acquired lock by this provider.
    • getCurrentLock

      DBLockProvider.Namespace getCurrentLock()
      Returns the current provider namespace locked or null
      Returns:
      The namespace locked or null if there is no lock
    • supportsForcedUnlock

      boolean supportsForcedUnlock()
      Returns:
      true if provider supports forced unlock at startup
    • destroyLockInfo

      void destroyLockInfo()
      Will destroy whole state of DB lock (drop table/collection to track locking).