Interface RaftControllerOptions

Controller options that should be provided when bootstrapping a RaftController in Coaty. Are used to configure the controller.

Bootstrapping a RaftController in Coaty looks like this:

 // Define RaftControllerOptions
const opts: RaftControllerOptions = {
id: "1"
stateMachine: new YourRaftStateMachineImplementation(),
shouldCreateCluster: true,
};

// Create Components and Configuration
const components: Components = { controllers: { RaftController } };
const configuration: Configuration = { controllers: { RaftController: opts }, ... };

// Bootstrap RaftController
const container = Container.resolve(components, configuration);
const raftController = container.getController<RaftController>("RaftController");

Hierarchy

  • RaftControllerOptions

Properties

cluster?: string

Id of the Raft cluster of this RaftController.

If not given, the empty string is used.

This option enables users to define multiple Raft clusters with different RaftStateMachine implementations that can run in parallel.

configuration?: RaftConfiguration

RaftConfiguration that can be used to further configure the underlying Raft implementation.

If not given, the default configuration is used.

databaseKey?: string

Key in Coaty Configuration.databaseOptions which defines the location of the Raft persistency store (optional).

If not given, a default database key named "raftdb" is used.

id: string

Id of the RaftController. Has to be unique among all RaftControllers in the given Raft cluster named by property "cluster" (or default one). Must not be an empty string.

Remark

Ids cannot be reused within a cluster after the old controller has left by disconnecting.

Note that if the standard RaftCommunication implementation with Coaty event patterns is used, an id must not contain the following characters: NULL (U+0000), # (U+0023), + (U+002B), / (U+002F).

Basically, consider using UUID v4 strings to ensure uniqueness within the context of a Raft cluster.

shouldCreateCluster: boolean

Defines whether or not the RaftController should create a new Raft cluster when it is first started. It is required that exactly one RaftController per cluster has this variable set to true to create the initial Raft cluster. Multiple RaftControllers in the same cluster having this variable set to true will lead to undefined behavior.

Remark

The RaftController that creates the Raft cluster is not required to stay in the cluster. It is possible to use one designated controller for creating the cluster that disconnects after the cluster is up and running. In this case it is important that at least one other controller has connected before the "creating" controller disconnects.

stateMachine: RaftStateMachine

Will be used internally to describe the replicated state machine (RSM) of the Raft cluster. All controllers in a cluster must use the same RaftStateMachine implementation and provide a new instance of it here.

Generated using TypeDoc