Skip to content

Commit

Permalink
set DefaultKeyspaceGroupReplicaPriority as 0
Browse files Browse the repository at this point in the history
Signed-off-by: lhy1024 <admin@liudos.us>
  • Loading branch information
lhy1024 committed Jun 19, 2023
1 parent 6485d6d commit 12d9e5c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 27 deletions.
2 changes: 1 addition & 1 deletion pkg/mcs/utils/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ const (
DefaultKeyspaceGroupReplicaCount = 2

// DefaultKeyspaceGroupReplicaPriority is the default priority of a keyspace group replica.
DefaultKeyspaceGroupReplicaPriority = 100
DefaultKeyspaceGroupReplicaPriority = 0
)
59 changes: 35 additions & 24 deletions tests/pdctl/keyspace/keyspace_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"encoding/json"
"fmt"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -217,35 +218,45 @@ func TestSetNodeAndPriorityKeyspaceGroup(t *testing.T) {
})

// set-priority keyspace group.
testutil.Eventually(re, func() bool {
args := []string{"-u", pdAddr, "keyspace-group", "set-priority", defaultKeyspaceGroupID, s1.GetAddr(), "200"}
output, err := pdctl.ExecuteCommand(cmd, args...)
re.NoError(err)
fmt.Println(string(output))
return strings.Contains(string(output), "Success")
})
checkPriority := func(p int) {
testutil.Eventually(re, func() bool {
args := []string{"-u", pdAddr, "keyspace-group", "set-priority", defaultKeyspaceGroupID, s1.GetAddr()}
if p >= 0 {
args = append(args, strconv.Itoa(p))
} else {
args = append(args, "--", strconv.Itoa(p))
}
output, err := pdctl.ExecuteCommand(cmd, args...)
re.NoError(err)
fmt.Println(string(output))
return strings.Contains(string(output), "Success")
})

// check keyspace group information.
args := []string{"-u", pdAddr, "keyspace-group"}
output, err := pdctl.ExecuteCommand(cmd, append(args, defaultKeyspaceGroupID)...)
re.NoError(err)
var keyspaceGroup endpoint.KeyspaceGroup
err = json.Unmarshal(output, &keyspaceGroup)
re.NoError(err)
re.Equal(utils.DefaultKeyspaceGroupID, keyspaceGroup.ID)
re.Len(keyspaceGroup.Members, 2)
for _, member := range keyspaceGroup.Members {
re.Contains([]string{s1.GetAddr(), s2.GetAddr()}, member.Address)
if member.Address == s1.GetAddr() {
re.Equal(200, member.Priority)
} else {
re.Equal(100, member.Priority)
// check keyspace group information.
args := []string{"-u", pdAddr, "keyspace-group"}
output, err := pdctl.ExecuteCommand(cmd, append(args, defaultKeyspaceGroupID)...)
re.NoError(err)
var keyspaceGroup endpoint.KeyspaceGroup
err = json.Unmarshal(output, &keyspaceGroup)
re.NoError(err)
re.Equal(utils.DefaultKeyspaceGroupID, keyspaceGroup.ID)
re.Len(keyspaceGroup.Members, 2)
for _, member := range keyspaceGroup.Members {
re.Contains([]string{s1.GetAddr(), s2.GetAddr()}, member.Address)
if member.Address == s1.GetAddr() {
re.Equal(p, member.Priority)
} else {
re.Equal(0, member.Priority)
}
}
}

checkPriority(200)
checkPriority(-200)

// params error for set-node.
args = []string{"-u", pdAddr, "keyspace-group", "set-node", defaultKeyspaceGroupID, s1.GetAddr()}
output, err = pdctl.ExecuteCommand(cmd, args...)
args := []string{"-u", pdAddr, "keyspace-group", "set-node", defaultKeyspaceGroupID, s1.GetAddr()}
output, err := pdctl.ExecuteCommand(cmd, args...)
re.NoError(err)
re.Contains(string(output), "invalid num of nodes")
args = []string{"-u", pdAddr, "keyspace-group", "set-node", defaultKeyspaceGroupID, "", ""}
Expand Down
4 changes: 2 additions & 2 deletions tools/pd-ctl/pdctl/command/keyspace_group_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func newSetNodesKeyspaceGroupCommand() *cobra.Command {
func newSetPriorityKeyspaceGroupCommand() *cobra.Command {
r := &cobra.Command{
Use: "set-priority <keyspace_group_id> <tso_node_addr> <priority>",
Short: "set the priority of tso nodes for keyspace group with the given ID",
Short: "set the priority of tso nodes for keyspace group with the given ID. If the priority is negative, it need to add a prefix with -- to avoid identified as flag.",
Run: setPriorityKeyspaceGroupCommandFunc,
}
return r
Expand Down Expand Up @@ -150,7 +150,7 @@ func setPriorityKeyspaceGroupCommandFunc(cmd *cobra.Command, args []string) {
return
}

priority, err := strconv.ParseUint(args[2], 10, 32)
priority, err := strconv.ParseInt(args[2], 10, 32)
if err != nil {
cmd.Printf("Failed to parse the priority: %s\n", err)
return
Expand Down

0 comments on commit 12d9e5c

Please sign in to comment.