Click here to Skip to main content
15,886,067 members
Articles / WCF
Tip/Trick

Managing server failover in WCF

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
4 Mar 2013CPOL 7.8K   204   4  
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)


Written By
Software Developer (Senior) Better Place
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --