futriix/tests/integration/replica-redirect.tcl
zhaozhao.zz 28c5a17edf
replica redirect read&write to primary in standalone mode (#325)
To implement #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 <zhaozhao.zz@alibaba-inc.com>
2024-06-27 19:00:45 +08:00

37 lines
1.1 KiB
Tcl

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
} {}
}
}