Skip to main content
Version: v1

Quorum Class

The Quorum distributed data structure provides key/value storage with a cautious conflict resolution strategy. This strategy optimizes for all clients being aware of the change prior to considering the value as accepted.

It is still experimental and under development. Please do try it out, but expect breaking changes in the future.

Signature​

export declare class Quorum extends SharedObject<IQuorumEvents> implements IQuorum

Extends: SharedObject<IQuorumEvents

Implements: IQuorum

Remarks​

### Creation

To create a Quorum, call the static create method:

const quorum = Quorum.create(this.runtime, id);

### Usage

Setting and reading values is somewhat similar to a SharedMap. However, because the acceptance strategy cannot be resolved until other clients have witnessed the set, the new value will only be reflected in the data after the consensus is reached.

quorum.on("pending", (key: string) => {
console.log(quorum.getPending(key));
});
quorum.on("accepted", (key: string) => {
console.log(quorum.get(key));
});
quorum.set("myKey", "myValue");

// Reading from the quorum prior to the async operation's completion will still return the old value.
console.log(quorum.get("myKey"));

The acceptance process has two stages. When an op indicating a client's attempt to set a value is sequenced, we first verify that it was set with knowledge of the most recently accepted value (consensus-like FWW). If it meets this bar, then the value is "pending". During this time, clients may observe the pending value and act upon it, but should be aware that not all other clients may have witnessed the value yet. Once all clients that were connected at the time of the value being set have explicitly acknowledged the new value, the value becomes "accepted". Once the value is accepted, it once again becomes possible to set the value, again with consensus-like FWW resolution.

### Eventing

Quorum is an EventEmitter, and will emit events when a new value is accepted for a key.

quorum.on("accept", (key: string) => {
console.log(`New value was accepted for key: ${ key }, value: ${ quorum.get(key) }`);
});

Constructors​

ConstructorDescription
(constructor)(id, runtime, attributes)Constructs a new quorum. If the object is non-local an id and service interfaces will be provided

Static Methods​

MethodReturn TypeDescription
create(runtime, id)QuorumCreate a new Quorum
getFactory()IChannelFactoryGet a factory for Quorum to register with the data store.

Methods​

MethodReturn TypeDescription
applyStashedOp()void
delete(key)voidDeletes the key/value pair at the given key. After issuing the delete, the delete is in "pending" state until all connected clients have ack'd the delete. The accepted value remains unchanged until that time.
get(key)anyGets the accepted value for the given key.
getPending(key)anyGets the pending value for the given key.
has(key)booleanChecks if the quorum has an accepted value for the given key.
set(key, value)voidSets the value for the given key. After setting the value, it will be in "pending" state until all connected clients have ack'd the set. The accepted value remains unchanged until that time.

Constructor Details​

(constructor)​

Constructs a new quorum. If the object is non-local an id and service interfaces will be provided

Signature​

constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes);

Parameters​

ParameterTypeDescription
idstringoptional name of the quorum
runtimeIFluidDataStoreRuntimedata store runtime the quorum belongs to
attributesIChannelAttributes

Method Details​

applyStashedOp​

Signature​

applyStashedOp(): void;

create​

Create a new Quorum

Signature​

static create(runtime: IFluidDataStoreRuntime, id?: string): Quorum;

Parameters​

ParameterModifiersTypeDescription
runtimeIFluidDataStoreRuntimedata store runtime the new quorum belongs to
idoptionalstringoptional name of the quorum

Returns​

newly created quorum (but not attached yet)

Return type: Quorum

delete​

Deletes the key/value pair at the given key. After issuing the delete, the delete is in "pending" state until all connected clients have ack'd the delete. The accepted value remains unchanged until that time.

Signature​

delete(key: string): void;

Parameters​

ParameterTypeDescription
keystringthe key to delete

get​

Gets the accepted value for the given key.

Signature​

get(key: string): any;

Parameters​

ParameterTypeDescription
keystringThe key to retrieve from

Returns​

Return type: any

getFactory​

Get a factory for Quorum to register with the data store.

Signature​

static getFactory(): IChannelFactory;

Returns​

a factory that creates and load Quorum

Return type: IChannelFactory

getPending​

Gets the pending value for the given key.

Signature​

getPending(key: string): any;

Parameters​

ParameterTypeDescription
keystringThe key to retrieve from

Returns​

Return type: any

has​

Checks if the quorum has an accepted value for the given key.

Signature​

has(key: string): boolean;

Parameters​

ParameterTypeDescription
keystringThe key to check

Returns​

Return type: boolean

set​

Sets the value for the given key. After setting the value, it will be in "pending" state until all connected clients have ack'd the set. The accepted value remains unchanged until that time.

Signature​

set(key: string, value: unknown): void;

Parameters​

ParameterTypeDescription
keystringThe key to set
valueunknownThe value to store