IParitionLoadBalancingStrategy Interface
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
A strategy defines which leases should be taken by the current host in a certain moment.
public interface IParitionLoadBalancingStrategy
type IParitionLoadBalancingStrategy = interface
Public Interface IParitionLoadBalancingStrategy
Examples
public class CustomStrategy : IParitionLoadBalancingStrategy
{
private string hostName;
private string hostVersion;
private TimeSpan leaseExpirationInterval;
private const string VersionPropertyKey = "version";
public IEnumerable<ILease> SelectLeasesToTake(IEnumerable<ILease> allLeases)
{
var takenLeases = this.FindLeasesToTake(allLeases);
foreach (var lease in takenLeases)
{
lease.Properties[VersionPropertyKey] = this.hostVersion;
}
return takenLeases;
}
private IEnumerable<ILease> FindLeasesToTake(IEnumerable<ILease> allLeases)
{
List<ILease> takenLeases = new List<ILease>();
foreach (var lease in allLeases)
{
if (string.IsNullOrWhiteSpace(lease.Owner) || this.IsExpired(lease))
{
takenLeases.Add(lease);
}
if (lease.Owner != this.hostName)
{
var ownerVersion = lease.Properties[VersionPropertyKey];
if (ownerVersion < this.hostVersion)
{
takenLeases.Add(lease);
}
// more logic for leases owned by other hosts
}
}
return takenLeases;
}
private bool IsExpired(ILease lease)
{
return lease.Timestamp.ToUniversalTime() + this.leaseExpirationInterval < DateTime.UtcNow;
}
}
Remarks
It can set new Properties for all returned leases if needed, including currently owned leases.
Methods
SelectLeasesToTake(IEnumerable<ILease>) |
Select leases that should be taken for processing. This method will be called periodically with LeaseAcquireInterval |
Applies to
Azure SDK for .NET
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for