Table of Contents

Class FencingTokenMinting

Namespace
Excalibur.Dispatch.LeaderElection.Fencing
Assembly
Excalibur.Dispatch.LeaderElection.Abstractions.dll

Mints a fencing token for a leadership tenure, retrying only the failures that retrying can fix.

public static class FencingTokenMinting
Inheritance
FencingTokenMinting
Inherited Members

Remarks

A tenure must not be declared without a valid token, so every provider mints one at the moment it takes the lock and relinquishes leadership if it cannot. That made this loop provider-agnostic, and it was duplicated into each provider instead — where the copies drifted apart on which failures are worth retrying. One implementation, so the retry policy for a guarantee-critical step has a single home.

Fields

DefaultMaxAttempts

The number of mint attempts before leadership is relinquished.

public const int DefaultMaxAttempts = 3

Field Value

int

Remarks

Deliberately small and without a delay between attempts. Every attempt spends part of the grace period during which the node still believes it may lead, so a slow retry schedule here does not buy reliability — it widens the window in which a node acts on an un-advanced fence.

Methods

MintWithRetryAsync(IFencingTokenIssuer, string, CancellationToken, int)

Mints a fencing token, retrying transient failures up to maxAttempts times.

public static Task<long> MintWithRetryAsync(IFencingTokenIssuer provider, string resourceId, CancellationToken cancellationToken, int maxAttempts = 3)

Parameters

provider IFencingTokenIssuer

The provider that issues tokens for this resource.

resourceId string

The resource the leadership tenure covers.

cancellationToken CancellationToken

Cancels the mint.

maxAttempts int

Attempts before giving up; defaults to DefaultMaxAttempts.

Returns

Task<long>

The minted token.

Exceptions

ArgumentNullException

provider or resourceId is null.

FencingTokenExhaustedException

No strictly-positive token can be issued because the mint domain is exhausted. Raised on the first attempt and never retried: it is permanent, so retrying returns the same answer while consuming the grace period, and the caller is documented to handle this type rather than to unwrap it from another exception.

OperationCanceledException

cancellationToken was cancelled.

InvalidOperationException

Every attempt failed for a retryable reason. The last failure is the inner exception. The caller must relinquish leadership rather than act as a leader whose fence never advanced.