public class FallbackTarget extends Object implements 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()
.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_CHECK_INTERVAL
Default check interval (2000ms).
|
static int |
DEFAULT_MIN_AVAILABLE_TIME
Default minimum available type (10000ms).
|
static int |
DEFAULT_MIN_UNAVAILABLE_TIME
Default minimum unavailable type (30000ms).
|
static int |
DEFAULT_TRANSACTION_TIMEOUT
Default transaction timeout for assessing availability (1000ms).
|
protected Logger |
log |
Constructor and Description |
---|
FallbackTarget() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
checkAvailability(FallbackKVDatabase fallbackDB)
Perform an availability assessment of the underlying
RaftKVDatabase associated with this instance. |
FallbackTarget |
clone() |
int |
getCheckInterval()
Get the interval between availability checks.
|
Date |
getLastActiveTime()
Get the last time this target was the active database.
|
Date |
getLastChangeTime()
Get the time of the last change in availability of this target, if known.
|
int |
getMinAvailableTime()
Get the minimum amount of time after becoming available before allowing this instance to become unavailable again.
|
int |
getMinUnavailableTime()
Get the minimum amount of time after becoming unavailable before allowing this instance to become available again.
|
RaftKVDatabase |
getRaftKVDatabase()
Get the
RaftKVDatabase . |
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. |
int |
getTransactionTimeout()
Get the transaction timeout used when determining database availability.
|
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. |
boolean |
isAvailable()
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 |
setRaftKVDatabase(RaftKVDatabase raft)
Set the
RaftKVDatabase . |
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. |
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 our
RaftKVDatabase cluster has become unavailable. |
String |
toString() |
public static final int DEFAULT_TRANSACTION_TIMEOUT
setTransactionTimeout()
,
Constant Field Valuespublic static final int DEFAULT_CHECK_INTERVAL
setCheckInterval()
,
Constant Field Valuespublic static final int DEFAULT_MIN_AVAILABLE_TIME
setMinAvailableTime()
,
Constant Field Valuespublic static final int DEFAULT_MIN_UNAVAILABLE_TIME
setMinUnavailableTime()
,
Constant Field Valuesprotected final Logger log
public RaftKVDatabase getRaftKVDatabase()
RaftKVDatabase
.public void setRaftKVDatabase(RaftKVDatabase raft)
RaftKVDatabase
.raft
- underlying databasepublic int getTransactionTimeout()
public void setTransactionTimeout(int timeout)
Default is DEFAULT_TRANSACTION_TIMEOUT
.
timeout
- timeout in millisecondsIllegalArgumentException
- if timeout
is not greater than zeropublic int getCheckInterval()
public void setCheckInterval(int checkInterval)
Default is DEFAULT_CHECK_INTERVAL
.
checkInterval
- check interval in millisecondsIllegalArgumentException
- if checkInterval
is not greater than zeropublic int getMinAvailableTime()
public void setMinAvailableTime(int minAvailableTime)
Default is DEFAULT_MIN_AVAILABLE_TIME
.
minAvailableTime
- minimum available time in millisecondsIllegalArgumentException
- if minAvailableTime
is not greater than zeropublic int getMinUnavailableTime()
public void setMinUnavailableTime(int minUnavailableTime)
Default is DEFAULT_MIN_UNAVAILABLE_TIME
.
minUnavailableTime
- minimum unavailable time in millisecondsIllegalArgumentException
- if minUnavailableTime
is not greater than zeropublic MergeStrategy getUnavailableMergeStrategy()
RaftKVDatabase
cluster has become unavailable.public void setUnavailableMergeStrategy(MergeStrategy strategy)
RaftKVDatabase
cluster has become unavailable.
Default is OverwriteMergeStrategy
.
strategy
- unavailable merge strategyIllegalArgumentException
- if strategy
is nullpublic MergeStrategy getRejoinMergeStrategy()
RaftKVDatabase
cluster has become available.public void setRejoinMergeStrategy(MergeStrategy strategy)
RaftKVDatabase
cluster has become available again.
Default is NullMergeStrategy
.
strategy
- rejoin merge strategyIllegalArgumentException
- if strategy
is nullpublic boolean isAvailable()
public Date getLastChangeTime()
public Date getLastActiveTime()
protected boolean checkAvailability(FallbackKVDatabase fallbackDB)
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.
fallbackDB
- parent fallback databasepublic FallbackTarget clone()
Copyright © 2022. All rights reserved.