From 496c25f00133cad38b9d12f3566841ba4c21b91c Mon Sep 17 00:00:00 2001 From: takenliu Date: Tue, 22 Jun 2021 14:56:56 +0800 Subject: [PATCH] [bugfix] do cluster failover don't break client connections. --- src/tendisplus/commands/command.cpp | 2 +- .../integrate_test/clustertestFailover.go | 18 ++++++++++++++++++ src/tendisplus/integrate_test/common.go | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/tendisplus/commands/command.cpp b/src/tendisplus/commands/command.cpp index 32c5ba3a..b36967b1 100644 --- a/src/tendisplus/commands/command.cpp +++ b/src/tendisplus/commands/command.cpp @@ -278,7 +278,7 @@ Expected Command::runSessionCmd(Session* sess) { sess->getServerEntry()->setTsEp(sess->getCtx()->getTsEP()); } } else { - if (sess->getCtx()->isReplOnly()) { + if (sess->getCtx()->isReplOnly() && sess->getCtx()->isMaster()) { // NOTE(vinchen): If it's a slave, the connection should be closed // when there is an error. And the error should be log ServerEntry::logError(v.status().toString(), sess); diff --git a/src/tendisplus/integrate_test/clustertestFailover.go b/src/tendisplus/integrate_test/clustertestFailover.go index 1bac02aa..6b68a38b 100644 --- a/src/tendisplus/integrate_test/clustertestFailover.go +++ b/src/tendisplus/integrate_test/clustertestFailover.go @@ -6,6 +6,7 @@ package main import ( "flag" + "fmt" "github.com/ngaut/log" "tendisplus/integrate_test/util" "os/exec" @@ -125,6 +126,23 @@ func testCluster(clusterIp string, clusterPortStart int, clusterNodeNum int) { <-channel log.Infof("cluster adddata end") + // when do cluster failover, old master change to slave, it shouldn't close the clients connection + // so redis-benchmark shouldn't print log: "Error from server: ERR server connection close" + logFilePath := fmt.Sprintf("benchmark_%d.log", predixy.RedisServer.Port) + log.Infof("check redis-benchmark log file: %s", logFilePath) + logcontent := "Error from server: ERR server connection close" + cmd := fmt.Sprintf("grep \"%s\" %s|wc -l", logcontent, logFilePath) + out, err := exec.Command("sh", "-c", cmd).CombinedOutput() + if err != nil { + log.Fatalf("grep %s failed %v", logFilePath, err) + return + } + log.Infof("logcontent: %s", string(out)) + if string(out) != "0\n" { + log.Fatalf("%s logcontent: %s", logFilePath, string(out)) + return + } + // wait predixy add data end time.Sleep(30 * time.Second) diff --git a/src/tendisplus/integrate_test/common.go b/src/tendisplus/integrate_test/common.go index fc9829e9..eec227f7 100644 --- a/src/tendisplus/integrate_test/common.go +++ b/src/tendisplus/integrate_test/common.go @@ -136,7 +136,7 @@ func addData(m *util.RedisServer, num int, prefixkey string) { }*/ logFilePath := fmt.Sprintf("benchmark_%d.log", m.Port) var cmd string - cmd = fmt.Sprintf("../../../bin/redis-benchmark -h %s -p %d -c 20 -n %d -r 8 -i -f %s -t %s -a %s > %s 2>&1", + cmd = fmt.Sprintf("../../../bin/redis-benchmark -h %s -p %d -c 20 -n %d -r 8 -i -f %s -t %s -a %s -e > %s 2>&1", m.Ip, m.Port, num, prefixkey, *benchtype, *auth, logFilePath) log.Infof("addData cmd:%s", cmd) args := []string{}