Administration
By Roberto Arato of aratoingegneria.it
Everything is done with nexfsctl, from any machine that has an
administrator certificate (a meta node, or a name listed in "admins", see
Configuration). Every command answers with a JSON
object on one line, errors included:
nexfsctl node list
{"nodes": [{"id": 1, "name": "node-1", "address": "10.20.0.11", "port": 7400, "total": 1999...
nexfsctl node drain 9
{"error": "Device or resource busy", "code": -16}
The exit code is 0 if the command succeeded, 1 if it answered with an error, 2 if it was mistyped. This way a script, or NEX, reads it without parsing free text.
The state of the cluster
| Command | What it tells you |
|---|---|
nexfsctl ping |
{"alive": true} if a meta node responds |
nexfsctl quorum |
{"quorum": true} if the majority of meta nodes respond |
nexfsctl status |
the state of the meta node that responds: role, leader, term, log |
nexfsctl health |
everything in one call: overall status (ok, warning, error) with the reasons, nodes, blocks, rebuilds in progress, space, traffic |
nexfsctl space |
total and free space, files, number of copies, whether a conversion is in progress |
nexfsctl node list |
the data nodes, with space, whether they are alive and their state |
health is made for alerts and dashboards: the same format for everyone, one
field for each thing that can go wrong. With --no-traffic it does not ask
the data nodes for traffic (it answers sooner).
The state of a data node is one of:
| State | Meaning |
|---|---|
in-service |
working |
maintenance |
stopped briefly, on purpose: its copies are not rebuilt elsewhere |
draining |
being drained: its copies are moving to the others |
drained |
drained: it can be shut down and removed |
quarantine |
its disk is not the one the metadata knew: waiting for a decision |
Copies
nexfsctl copies 3 # the cluster number, for new blocks and (in the background) for existing ones
nexfsctl copies 1 /scratch # one folder, subfolders included
nexfsctl copies default /scratch # back to the cluster number
The cluster accepts from 1 to 4 copies, a folder from 1 to 3. The change
applies immediately to what is created from then on; for what already exists
it works in the background, and space reports "converting": true until it
has finished.
Adding a machine
The simple way is the one of the Tutorial: an entry code made on a meta node, and one command on the new machine. On a meta node:
sudo nexfs-setup token --role meta --uses 1 --ttl 30
Entry code (roles meta, 1 use, valid 30 minutes):
PFQN-4ZWM-88X1-JBVN-GHY1-781V-H40V-JKGJ
On the new machine, with its disk formatted and mounted on
/srv/nexfs/disk0 and the package installed (steps 1 and 2 of the tutorial):
sudo nexfs-setup join 192.168.203.146 PFQN-4ZWM-88X1-JBVN-GHY1-781V-H40V-JKGJ --meta --disk /srv/nexfs/disk0
sudo systemctl enable --now nexfs-client@nex.service # if it also mounts the filesystem
This machine joined the cluster as a meta node: node-4, id 4, in 5 seconds.
--role data and --data make a data node only (more space, no vote);
--client a machine that only mounts. A one-use code disappears from
nexfs-setup token list once used. The new node gets new blocks at once, and
rebalancing gives it its share of the existing ones in the background (about
40 seconds for 200 MB in the test).
Adding a data node by hand
On the new machine, with the package installed and its certificate:
nexfsctl node add --node node-4 --address 10.20.0.14 --id 4 \
--like /path/to/a/cluster/configuration.json \
--disk /srv/nexfs/disk0 --disk /srv/nexfs/disk1
--like takes the list of meta nodes and the CA from an existing
configuration; the command writes /etc/nexfs/nexfs.json, prepares the
folders, starts the service and waits for the node to register. Before that,
an administrator must have admitted it:
nexfsctl node allow node-4 # the name in its certificate
nexfsctl node allowed # who is admitted
nexfsctl node revoke node-4 # change of mind (until it has registered)
A new data node receives new blocks right away, and rebalancing brings it its share of the existing ones in the background.
Rebalancing
nexfsctl rebalance # {"rate_mb_s": N, "moving": N}
nexfsctl rebalance rate 50 # at most 50 MiB/s
nexfsctl rebalance off # stopped
Copies move from the fullest nodes to the emptiest ones at a limited speed, never going below the desired number of copies.
Maintenance and draining
nexfsctl node maintenance 4 on # the node stops briefly (a reboot, a new kernel)
nexfsctl node maintenance 4 off # it is back
nexfsctl node drain 4 # its copies move to the others
nexfsctl node drain 4 --cancel # change of mind
nexfsctl node forget 4 # drained and shut down: removed from the list
- In maintenance the node's copies are not rebuilt elsewhere: the node
comes back and catches up only on what has changed. The command is refused
(
-16) if a block would be left below the minimum needed to write. - Draining is refused if the remaining nodes are not enough for the
number of copies (
-16) or do not have the space (-28). - A forgotten node also loses its admission: if it started again it would be refused.
A data node that shuts down without maintenance is not a problem: writes
continue on the other copies, and if it does not come back within 10 minutes
(timeouts.replace_after_s) its copies are rebuilt elsewhere. Stopping it
with systemctl stop nexfsd (an orderly shutdown) also avoids copying again
the blocks written in the last few seconds.
Disks
A data node has one folder per disk ("disks"). If a disk fails, the node
carries on with the others and the blocks that were on it are rebuilt from
another copy; a new disk mounted in the empty slot is picked up
automatically.
If the failed disk was the only one of the node, the node stops being a data node; if it is also a meta node it keeps its vote and goes on as a metadata node only:
nexfsd: no disk of this node holds its block store any more: the node restarts as a metadata node only, until a disk is usable
nexfsd: this node goes on as a metadata node only; its data role starts again by itself when a disk folder changes (a new disk mounted there, with owner nexfs)
nexfsctl health shows data_node_down for it. The other nodes keep the
copies, and if the node does not come back within 10 minutes its copies are
rebuilt elsewhere.
Adding a disk
A data node holds up to 16 disks. A new one is prepared like the replacement
below (check the name with lsblk: everything on it is erased), in a folder
of its own, then given to NEXFS:
sudo mkfs.ext4 -q -L nexfs-disk1 /dev/sdc
sudo mkdir -p /srv/nexfs/disk1
echo "LABEL=nexfs-disk1 /srv/nexfs/disk1 ext4 defaults,noatime,nofail 0 2" | sudo tee -a /etc/fstab
sudo mount /srv/nexfs/disk1
sudo nexfsctl disk add /srv/nexfs/disk1
nexfsctl disk add puts the folder in "disks", opens it to the service
(nexfsd runs as the user nexfs with the system read-only: without this step
it would see the new disk as read-only) and restarts nexfsd in an orderly way.
At start the disk joins those of the node:
dischi: disk 1 is new: it joins the block stores of this node
New blocks are created on the disk with the most free space; those already
there stay where they are, so the node has no extra work while it serves the
cluster. The disks fill up differently, and that is normal. The command refuses
a folder that is not empty, one on the same disk as another (its space would
count twice) and the one holding the block key. With NEX,
sudo nexctl storage disk-add sdc is enough: it also formats and mounts.
If the new disk fails, what follows applies: the node goes on with its other disks and the copies that were there are rebuilt from the other nodes. In the test (a disk pulled out with 103 copies on it) nexfsd waited a few seconds on the read that did not come back, then wrote
nexfsd: a disk of this node is gone: 103 block copies were on it, 103 will be rebuilt, 0 blocks are LOST (it had their only copy)
and the cluster stayed "ok".
Replacing a disk
With the new disk in the machine (here it appears as /dev/sdc: check the name
with lsblk, everything on it is erased):
sudo umount /srv/nexfs/disk0 # the dead disk
sudo mkfs.ext4 -q -L nexfs-disk0 /dev/sdc
sudo mount /srv/nexfs/disk0 # by its label, as in /etc/fstab
sudo chown nexfs:nexfs /srv/nexfs/disk0 # nexfsd runs as the nexfs user
Nothing else: within a few seconds nexfsd sees the new disk, restarts with it,
and the cluster rebuilds its copies. In the test the node was serving blocks
again within 10 seconds of the chown, and nexfsctl health was back to
"ok" within 15 seconds:
nexfsd: the disk folder /srv/nexfs/disk0 changed: restarting to open the block store
nexfsd: new block store in /srv/nexfs/disk0
nexfsd: quarantine over: this node serves blocks again
Write nofail in the /etc/fstab line of each data disk (as in the
tutorial): if a disk dies while the machine is off, the machine still starts,
and nexfsd waits for the disk as above. Disk names can change at every boot
(/dev/sdc today, /dev/sdb after a reboot): check with lsblk right before
mkfs. If the mount fails, nexfsd does not use the empty folder left on the
system disk:
nexfsd: the disk of /srv/nexfs/disk0 is in /etc/fstab but it is not mounted: not used
Meta nodes
Meta nodes hold the filesystem index (names, permissions, where each block is) and vote: with three, the cluster survives the loss of one, with five the loss of two. A cluster starts with a single meta node and grows while running.
Adding a meta node. First you admit it, then on the new machine:
sudo nexfsctl node allow node-2 # from an administrator
sudo nexfsctl meta add --node node-2 --address 10.20.0.12 --id 2 \
--like /tmp/nexfs-node-1.json --disk /srv/nexfs/disk0 \
--ca /etc/nexfs/pki/ca.crt --cert /etc/nexfs/pki/node-2.crt --key /etc/nexfs/pki/node-2.key
{"added": true, "id": 2, "node": "node-2", "role": "meta", "seconds": 5}
The new node receives the whole index, and once it has caught up it votes (a
few seconds). With --disk it also acts as a data node. The other machines
do not need to be touched: they learn about it from the cluster.
nexfsctl meta list # the members: who votes, who is a learner, the witness
nexfsctl meta remove 3 # node 3 leaves the cluster; then you stop it
meta remove refuses to remove the leader (-16: you stop it, and the others
elect a new one) and the last voting node.
| Command | What it does |
|---|---|
nexfsctl meta maintenance ID on |
the meta node does not vote until it comes back: the others do not wait for it to restart after an abrupt shutdown |
nexfsctl meta maintenance ID off |
it votes again (only once it has caught up) |
nexfsctl meta restart-from-disk --accept-loss |
after a general shutdown, if a meta node is never coming back: the ones present restart from what they have on disk |
The leader cannot be put in maintenance (-16): you stop it, and the others
elect a new one within a few seconds. After a general shutdown the meta nodes
restart by themselves when they are all back; restart-from-disk is needed
only when one will not come back, and it can lose the last changes that were
confirmed only in the memory of the nodes that were shut down (that is why it
asks for --accept-loss).
Removing a machine for good
Here node-3, a meta node and a data node, id 3. The others must be enough
without it: for the number of copies (with three copies, at least three other
data nodes), for the space, and for the vote (add a machine first if the meta
nodes would drop below three). From any other node:
sudo nexfsctl node drain 3 # its copies move to the others
sudo nexfsctl node list # wait for "state": "drained"
{"id": 3, "state": "draining"}
200 MB took a few seconds in the test; the time depends on how much the node
holds and on nexfsctl rebalance rate. Then:
sudo nexfsctl meta remove 3 # it leaves the meta nodes (refused with -16 if it is the leader:
# restart its nexfsd, the others elect a new one, then repeat)
{"removed": true, "id": 3}
On node-3:
sudo systemctl disable --now nexfs-client@nex.service nexfsd
sudo apt purge nexfs nexfs-server nexfs-client nexfs-tools libnexfs0 # also /etc/nexfs: configuration, certificates, keys
Back on another node, once nexfsctl node list shows "alive": false for
it (15 seconds after it stopped):
sudo nexfsctl node forget 3
{"forgotten": true}
The node also loses its admission: if it started again it would be refused.
/var/lib/nexfs and the data disk of node-3 are left in place: erase them
by hand when the machine leaves for good.
Upgrading
One node at a time, without stopping the cluster:
sudo apt install ./nexfs*_X.Y.Z_amd64.deb ./libnexfs0_X.Y.Z_amd64.deb # restarts the service, if it was running
sudo systemctl reload nexfs-client@nex.service # the client switches to the new program, still mounted
sudo nexfsctl health --no-traffic # "ok" before moving to the next node
In the lab, three nodes went from 0.9.6 to 0.9.7 one after the other, each one
back to "ok" right away, while a program on another node kept writing and
reading a file in /nex without a single error.
During the upgrade the cluster works with nodes on different versions; the
clients move to another node by themselves while one restarts. On the
clients, the filesystem stays mounted: systemctl reload of the unit that
mounts it (see The client) switches to the new program without
unmounting. To roll back, you install the previous version in the same way.
When all metadata nodes run the new version, the upgrade is completed by raising the metadata level:
nexfsctl meta level # the current level, and how far all metadata nodes can go
nexfsctl meta level --raise # raises it, only if every metadata node answers and can apply it
The metadata nodes apply the same commands, each with its own program: a
command that a new version applies in a more precise way is switched on only
at that point, so during the upgrade all nodes stay in agreement.
nexfsctl health reminds you of this step with a meta_level_low reason (a
notice: the cluster status stays what it is). Once the level is raised, you
do not go back to a version that does not know it.
From 0.9.10 the highest level is 4: clients get some already placed blocks in advance, and the first write of a new file no longer waits for the metadata nodes (archive extraction and builds are faster). Until the level is raised, everything works as with the previous version.
From 0.9.15 the highest level is 6: the space of a file deleted together with
its folder (as rm -rf does) is freed right away even when other folders have
snapshots. The space of files deleted before the level is raised comes back
when the snapshots older than that moment are removed.
From 0.9.16 the highest level is 7: removing a snapshot keeps every block that another snapshot still sees, also for a file that was moved between folders with snapshots and then deleted. Raise the level after updating all the metadata nodes.
From 0.9.17 the highest level is 8: a block with no copy left stays a visible error also when a file is shortened or a snapshot keeps its earlier version, instead of turning into a part of the file full of zeros; and a refused change of permissions does not leave the extended permissions (ACL) of the file half done; and several computers adding lines at the end of the same file (for example a shared log) never overwrite each other's lines. Raise the level after updating all the metadata nodes.
If by mistake a metadata node with an older program is still in the cluster when
the level is raised, that node stops by itself and writes
update this metadata node in its log: the others keep working. Just update the
package on that node and restart it (systemctl restart nexfsd): it catches up
by itself.
Checking a stopped node
systemctl stop nexfsd
nexfsctl check # refuses if the daemon is running (--force to try anyway)
It checks the metadata store, the consensus log, the term and vote file and every block on the node's disks, with their checksums, without writing anything. It exits with 1 if it finds damage, and says what.
Repairing it
nexfsctl check --repair # the plan: what it would do, nothing changes
nexfsctl check --repair --yes # does it
systemctl start nexfsd # the cluster restores the copies
The repair never deletes anything: what it takes away goes to a
repair-DATE folder inside the disk or the state directory. Then the
cluster puts everything back in place with the copies on the other nodes:
- Damaged blocks on a data disk become doubtful. When nexfsd starts,
the node rebuilds each of them from another complete copy, and
nexfsctl healthshows them incopies_to_rebuilduntil they are done. - A damaged metadata store or consensus log is moved aside, and the node is marked amnesiac. When nexfsd starts it catches up from the leader, and its vote counts again only once it has everything.
It works on metadata only when the other metadata nodes answer and are a
majority on their own, with a leader: otherwise some confirmed changes might
exist only on this node, and it waits until they are back. It also refuses
if the term and vote file is missing or damaged; then the node is rebuilt:
nexfsctl meta remove ID from another node, then nexfsctl meta add with a
new id and an empty state directory.
Backing up and restoring
Copies protect against a broken disk or machine, not against a file deleted by mistake or a whole site lost: for that you keep a backup somewhere else. A snapshot gives you a picture of the filesystem that does not change while you copy it:
sudo mkdir /nex/.snap/backup # the whole filesystem, now
sudo tar -C /nex/.snap/backup -cpzf /var/backups/nex-backup.tar.gz .
sudo rmdir /nex/.snap/backup # its blocks are freed
-p keeps owners and permissions. Any other tool works the same way on the
snapshot folder (rsync -a, a backup program). The archive is made while
the cluster keeps working. To restore, into a new folder or in place:
sudo mkdir /nex/restore
sudo tar -C /nex/restore -xpzf /var/backups/nex-backup.tar.gz
The restored files had the same SHA-256 as the originals. Folder settings are
not files and are not in the archive: write down the quotas
(getfattr -n nexfs.quota.max_bytes FOLDER) and the copies per folder you
changed, and set them again after a restore. The control store, if programs
use it, is saved table by table with nexfsctl kv export (see below).
The control store
Keys and values for the programs that coordinate the cluster (NEX uses it for services, queues, leaders and secrets), with full durability:
nexfsctl kv put services web '{"node": 3}'
nexfsctl kv get services web
nexfsctl kv put-if services web '{"node": 3}' '{"node": 5}' # only if the first value still holds
nexfsctl kv list services
nexfsctl kv export services > services.jsonl # and kv import to load them back
nexfsctl kv listen services 60 # the notifications, one line each
nexfsctl lock acquire leaders election node-3 15 # an expiring lock, with a token
The same things, from programs, with libnexfs.