Interface DbLockHandler


  • public interface DbLockHandler
    Manages the database lock, via the db_lock table. The database lock avoids 2 independent Cyclos instances from using the same database at the same time, which could lead to data corruption.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int KEEPALIVE_SECONDS
      Interval in seconds which nodes should update the db_lock row
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void keepalive​(String hostId)
      Send a keep-alive to the database
      void lock​(String host, DbLock dbLock)
      Locks the database, by either inserting or updating the existing row in db_lock table, and schedules a timer to update the table every few seconds
      void prepare()
      Makes sure the table exists
      DbLock read()
      Return the current row, if any
      void sleepUntilTryingAgain​(DbLock dbLock)
      Sleeps for a few seconds before attempting to check again if the db is locked
      void throwAlreadyLocked​(DbLock dbLock)
      Throws an appropriate error indicating the current db is already locked
      void unlock()
      Delete the row
    • Field Detail

      • KEEPALIVE_SECONDS

        static final int KEEPALIVE_SECONDS
        Interval in seconds which nodes should update the db_lock row
        See Also:
        Constant Field Values
    • Method Detail

      • keepalive

        void keepalive​(String hostId)
        Send a keep-alive to the database
      • lock

        void lock​(String host,
                  @Nullable
                  DbLock dbLock)
        Locks the database, by either inserting or updating the existing row in db_lock table, and schedules a timer to update the table every few seconds
      • prepare

        void prepare()
        Makes sure the table exists
      • read

        @Nullable
        DbLock read()
        Return the current row, if any
      • sleepUntilTryingAgain

        void sleepUntilTryingAgain​(@Nonnull
                                   DbLock dbLock)
        Sleeps for a few seconds before attempting to check again if the db is locked
      • throwAlreadyLocked

        void throwAlreadyLocked​(@Nullable
                                DbLock dbLock)
        Throws an appropriate error indicating the current db is already locked
      • unlock

        void unlock()
        Delete the row