Skip to content

Commit

Permalink
Merge branch 'bugfix1' into 'master' (merge request !374)
Browse files Browse the repository at this point in the history
[bugfix] do cluster failover don't break client connections. #79
### MR描述
<!--- 详细描述MR的细节 -->
cluster failover的时候,主节点切了从,不应该断开客户端连接,应该返回moved错误。

### 修改动机和上下文背景
<!--- 为什么需要此修改, 解决了什么问题 -->
<!---如果解决了相关的#issue, 在此处进行关联(#issue, close #issue) -->

### 此MR如何进行测试 ?
<!--- 请描述测试MR的细节 -->
<!--- 包括测试的环境以及执行的测试用例 -->
<!--- 说明 change 如何影响其他部分的代码 etc. -->
```
predixy下面挂tendis集群。
往predixy压测:
redis-benchmark -h 127.0.0.1 -p 51000 -a tendis+test -t set -n 10000000 -c 50 -r 30000000 -d 256 -R -e
执行failover:
redis-cli -p 54003 -a tendis+test cluster failover
此时redis-benchmark客户端不应该报错:
Error from server: ERR server connection close
```
### change 类型
<!---你的代码引入了何种类型的change, 在所有关联的复选框前选择"x" -->
- [ ] Bug fix (修复了issue的非侵入式修改)
- [ ] New feature (增加功能的非侵入式修改)
- [ ] Breaking change (修复或者增加特性, 但是会造成现有行为的非预期行为)

### 清单
<!--- 查看下述选项,并进行"x"勾选 -->
<!--- 如果你对所有都不确定, 请随时咨询我们 -->
- [ ] 遵循项目的Code-Style
- [ ] Change 需要文档的修改
- [ ] 我已经进行相关文档的修改
- [ ] 我的MR已经通过的相关流水线测试
  • Loading branch information
TendisDev committed Jul 1, 2021
2 parents dc0834d + 496c25f commit 532b9a9
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 532b9a9

Please sign in to comment.