Created
May 6, 2015 18:19
-
-
Save hyrmn/7262c3d7450793550e48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AzureFriendlyReplicationInformer : ReplicationInformer | |
{ | |
public AzureFriendlyReplicationInformer(DocumentConvention conventions) | |
: base(conventions) | |
{ | |
} | |
public override bool ShouldExecuteUsing(string operationUrl, int currentRequest, string method, bool primary) | |
{ | |
if (primary == false) | |
AssertValidOperation(method); | |
var failureCounter = GetHolder(operationUrl); | |
if (failureCounter.Value == 0 || failureCounter.ForceCheck) | |
{ | |
failureCounter.LastCheck = SystemTime.UtcNow; | |
return true; | |
} | |
if (currentRequest % CheckRepititionRate(failureCounter.Value) == 0) | |
{ | |
failureCounter.LastCheck = SystemTime.UtcNow; | |
return true; | |
} | |
if ((SystemTime.UtcNow - failureCounter.LastCheck) > conventions.MaxFailoverCheckPeriod) | |
{ | |
failureCounter.LastCheck = SystemTime.UtcNow; | |
return true; | |
} | |
return false; | |
} | |
private int CheckRepititionRate(long value) | |
{ | |
if (value < 10000) | |
return 1000; | |
if (value < 100000) | |
return 10000; | |
return 100000; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment