Class DefaultFailureDetector
- java.lang.Object
-
- io.hekate.cluster.health.DefaultFailureDetector
-
- All Implemented Interfaces:
FailureDetector
,JmxSupport<DefaultFailureDetectorJmx>
,ConfigReportSupport
public class DefaultFailureDetector extends Object implements FailureDetector, JmxSupport<DefaultFailureDetectorJmx>, ConfigReportSupport
Default implementation ofFailureDetector
interface.This implementation organizes all nodes into a ring with each node being monitored by a configurable number of other nodes. Monitoring is based on periodic exchange of heartbeat messages with a configurable time interval and a configurable amount of acceptable heartbeat losses.
Configuration options of this failure detector are represented by the
DefaultFailureDetectorConfig
class with the following properties:Failure detection quorum
- specifies how many nodes will be monitored by this nodeHeartbeat interval
- time interval in milliseconds between attempts of sending a heartbeat request message to the monitored nodeHeartbeat loss threshold
- acceptable amount of lost heartbeats before considering the monitored node to be failed. Note that heartbeat is considered to be lost if no response for it was received during theheartbeat interval
.
-
-
Constructor Summary
Constructors Constructor Description DefaultFailureDetector()
Constructs a new instance with the default configuration options.DefaultFailureDetector(DefaultFailureDetectorConfig cfg)
Constructs a new instance using the specified configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
failureQuorum()
Return the amount of nodes that should agree on some particular node failure before removing such node from the cluster.long
heartbeatInterval()
Returns the time interval in milliseconds between heartbeat sending rounds (seeFailureDetector.heartbeatTick()
).int
heartbeatLossThreshold()
Returns the amount of heartbeats that can be lost before considering a node failure.Collection<ClusterAddress>
heartbeatTick()
Runs a heartbeat tick and returns a set of cluster node addresses that should received a heartbeat request message.void
initialize(FailureDetectorContext context)
Initialized this failure detector with the runtime context.boolean
isAlive(ClusterAddress node)
Returnstrue
if cluster node at the specified address is known to be alive.boolean
isMonitored(ClusterAddress node)
Returnstrue
if the specified node is in the list ofmonitored()
nodes.DefaultFailureDetectorJmx
jmx()
Creates a JMX object.List<ClusterAddress>
monitored()
Returns addresses of all nodes that are monitored by this failure detector.void
onConnectFailure(ClusterAddress node)
Notifies this failure detector upon failure while trying to connect to a remote node.void
onHeartbeatReply(ClusterAddress node)
Notifies this failure detector on heartbeat reply message from a remote node.boolean
onHeartbeatRequest(ClusterAddress from)
Notifies this failure detector on heartbeat request message form a remote node.void
report(ConfigReporter report)
Report configuration.void
terminate()
Terminates this failure detector.String
toString()
void
update(Set<ClusterAddress> nodes)
Updates this failure detector with the latest information about all known cluster nodes addresses (including local node address).
-
-
-
Constructor Detail
-
DefaultFailureDetector
public DefaultFailureDetector()
Constructs a new instance with the default configuration options.Please see the documentation of
DefaultFailureDetectorConfig
for information about default values.
-
DefaultFailureDetector
public DefaultFailureDetector(DefaultFailureDetectorConfig cfg)
Constructs a new instance using the specified configuration.- Parameters:
cfg
- Configuration.
-
-
Method Detail
-
report
public void report(ConfigReporter report)
Description copied from interface:ConfigReportSupport
Report configuration.- Specified by:
report
in interfaceConfigReportSupport
- Parameters:
report
- Reporter.
-
initialize
public void initialize(FailureDetectorContext context) throws HekateException
Description copied from interface:FailureDetector
Initialized this failure detector with the runtime context.- Specified by:
initialize
in interfaceFailureDetector
- Parameters:
context
- Context.- Throws:
HekateException
- If this failure detector couldn't be initialized.
-
heartbeatInterval
public long heartbeatInterval()
Description copied from interface:FailureDetector
Returns the time interval in milliseconds between heartbeat sending rounds (seeFailureDetector.heartbeatTick()
).If the returned value if less than or equals to zero then health monitoring will be completely disabled and
FailureDetector.heartbeatTick()
/FailureDetector.isAlive(ClusterAddress)
methods will never be called.- Specified by:
heartbeatInterval
in interfaceFailureDetector
- Returns:
- Time interval in milliseconds between heartbeat sending rounds.
-
failureQuorum
public int failureQuorum()
Description copied from interface:FailureDetector
Return the amount of nodes that should agree on some particular node failure before removing such node from the cluster.The value of this parameter is expected to be greater than or equals to 1. If values is less then 1 then it will be automatically adjusted to 1.
- Specified by:
failureQuorum
in interfaceFailureDetector
- Returns:
- Amount of nodes that should agree on some particular node failure before removing such node from the cluster.
-
terminate
public void terminate()
Description copied from interface:FailureDetector
Terminates this failure detector.- Specified by:
terminate
in interfaceFailureDetector
-
isAlive
public boolean isAlive(ClusterAddress node)
Description copied from interface:FailureDetector
Returnstrue
if cluster node at the specified address is known to be alive. Returnsfalse
if node is considered to be failed.- Specified by:
isAlive
in interfaceFailureDetector
- Parameters:
node
- Node address.- Returns:
true
if node is alive orfalse
if node is considered to be failed.
-
heartbeatTick
public Collection<ClusterAddress> heartbeatTick()
Description copied from interface:FailureDetector
Runs a heartbeat tick and returns a set of cluster node addresses that should received a heartbeat request message.The time interval between heartbeat ticks is controlled by
FailureDetector.heartbeatInterval()
method.- Specified by:
heartbeatTick
in interfaceFailureDetector
- Returns:
- Set of cluster node addresses for heartbeat request message sending.
- See Also:
FailureDetector.onHeartbeatRequest(ClusterAddress)
-
onHeartbeatRequest
public boolean onHeartbeatRequest(ClusterAddress from)
Description copied from interface:FailureDetector
Notifies this failure detector on heartbeat request message form a remote node. Returns a boolean flag indicating whether a heartbeat reply should be send (true
) or heartbeat replies are not supported (false
).- Specified by:
onHeartbeatRequest
in interfaceFailureDetector
- Parameters:
from
- Address of the heartbeat request sender node.- Returns:
true
if heartbeat reply should be send back to the requester.- See Also:
FailureDetector.heartbeatTick()
,FailureDetector.onHeartbeatReply(ClusterAddress)
-
onHeartbeatReply
public void onHeartbeatReply(ClusterAddress node)
Description copied from interface:FailureDetector
Notifies this failure detector on heartbeat reply message from a remote node.- Specified by:
onHeartbeatReply
in interfaceFailureDetector
- Parameters:
node
- Address of heartbeat reply sender node.
-
onConnectFailure
public void onConnectFailure(ClusterAddress node)
Description copied from interface:FailureDetector
Notifies this failure detector upon failure while trying to connect to a remote node.- Specified by:
onConnectFailure
in interfaceFailureDetector
- Parameters:
node
- Address of a failed node.
-
update
public void update(Set<ClusterAddress> nodes)
Description copied from interface:FailureDetector
Updates this failure detector with the latest information about all known cluster nodes addresses (including local node address).Note that the specified addresses set can include nodes that just started joining and are not within cluster service's
topology
.- Specified by:
update
in interfaceFailureDetector
- Parameters:
nodes
- Cluster node addresses.
-
heartbeatLossThreshold
public int heartbeatLossThreshold()
Returns the amount of heartbeats that can be lost before considering a node failure.- Returns:
- Amount of heartbeats that can be lost before considering a node failure.
- See Also:
DefaultFailureDetectorConfig.setHeartbeatLossThreshold(int)
-
monitored
public List<ClusterAddress> monitored()
Returns addresses of all nodes that are monitored by this failure detector.- Returns:
- Addresses of all nodes that are monitored by this failure detector.
-
isMonitored
public boolean isMonitored(ClusterAddress node)
Returnstrue
if the specified node is in the list ofmonitored()
nodes.- Parameters:
node
- Node to check.- Returns:
true
if the specified node is in the list ofmonitored()
nodes.
-
jmx
public DefaultFailureDetectorJmx jmx()
Description copied from interface:JmxSupport
Creates a JMX object.- Specified by:
jmx
in interfaceJmxSupport<DefaultFailureDetectorJmx>
- Returns:
- JMX object.
-
-