NEXItaliano

NEXFS › Documentation › nexfsctl command reference

nexfsctl command reference

By Roberto Arato of aratoingegneria.it

nexfsctl is the administration tool of NEXFS. This page has one section per command: what it does, an example and its answer. The general picture (when to put a node in maintenance, how to grow the cluster, how to upgrade) is in Administration.

How it answers

nexfsctl [-c FILE] COMMAND [ARGUMENTS]
  • -c FILE is the configuration to use (default /etc/nexfs/nexfs.json): the list of meta nodes and the certificates are enough, see Configuration. It goes before the command.
  • Every command answers with a JSON object on one line, errors included: {"error": "...", "code": -16}. The code is the negated Linux error number (-2 not found, -16 busy, -28 no space, -125 someone else came first).
  • The exit code is 0 if the command succeeded, 1 if it answered with an error, 2 if it was mistyped (the usage goes to standard error).
  • Commands that change the cluster are accepted only from administrators: the meta nodes and the names listed in "admins".

The examples below were run on a test cluster with three meta nodes (node-a, node-b, node-c, ids 1 to 3) and three data nodes (node-d, node-e, node-f, ids 4 to 6), all on one machine, with a /projects/scratch folder in the filesystem. The answers are the real ones; long lists are shortened with .... Commands that set up a machine, or that need the daemon stopped, are shown in plain text blocks, with the shape of their answer.

Cluster state

version

The version of nexfsctl. It does not contact the cluster.

nexfsctl version
{"version": "0.9.8"}

ping

Whether a meta node answers. It is the quickest check that the cluster can be reached with this configuration.

nexfsctl ping
{"alive": true}

quorum

Whether the majority of meta nodes answers, that is whether the filesystem can work.

nexfsctl quorum
{"quorum": true}

status

The state of the meta node that answers: its version and roles, how long it has been running, and its view of the consensus (role, leader, term, log position, members). requests counts the requests the node has served since it started, by type (lookup, create, block_read, block_write, kv_get...): how many, how many got an answer other than success (not always a fault: a lookup of a missing name, or a node that is not the leader), and the average and longest time from arrival to answer, in microseconds. Only the types the node has served appear.

nexfsctl status
{"node": "node-a", "id": 1, "version": "1.0.0~beta5", "roles": ["meta", "data"], "protocol": [1, 1], "state_level_max": 8, "uptime_s": 5, "requests": {}, "consensus": {"role": "leader", "leader": 1, "term": 1, "last_index": 38, "committed_memory": 38, "committed_disk": 38, "applied": 38, "amnesiac": false, "members": [1, 2, 3], "learners": []}}

health

The whole cluster in one call, for alerts and dashboards: an overall status (ok, warning or error), the reasons behind it, meta and data nodes, blocks and copies to rebuild, rebalancing, space and the client traffic measured over one second. With --no-traffic it skips the traffic and answers sooner (the two traffic fields are null). It exits with 0 also when the status is not ok: read status.

nexfsctl health
nexfsctl health --no-traffic
{"status": "ok", "reasons": [], "quorum": true, "leader": 1, "meta_nodes": 3, "meta_nodes_up": 3, "state_level": 2, "data_nodes": 3, "data_nodes_up": 3, "blocks": 3, "blocks_degraded": 0, "copies_to_rebuild": 0, "copies_leaving": 0, "blocks_waiting_copies": 0, "rebuild": {"active": false, "moving": 0, "rate_mb_s": 32}, "copies": 3, "bytes_total": 808282435584, "bytes_free": 727801638912, "bytes_used": 80480796672, "read_bytes_s": 0, "write_bytes_s": 0}
{"status": "ok", "reasons": [], "quorum": true, "leader": 1, ..., "read_bytes_s": null, "write_bytes_s": null}

Each reason has a code, a severity and a message; there is an example under node maintenance.

Copies and space

space

Total and free space of the data nodes in bytes, the number of files and folders (inodes), the number of copies the cluster keeps, and whether some blocks are still being brought to that number (converting).

