Info |
---|
Show a server is available by periodically sending a message to all the other servers : https://martinfowler.com/articles/patterns-of-distributed-systems/heartbeat.html |
Problem
When multiple servers form a cluster, the servers are responsible for storing some portion of the data, based on the partitioning and replication schemes used. Timely detection of server failures is important to make sure corrective actions can be taken by making some other server responsible for handling requests for the data on failed servers.
On the sending server side, the scheduler executes a method to send heartbeat messages : class SendingServer…
Code Block | ||
---|---|---|
| ||
private void sendHeartbeat() throws IOException { socketChannel.blockingSend(newHeartbeatRequest(serverId)); } |
On the receiving server, the failure detection mechanism has a similar scheduler started. At regular intervals, it checks if the heartbeat was received or not : class AbstractFailureDetector…
Code Block | ||
---|---|---|
| ||
private HeartBeatScheduler heartbeatScheduler = new HeartBeatScheduler(this::heartBeatCheck, 100l); abstract void heartBeatCheck(); abstract void heartBeatReceived(T serverId); |
A method to periodically check the heartbeat status and detect possible failures.