Table of Contents

Class FencedPublicationStore

Namespace
Virtufin.Api.Services
Assembly
Virtufin.Api.dll

The publication fence on any Dapr state store with ETags (and the TRANSACTIONAL capability the guarded writes use). Every change is one ETag-guarded write of a single key, the one thing all such stores make atomic.

Heartbeat fencing: publishers do not pass the fence per frame. The holder renews its lease every second or so; a superseded holder learns it from a rejected renewal and stops, so a stale owner publishes for at most one renewal interval after its successor claims. Times are this replica's UTC clock, as for WorkManager's recovery lease.

public sealed class FencedPublicationStore
Inheritance
FencedPublicationStore
Inherited Members

Constructors

FencedPublicationStore(IPublicationStateStore, FencedPublicationKeys?, TimeProvider?)

The publication fence on any Dapr state store with ETags (and the TRANSACTIONAL capability the guarded writes use). Every change is one ETag-guarded write of a single key, the one thing all such stores make atomic.

Heartbeat fencing: publishers do not pass the fence per frame. The holder renews its lease every second or so; a superseded holder learns it from a rejected renewal and stops, so a stale owner publishes for at most one renewal interval after its successor claims. Times are this replica's UTC clock, as for WorkManager's recovery lease.

public FencedPublicationStore(IPublicationStateStore state, FencedPublicationKeys? keys = null, TimeProvider? time = null)

Parameters

state IPublicationStateStore
keys FencedPublicationKeys
time TimeProvider

Methods

ChangeAsync(string, string, string, bool, TimeSpan, CancellationToken)

A fresh next claims the fence: allowed when expected is the current token, the fence is absent or inactive, or its lease expired. next equal to expected renews or revokes, for the holder only, and never reactivates an inactive fence.

public Task<bool> ChangeAsync(string connectionId, string expected, string next, bool active, TimeSpan lease, CancellationToken cancellationToken = default)

Parameters

connectionId string
expected string
next string
active bool
lease TimeSpan
cancellationToken CancellationToken

Returns

Task<bool>

HoldsAsync(string, string, CancellationToken)

Whether token holds the active fence (one read).

public Task<bool> HoldsAsync(string connectionId, string token, CancellationToken cancellationToken = default)

Parameters

connectionId string
token string
cancellationToken CancellationToken

Returns

Task<bool>

SweepAsync(Action<string, Exception>?, CancellationToken)

Removes fences that are inactive or expired and older than two leases, and drops them from the index.

public Task SweepAsync(Action<string, Exception>? onError, CancellationToken cancellationToken)

Parameters

onError Action<string, Exception>
cancellationToken CancellationToken

Returns

Task