nexfsctl space
{"total": 808282435584, "free": 727718952960, "inodes": 6, "copies": 3, "converting": false}

copies (cluster)

copies N changes the number of copies kept by the cluster, from 1 to 4. New blocks get it at once; existing blocks are converted in the background, and converting stays true until they are done. It answers like space.

nexfsctl copies 2
nexfsctl space
{"total": 808282435584, "free": 727718952960, "inodes": 6, "copies": 2, "converting": true}
{"total": 808282435584, "free": 727718952960, "inodes": 6, "copies": 2, "converting": true}

copies (directory)

copies N PATH sets the number of copies (1, 2 or 3) of one folder and everything below it; copies default PATH goes back to the cluster number (the answer then says 0). PATH is the path inside the filesystem, from its root: with the filesystem mounted on /nex, the folder /nex/projects/scratch is /projects/scratch. Like the cluster number, it applies at once to new files and in the background to existing ones.

nexfsctl copies 1 /projects/scratch
nexfsctl copies default /projects/scratch
nexfsctl copies 2 /projects/missing  # exit 1
{"path": "/projects/scratch", "copies": 1}
{"path": "/projects/scratch", "copies": 0}
{"error": "no such directory", "code": -2}

rebalance

The speed of rebalancing (MiB per second) and how many copies are moving between data nodes right now. Rebalancing moves copies from the fullest nodes to the emptiest ones, never going below the number of copies.

nexfsctl rebalance
{"rate_mb_s": 32, "moving": 0}

rebalance rate

Changes the speed, from 0 to 65536 MiB per second.

nexfsctl rebalance rate 50
{"rate_mb_s": 50, "moving": 0}

rebalance off

Stops rebalancing, like rate 0. rebalance rate N starts it again.

nexfsctl rebalance off
nexfsctl rebalance rate 32
{"rate_mb_s": 0, "moving": 0}
{"rate_mb_s": 32, "moving": 0}

Data nodes

node list

The data nodes, with address, total and free space, whether they answer (alive) and their state: in-service, maintenance, draining, drained or quarantine (see Administration).

nexfsctl node list
{"nodes": [{"id": 4, "name": "node-d", "address": "127.0.0.1", "port": 36535, "total": 269427478528, "free": 242572984320, "alive": true, "state": "in-service"}, {"id": 5, "name": "node-e", ...}, {"id": 6, "name": "node-f", ...}]}

node allowed

The names admitted as data nodes (the names in their certificates), followed by the clients that joined through the entry channel, as c/NAME: every machine counts towards the node limit of the edition (see Edition and license).

nexfsctl node allowed
{"allowed": ["node-d", "node-e", "node-f", "c/pc-office"]}

node allow

Admits a certificate name, before the node is added: a data node that is not a meta node registers only if its name is admitted. A new meta node is admitted the same way before meta add. It answers with the updated list. A new name is refused when the cluster already has as many nodes as its edition allows (error -122): license status shows the limit.

nexfsctl node allow node-g
{"allowed": ["node-d", "node-e", "node-f", "node-g"]}

node revoke

Withdraws an admission. It applies to names that have not registered yet. With c/NAME it removes a client that no longer uses the cluster, so it no longer counts towards the limit.

nexfsctl node revoke node-g
nexfsctl node revoke c/pc-office
{"allowed": ["node-d", "node-e", "node-f"]}

node maintenance

node maintenance ID on stops a data node for a short while (a reboot, a new kernel): its copies are not rebuilt elsewhere, and when it comes back it catches up only on what changed. off puts it back in service. on is refused with -16 if some block would be left below the minimum needed to write. health shows the node with a warning while it is in maintenance.

nexfsctl node maintenance 6 on
nexfsctl health --no-traffic
nexfsctl node maintenance 6 off
{"id": 6, "state": "maintenance"}
{"status": "warning", "reasons": [{"code": "data_node_maintenance", "severity": "warning", "message": "data node 6 (node-f) is in maintenance"}], "quorum": true, ..., "read_bytes_s": null, "write_bytes_s": null}
{"id": 6, "state": "in-service"}

node drain

