Class LeaseTransactExtensions
- Namespace
- DynaSharp.Coordination
- Assembly
- DynaSharp.Coordination.dll
The fencing of a write in DynamoDB: a step of TransactWrite() that lets the transaction commit only while a lease holds its lock.
public static class LeaseTransactExtensions
- Inheritance
-
LeaseTransactExtensions
- Inherited Members
Methods
IsHeld<TChain>(TChain)
Adds the check of IsHeld<TChain>(TChain, Lease) for Current, the lease of the term of RunAsLeaderAsync(string, TimeSpan, Func<Lease, CancellationToken, Task>, CancellationToken)
that the calling code runs in, so that work deep in a call graph fences its writes without the lease passed down to it.
For example await client.TransactWrite().IsHeld().Put(orders, order).SendAsync(ct);.
public static ConditionStep IsHeld<TChain>(this TChain chain) where TChain : ITransactWriteChain<TChain>, allows ref struct
Parameters
chainTChainThe command or step before this, which this replaces.
Returns
- ConditionStep
The step, which takes more conditions with
If.
Type Parameters
TChainThe type of the command or step before this.
Remarks
The lease is taken when the step is added. Work that outlives its term keeps the lease that ended, and the transaction fails at DynamoDB, as fencing should. A lease from TryAcquireAsync(string, TimeSpan, CancellationToken) or AcquireAsync(string, TimeSpan, CancellationToken) is never current: pass it to IsHeld<TChain>(TChain, Lease). Current says where else it is null.
Exceptions
- InvalidOperationException
No lease is current: the code runs outside the work of RunAsLeaderAsync(string, TimeSpan, Func<Lease, CancellationToken, Task>, CancellationToken), or started before its term.
IsHeld<TChain>(TChain, Lease)
Adds a condition check on the item of the lock, so that the transaction commits only if the lock is still held by this lease:
await client.TransactWrite().IsHeld(lease).Put(orders, order).SendAsync(ct);.
public static ConditionStep IsHeld<TChain>(this TChain chain, Lease lease) where TChain : ITransactWriteChain<TChain>, allows ref struct
Parameters
chainTChainThe command or step before this, which this replaces.
leaseLeaseThe lease.
Returns
- ConditionStep
The step, which takes more conditions with
If.
Type Parameters
TChainThe type of the command or step before this.
Remarks
Fencing. A contender that took the lock over has written its own owner and a higher FencingToken, so the transaction of a holder that lost its lease, and may not know it yet, is cancelled instead of overwriting the work of the next one. The check reads the item at the moment the transaction commits, which is what makes it safe; Ended is only what this process knows. A transaction that fails it throws TransactionCanceledException with ConditionalCheckFailed for this step. A lease that ran out on the local clock still passes while nobody has taken the lock over, which is safe, because nobody else holds it. The lock item must be in a table of the same account and region as the other items of the transaction.
Exceptions
- ArgumentNullException
leaseis null.
IsHeld<TChain>(TChain, Lease, out TransactMarker)
Adds the check of IsHeld<TChain>(TChain, Lease), and hands out its marker, which tells a lost lease from another reason the transaction failed.
public static ConditionStep IsHeld<TChain>(this TChain chain, Lease lease, out TransactMarker marker) where TChain : ITransactWriteChain<TChain>, allows ref struct
Parameters
chainTChainThe command or step before this, which this replaces.
leaseLeaseThe lease.
markerTransactMarkerWhat finds this check in a cancelled transaction:
exception.ReasonFor(marker).
Returns
- ConditionStep
The step, which takes more conditions with
If.
Type Parameters
TChainThe type of the command or step before this.
Exceptions
- ArgumentNullException
leaseis null.
IsHeld<TChain>(TChain, out TransactMarker)
Adds the check of IsHeld<TChain>(TChain) for Current, and hands out its marker, which tells a lost lease from another reason the transaction failed.
public static ConditionStep IsHeld<TChain>(this TChain chain, out TransactMarker marker) where TChain : ITransactWriteChain<TChain>, allows ref struct
Parameters
chainTChainThe command or step before this, which this replaces.
markerTransactMarkerWhat finds this check in a cancelled transaction:
exception.ReasonFor(marker).
Returns
- ConditionStep
The step, which takes more conditions with
If.
Type Parameters
TChainThe type of the command or step before this.
Exceptions
- InvalidOperationException
No lease is current: the code runs outside the work of RunAsLeaderAsync(string, TimeSpan, Func<Lease, CancellationToken, Task>, CancellationToken), or started before its term.