Class FallbackTarget

java.lang.Object
io.permazen.kv.raft.fallback.FallbackTarget
All Implemented Interfaces:
Cloneable

public class FallbackTarget extends Object implements Cloneable
Represents one of the underlying RaftKVDatabases managed by a FallbackKVDatabase.

Instances must at least be configured with the associated RaftKVDatabase; all other properties have defaults. Two MergeStrategys are configured to handle switching into (see setUnavailableMergeStrategy()) and out of (see setRejoinMergeStrategy()) standalone mode.

Other parameters configure how cluster availability is determined and enforce hysteresis; see setTransactionTimeout(), setCheckInterval(), setMinAvailableTime(), and setMinUnavailableTime().

  • Field Details

  • Constructor Details

    • FallbackTarget

      public FallbackTarget()
  • Method Details

    • getRaftKVDatabase

      public RaftKVDatabase getRaftKVDatabase()
      Returns:
      underlying database
    • setRaftKVDatabase

      public void setRaftKVDatabase(RaftKVDatabase raft)
      Parameters:
      raft - underlying database
    • getTransactionTimeout

      public int getTransactionTimeout()
      Get the transaction timeout used when determining database availability.
      Returns:
      transaction timeout in milliseconds
    • setTransactionTimeout

      public void setTransactionTimeout(int timeout)
      Configure the transaction timeout used when determining database availability.

      Default is DEFAULT_TRANSACTION_TIMEOUT.

      Parameters:
      timeout - timeout in milliseconds
      Throws:
      IllegalArgumentException - if timeout is not greater than zero
    • getCheckInterval

      public int getCheckInterval()
      Get the interval between availability checks.
      Returns:
      check interval in milliseconds
    • setCheckInterval

      public void setCheckInterval(int checkInterval)
      Configure the interval between availability checks.

      Default is DEFAULT_CHECK_INTERVAL.

      Parameters:
      checkInterval - check interval in milliseconds
      Throws:
      IllegalArgumentException - if checkInterval is not greater than zero
    • getMinAvailableTime

      public int getMinAvailableTime()
      Get the minimum amount of time after becoming available before allowing this instance to become unavailable again.
      Returns:
      minimum available time in milliseconds
    • setMinAvailableTime

      public void setMinAvailableTime(int minAvailableTime)
      Configure the minimum amount of time after becoming available before allowing this instance to become unavailable again.

      Default is DEFAULT_MIN_AVAILABLE_TIME.

      Parameters:
      minAvailableTime - minimum available time in milliseconds
      Throws:
      IllegalArgumentException - if minAvailableTime is not greater than zero
    • getMinUnavailableTime

      public int getMinUnavailableTime()
      Get the minimum amount of time after becoming unavailable before allowing this instance to become available again.
      Returns:
      minimum unavailable time in milliseconds
    • setMinUnavailableTime

      public void setMinUnavailableTime(int minUnavailableTime)
      Configure the minimum amount of time after becoming unavailable before allowing this instance to become available again.

      Default is DEFAULT_MIN_UNAVAILABLE_TIME.

      Parameters:
      minUnavailableTime - minimum unavailable time in milliseconds
      Throws:
      IllegalArgumentException - if minUnavailableTime is not greater than zero
    • getUnavailableMergeStrategy

      public MergeStrategy getUnavailableMergeStrategy()
      Get the merge strategy to apply when transitioning from this database to a lower priority database because our RaftKVDatabase cluster has become unavailable.
      Returns:
      unavailable merge strategy
    • setUnavailableMergeStrategy

      public void setUnavailableMergeStrategy(MergeStrategy strategy)
      Configure the merge strategy to apply when transitioning from this database to a lower priority database because our RaftKVDatabase cluster has become unavailable.

      Default is OverwriteMergeStrategy.

      Parameters:
      strategy - unavailable merge strategy
      Throws:
      IllegalArgumentException - if strategy is null
    • getRejoinMergeStrategy

      public MergeStrategy getRejoinMergeStrategy()
      Get the merge strategy to apply when transitioning from a lower priority database to this database because our RaftKVDatabase cluster has become available.
      Returns:
      rejoin merge strategy
    • setRejoinMergeStrategy

      public void setRejoinMergeStrategy(MergeStrategy strategy)
      Configure the merge strategy to apply when transitioning from a lower priority database to this database because our RaftKVDatabase cluster has become available again.

      Default is NullMergeStrategy.

      Parameters:
      strategy - rejoin merge strategy
      Throws:
      IllegalArgumentException - if strategy is null
    • isAvailable

      public boolean isAvailable()
      Get the current availability of this target.
      Returns:
      true if this target is currently available, otherwise false
    • getLastChangeTime

      public Date getLastChangeTime()
      Get the time of the last change in availability of this target, if known.
      Returns:
      time this target's availability last changed, or null if unknown or no change has occurred
    • getLastActiveTime

      public Date getLastActiveTime()
      Get the last time this target was the active database.
      Returns:
      last active time of this target, or null if never active
    • checkAvailability

      protected boolean checkAvailability(FallbackKVDatabase fallbackDB)
      Perform an availability assessment of the underlying RaftKVDatabase associated with this instance.

      This method may block for as long as necessary to determine availability, but it should not block indefinitely. If a KVTransaction is opened, setTimeout() should be used to set a time limit.

      This method will not be invoked concurrently by two different threads.

      If this method throws an unchecked exception, the database will be assumed to be unavailable.

      The implementation in FallbackTarget determines availability by attempting to commit a read-only, Consistency.LINEARIZABLE transaction within the configured maximum timeout.

      Parameters:
      fallbackDB - parent fallback database
      Returns:
      true if database is available, false otherwise
    • clone

      public FallbackTarget clone()
      Overrides:
      clone in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object