Pooling configuration with the Raft store¶
Experimental
The Raft store is experimental: its implementation is still in progress and the procedures in this page may change.
With the Raft store, there is no external database: each node of the pool stores the data on its own disk and replicates it directly with the other nodes of the pool through the Raft consensus protocol. The nodes of the pool are the datastore of the pool.
To pool a set of DSS instances with the Raft store:
- Prerequisites: the tools and the running infrastructure.
- Certificates: each organization generates its own certificate authority (CA) and its nodes' certificates, and the CAs are exchanged so that every member of the pool trusts every other.
- Forming the pool: the first participant bootstraps the Raft groups with its own nodes; whenever a new node joins the pool, an existing node adds it.
- Managing the pool: the day-2 operations on the pool: adding, removing and replacing nodes.
Prerequisites¶
- A running Kubernetes platform deployed as infrastructure
- A recent version of python 3 to run the
dss-certs.pyscript, in thedeploy/operations/certificates-managementfolder of this repository. - OpenSSL, used by
dss-certs.pyto generate the certificates.
The commands below are run from the workspace folder generated by Terraform
during the infrastructure deployment
(terraform output -raw workspace_location). It holds two helpers:
get-credentials.shgets the credentials of the cluster: run it once before the commands below.dss-certs.shcallsdss-certs.pywith the name, organization, cluster context, namespace, number of nodes and public address of the nodes of this DSS instance already set.
Without Terraform
Replace ./dss-certs.sh by ./dss-certs.py, run from the
deploy/operations/certificates-management folder, with these options:
--name <NAME>: a name identifying this DSS instance, the same in every command;--organization <ORGANIZATION>: the name of your organization;--cluster-context $CLUSTER_CONTEXT --namespace $NAMESPACE;--nodes-count N;--nodes-public-address '<ID>.raft.dss.example.com': the public address of the nodes, where<ID>is typed as is: the script replaces it with the node number (0-based, the order of the pods of the deployment).
In the instructions below:
$CLUSTER_CONTEXTis the name of the Kubernetes cluster deployed as infrastructure onto which services will be deployed.$NAMESPACEis the namespace for this DSS instanceENDPOINTis thehost:portpair at which the other participants of the pool reach the Raft listener of one node of this instance (e.g.0.raft.dss.example.com:2407). It must be unique in the pool and be reachable by the other participants: the deployment tools expose it with one load balancer (or static IP) per node.Nis the number of DSS nodes of this instance.
Note
All participants of a DSS pool must use the same datastore. A pool cannot mix nodes running the Raft store and nodes running a SQL datastore.
Certificates¶
Each participant operates its own certificate authority (CA) and issues one certificate per node. Every node holds the PEM bundle of the CAs of all the participants of the pool (including its own) and accepts a Raft connection only from a peer whose certificate is signed by one of them. This bundle defines the boundaries of the pool: it must be identical on every node of the pool before the nodes can be added to it.
Creating the certificates of your organization¶
-
Initialize the certificates of this participant:
-
If this DSS instance joins an existing pool, import the bundle of the CAs of the pool, provided by any one participant of the pool with
./dss-certs.sh get-pool-ca, saved inPOOL_CA_FILE: -
Generate the certificates of the
Nraft nodes: -
Apply the certificates on the cluster to create the
dss.raft.certssecret. It contains, for each node of this instance, its certificatenode.raft-<ID>.crtand its private keynode.raft-<ID>.key, and the bundle of the CAs of the pool inca.crt:Run
applyagain after every modification of the certificates (pool CA added or removed, new number of nodes). The nodes read their certificate and the CA bundle only at startup, so after the secret is updated they must be restarted.
Adding the certificates of a new organization to an existing pool¶
When a DSS instance with its own CA joins a pool, every existing participant must accept the CA of this DSS instance.
-
Get the CA of this DSS instance with
./dss-certs.sh get-caand provide it to each participant of the existing pool. -
Each existing participant, upon receipt of the CA of this DSS instance, imports it and updates its certificates with its own
dss-certs.sh:
and restarts its nodes: the nodes read the CA bundle only at startup, so they must be restarted to accept the new CA.
- Every participant should then compare the hash of its pool of CAs
(displayed by
add-pool-caand by./dss-certs.sh list-pool-ca) to make sure they work with the same coherent set of certificates.
Danger
Do not proceed until every participant of the existing pool has positively confirmed that its DSS instance accepts the CA of this DSS instance.
Restarting the nodes¶
The data of a node (its identity, its Raft log and its snapshots) is stored on
the persistent volume raft-data of its pod, mounted at /raft_data. A
restarted node reloads it and rejoins the pool: it replays its log, or
receives a snapshot from a peer if it has been down too long.
The nodes of a participant are restarted with a single command; the stateful set restarts them one at a time, in reverse pod order (from the highest node number to the lowest), waiting for a node to be ready before restarting the next one:
(With the helm chart, the statefulset is named <release>-core-service, e.g.
dss-core-service.)
Warning
Do not restart the nodes of the pool all at once, for instance with all the participants restarting their nodes at the same time after a CA update: a group that loses the majority of its voters stops serving reads and writes. Coordinate the restarts so that a majority of the voters of each group stays up.
Use this to restart the nodes whenever the dss.raft.certs secret has been
updated (see certificates).
If the data directory of a node is lost or corrupted, the node must not be started with an empty one: it would regenerate its identity and simply wait to be added to the pool, while the pool still remembers its previous one. Remove the old identity from the pool, delete the data directory, restart the node and add it back to the pool: see replacing a node.
Forming the pool¶
If you are the first participant¶
This DSS instance creates the pool (it is the first instance, or one of the instances creating the pool at the same time as other participants).
-
In the deployment configuration of this instance, enable the automatic bootstrap feature:
raft_automatic_bootstrapin the terraform variables,raft.automaticBootstrapin the helm chart, orautomaticBootstrapin theraftsection of the tankamain.jsonnet(set automatically from the terraform variables).Note
The automatic bootstrap must be enabled on one participant only: if several nodes bootstrap at the same time, independent pools are created. It should be disabled again once the pool is formed: with it still enabled, a node that starts with an empty data directory would bootstrap a new pool instead of waiting to be added back to the existing one.
-
If other participants create their instances at the same time, list the
ENDPOINTof their nodes in theautomaticBootstrapNodessetting of this instance (raft_automatic_bootstrap_nodesin the terraform variables). -
Deploy the services as described in services deployment. The other participants deploy normally: their nodes start waiting and are added by this instance as soon as they are reachable.
-
The first node of this instance bootstraps the three Raft groups (
aux,ridandscd) with itself as their only member, then adds the other nodes of this instance and the nodes of the other participants, one at a time, retrying until all of them are members. -
Check that the nodes have joined the pool:
dssctl raft nodeon one of them should reportmemberin every Raft group, anddssctl raft listshould list all the nodes of the pool (inspecting the membership).
Alternatively, you can do the bootstrap manually with the dssctl CLI (see
running dssctl for how to run dssctl against a node of
the pool):
bootstrap is run on the first node: it bootstraps the three Raft groups
with itself as their only member. add is then run once for each other node
of the pool, from any member of the pool.
If you are joining an existing pool¶
This DSS instance joins a pool that already exists. Its nodes start with an empty data directory and wait to be added to the pool by an existing node.
-
Keep the automatic bootstrap feature disabled in the deployment configuration of this instance.
-
Complete the certificates of this instance and make sure that the existing participants accept its CA (see adding the certificates of a new organization).
-
Make sure the
--raft_cluster_idof this instance is the same as the one of the existing pool:raft_cluster_idin the terraform variables,raft.clusterIDin the helm chart values, orclusterIDin theraftsection of the tankamain.jsonnet(default1). A node with a different ID cannot join the pool. -
Deploy the services as described in services deployment.
-
An existing node adds the nodes of this instance to the pool, one at a time: see adding a node. Once a node is added, the change is known to every member of the pool: no other participant has to do anything for the membership.
-
Verify that the new nodes are
memberin every Raft group on this instance and on the existing instances (inspecting the membership).
Managing the pool¶
This section describes how to manage the membership of a pool. A DSS node
running the Raft store is a member of three Raft groups (one per service:
aux, rid and scd), each with its own membership. Adding a node to the
pool means adding it to the three groups; the same applies to removal. The
membership is managed with the dssctl raft commands, which talk to the
admin API of a node over the Unix socket it serves at --admin_socket
(default /run/dss/admin.sock). Any node of the pool can be used: a
participant may manage the pool through any node it can reach.
Restarting the nodes, for instance after updating their certificates, is described in restarting the nodes.
Running dssctl¶
dssctl is in the DSS image, inside every core-service pod:
where $POD is the name of a core-service pod of any node of the pool
(<release>-core-service-0 with the helm chart, e.g. dss-core-service-0, or
core-service-0 with the tanka files).
Common options:
| Option | Description |
|---|---|
--groups |
Comma-separated list of the Raft groups to act on (aux, rid, scd); all of them if not set. |
--admin_socket |
Path of the admin socket of the node, matching its --admin_socket; default /run/dss/admin.sock. |
--admin_timeout |
Timeout of each request to the admin API; default 1m. |
A command is executed independently for each selected group: it may
succeed for some groups and fail for others. When that happens, rerun the
command with --groups limited to the failed groups.
Inspecting the membership¶
dssctl raft node describes the node serving the admin API in each of its
groups: its state (waiting, member or removed), its ID and its URL.
dssctl raft list lists, for each group, the nodes that are or were members
of it, sorted by URL (so that the groups list the nodes in the same order),
with the current leader marked:
A node has a different ID in each group: the IDs are generated when the node starts for the first time with an empty data directory and are stored in it.
Adding a node¶
A node is added to the pool one at a time, from any member of the pool. The node to add must:
- be running and waiting, i.e. started with an empty data directory (a node that was never added to the pool, or whose data directory was deleted);
- have its participant's CA in the CA bundle of every member of the pool, otherwise the TLS handshake between the members and the node fails (see certificates);
- be reachable by the members at its
--raft_peer_url(itsENDPOINT); - use a URL that is not already used by another member of the pool.
The member reads the ID of the node to add from the node itself, on its Raft listener; the node then learns the configuration and the data of the group from the leader. The added node joins directly as a voter: as soon as the command returns, it counts in the quorum of the group. The command returns once the change is adopted by the group.
Verify the addition with dssctl raft list on the node used and on at least
one other participant's node: the new node should be member in every group.
Removing a node¶
A node is removed one at a time, from any member of the pool:
or, for a single group selected with --groups, by its ID in that group:
Properties of a removal:
- A removed node stops itself when the removal is applied and its state
becomes
removed. It does not need to be reachable for the removal to succeed. - The ID of a removed node is retired permanently: it can never be added back to the group. A node that is removed and re-added comes back with a new ID (see Replacing a node).
- A voter cannot be removed if the group would be left with fewer than three voters.
- Removing a voter changes the quorum immediately, and removing the current leader triggers an election.
Verify the removal with dssctl raft list: the node is gone from the members
and its ID is in the list of removed IDs.
Replacing a node¶
If a node must come back at the same URL with a new data directory (typically after its data directory was lost or corrupted):
-
With four voters or more in each group: remove the node (
dssctl raft remove --url https://<ENDPOINT>), delete the data directory of the pod (theraft-datapersistent volume), restart the pod (it generates new IDs and waits) and add it back (dssctl raft add --url https://<ENDPOINT>). -
With exactly three voters in a group, the group cannot go below the minimum of three voters, so the node must be restarted with a different
--raft_peer_url(a newENDPOINT) and added to the groups before its old identity is removed.
In both cases the node comes back as a new node, with new IDs in every group: it receives a snapshot from the pool and catches up on the entries since.
After a membership change¶
- Verify the membership on at least two participants of the pool: every member of a group holds the same membership once the change is adopted.
- If a participant leaves the pool entirely, the remaining participants should eventually remove its CA from their pool of CAs: see leaving a pool.
- The certificates must be rotated independently of the membership: see certificates.
Next steps¶
Proceed to services deployment.