Class FallbackTarget
- All Implemented Interfaces:
Cloneable
RaftKVDatabase
s managed by a FallbackKVDatabase
.
Instances must at least be configured with the associated RaftKVDatabase
; all other properties have defaults.
Two MergeStrategy
s 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 Summary
Modifier and TypeFieldDescriptionstatic final int
Default check interval (2000ms).static final int
Default minimum available type (10000ms).static final int
Default minimum unavailable type (30000ms).static final int
Default transaction timeout for assessing availability (1000ms).protected final Logger
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
checkAvailability
(FallbackKVDatabase fallbackDB) Perform an availability assessment of the underlyingRaftKVDatabase
associated with this instance.clone()
int
Get the interval between availability checks.Get the last time this target was the active database.Get the time of the last change in availability of this target, if known.int
Get the minimum amount of time after becoming available before allowing this instance to become unavailable again.int
Get the minimum amount of time after becoming unavailable before allowing this instance to become available again.Get theRaftKVDatabase
.Get the merge strategy to apply when transitioning from a lower priority database to this database because ourRaftKVDatabase
cluster has become available.int
Get the transaction timeout used when determining database availability.Get the merge strategy to apply when transitioning from this database to a lower priority database because ourRaftKVDatabase
cluster has become unavailable.boolean
Get the current availability of this target.void
setCheckInterval
(int checkInterval) Configure the interval between availability checks.void
setMinAvailableTime
(int minAvailableTime) Configure the minimum amount of time after becoming available before allowing this instance to become unavailable again.void
setMinUnavailableTime
(int minUnavailableTime) Configure the minimum amount of time after becoming unavailable before allowing this instance to become available again.void
Set theRaftKVDatabase
.void
setRejoinMergeStrategy
(MergeStrategy strategy) Configure the merge strategy to apply when transitioning from a lower priority database to this database because ourRaftKVDatabase
cluster has become available again.void
setTransactionTimeout
(int timeout) Configure the transaction timeout used when determining database availability.void
setUnavailableMergeStrategy
(MergeStrategy strategy) Configure the merge strategy to apply when transitioning from this database to a lower priority database because ourRaftKVDatabase
cluster has become unavailable.toString()
-
Field Details
-
DEFAULT_TRANSACTION_TIMEOUT
public static final int DEFAULT_TRANSACTION_TIMEOUTDefault transaction timeout for assessing availability (1000ms).- See Also:
-
DEFAULT_CHECK_INTERVAL
public static final int DEFAULT_CHECK_INTERVALDefault check interval (2000ms).- See Also:
-
DEFAULT_MIN_AVAILABLE_TIME
public static final int DEFAULT_MIN_AVAILABLE_TIMEDefault minimum available type (10000ms).- See Also:
-
DEFAULT_MIN_UNAVAILABLE_TIME
public static final int DEFAULT_MIN_UNAVAILABLE_TIMEDefault minimum unavailable type (30000ms).- See Also:
-
log
-
-
Constructor Details
-
FallbackTarget
public FallbackTarget()
-
-
Method Details
-
getRaftKVDatabase
Get theRaftKVDatabase
.- Returns:
- underlying database
-
setRaftKVDatabase
Set theRaftKVDatabase
.- 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
- iftimeout
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
- ifcheckInterval
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
- ifminAvailableTime
is not greater than zero
-
getRejoinMergeStrategy
Get the merge strategy to apply when transitioning from a lower priority database to this database because ourRaftKVDatabase
cluster has become available.- Returns:
- rejoin merge strategy
-
setRejoinMergeStrategy
Configure the merge strategy to apply when transitioning from a lower priority database to this database because ourRaftKVDatabase
cluster has become available again.Default is
NullMergeStrategy
.- Parameters:
strategy
- rejoin merge strategy- Throws:
IllegalArgumentException
- ifstrategy
is null
-
isAvailable
public boolean isAvailable()Get the current availability of this target.- Returns:
- true if this target is currently available, otherwise false
-
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
Get the last time this target was the active database.- Returns:
- last active time of this target, or null if never active
-
checkAvailability
Perform an availability assessment of the underlyingRaftKVDatabase
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
-
toString
-