Class LWWRegister<T>
Implements a 'Last Writer Wins Register' CRDT, also called a 'LWW-Register'.
It is described in the paper A comprehensive study of Convergent and Commutative Replicated Data Types.
Merge takes the register with highest timestamp. Note that this relies on synchronized clocks. LWWRegister<T> should only be used when the choice of value is not important for concurrent updates occurring within the clock skew.
Merge takes the register updated by the node with lowest address (UniqueAddress is ordered) if the timestamps are exactly the same.
Instead of using timestamps based on DateTime.UtcNow time it is possible to
use a timestamp value based on something else, for example an increasing version number
from a database record that is used for optimistic concurrency control.
For first-write-wins semantics you can use the ReverseClock instead of the [[LWWRegister#defaultClock]]
This class is immutable, i.e. "modifying" methods return a new instance.
Implements
Inherited Members
Namespace: Akka.DistributedData
Assembly: Akka.DistributedData.dll
Syntax
[Serializable]
public sealed class LWWRegister<T> : IReplicatedData<LWWRegister<T>>, IReplicatedData, IReplicatedDataSerialization, IEquatable<LWWRegister<T>>
Type Parameters
| Name | Description |
|---|---|
| T | TBD |
Constructors
| Edit this page View SourceLWWRegister(UniqueAddress, T)
TBD
Declaration
public LWWRegister(UniqueAddress node, T initial)
Parameters
| Type | Name | Description |
|---|---|---|
| UniqueAddress | node | TBD |
| T | initial | TBD |
LWWRegister(UniqueAddress, T, Clock<T>)
TBD
Declaration
public LWWRegister(UniqueAddress node, T initial, Clock<T> clock)
Parameters
| Type | Name | Description |
|---|---|---|
| UniqueAddress | node | TBD |
| T | initial | TBD |
| Clock<T> | clock | TBD |
LWWRegister(UniqueAddress, T, long)
TBD
Declaration
public LWWRegister(UniqueAddress node, T value, long timestamp)
Parameters
| Type | Name | Description |
|---|---|---|
| UniqueAddress | node | TBD |
| T | value | TBD |
| long | timestamp | TBD |
Fields
| Edit this page View SourceDefaultClock
Default clock is using max between DateTime.UtcNow.Ticks and current timestamp + 1.
Declaration
public static readonly Clock<T> DefaultClock
Field Value
| Type | Description |
|---|---|
| Clock<T> |
ReverseClock
Reverse clock can be used for first-write-wins semantics. It's counting backwards, using min between -DateTime.UtcNow.Ticks and current timestamp - 1.
Declaration
public static readonly Clock<T> ReverseClock
Field Value
| Type | Description |
|---|---|
| Clock<T> |
Properties
| Edit this page View SourceRegisterType
Declaration
public Type RegisterType { get; }
Property Value
| Type | Description |
|---|---|
| Type |
Timestamp
Returns a timestamp used to determine precedence in current register updates.
Declaration
public long Timestamp { get; }
Property Value
| Type | Description |
|---|---|
| long |
UpdatedBy
Returns a unique address of the last cluster node, that updated current register value.
Declaration
public UniqueAddress UpdatedBy { get; }
Property Value
| Type | Description |
|---|---|
| UniqueAddress |
Value
Returns value of the current register.
Declaration
public T Value { get; }
Property Value
| Type | Description |
|---|---|
| T |
Methods
| Edit this page View SourceEquals(LWWRegister<T>)
Declaration
public bool Equals(LWWRegister<T> other)
Parameters
| Type | Name | Description |
|---|---|---|
| LWWRegister<T> | other |
Returns
| Type | Description |
|---|---|
| bool |
Equals(object)
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj |
Returns
| Type | Description |
|---|---|
| bool |
Overrides
| Edit this page View SourceGetHashCode()
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int |
Overrides
| Edit this page View SourceMerge(IReplicatedData)
TBD
Declaration
public IReplicatedData Merge(IReplicatedData other)
Parameters
| Type | Name | Description |
|---|---|---|
| IReplicatedData | other | TBD |
Returns
| Type | Description |
|---|---|
| IReplicatedData | TBD |
Merge(LWWRegister<T>)
TBD
Declaration
public LWWRegister<T> Merge(LWWRegister<T> other)
Parameters
| Type | Name | Description |
|---|---|---|
| LWWRegister<T> | other | TBD |
Returns
| Type | Description |
|---|---|
| LWWRegister<T> | TBD |
ToString()
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string |
Overrides
| Edit this page View SourceWithValue(UniqueAddress, T, Clock<T>)
Change the value of the register.
You can provide your clock implementation instead of using timestamps based
on DateTime.UtcNow.Ticks time. The timestamp can for example be an
increasing version number from a database record that is used for optimistic
concurrency control.
Declaration
public LWWRegister<T> WithValue(UniqueAddress node, T value, Clock<T> clock = null)
Parameters
| Type | Name | Description |
|---|---|---|
| UniqueAddress | node | TBD |
| T | value | TBD |
| Clock<T> | clock | TBD |
Returns
| Type | Description |
|---|---|
| LWWRegister<T> | TBD |
Edit this page