ConsensusRegisterCollectionClass Class
A distributed data structure that holds a set of registers with update versions. On concurrent updates, a register internally stores all possible versions of a value by using reference sequence number of the incoming update.
Using all the stored versions, we can then distinguish amongst different read policies. Below are the policies we support:
Atomic: Atomicity requires a linearizable register. A linearizable register behaves as if there is only a single copy of the data, and that every operation appears to take effect atomically at one point in time. This definition implies that operations are executed in an well-defined order. On a concurrent update, we perform a compare-and-set operation, where we compare a register sequence number with the incoming reference sequence number. The earliest operation overwriting prior sequence numbers wins since every client reaches to an agreement on the value. So we can safely return the first value.
LWW: The last write to a key always wins.
To use, import via @fluidframework/register-collection/legacy.
For more information about our API support guarantees, see here.
Signature
export declare class ConsensusRegisterCollection<T> extends SharedObject<IConsensusRegisterCollectionEvents> implements IConsensusRegisterCollection<T>
Extends: SharedObject<IConsensusRegisterCollectionEvents>
Implements: IConsensusRegisterCollection<T>
Type Parameters
| Parameter | Description |
|---|---|
| T |
Constructors
| Constructor | Alerts | Description |
|---|---|---|
| (constructor)(id, runtime, attributes) | Beta | Constructs a new consensus register collection. If the object is non-local an id and service interfaces will be provided |
Methods
| Method | Alerts | Modifiers | Return Type | Description |
|---|---|---|---|---|
| applyStashedOp() | Beta | void | ||
| keys() | Beta | string[] | ||
| loadCore(storage) | Beta | Promise<void> | ||
| onDisconnect() | Beta | void | ||
| processMessagesCore(messagesCollection) | Beta | void | ||
| read(key, readPolicy) | Beta | T | undefined | Returns the most recent local value of a register. | |
| readVersions(key) | Beta | T[] | undefined | ||
| rollback(content, localOpMetadata) | Beta | sealed | void | |
| summarizeCore(serializer) | Beta | ISummaryTreeWithStats | ||
| write(key, value) | Beta | Promise<boolean> | Creates a new register or writes a new value. Returns a promise that will resolve when the write is acked. |
Constructor Details
(constructor)
Constructs a new consensus register collection. If the object is non-local an id and service interfaces will be provided
For more information about our API support guarantees, see here.
Signature
constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes);
Parameters
| Parameter | Type | Description |
|---|---|---|
| id | string | |
| runtime | IFluidDataStoreRuntime | |
| attributes | IChannelAttributes |
Method Details
applyStashedOp
For more information about our API support guarantees, see here.
Signature
protected applyStashedOp(): void;
keys
For more information about our API support guarantees, see here.
Signature
keys(): string[];
Returns
Return type: string[]
loadCore
For more information about our API support guarantees, see here.
Signature
protected loadCore(storage: IChannelStorageService): Promise<void>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| storage | IChannelStorageService |
Returns
Return type: Promise<void>
onDisconnect
For more information about our API support guarantees, see here.
Signature
protected onDisconnect(): void;
processMessagesCore
For more information about our API support guarantees, see here.
Signature
protected processMessagesCore(messagesCollection: IRuntimeMessageCollection): void;
Parameters
| Parameter | Type | Description |
|---|---|---|
| messagesCollection | IRuntimeMessageCollection |
read
Returns the most recent local value of a register.
For more information about our API support guarantees, see here.
Signature
read(key: string, readPolicy?: ReadPolicy): T | undefined;
Parameters
| Parameter | Modifiers | Type | Description |
|---|---|---|---|
| key | string | The key to read | |
| readPolicy | optional | ReadPolicy | The ReadPolicy to apply. Defaults to Atomic. |
Returns
Return type: T | undefined
readVersions
For more information about our API support guarantees, see here.
Signature
readVersions(key: string): T[] | undefined;
Parameters
| Parameter | Type | Description |
|---|---|---|
| key | string |
Returns
Return type: T[] | undefined
rollback
For more information about our API support guarantees, see here.
This type is "sealed," meaning that code outside of the library defining it should not implement or extend it. Future versions of this type may add members or make typing of readonly members more specific.
Signature
/** @sealed */
protected rollback(content: unknown, localOpMetadata: unknown): void;
Parameters
| Parameter | Type | Description |
|---|---|---|
| content | unknown | |
| localOpMetadata | unknown |
summarizeCore
For more information about our API support guarantees, see here.
Signature
protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;
Parameters
| Parameter | Type | Description |
|---|---|---|
| serializer | IFluidSerializer |
Returns
Return type: ISummaryTreeWithStats
write
Creates a new register or writes a new value. Returns a promise that will resolve when the write is acked.
For more information about our API support guarantees, see here.
Signature
write(key: string, value: T): Promise<boolean>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| key | string | |
| value | T |
Returns
Promise if write was non-concurrent
Return type: Promise<boolean>