Skip to content

Commit

Permalink
[bugfix] do cluster failover don't break client connections.
Browse files Browse the repository at this point in the history
  • Loading branch information
takenliu committed Jun 22, 2021
1 parent 2128a5f commit 496c25f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/tendisplus/commands/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ Expected<std::string> 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);
Expand Down
18 changes: 18 additions & 0 deletions src/tendisplus/integrate_test/clustertestFailover.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main

import (
"flag"
"fmt"
"github.com/ngaut/log"
"tendisplus/integrate_test/util"
"os/exec"
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/tendisplus/integrate_test/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down

0 comments on commit 496c25f

Please sign in to comment.