Kahuna CLI
The Kahuna CLI (kahuna-cli) lets you work with a Kahuna cluster from a terminal, much as redis-cli or psql do for Redis and PostgreSQL. You type commands or Kahuna Script and see the results immediately. You don't need to write application code.
- Learning: explore Kahuna and try commands, as the tutorials do.
- Inspection: read a key and its revision during development or an incident. You can also scan a bucket, or acquire and release a lock by hand.
- Script tests: test a script before you put it in an application.
- Administration: manage the cluster, for example its membership and backups.
- Watches: watch persistent key changes while you test configuration or service behavior. See Watch Key Changes.
- Automation: run operational tasks from shell scripts with single-command mode.
For application code, use the .NET or TypeScript client instead.
You can install the CLI in three ways.
Homebrew
On macOS or Linux, Homebrew installs both the CLI and the server. You don't need a separate .NET installation.
brew install kahunakv/tap/kahuna
kahuna-cli -c "http://127.0.0.1:8083"
The command connects to an already running server. See Homebrew server setup to start one locally.
.NET Global Tool
With the .NET SDK installed, install kahuna-cli as a global tool.
dotnet tool install -g Kahuna.Control
Then start the CLI.
kahuna-cli
Kahuna Shell 1.0.0
kahuna-cli> get my-config
r14 my-value 18ms
This command updates the CLI to a new release.
dotnet tool update -g Kahuna.Control
Docker
With Docker, run the CLI in a container.
docker run --name kahuna-cli --network=host -d kahunakv/kahuna-cli:latest
Then open an interactive shell in it. /app/run.sh starts the CLI with no arguments. This means that it connects to the default endpoint http://127.0.0.1:8083.
docker exec -it kahuna-cli /app/run.sh
Kahuna Shell 1.0.0
kahuna-cli> get my-config
r14 my-value 18ms
To pass a connection string or run a single command, call the CLI directly.
docker exec -it kahuna-cli dotnet /app/Kahuna.Control.dll -c "https://kahuna-1:8082" --insecure
docker exec kahuna-cli dotnet /app/Kahuna.Control.dll -c "http://127.0.0.1:8083" --get my-config
Interactive Mode
If you don't pass command-line parameters, kahuna-cli enters interactive mode. You can then execute commands and view their results in real time. Any input that isn't one of the shell commands below executes as a Kahuna Script, such as get my-config or set my-config "value".
| Command | What it does |
|---|---|
lock <name> <expiry-ms> | Acquires a persistent lock and prints f<fencing-token> acquired <owner>. The handle is stored in the shell. |
elock <name> <expiry-ms> | Same, with an ephemeral lock. |
extend-lock <name> <expiry-ms> / eextend-lock ... | Extends a lock this shell acquired. |
get-lock <name> / eget-lock <name> | Prints the fencing token and owner of a lock this shell acquired. |
unlock <name> / eunlock <name> | Releases a lock this shell acquired. |
create-sequence, get-sequence, next-sequence, reserve-sequence, update-sequence, delete-sequence | Sequencer commands. See CLI interactive mode for their arguments. |
watch <prefix> [keys-only] | Streams committed changes to persistent keys. See Watch Key Changes. |
cluster members | Prints the cluster roster. |
cluster leave <node-endpoint> | Asks that node to leave the cluster. The endpoint is required. |
backup full, backup coordinated, list backups | Backup commands. See Backup and Restore. |
run <file> | Prints and executes the script in a file. |
clear | Clears the screen. |
exit or quit | Leaves the shell. Ctrl+C on an empty prompt does the same. |
The lock commands work only on locks acquired in the current session. If this shell didn't lock a name, the lock commands print not acquired or not found for it. On exit, the shell releases its locks. To work with a lock from another process, use the single-command flags with --owner.
Scripts typed at the prompt or loaded with run are cancelled on the client after -t/--default-timeout seconds (default 10). A cancelled call does not tell you whether the server applied it.
Multiline Scripts
If you press Enter in an open IF, FOR, SWITCH, or BEGIN block, input continues at the ...> prompt. Input also continues in an unfinished single-quoted or double-quoted string. When all blocks and quotes are closed, Enter submits the script.
kahuna-cli> begin
...> set `messages/welcome` "first line
...> second line"
...> commit
...> end
Two trailing blank lines submit the current input, even if it is unfinished. The server then returns syntax errors. The continuation check is a lightweight check of blocks and quotes. It isn't a full parser. Malformed input that appears complete is submitted for server validation. CLI commands such as lock and run submit at once. Words in their arguments don't open blocks.
Connection String
By default, kahuna-cli connects to the local cleartext gRPC endpoint on port 8083. The local Docker standalone server exposes this endpoint.
kahuna-cli
This command is the same as the next one.
kahuna-cli -c "http://127.0.0.1:8083"
To connect to other servers, list them with the -c flag.
kahuna-cli -c "https://kahuna-dev.company.internal:8082,https://kahuna-dev.company.internal:8084"
You can also connect to the HTTPS endpoint and allow the local development certificate.
kahuna-cli -c "https://127.0.0.1:8082" --insecure
For a three-node cluster, pass all reachable endpoints in one comma-separated connection string.
kahuna-cli \
-c "https://127.0.0.1:8082,https://127.0.0.1:8084,https://127.0.0.1:8086" \
--insecure
Single-Command Mode
The CLI can also execute one operation and exit. These examples show common operations.
kahuna-cli --set my-config --value my-value
kahuna-cli --get my-config
kahuna-cli --get-by-prefix services
kahuna-cli --scan-by-prefix services
kahuna-cli --lock jobs/email --expires 30000
kahuna-cli --extend-lock jobs/email --owner <owner> --expires 30000
kahuna-cli --unlock jobs/email --owner <owner>
--lock acquires a persistent lock and exits, but it doesn't release the lock. The lock lasts until --expires milliseconds pass or you release it. --expires is required. If you omit it, the acquisition fails. The output shows the owner that you need for --extend-lock and --unlock.
$ kahuna-cli --lock jobs/email --expires 30000
f0 acquired b6be30d1dbba430697d27f66cf80669c
$ kahuna-cli --extend-lock jobs/email --owner b6be30d1dbba430697d27f66cf80669c --expires 60000
f0 extended
$ kahuna-cli --unlock jobs/email --owner b6be30d1dbba430697d27f66cf80669c
unlocked
If another process has the lock, --lock prints f-1 not acquired <owner> and doesn't wait. The owner in that line is the one that the failed attempt generated. It isn't the current owner of the lock. A wrong owner makes --unlock print not unlocked. It also makes --extend-lock print KahunaException: Failed to extend: LockResponseTypeInvalidOwner. These three flags always use persistent durability.
These commands work with the distributed sequencer.
kahuna-cli --create-sequence orders --initial-value 0 --increment 1
kahuna-cli --get-sequence orders
kahuna-cli --next-sequence orders --idempotency-key request-123
kahuna-cli --reserve-sequence orders --count 100 --idempotency-key batch-456
kahuna-cli --delete-sequence orders
--update-sequence rewrites a sequence. Before you use it, see CLI single-command mode and Updating a Sequence.
With --format json, single-command operations print JSON. --unlock and --extend-lock print only True or False. Interactive mode always prints text.
-t/--default-timeout applies only to scripts in interactive mode; single-command operations do not read it.
Watch Key Changes
Use watch in interactive mode to see committed changes to persistent keys under a prefix.
kahuna-cli> watch config/prod/search/
kahuna-cli> watch config/prod/search/ keys-only
For a set event, the first command prints the new value. Use keys-only to leave out value bytes when you need only the key and revision. Press Ctrl+C or Esc to stop the watch and return to the prompt.
You can also run the same watch directly from a terminal.
kahuna-cli --watch config/prod/search/ --watch-keys-only
kahuna-cli --watch config/prod/search/ --format json
The command continues until you press Ctrl+C or the stream ends. It prints progress watermarks when the cluster enables --commit-admission-lag-ms. To replay retained changes above a watermark, pass the timestamp from a progress line to --watch-from.
kahuna-cli --watch config/prod/search/ --watch-from 1:1792504674003:0
Resume requires the commit admission window on all nodes and enough retained log history. A watch doesn't take a history hold automatically. To take one, use the history-hold flags.
# Keep partitions 1 and 2's log from a timestamp for 10 minutes (the default --lease-ms)
kahuna-cli --history-hold-acquire config-consumer --partitions 1,2 --history-from 1:1792504674003:0
# Renew holds, moving them forward to a newer timestamp when --history-from is given
kahuna-cli --history-hold-renew <hold-id>,<hold-id> --history-from 1:1792504680000:0 --lease-ms 600000
kahuna-cli --history-hold-list --holder config-consumer
kahuna-cli --history-hold-release <hold-id>,<hold-id>
--history-from takes node:physical:counter or physical milliseconds alone. The acquire command prints one line for each hold, with its ID. Pass those IDs to the renew and release flags. If the stream shows lagged or history unavailable, some changes may be missing from the output. For recovery behavior, see Watch Persistent Key Changes. For an application example, see the watch recipe.
Cluster Membership
Use --cluster-members to inspect the live cluster roster.
kahuna-cli -c "https://kahuna-1:8082" --cluster-members
The output includes the membership version and the local role, with an Initialized flag. Initialized tells you whether the contacted node completed cluster initialization. A node can appear in membership before it is ready to serve key/value traffic. For load balancer or orchestrator probes, use the server readiness endpoint GET /v1/cluster/health.
When servers require an admin key, add --admin-key-file /path/to/admin-keys to kahuna-control admin commands. See Admin Operations Authorization.
Use --cluster-leave to decommission a node. The command commits the removal of the node from the cluster roster.
kahuna-cli \
-c "https://kahuna-1:8082,https://kahuna-2:8082,https://kahuna-3:8082" \
--cluster-leave \
--node "https://kahuna-3:8082"
Stop the process only after the response shows that the node left. A leave that would remove the last voter needed to keep the cluster available is refused. A voter is a member that counts toward the quorum.
Evicted means that the node was evicted during the leave, and its replicas weren't evacuated. Keep the process running until it rejoins. Then retry the leave.
On a cluster that uses replica placement, leave drains the node first. The response includes drained when the replicas that it hosted were moved to other nodes before removal. DrainTimedOut means that the node wasn't removed from the roster. Retry later, or raise --raft-decommission-drain-timeout.
Replica Placement
Use --cluster-placement to inspect replica placement for each partition.
kahuna-cli -c "https://kahuna-1:8082" --cluster-placement
kahuna-cli -c "https://kahuna-1:8082" --cluster-placement --format json
The output describes the placement of the cluster and of each partition.
| Information | Meaning |
|---|---|
| Global replication factor | The server-wide replication factor |
| Rebalancer state | Whether the placement rebalancer is enabled |
| Effective replication factor | The replication factor of each partition |
| Replicas | The replica endpoints of each partition, with their roles |
| Local partitions | The partitions that the contacted node hosts |
Set a per-partition replication factor override with --set-replication-factor and --partition.
kahuna-cli \
-c "https://kahuna-1:8082,https://kahuna-2:8082,https://kahuna-3:8082" \
--set-replication-factor 5 \
--partition 3
Use 0 to clear the override. The partition then inherits the server-wide replication factor.
kahuna-cli -c "https://kahuna-1:8082" \
--set-replication-factor 0 \
--partition 3
For the server flags and operational behavior, see Replication Factor and Replica Placement.
Key-Range Administration
Key-range administration is available in single-command mode for operators and tests.
# Inspect the range map
kahuna-cli -c "https://kahuna-1:8082" --ranges
kahuna-cli -c "https://kahuna-1:8082" --ranges --key-space users
# Register or unregister a key space
kahuna-cli \
-c "https://kahuna-1:8082,https://kahuna-2:8082,https://kahuna-3:8082" \
--register-key-range users
kahuna-cli \
-c "https://kahuna-1:8082,https://kahuna-2:8082,https://kahuna-3:8082" \
--unregister-key-range users
# Force a split at an exact key
kahuna-cli \
-c "https://kahuna-1:8082,https://kahuna-2:8082,https://kahuna-3:8082" \
--split-range users \
--split-key users/0500
# Run the merge pass on demand
kahuna-cli -c "https://kahuna-1:8082" --merge-ranges
--register-key-range and --unregister-key-range are sent to all endpoints in the connection string. Each node stores a separate copy of the routing mode. This means that the listed nodes switch at once. Other nodes switch when they apply the replicated range map. Use --node only if you want to target one node on purpose. In this case, the other nodes switch later.
--split-range and --merge-ranges execute only on the leader of partition 0 (the system partition), which has the range map. The CLI tries the connected endpoints until one of them takes the request. For split responses, check determinate. An indeterminate response means that the map can change later. Read --ranges again before you decide what happened.
For routing behavior and split and merge outcomes, see Key-Range Sharding.
Backup and Restore
The target server must be started with --pitr-backup-dir. For production clusters, point all nodes at the same shared backup directory, and set the same --pitr-backup-cluster-id. Backups and catalog operations go to the node that -c selects. Its visible catalog is the content that this node sees at --pitr-backup-dir.
# Create backups
kahuna-cli -c "https://kahuna-1:8082" --backup-full
kahuna-cli -c "https://kahuna-1:8082" --backup-coordinated
kahuna-cli -c "https://kahuna-1:8082" \
--backup-incremental \
--parent-backup-id <backup-id>
# Inspect and validate
kahuna-cli -c "https://kahuna-1:8082" --list-backups
kahuna-cli -c "https://kahuna-1:8082" --backup-chain <leaf-backup-id>
# Reclaim backup disk or preview what would be deleted
kahuna-cli -c "https://kahuna-1:8082" --backup-gc
kahuna-cli -c "https://kahuna-1:8082" --backup-gc --backup-gc-dry-run
Use a coordinated backup when all partitions must share one cluster snapshot timestamp. Use the returned backup ID as the parent of the next incremental backup.
Coordinated backups are accepted only by the current backup coordinator, the node leading partition 0 (the system partition). If the command reports NotBackupCoordinator, retry against the current coordinator or another endpoint that routes to it.
An incremental backup can't be built if the write-ahead log (WAL) entries after its parent backup were already compacted. In this case, Kahuna takes a full backup. The command output or the JSON fields report the substitution.
Restore writes a new storage directory on the server that handles the request.
# Restore through the end of the selected chain
kahuna-cli -c "https://kahuna-1:8082" \
--restore <leaf-backup-id> \
--target-dir /var/lib/kahuna/restored
# Restore through a specific Unix timestamp in milliseconds
kahuna-cli -c "https://kahuna-1:8082" \
--restore <leaf-backup-id> \
--target-dir /var/lib/kahuna/restored-at-t \
--target-time-ms 1781478000000
--target-dir is a path on the server. It isn't a path on the computer where you use the CLI. Restore doesn't modify the running node. Start a new node with the restored path and the same storage adapter and revision.
For remote restore, start the server with --pitr-restore-root, and choose a target directory below that root. Some targets are refused.
- Targets outside the root
- Symlinked paths
- Paths that overlap protected paths
- Destinations that aren't empty
Interactive mode has three backup commands.
kahuna-cli> backup full
kahuna-cli> backup coordinated
kahuna-cli> list backups
For more information, such as retention and restore constraints, see Backups and Point-in-Time Recovery.
Leave Requests and Elections
A node that requested leave continues to take part in elections until its removal commits. A removal that timed out can also commit later. After an uncertain leave response, check --cluster-members before you stop the node. Then finish the decommission explicitly. For how candidacy and automatic rejoin are suppressed, see Leave Requests and Elections.