Skip to content

Commit

Permalink
allow READONLY&READWRITE only after CLIENT CAPA REDIRECT for standalo…
Browse files Browse the repository at this point in the history
…ne mode

Signed-off-by: zhaozhao.zz <[email protected]>
  • Loading branch information
soloestoy committed Nov 25, 2024
1 parent 653d5f7 commit c87b50f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -1471,12 +1471,24 @@ void askingCommand(client *c) {
* In this mode replica will not redirect clients as long as clients access
* with read-only commands to keys that are served by the replica's primary. */
void readonlyCommand(client *c) {
if (server.cluster_enabled == 0 && !(c->capa & CLIENT_CAPA_REDIRECT)) {
addReplyError(c, "This instance has cluster support disabled,"
" you need to execute the CLIENT CAPA REDIRECT command,"
" before you can use the READONLY command in standalone mode.");
return;
}
c->flag.readonly = 1;
addReply(c, shared.ok);
}

/* The READWRITE command just clears the READONLY command state. */
void readwriteCommand(client *c) {
if (server.cluster_enabled == 0 && !(c->capa & CLIENT_CAPA_REDIRECT)) {
addReplyError(c, "This instance has cluster support disabled,"
" you need to execute the CLIENT CAPA REDIRECT command,"
" before you can use the READWRITE command in standalone mode.");
return;
}
c->flag.readonly = 0;
addReply(c, shared.ok);
}
Expand Down
5 changes: 5 additions & 0 deletions tests/integration/replica-redirect.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ start_server {tags {needs:repl external:skip}} {
set replica_port [srv 0 port]
set replica_pid [srv 0 pid]

test {READONLY and READWRITE commands are disabled by default} {
assert_error {*cluster*disabled*READONLY*standalone*} {r readonly}
assert_error {*cluster*disabled*READWRITE*standalone*} {r readwrite}
}

test {write command inside MULTI is QUEUED, EXEC should be REDIRECT} {
set rr [valkey_client]
$rr client capa redirect
Expand Down

0 comments on commit c87b50f

Please sign in to comment.