forked from valkey-io/valkey
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replica redirect read&write to primary in standalone mode (valkey-io#325
) To implement valkey-io#319 1. replica is able to redirect read and write commands to it's primary in standalone mode * reply with "-REDIRECT primary-ip:port" 2. add a subcommand `CLIENT CAPA redirect`, a client can announce the capability to handle redirection * if a client can handle redirection, the data access commands (read and write) will be redirected 3. allow `readonly` and `readwrite` command in standalone mode, may be a breaking change * a client with redirect capability cannot process read commands on a replica by default * use READONLY command can allow read commands on a replica --------- Signed-off-by: zhaozhao.zz <[email protected]>
- Loading branch information
Showing
7 changed files
with
106 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"CAPA": { | ||
"summary": "A client claims its capability.", | ||
"complexity": "O(1)", | ||
"group": "connection", | ||
"since": "8.0.0", | ||
"arity": -3, | ||
"container": "CLIENT", | ||
"function": "clientCommand", | ||
"command_flags": [ | ||
"NOSCRIPT", | ||
"LOADING", | ||
"STALE" | ||
], | ||
"acl_categories": [ | ||
"CONNECTION" | ||
], | ||
"reply_schema": { | ||
"const": "OK" | ||
}, | ||
"arguments": [ | ||
{ | ||
"multiple": "true", | ||
"name": "capability", | ||
"type": "string" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
start_server {tags {needs:repl external:skip}} { | ||
start_server {} { | ||
set primary_host [srv -1 host] | ||
set primary_port [srv -1 port] | ||
|
||
r replicaof $primary_host $primary_port | ||
wait_for_condition 50 100 { | ||
[s 0 master_link_status] eq {up} | ||
} else { | ||
fail "Replicas not replicating from primary" | ||
} | ||
|
||
test {replica allow read command by default} { | ||
r get foo | ||
} {} | ||
|
||
test {replica reply READONLY error for write command by default} { | ||
assert_error {READONLY*} {r set foo bar} | ||
} | ||
|
||
test {replica redirect read and write command after CLIENT CAPA REDIRECT} { | ||
r client capa redirect | ||
assert_error "REDIRECT $primary_host:$primary_port" {r set foo bar} | ||
assert_error "REDIRECT $primary_host:$primary_port" {r get foo} | ||
} | ||
|
||
test {non-data access commands are not redirected} { | ||
r ping | ||
} {PONG} | ||
|
||
test {replica allow read command in READONLY mode} { | ||
r readonly | ||
r get foo | ||
} {} | ||
} | ||
} |