Fencing token reader and issuer split
IFencingTokenProvider observes an authoritative mark and validates a pinned token. It no longer exposes IssueTokenAsync. Code that actually advances the mark uses IFencingTokenIssuer, which extends that reader contract. This is an intentional pre-RC source/API change; there is no compatibility mint that guesses whether a reader can issue.
Observation-only consumers
Middleware and resource validation continue to use IFencingTokenProvider. A custom reader implements IFencingTokenProvider; observation-only application code calls its existing members through that interface:
using System.Threading;
using System.Threading.Tasks;
using Excalibur.Dispatch.LeaderElection.Fencing;
public static class FencingObservation
{
public static ValueTask<long?> GetTokenAsync(IFencingTokenProvider reader, string resourceId, CancellationToken cancellationToken) =>
reader.GetTokenAsync(resourceId, cancellationToken);
public static ValueTask<bool> ValidateTokenAsync(IFencingTokenProvider reader, string resourceId, long token, CancellationToken cancellationToken) =>
reader.ValidateTokenAsync(resourceId, token, cancellationToken);
}
Keep its existing registration:
using System.Diagnostics.CodeAnalysis;
using Excalibur.Dispatch.LeaderElection.Fencing;
using Microsoft.Extensions.DependencyInjection;
public static class ReaderRegistration
{
public static void Configure<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TProvider>(IServiceCollection services)
where TProvider : class, IFencingTokenProvider =>
services.AddFencingTokenSupport<TProvider>();
}
TProvider is the application’s real read-only implementation, supplied when calling this generic registration wrapper. This helper registers observation and middleware; it does not advertise an issuer. Kubernetes reads the token generated by a real ownership transition and remains observation-only. Do not cast it to an issuer or replace the missing method with an unsupported-operation stub.
Minting consumers
A custom issuing provider implements IFencingTokenIssuer, including the inherited observation members. Minting application code calls its issuing member explicitly:
using System.Threading;
using System.Threading.Tasks;
using Excalibur.Dispatch.LeaderElection.Fencing;
public static class FencingIssuance
{
public static ValueTask<long> IssueTokenAsync(IFencingTokenIssuer issuer, string resourceId, CancellationToken cancellationToken) =>
issuer.IssueTokenAsync(resourceId, cancellationToken);
}
Change the dependency of code that mints (including calls to FencingTokenMinting.MintWithRetryAsync) from IFencingTokenProvider to IFencingTokenIssuer. Register the real issuing implementation through the existing fencing extension family:
using System.Diagnostics.CodeAnalysis;
using Excalibur.Dispatch.LeaderElection.Fencing;
using Microsoft.Extensions.DependencyInjection;
public static class IssuerRegistration
{
public static void Configure<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TIssuer>(IServiceCollection services)
where TIssuer : class, IFencingTokenIssuer =>
services.AddFencingTokenIssuerSupport<TIssuer>();
}
TIssuer is the application’s real implementation, not a framework-provided counter or fake. The default issuer view forwards to the selected reader only when that reader implements the issuing capability. A selected read-only replacement refuses issuer resolution actionably; it never mints through an unrelated fallback. Generic registration preserves ordinary DI constructor selection and creates separate selected instances for separate service providers. The view is nonowning, so a disposable selected provider is not captured for disposal twice. The instance overload intentionally shares the externally owned instance across containers and leaves its disposal to the caller.
Explicitly registering an independent IFencingTokenIssuer bypasses that default view—even if only that slot is overridden. Such a composition owns consistency between its reader and issuer authorities; no physical-backend equivalence is inferred. Tokens from unrelated authorities are not interchangeable. Existing explicit nonfencing constructors and WithoutFencingTokens() remain intentional opt-outs; narrowing the capability is not permission to silently drop an enabled default fence.
The six self-minting built-in providers expose the issuer through their normal registrations; their public acquisition dependencies become the narrower type. Kubernetes does not expose it. This migration does not change the configured store, leases, renewal, cancellation, retry attempts, or counter arithmetic. It does not make all mint/leadership acquisitions one transaction.
Preserve the fencing limits
Generation is linearized by the authoritative store, not by asynchronous return order. A lost acknowledgment can leave a generated mark visible even when the caller received no token. Absence/unadvanced state returns null; unreadable state throws. Neither becomes a fabricated zero.
Capture the authoritative token once at leadership transition and pin it for that tenure. Validation remains a positive recorded mark and a presented token at or above it; changing >= to == can refuse the live incumbent. A successful validation observes a past instant and grants no safety interval after return. A protected durable write must enforce the fence in its own atomic mutation.
Counter deletion or rollback can admit old tokens under >=; this split adds no durable tenure identity or reset protection. Preserve the backing store’s configured counter history. Keep provider-specific durability/co-atomicity limits and application idempotency requirements. Generic metadata annotations support reflection-free DI analysis; they are not proof that every provider, native SDK or application runs under NativeAOT.
Authority, failures and leadership loss
All contenders for one resource must use the same election/mark authority and retained counter history. For in-memory election, that means the same InMemoryLeaderElectionSharedState instance; the default is static within one process, while explicitly separate instances form separate scopes. This is not cross-process fencing.
A completed validation can reject a stale token. Authority I/O/consistency/parse faults and cancellation propagate and prevent the middleware's next delegate from running; they are not silently converted to staleness. Preserve the original exception for outer retry/classification and honor caller cancellation. Reads cannot use a lagging replica as a fallback.
On leadership loss, discard the pinned token and stop admitting new protected work. Do not reread the mutable mark to borrow a successor's token. Already in-flight writes still need the resource's atomic fencing comparison. Store restart/restore durability is provider/configuration-specific and UNVERIFIED here; deleting or restoring counter history is not detected by this API.