Unverified Commit 1eb4baa5 authored by Mikhail Fesenko's avatar Mikhail Fesenko Committed by GitHub
Browse files

Direct redis-cli repl prints to stderr, because --rdb can print to stdout....


Direct redis-cli repl prints to stderr, because --rdb can print to stdout. fflush stdout after responses  (#9136)

1. redis-cli can output --rdb data to stdout
   but redis-cli also write some messages to stdout which will mess up the rdb.

2. Make redis-cli flush stdout when printing a reply
  This was needed in order to fix a hung in redis-cli test that uses
  --replica.
   Note that printf does flush when there's a newline, but fwrite does not.

3. fix the redis-cli --replica test which used to pass previously
   because it didn't really care what it read, and because redis-cli
   used printf to print these other things to stdout.

4. improve redis-cli --replica test to run with both diskless and disk-based.
Co-authored-by: default avatarOran Agra <oran@redislabs.com>
Co-authored-by: default avatarViktor Söderqvist <viktor@zuiderkwast.se>
parent 3a26f61f
...@@ -1342,6 +1342,7 @@ static int cliReadReply(int output_raw_strings) { ...@@ -1342,6 +1342,7 @@ static int cliReadReply(int output_raw_strings) {
if (output) { if (output) {
out = cliFormatReply(reply, config.output, output_raw_strings); out = cliFormatReply(reply, config.output, output_raw_strings);
fwrite(out,sdslen(out),1,stdout); fwrite(out,sdslen(out),1,stdout);
fflush(stdout);
sdsfree(out); sdsfree(out);
} }
freeReplyObject(reply); freeReplyObject(reply);
...@@ -7070,7 +7071,7 @@ static void latencyDistMode(void) { ...@@ -7070,7 +7071,7 @@ static void latencyDistMode(void) {
#define RDB_EOF_MARK_SIZE 40 #define RDB_EOF_MARK_SIZE 40
void sendReplconf(const char* arg1, const char* arg2) { void sendReplconf(const char* arg1, const char* arg2) {
printf("sending REPLCONF %s %s\n", arg1, arg2); fprintf(stderr, "sending REPLCONF %s %s\n", arg1, arg2);
redisReply *reply = redisCommand(context, "REPLCONF %s %s", arg1, arg2); redisReply *reply = redisCommand(context, "REPLCONF %s %s", arg1, arg2);
/* Handle any error conditions */ /* Handle any error conditions */
...@@ -7130,7 +7131,7 @@ unsigned long long sendSync(redisContext *c, char *out_eof) { ...@@ -7130,7 +7131,7 @@ unsigned long long sendSync(redisContext *c, char *out_eof) {
} }
*p = '\0'; *p = '\0';
if (buf[0] == '-') { if (buf[0] == '-') {
printf("SYNC with master failed: %s\n", buf); fprintf(stderr, "SYNC with master failed: %s\n", buf);
exit(1); exit(1);
} }
if (strncmp(buf+1,"EOF:",4) == 0 && strlen(buf+5) >= RDB_EOF_MARK_SIZE) { if (strncmp(buf+1,"EOF:",4) == 0 && strlen(buf+5) >= RDB_EOF_MARK_SIZE) {
......
...@@ -294,9 +294,9 @@ start_server {tags {"cli"}} { ...@@ -294,9 +294,9 @@ start_server {tags {"cli"}} {
assert_equal {key:2} [run_cli --scan --quoted-pattern {"*:\x32"}] assert_equal {key:2} [run_cli --scan --quoted-pattern {"*:\x32"}]
} }
test "Connecting as a replica" { proc test_redis_cli_repl {} {
set fd [open_cli "--replica"] set fd [open_cli "--replica"]
wait_for_condition 500 500 { wait_for_condition 500 100 {
[string match {*slave0:*state=online*} [r info]] [string match {*slave0:*state=online*} [r info]]
} else { } else {
fail "redis-cli --replica did not connect" fail "redis-cli --replica did not connect"
...@@ -305,12 +305,28 @@ start_server {tags {"cli"}} { ...@@ -305,12 +305,28 @@ start_server {tags {"cli"}} {
for {set i 0} {$i < 100} {incr i} { for {set i 0} {$i < 100} {incr i} {
r set test-key test-value-$i r set test-key test-value-$i
} }
r client kill type slave
catch { wait_for_condition 500 100 {
assert_match {*SET*key-a*} [read_cli $fd] [string match {*test-value-99*} [read_cli $fd]]
} else {
fail "redis-cli --replica didn't read commands"
} }
close_cli $fd fconfigure $fd -blocking true
r client kill type slave
catch { close_cli $fd } err
assert_match {*Server closed the connection*} $err
}
test "Connecting as a replica" {
# Disk-based master
assert_match "OK" [r config set repl-diskless-sync no]
test_redis_cli_repl
# Disk-less master
assert_match "OK" [r config set repl-diskless-sync yes]
assert_match "OK" [r config set repl-diskless-sync-delay 0]
test_redis_cli_repl
} {} {needs:repl} } {} {needs:repl}
test "Piping raw protocol" { test "Piping raw protocol" {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment