Introduction
In this article I will talk about server failover and how to manage it.
Solution Summary
Here is the message sequence diagram for a vanilla case.
Here is the problematic scenario that we are going to solve:
- Concurrency problem. In our case it could happen that some services send messages
at the same time. This problem will be solved with the
Vector Clock algorithm.
- Critical section - System activation should be performed in the critical section.
Pseudo code
procedure OnMessageArrived(msg)
isGreater = msg.VectorClockTimeStamp > currentVectorClockTimeStamp
isLess = msg.VectorClockTimeStamp < currentVectorClockTimeStamp
if ( isGreater ) then
currentClockTimeStamp = msg.VectorClockTimeStamp
else if ( isLess == false )
concurrency error
end if
...
call appropriate message handler
procedure Activate(msg)
if ( AcquireLockFromAllServicesApproved() ) then
isActivated = true
SendHeartBeat()
ReleaseLock()
End if
procedure Deactivate(msg)
isActivated = false
SendHeartBeat()
//message handlers
procedure HandleHeartBeatFromOther(msg)
//do something
procedure HandleOtherSystemAcquiredLock(msg)
if (CurrentSystemInLock)
return LockNotAprooved;
Else
return LockAprooved;
End if
procedure HandleOtherSystemReleasedLock(msg)
//do something
Demo
- Download demo and runner.bat.
- Three applications will be created, just press Start.