Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / WCF

Managing server failover in WCF

0.00/5 (No votes)
4 Mar 2013CPOL 7.9K   204  
In this article I will talk about server failover and how to manage it.

Sample Image

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.

Sample Image - maximum width is 600 pixels

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

VB
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)