Table of Contents

Class TriggerMetadataStore

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

The trigger metadata records, in the api's state store (IPublicationStateStore): read with their ETags, created only if absent, and replaced by compare-and-swap, so two membership changes on one trigger never lose each other (resource-groups, Atomic Membership Changes).

public sealed class TriggerMetadataStore
Inheritance
TriggerMetadataStore
Inherited Members

Constructors

TriggerMetadataStore(IPublicationStateStore)

The trigger metadata records, in the api's state store (IPublicationStateStore): read with their ETags, created only if absent, and replaced by compare-and-swap, so two membership changes on one trigger never lose each other (resource-groups, Atomic Membership Changes).

public TriggerMetadataStore(IPublicationStateStore state)

Parameters

state IPublicationStateStore

Fields

MaxChangeAttempts

Compare-and-swap attempts before a change gives up with ABORTED. Each lost attempt means another writer changed the same trigger meanwhile; a handful of concurrent group deletions or tag edits on one trigger settle well within this.

public const int MaxChangeAttempts = 16

Field Value

int

Methods

AddToIndexAsync(string, long, CancellationToken)

Enters id in the index at addedMs, before its record is written.

public Task AddToIndexAsync(string id, long addedMs, CancellationToken cancellationToken)

Parameters

id string
addedMs long
cancellationToken CancellationToken

Returns

Task

ChangeAsync(string, Func<TriggerMetadata>, Func<TriggerMetadata, TriggerMetadata?>, CancellationToken)

Applies change to the record of id by compare-and-swap, repeating it on a lost race, and answers the record as written (or as found, when change answers null: nothing to change). A trigger without a record starts from absent. change may throw to refuse. A trigger whose id holds no record (HoldsRecord(string)) is refused with INVALID_ARGUMENT naming id.

public Task<(TriggerMetadata Record, bool Changed)> ChangeAsync(string id, Func<TriggerMetadata> absent, Func<TriggerMetadata, TriggerMetadata?> change, CancellationToken cancellationToken)

Parameters

id string
absent Func<TriggerMetadata>
change Func<TriggerMetadata, TriggerMetadata>
cancellationToken CancellationToken

Returns

Task<(TriggerMetadata Record, bool Changed)>

The record and whether it was written.

DeleteAsync(string, CancellationToken)

Deletes the record of id, if any, and its index entry.

public Task DeleteAsync(string id, CancellationToken cancellationToken)

Parameters

id string
cancellationToken CancellationToken

Returns

Task

GetAsync(string, CancellationToken)

The record of id and its ETag; null when there is none.

public Task<(TriggerMetadata? Record, string ETag)> GetAsync(string id, CancellationToken cancellationToken)

Parameters

id string
cancellationToken CancellationToken

Returns

Task<(TriggerMetadata Record, string ETag)>

GetIndexAsync(CancellationToken)

The index: every trigger id that has (or is about to have) a record, with when it was added (Unix milliseconds). It is how records whose job is gone are found.

public Task<IReadOnlyDictionary<string, long>> GetIndexAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

Task<IReadOnlyDictionary<string, long>>

GetManyAsync(IReadOnlyList<string>, CancellationToken)

The records of ids that exist, by id.

public Task<IReadOnlyDictionary<string, TriggerMetadata>> GetManyAsync(IReadOnlyList<string> ids, CancellationToken cancellationToken)

Parameters

ids IReadOnlyList<string>
cancellationToken CancellationToken

Returns

Task<IReadOnlyDictionary<string, TriggerMetadata>>

HoldsRecord(string)

Whether id can have a record: a UUID in canonical form, as every trigger id is since api 0.34. A Dapr job scheduled before (api 0.33 took text ids such as instruments-<worker id>) has an id no record key admits: it has no record, is listed with no tags, groups or owner, and can be deleted, but takes no metadata.

public static bool HoldsRecord(string id)

Parameters

id string

Returns

bool

TryCreateAsync(TriggerMetadata, CancellationToken)

Writes record only if its trigger has none; false if it has.

public Task<bool> TryCreateAsync(TriggerMetadata record, CancellationToken cancellationToken)

Parameters

record TriggerMetadata
cancellationToken CancellationToken

Returns

Task<bool>

TryReplaceAsync(TriggerMetadata, string, CancellationToken)

Replaces the record if its ETag is still etag; false if it changed.

public Task<bool> TryReplaceAsync(TriggerMetadata record, string etag, CancellationToken cancellationToken)

Parameters

record TriggerMetadata
etag string
cancellationToken CancellationToken

Returns

Task<bool>