Drains a data node: its copies move to the other nodes, and when it is empty its state becomes drained. It is refused with -16 if the remaining nodes are fewer than the copies wanted, and with -28 if they do not have the space. --cancel puts the node back in service. --dry-run only tells whether it could, with the same checks and the reasons (problems), without changing anything; warnings lists the other nodes that do not answer at that moment.

nexfsctl node drain 6 --dry-run
nexfsctl node drain 6
nexfsctl node drain 6 --cancel
{"id": 6, "name": "node-f", "allowed": true, "copies": 2, "other_nodes": 2, "bytes_to_move": 9000000, "bytes_free_elsewhere": 120000000000, "problems": [], "warnings": []}
{"id": 6, "state": "draining"}
{"id": 6, "state": "in-service"}

node forget

Removes from the list a data node that is drained and shut down, together with its admission: if it started again it would be refused. On a node still in service, or still running, it is refused with -16.

nexfsctl node forget 6  # exit 1
{"error": "the node is not drained yet, or its daemon is still running", "code": -16}

The normal sequence, when a data node leaves for good:

nexfsctl node drain 6           # wait for "state": "drained" in node list
systemctl stop nexfsd           # on the node itself
nexfsctl node forget 6
{"forgotten": true}

node add

Run on the new machine, with the package installed and its certificate: it adds this machine to the cluster as a data node. It reads the meta nodes (and the CA, if --ca is not given) from the configuration of a cluster node (--like), writes the configuration (the -c file, default /etc/nexfs/nexfs.json; an existing file is never overwritten), creates the state and disk folders, starts the nexfsd service and waits up to a minute for the node to register. The name must be admitted first with node allow, and the --id must not belong to another node.

nexfsctl node add --node node-g --address 10.20.0.17 --id 7 \
    --like /tmp/nexfs-node-a.json --disk /srv/nexfs/disk0 --disk /srv/nexfs/disk1 \
    --cert /etc/nexfs/pki/node-g.crt --key /etc/nexfs/pki/node-g.key
{"added": true, "id": 7, "node": "node-g", "role": "data", "seconds": 3}
Option Default
--port N 7400
--disk DIR (one per disk, repeatable) /var/lib/nexfs/disco0
--state-dir DIR /var/lib/nexfs
--ca FILE, --cert FILE, --key FILE the CA of the --like file, /etc/nex/pki/node.crt, /etc/nex/pki/node.key
--encryption-key FILE none: the blocks are not encrypted (see Security); the key must not be on a data disk
--no-service the service is started; with this option it waits for someone else to start nexfsd

disk add

Run on the data node, as root, when it gets one more disk: the disk must first be formatted and mounted on an empty folder (nexctl storage disk-add does this in NEX). The command appends the folder to "disks" in the configuration, rewrites the service file so that nexfsd can write there (ReadWritePaths: the service runs with ProtectSystem=strict, and without that line the new disk would be read-only) and restarts nexfsd. On restart the node welcomes the disk into its family of disks (in the log: disk N is new: it joins the block stores of this node) and creates new blocks there, always choosing the freest disk; the blocks already stored stay where they are.

nexfsctl disk add /srv/nexfs/disco1
{"node": "node-c", "disk": "/srv/nexfs/disco1", "disks": 2, "restarted": true}

The folder must be an absolute path, exist, be empty (lost+found is fine), sit on a different filesystem from the node's other disks and not hold the block encryption key; a data node uses at most 16 disks. If any of these is missing the command changes nothing:

nexfsctl disk add /srv/nexfs/disco1  # exit 1
{"error": "the disk folder is not empty: a new disk starts empty", "code": -39}
Option Default
--no-restart nexfsd restarts at once; with this option the configuration is ready and whoever runs the command restarts it

Edition and license

NEXFS has the same editions as NEX, and one license covers both:

Edition Nodes License
Free up to 4 none, no registration
Trial as Enterprise 30 days, once per cluster
Base up to 32 signed, yearly
Enterprise up to 128 (more on request) signed, yearly, with the paid modules

