This crate provides a command line client for Xline.
-
endpoints <SERVER_NAME ADDR>... -- Set Xline endpoints, which are separated by ','
# connect to servers with specific addresses ./xlinectl --endpoints "127.0.0.1:2379"
-
user <USERNAME[:PASSWD]> -- The name of the user, this provide a shorthand to set password
# connect to servers using user `foo` with password `bar` ./xlinectl --user foo:bar
-
password -- The password of the user, should exist if password not set in
--user
# connect to servers using user `foo` with password `bar` ./xlinectl --user foo --password bar
-
wait_synced_timeout -- The timeout for Curp client waiting synced(in secs) [default: 2]
-
propose_timeout -- The timeout for Curp client proposing request(in secs) [default: 1]
-
retry_timeout -- The timeout for Curp client retry interval(in millis) [default: 50]
-
printer_type -- The format of the result that will be printed [default: SIMPLE] [possible values: SIMPLE, FIELD]
The Simple printer will only print simplified output. The Field printer will first print the response header and then print each of the response fields.
Puts the given key-value into the store. If key already holds a value, it is overwritten.
put [options] <key> <value>
- lease -- lease ID to attach to the key [default: 0]
- prev_kv -- return the previous key-value pair before modification
- ignore_value -- updates the key using its current value
- ignore_lease -- updates the key using its current lease
OK
# put key `foo` with value `bar` and attach the lease `123` to the key
./xlinectl put foo bar --lease=123
OK
# detach the lease by updating with empty lease
./xlinectl put foo --ignore-value
OK
# same as above
./xlienctl put foo bar --lease=123
OK
# use existing lease
./xlinectl put foo bar1 --ignore-lease
OK
Gets the key or a range of keys
get [options] <key> [range_end]
- consistency -- Linearizable(L) or Serializable(S) [default: L]
- order -- Order of results; ASCEND or DESCEND
- sort_by -- Sort target; CREATE, KEY, MODIFY, VALUE, or VERSION
- limit -- Maximum number of results [default: 0]
- prefix -- Get keys with matching prefix (conflicts with range_end)
- from_key -- Get keys that are greater than or equal to the given key using byte compare (conflicts with prefix and range_end)
- rev -- Specify the kv revision [default: 0]
- keys_only -- Get only the keys
- count_only -- Get only the count (conflicts with keys_only)
<key0>
<value0>
<key1>
<value1>
...
./xlinectl put foo bar
OK
./xlinectl put foo1 bar1
OK
./xlinectl put foo2 bar2
OK
# get the key `foo`
./xlinectl get foo
foo
bar
# get all keys prefixed with `foo`
./xlinectl get foo --prefix
foo
bar
foo1
bar1
foo2
bar2
# get all keys prefixed with `foo` sort in descend order
./xlinectl get foo --prefix --order DESCEND
foo2
bar2
foo1
bar1
foo
bar
# get all keys from `foo` to `foo3`
./xlinectl get foo1 foo3
foo1
bar1
foo2
bar2
Deletes the key or a range of keys
delete [options] <key> [range_end]
- prefix -- delete keys with matching prefix
- prev_kv -- return deleted key-value pairs
- from_key -- delete keys that are greater than or equal to the given key using byte compare
<number_of_keys_deleted>
[prev_key]
[prev_value]
...
./xlinectl put foo bar
# delete the key `foo`
./xlinectl delete foo
1
./xlinectl put foo bar
./xlinectl put foo1 bar1
./xlinectl put foo2 bar2
# delete all keys prefixed with `foo`
./xlinectl delete foo --prefix
3
Txn processes all the requests in one transaction
txn [options]
- interactive -- set interactive mode
The ebnf is the same as etcdctl
<Txn> ::= <CMP>* "\n" <THEN> "\n" <ELSE> "\n"
<CMP> ::= (<CMPCREATE>|<CMPMOD>|<CMPVAL>|<CMPVER>|<CMPLEASE>) "\n"
<CMPOP> ::= "<" | "=" | ">"
<CMPCREATE> := ("c"|"create")"("<KEY>")" <CMPOP> <REVISION>
<CMPMOD> ::= ("m"|"mod")"("<KEY>")" <CMPOP> <REVISION>
<CMPVAL> ::= ("val"|"value")"("<KEY>")" <CMPOP> <VALUE>
<CMPVER> ::= ("ver"|"version")"("<KEY>")" <CMPOP> <VERSION>
<CMPLEASE> ::= "lease("<KEY>")" <CMPOP> <LEASE>
<THEN> ::= <OP>*
<ELSE> ::= <OP>*
<OP> ::= ((see put, get, del xlinectl command syntax)) "\n"
<KEY> ::= (%q formatted string)
<VALUE> ::= (%q formatted string)
<REVISION> ::= "\""[0-9]+"\""
<VERSION> ::= "\""[0-9]+"\""
<LEASE> ::= "\""[0-9]+\""
<succeed>
[child requests]
<succeed>
can be SUCCESS | FAILURE
non-interactive mode
./xlinectl txn <<<'mod("key1") > "0"
get key1
put key1 "val1"
put key2 "some-val"
'
interactive mode
./xlinectl txn --interactive
compares:
mod("key1") > "0"
successful request:
get key1
failure request:
put key1 "val1"
put key2 "some-val"
COMPACTION discards all Xline event history prior to a given revision. Since Xline uses a multiversion concurrency control model, it preserves all key updates as event history. When the event history up to some revision is no longer needed, all superseded keys may be compacted away to reclaim storage space in the Xline backend database.
compaction [options] <revision>
- physical -- To wait for compaction to physically remove all old revisions
Compacted
...
# compact revision less than 123
./xlinectl compaction 123
Compacted
# wait for compaction to physically remove all old revisions
./xlinectl compaction 234 --physical
Compacted
Watches events stream on keys or prefixes
watch [options] [key] [range_end]
- prefix -- Watch a prefix
- rev -- Revision to start watching
- pre_kv -- Get the previous key-value pair before the event happens
- progress_notify -- Get periodic watch progress notification from server
- interactive -- Interactive mode
<event0>
[prev_key0]
[prev_value0]
<key0>
<value0>
<event1>
[prev_key1]
[prev_value1]
<key1>
<value1>
...
<event>
can be PUT | DELETE
non-interactive mode, which will continuously get output from response stream
# Watch key `foo`
./xlinectl watch foo
# Watch a range of keys from foo to foo3
./xlinectl watch foo foo3
interactive mode, which can start or cancel a watch
./xlinectl watch --interactive
watch foo foo3
# assume the returned watch id is 100 in previous command
cancel 100
Create a lease with a given TTL
grant <ttl>
<lease_id>
# create a new lease with 100s TTL
./xlinectl lease grant 100
8927807922788821579
Revoke a lease
revoke <leaseId>
Revoked
./xlinectl lease grant 100
8927807922788821579
# Revoke a lease with leaseId 123
./xlinectl lease revoke 8927807922788821579
Revoked
Get lease ttl information
timetolive <leaseId>
<TTL>
./xlinectl lease grant 100
8927807922788821579
# Get the TTL of a lease with leaseId 123
./xlinectl lease timetolive 8927807922788821579
93
List all active leases
list
<lease0>
<lease1>
...
./xlinectl lease grant 100
8927807922788821579
./xlinectl lease grant 100
6334008358021467690
# List all leases
./xlinectl lease list
8927807922788821579
6334008358021467690
lease keep alive periodically
keep_alive [options] <leaseId>
- once -- keep alive once
<TTL>
./xlinectl lease grant 100
8927807922788821579
# keep alive forever with leaseId 123 until the process receive `SIGINT`, each time print the TTL
./xlinectl lease keep_alive 8927807922788821579
100
100
...
# renew the lease ttl only once
./xlinectl lease keep_alive 123 --once
100
MEMBER provides commands for managing Xline cluster membership.
MEMBER ADD introduces a new member into the Xline cluster as a new peer.
member add [options] <peer_urls>
- is_learner -- Add as learner
<member_id>
# Add a member whose addresses are [127.0.0.1:2379, 127.0.0.1:2380]
./xlinectl member add "10.0.0.1:2379,10.0.0.2:2379"
16151281779493828828
MEMBER UPDATE sets the peer URLs for an existing member in the Xline cluster.
member update <ID> <peer_urls>
Member updated
./xlinectl member add "10.0.0.1:2379,10.0.0.2:2379"
16151281779493828828
# Add a member whose addresses are [127.0.0.1:2379, 127.0.0.1:2380]
./xlinectl member update 16151281779493828828 "10.0.0.3:2379,10.0.0.4:2379"
MEMBER ADD introduces a new member into the Xline cluster as a new peer.
member list
- linearizable -- to use linearizable fetch
<member_id1>
<member_id2>
...
# List all members
./xlinectl member list
16151281779493828828
16375331871075283369
16171997749406652082
MEMBER REMOVE removes a member of an Xline cluster from participating in cluster consensus.
member remove <ID>
Member removed
# Remove a member
./xlinectl member remove 16151281779493828828
Member removed
MEMBER PROMOTE promotes a learner of an Xline cluster to member
member promote <ID>
Member promoted
# Remove a member
./xlinectl member promote 16151281779493828828
Member promoted
Get snapshots of xline nodes
Save snapshot to file
snapshot save <filename>
snapshot saved to: <filename>
# Save snapshot to /tmp/foo
./xlinectl snapshot save /tmp/foo.snapshot
snapshot saved to: /tmp/foo.snapshot
Acquire a lock, which will return a unique key that exists so long as the lock is held.
lock <lockname> [command arg1 arg2 ...]
# Hold a lock named foo until `SIGINT` is received
./xlinectl lock foo
foo/df123ef45ef678f
# Acquire lock and execute `echo lock acquired`
./xlinectl lock foo echo lock acquired
lock acquired
# Acquire lock and execute `xlinectl put` command
./xlinectl lock foo ./xlinectl put foo bar
OK
Manage authentication
Enable authentication
auth enable
Authentication enabled
./xlinectl user add root rootpw
./xlienctl user grant-role root root
# Enable authentication
./xlinectl auth enable
Authentication enabled
Disable authentication
auth disable
Authentication disabled
# Disable authentication
./xlinectl --user root:root auth disable
Authentication disabled
Status of authentication
auth status
# Check the status of authentication
./xlinectl auth status
Role related commands
Create a new role
add <name>
Role added
# add a new role named 'foo'
./xlinectl --user=root:root role add foo
Role added
List role information
get <name>
Permmision: <perm_type0>
<key0>
[range_end0]
Permmision: <perm_type1>
<key1>
[range_end1]
...
./xlinectl --user=root:root grant_perm foo Read key
./xlinectl --user=root:root grant_perm foo ReadWrite key1
# Get role named 'foo'
./xlinectl --user=root:root role get foo
Permission: Read
key
Permission: Read
key1
Delete a role
delete <name>
Role deleted
./xlinectl --user=root:root role add foo
# delete the role named `foo`
./xlinectl --user=root:root role delete foo
Role deleted
List all roles
list
<role0>
<role1>
...
./xlinectl --user=root:root role add foo
./xlinectl --user=root:root role add foo1
# list all roles
./xlinectl --user=root:root role list
foo
foo1
Grant permission to a role, including Read, Write or ReadWrite
grant_perm [options] <name> <perm_type> <key> [range_end]
- prefix -- Get keys with matching prefix
- from_key -- Get keys that are greater than or equal to the given key using byte compare (conflicts with
range_end
)
Permission granted
# Grant read permission to role 'foo' for key 'bar' with read permission
./xlinectl --user=root:root role grant_perm foo READ bar
Permission granted
Revoke permission from a role
revoke_perm <name> <key> [range_end]
Permission revoked
# Revoke permission from role 'foo' for the range from 'bar' to 'bar2'
./xlinectl --user=root:root role revoke_perm foo bar bar2
Permission revoked
Add a new user
add [options] <name> [password]
- no_password -- Create without password
User added
# Add a new user with a specified password
./xlinectl --user=root:root user add foo bar
User added
# Add a new user without a password
./xlinectl --user=root:root user add foo1 --no_password
User added
Get a new user
get [options] <name>
- detail -- Show permissions of roles granted to the user
<role0>
<role1>
...
./xlinectl --user=root:root user grant_role foo role0
./xlinectl --user=root:root user grant_role foo role1
# Get a user named `foo`
./xlinectl --user=root:root user get foo
role0
role1
List all users
list
<user0>
<user1>
...
./xlinectl --user=root:root user add foo bar
./xlinectl --user=root:root user add foo1 bar1
# List all users
./xlinectl --user=root:root user list
foo
foo1
Change the password of a user
passwd <name> <password>
Password updated
# Change the password of user `foo` to `bar`
./xlinectl --user=root:root user passwd foo bar
Password updated
Grant role to a user
grant_role <name> <role>
Role granted
./xlinectl --user=root:root user add foo
./xlinectl --user=root:root role add bar
# Grant `bar` role to the user `foo`
./xlinectl --user=root:root grant_role foo bar
Role granted
Revoke role from a user
revoke_role <name> <role>
Role revoked
./xlinectl --user=root:root user add foo
./xlinectl --user=root:root role add bar
./xlinectl --user=root:root grant_role foo bar
# Revoke 'bar' role from the user 'foo'
./xlinectl --user=root:root revoke_role foo bar
Role revoked