Skip to content

Commit

Permalink
Added new CLIENT CAPA command along with other related modifications (#…
Browse files Browse the repository at this point in the history
…151)

to valkey-io/valkey#325 

---------

Signed-off-by: zhaozhao.zz <zhaozhao.zz@alibaba-inc.com>
Co-authored-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
  • Loading branch information
soloestoy and zuiderkwast authored Jun 27, 2024
1 parent c8644e8 commit dcee122
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
12 changes: 12 additions & 0 deletions commands/client-capa.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Clients can declare their capabilities to Valkey using the `CLIENT CAPA` command, and Valkey
will adjust the corresponding features for the current connection based on the declared client capabilities.

Multiple capabilities can be declared in the command. If any capabilities are unrecognized,
Valkey will ignore them instead of returning an error.

The capabilities currently supported are:

* `redirect` - This indicates that the client is capable of handling redirect messages.
When accessing a replica node in standalone mode, if a data operation is performed (read or write commands),
Valkey will return `-REDIRECT primary-ip:port` to this connection.
Using the `READONLY` command can enable this connection to execute read commands on the replica node.
12 changes: 8 additions & 4 deletions commands/readonly.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Enables read queries for a connection to a Valkey Cluster replica node.
Enables read queries for a connection to a Valkey replica node.

Normally replica nodes will redirect clients to the authoritative master for
In cluster mode, replica nodes will redirect clients to the authoritative primary for
the hash slot involved in a given command, however clients can use replicas
in order to scale reads using the `READONLY` command.

Expand All @@ -9,10 +9,14 @@ read possibly stale data and is not interested in running write queries.

When the connection is in readonly mode, the cluster will send a redirection
to the client only if the operation involves keys not served by the replica's
master node. This may happen because:
primary node. This may happen because:

1. The client sent a command about hash slots never served by the master of this replica.
1. The client sent a command about hash slots never served by the primary of this replica.
2. The cluster was reconfigured (for example resharded) and the replica is no longer able to serve commands for a given hash slot.
3. Since Valkey 8.0, if a slot migration is ongoing.
In this case the replica can return an ASK redirect or a TRYAGAIN error reply.
In earlier versions, replicas are not aware of ongoing slot migrations.

In standalone mode, by default, clients accessing a replica node can execute read queries, (which might read stale data) without entering readonly mode.

Since Valkey 8.0, if a client in standalone mode uses the `CLIENT CAPA redirect` command to declare its capability to handle redirections, then the replica node will send redirection messages to the client when executing both read and write commands. The client must issue the `READONLY` command to enter readonly mode before it can execute read commands.
10 changes: 7 additions & 3 deletions commands/readwrite.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Disables read queries for a connection to a Valkey Cluster replica node.
Disables read queries for a connection to a Valkey replica node.

Read queries against a Valkey Cluster replica node are disabled by default,
but you can use the `READONLY` command to change this behavior on a per-
Read queries against a Valkey Cluster replica node are disabled by default.

For standalone replica nodes, since Valkey 8.0, read queries are also disabled
for clients that have executed the `CLIENT CAPA redirect` command.

But you can use the `READONLY` command to change this behavior on a per-
connection basis. The `READWRITE` command resets the readonly mode flag
of a connection back to readwrite.

0 comments on commit dcee122

Please sign in to comment.