Every machine counts as a node: meta nodes, data nodes and clients. A cluster that already has its nodes never stops because of the license: only new nodes are refused when the limit is reached. A license that expires keeps working for 30 more days with a warning, then the cluster is back to the Free limits for new nodes. The data is never touched.

The license is stored in the control store, so every node sees it. Licenses are issued and renewed by the NEX website (https://nex.aratoingegneria.it).

license status

The edition, the state of the license, the limit and the nodes counted.

nexfsctl license status
{"edition": "free", "state": "none", "limit": 4, "nodes": 3, "cluster": "sha256:3f9a21c7...", "trial_used": false, "features": []}

state is none (no license: Free), valid, expiring (expired less than 30 days ago), expired or invalid, and then reason says why. With a license there are also id, holder, max_nodes, expires, renew_after, paid_until and features (the paid modules).

license trial

Starts the 30-day trial: the limits of the Enterprise edition and every module, without registration. It can be started once per cluster.

nexfsctl license trial

license import

Installs the license file downloaded from the NEX website, after checking its signature, its dates and that it belongs to this cluster.

nexfsctl license import license.json

license remove

Removes the license: the cluster is back to the Free edition.

nexfsctl license remove

Metadata nodes

meta list

The members of the metadata group: address, whether they vote (a node in maintenance or still catching up does not), and whether they are a witness.

nexfsctl meta list
{"members": [{"id": 1, "name": "node-a", "address": "127.0.0.1", "port": 36532, "voting": true, "witness": false}, {"id": 2, "name": "node-b", ...}, {"id": 3, "name": "node-c", ...}]}

meta level

The state level of the metadata, and how far all meta nodes can go (possible), with the version of each node. --raise raises the level to possible, only if every meta node answers: it is the last step of an upgrade, and health reminds you of it with the meta_level_low reason. Once the level is raised, you do not go back to a version that does not know it. When the level is already the highest, --raise changes nothing ("raised": false).

nexfsctl meta level
nexfsctl meta level --raise
{"level": 2, "possible": 2, "raised": false, "nodes": [{"id": 1, "name": "node-a", "version": "0.9.8", "state_level_max": 2}, {"id": 2, "name": "node-b", ...}, {"id": 3, "name": "node-c", ...}]}
{"level": 2, "possible": 2, "raised": false, "nodes": [...]}

meta maintenance

meta maintenance ID on takes a meta node out of the vote until it comes back: after an abrupt shutdown the others restart without waiting for it. off makes it vote again. on is refused with -16 for the leader (stop it, and the others elect another one) and when only one voting node would be left; off answers -115 while the node is not caught up yet (try again).

nexfsctl meta maintenance 3 on
nexfsctl meta maintenance 3 off
{"id": 3, "voting": false}
{"id": 3, "voting": true}

meta add

Run on the new machine: it adds this machine to the metadata group (and as a data node too, with --disk). It takes the same options as node add, plus --ca-key FILE (the CA key, for the joining channel of nexfs-setup). The configuration lists the meta nodes of the --like file, those that joined later and the new one. The node receives the whole index and, once caught up, votes; the command waits for that (up to three minutes). Admit the name first with node allow.

nexfsctl node allow node-g          # from an administrator
nexfsctl meta add --node node-g --address 10.20.0.17 --id 7 \
    --like /tmp/nexfs-node-a.json --disk /srv/nexfs/disk0 \
    --ca /etc/nexfs/pki/ca.crt --cert /etc/nexfs/pki/node-g.crt --key /etc/nexfs/pki/node-g.key
{"added": true, "id": 7, "node": "node-g", "role": "meta", "seconds": 5}

meta remove

The meta node leaves the group; then you stop it. It is refused with -16 for the leader (stop it first: the others elect another one) and for the last voting node.

nexfsctl meta remove 3
{"removed": true, "id": 3}

meta restart-from-disk

After a general shutdown the meta nodes restart by themselves when they are all back. If one is never coming back, this command makes the ones present restart from what they have on disk. The last changes confirmed only in the memory of the stopped nodes are given up, which is why it asks for --accept-loss; without it, it only explains why.

nexfsctl meta restart-from-disk  # exit 2
nexfsctl: restart-from-disk gives up what the stopped nodes had only in memory: add --accept-loss
nexfsctl meta restart-from-disk --accept-loss
{"reached": 2, "amnesiac": 0}

reached is how many meta nodes answered, amnesiac how many of them must catch up from the leader.

Setup

init

Creates a new cluster on this machine: the first node, meta and data, and the filesystem. It writes the configuration (the -c file, default /etc/nexfs/nexfs.json; if the file exists it stops, so an existing cluster is never touched), creates the folders, starts the nexfsd service and waits up to a minute for the node to answer. The other nodes join later with meta add and node add. nexfs-setup init does the same, preparing the certificates too (see Installation).

nexfsctl init --node node-a --address 10.20.0.10 --disk /srv/nexfs/disk0 \
    --ca /etc/nexfs/pki/ca.crt --cert /etc/nexfs/pki/node-a.crt --key /etc/nexfs/pki/node-a.key
{"initialized": true, "node": "node-a", "seconds": 4}

The options are those of node add without --id and --like (the first node has id 1), with a single --disk; the default CA is /etc/nex/pki/ca.crt. --ca-key FILE is accepted as in meta add.

Check and repair

These commands work on the disks of this node, with its daemon stopped, so they read the node's own configuration (-c, default /etc/nexfs/nexfs.json).

check

Checks the metadata store, the consensus log, the term and vote file (raft_state) and every block on the node's disks with its checksums, without writing anything. It refuses while nexfsd runs; --force checks anyway (the result may be wrong). Exit code 0 if nothing is damaged, 1 if something is.

systemctl stop nexfsd
nexfsctl check
{"node": "node-b", "archive": {"keys": 82, "pages": 10, "ok": true}, "log": {"ok": true, "first": 1, "last": 97, "entries_read": 97}, "raft_state": {"ok": true, "clean_stop": false}, "disks": [], "writes_avoided": 2, "ok": true}

On a data node with a damaged block:

nexfsctl check
{"node": "node-e", "disks": [{"path": "/srv/nexfs/disk0", "ok": false, "blocks": 3, "damaged_blocks": ["0000000000000001"]}], "writes_avoided": 0, "ok": false}

writes_avoided counts what opening the files would have tidied up by itself (for example the tail of a log cut by a shutdown): it is not damage.

check --repair

After the check, it shows the plan of the repair; with --yes it carries it out. Nothing is ever deleted: what is taken away goes to a repair-DATE folder inside the disk or the state folder. Damaged blocks become doubtful, and nexfsd, when it starts, rebuilds them from the other copies. A damaged store or log of a meta node is moved aside and the node catches up from the leader; this is done only when the other meta nodes answer and are a majority on their own. It cannot be used with --force. Exit code 0 if every damage was repaired, 1 otherwise (the reasons in refused).

nexfsctl check --repair
{"node": "node-e", "disks": [...], "ok": false, "repair": {"applied": false, "actions": [{"disk": "/srv/nexfs/disk0", "action": "mark 1 damaged blocks doubtful: nexfsd rebuilds them from the other copies when it starts"}], "refused": [], "note": "nothing changed: run again with --yes to apply"}}
nexfsctl check --repair --yes
{"node": "node-e", "disks": [...], "ok": false, "repair": {"applied": true, "actions": [{"disk": "/srv/nexfs/disk0", "action": "1 damaged blocks marked doubtful: nexfsd rebuilds them from the other copies when it starts", "saved_in": "/srv/nexfs/disk0/repair-20261019-201620"}], "refused": []}}
systemctl start nexfsd

Control store (kv)

Keys and values for the programs that coordinate the cluster (NEX keeps services, queues, leaders and secrets there), with full durability. Tables are created by the first write. Values are text: here they are small JSON objects, quoted for the shell.

kv put

Writes a key.

nexfsctl kv put services web '{"node": 3}'
nexfsctl kv put services db '{"node": 4}'
{"written": true}
{"written": true}

kv get

Reads a key; -2 if it is not there.

nexfsctl kv get services web
nexfsctl kv get services mail  # exit 1
{"value": "{\"node\": 3}"}
{"error": "No such file or directory", "code": -2}

kv tables

The tables of the store.

nexfsctl kv tables
{"tables": ["services"]}

kv list

The rows of a table in key order, or only those whose key starts with PREFIX.

nexfsctl kv list services
nexfsctl kv list services w
{"rows": [{"key": "db", "value": "{\"node\": 4}"}, {"key": "web", "value": "{\"node\": 3}"}]}
{"rows": [{"key": "web", "value": "{\"node\": 3}"}]}

kv put-if

Writes only if the key still holds the EXPECTED value; an empty EXPECTED ('') means "only if the key is not there". If someone changed it first, it answers -125 and writes nothing.

nexfsctl kv put-if services web '{"node": 3}' '{"node": 5}'
nexfsctl kv put-if services web '{"node": 3}' '{"node": 6}'  # exit 1
nexfsctl kv put-if services mail '' '{"node": 2}'
{"done": true}
{"error": "Operation canceled", "code": -125}
{"done": true}

kv del-if

Removes the key only if it holds the EXPECTED value.

nexfsctl kv del-if services mail '{"node": 2}'
{"done": true}

kv move-if

If the key FROM holds EXPECTED, removes it and writes the key TO with VALUE, in one step. It is the way to claim a job from a queue: whoever comes second gets -125.

nexfsctl kv put queue job-7 build
nexfsctl kv move-if queue job-7 build running/job-7 node-d
nexfsctl kv move-if queue job-7 build running/job-7 node-e  # exit 1
{"written": true}
{"done": true}
{"error": "Operation canceled", "code": -125}

kv del

Removes a key; existed says whether it was there.

nexfsctl kv del services db
nexfsctl kv del services db
{"existed": true}
{"existed": false}

kv export

The rows of a table, one JSON object per line, so a large table can be saved without holding it all in one object. It is the format that kv import reads.

nexfsctl kv export services
{"key": "web", "value": "{\"node\": 5}"}

kv import

Writes into a table the rows of kv export, read from FILE (or from the standard input). It can copy a table, or load back a saved one.

nexfsctl kv export services > services.jsonl
nexfsctl kv import services-copy services.jsonl
{"imported": 1}

kv publish

Sends a notification on a table to the programs listening on it, and waits up to WAIT_MS milliseconds (default 2000) for their confirmations: acks is how many confirmed. Here one program was listening.

nexfsctl kv publish services "web moved" 500
{"acks": 1}

kv listen

Subscribes to the notifications of a table for SECONDS (without SECONDS, until SIGTERM or Ctrl-C) and writes one line per notification, {"notification": "..."}. If the subscription drops, it subscribes again by itself and writes {"resubscribed": true}.

nexfsctl kv listen services 2
{"subscribed": true}
{"finished": true}

kv drop-table

Removes a table with all its rows.

nexfsctl kv drop-table services-copy
{"dropped": true}

Locks

Expiring locks, kept in a table of the control store: a holder takes a lock for some seconds and renews it while it works; if it stops renewing, the lock expires and someone else can take it. Every acquisition gets a growing token (fencing token), so a resource can refuse whoever holds an old one.

lock acquire

Takes the lock NAME of TABLE for HOLDER, for SECONDS (up to 86400). It is refused with -16 while someone else holds it.

nexfsctl lock acquire leaders election node-3 15
nexfsctl lock acquire leaders election node-5 15  # exit 1
{"token": 82}
{"error": "Device or resource busy", "code": -16}

lock owner

Who holds the lock, and with which token; {"owner": null} if it is free.

nexfsctl lock owner leaders election
{"owner": "node-3", "token": 82}

lock renew

Extends the lock by SECONDS for the same holder, keeping the token; -2 if it has already expired.

nexfsctl lock renew leaders election node-3 15
{"token": 82}

lock release

Releases the lock before it expires.

nexfsctl lock release leaders election node-3
nexfsctl lock owner leaders election
{"released": true}
{"owner": null}