Skip to content

Commit

Permalink
merge feature-1.6 with rump modification
Browse files Browse the repository at this point in the history
  • Loading branch information
vinllen committed May 26, 2019
2 parents 5f7f633 + ee58e1e commit 6af95d0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 28 deletions.
10 changes: 7 additions & 3 deletions src/redis-shake/common/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"strconv"

"redis-shake/configure"

redigo "github.com/garyburd/redigo/redis"
Expand Down Expand Up @@ -111,7 +110,8 @@ func ClusterNodeChoose(input []*ClusterNodeInfo, role string) []*ClusterNodeInfo
return ret
}

func GetAllClusterNode(client redigo.Conn, role string) ([]string, error) {
// return id list if choose == "id", otherwise address
func GetAllClusterNode(client redigo.Conn, role string, choose string) ([]string, error) {
ret, err := client.Do("cluster", "nodes")
if err != nil {
return nil, err
Expand All @@ -122,7 +122,11 @@ func GetAllClusterNode(client redigo.Conn, role string) ([]string, error) {

result := make([]string, 0, len(nodeListChoose))
for _, ele := range nodeListChoose {
result = append(result, ele.Address)
if choose == "id" {
result = append(result, ele.Id)
} else {
result = append(result, ele.Address)
}
}

return result, nil
Expand Down
2 changes: 1 addition & 1 deletion src/redis-shake/common/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func parseAddress(tp, address, redisType string, isSource bool) error {
// create client to fetch
tls := isSource && conf.Options.SourceTLSEnable || !isSource && conf.Options.TargetTLSEnable
client := OpenRedisConn(clusterList, auth, password, false, tls)
if addressList, err := GetAllClusterNode(client, role); err != nil {
if addressList, err := GetAllClusterNode(client, role, "address"); err != nil {
return err
} else {
if isSource {
Expand Down
27 changes: 3 additions & 24 deletions src/redis-shake/scanner/specialCloudScanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package scanner
import (
"strconv"
"fmt"
"bytes"

"redis-shake/common"
"redis-shake/configure"

Expand Down Expand Up @@ -35,32 +33,13 @@ func (scs *SpecialCloudScanner) NodeCount() (int, error) {
return int(count), nil
}
case utils.TencentCluster:
/*
* tencent cluster return:
* 10.1.1.1:2000> cluster nodes
* 25b21f1836026bd49c52b2d10e09fbf8c6aa1fdc 10.0.0.15:6379@11896 slave 36034e645951464098f40d339386e9d51a9d7e77 0 1531471918205 1 connected
* da6041781b5d7fe21404811d430cdffea2bf84de 10.0.0.15:6379@11170 master - 0 1531471916000 2 connected 10923-16383
* 36034e645951464098f40d339386e9d51a9d7e77 10.0.0.15:6379@11541 myself,master - 0 1531471915000 1 connected 0-5460
* 53f552fd8e43112ae68b10dada69d3af77c33649 10.0.0.15:6379@11681 slave da6041781b5d7fe21404811d430cdffea2bf84de 0 1531471917204 3 connected
* 18090a0e57cf359f9f8c8c516aa62a811c0f0f0a 10.0.0.15:6379@11428 slave ef3cf5e20e1a7cf5f9cc259ed488c82c4aa17171 0 1531471917000 2 connected
* ef3cf5e20e1a7cf5f9cc259ed488c82c4aa17171 10.0.0.15:6379@11324 master - 0 1531471916204 0 connected 5461-10922
*/
info, err := redis.Bytes(scs.client.Do("cluster", "nodes"))
var err error
scs.tencentNodes, err = utils.GetAllClusterNode(scs.client, conf.StandAloneRoleMaster, "id")
if err != nil {
return -1, err
}

lines := bytes.Split(info, []byte("\r\n"))
ret := make([]string, 0, len(lines)/2)
master := []byte("master")
for _, row := range lines {
col := bytes.Split(row, []byte(" "))
if len(col) >= 3 && bytes.Contains(col[2], master) {
ret = append(ret, string(col[0]))
}
}
scs.tencentNodes = ret
return len(ret), nil
return len(scs.tencentNodes), nil
default:
return -1, nil
}
Expand Down

0 comments on commit 6af95d0

Please sign in to comment.