Skip to content

Instantly share code, notes, and snippets.

@hyrmn
Created May 6, 2015 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyrmn/7262c3d7450793550e48 to your computer and use it in GitHub Desktop.
Save hyrmn/7262c3d7450793550e48 to your computer and use it in GitHub Desktop.
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