Table of Contents

Interface IFencedResource

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

A resource protected by the fencing-token pattern: it records the highest fencing token it has observed and rejects any operation whose token is below that high-water mark. A token at or above the mark is accepted, and the mark never moves backward.

public interface IFencedResource
Extension Methods

Remarks

This is the Chubby/Lamport sequencer rule applied to a protected resource: a stale leader that resumes activity after losing its lease presents a fencing token below the one a successor has already advanced the mark to, and the resource rejects the operation instead of applying it — preventing split-brain writes. See IFencingTokenProvider for how the token is minted, and Leadership for how a consumer pins the token for its tenure.

The relation is at-or-above, not strictly greater, and an implementation that strengthens it to strictly greater breaks its own leader. A fencing token identifies a leadership tenure, not an individual operation: the consumer captures the token once at the leadership transition and re-presents that same pinned value on every protected operation of the tenure (the pattern IFencingTokenProvider instructs consumers to follow). So the second and every later operation of the incumbent leader presents a token exactly equal to the mark its own first operation set. Requiring a strictly greater token refuses the live holder from its second write onward — the sequence a fence needs is non-decreasing, and only a strictly lower token identifies a superseded leader.

Methods

GuardAsync(long, CancellationToken)

Guards an operation with the given fencing token, advancing the resource's high-water mark when the token is accepted.

ValueTask GuardAsync(long fencingToken, CancellationToken cancellationToken)

Parameters

fencingToken long

The fencing token presented for this operation.

cancellationToken CancellationToken

The cancellation token to observe.

Returns

ValueTask

A task that completes when the guard check has been evaluated.

Exceptions

StaleFencingTokenException

Thrown when fencingToken is below the highest fencing token this resource has already observed — a superseded leader. A token equal to that high-water mark is the incumbent leader re-presenting its pinned per-tenure token and is accepted, not thrown on.