-
Notifications
You must be signed in to change notification settings - Fork 718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
keyspace: add priority of tso node for the keyspace group #6602
Changes from 3 commits
24c5f38
7d14069
6485d6d
12d9e5c
eaea132
f30d5fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -23,6 +23,7 @@ | |||||||
"github.com/pkg/errors" | ||||||||
"github.com/tikv/pd/pkg/errs" | ||||||||
"github.com/tikv/pd/pkg/mcs/utils" | ||||||||
"github.com/tikv/pd/pkg/slice" | ||||||||
"github.com/tikv/pd/pkg/storage/endpoint" | ||||||||
"github.com/tikv/pd/server" | ||||||||
"github.com/tikv/pd/server/apiv2/middlewares" | ||||||||
|
@@ -40,6 +41,7 @@ | |||||||
router.DELETE("/:id", DeleteKeyspaceGroupByID) | ||||||||
router.POST("/:id/alloc", AllocNodesForKeyspaceGroup) | ||||||||
router.POST("/:id/nodes", SetNodesForKeyspaceGroup) | ||||||||
router.POST("/:id/priority", SetPriorityForKeyspaceGroup) | ||||||||
router.POST("/:id/split", SplitKeyspaceGroupByID) | ||||||||
router.DELETE("/:id/split", FinishSplitKeyspaceByID) | ||||||||
router.POST("/:id/merge", MergeKeyspaceGroups) | ||||||||
|
@@ -325,7 +327,7 @@ | |||||||
c.AbortWithStatusJSON(http.StatusBadRequest, errs.ErrBindJSON.Wrap(err).GenWithStackByCause()) | ||||||||
return | ||||||||
} | ||||||||
if manager.GetNodesCount() < allocParams.Replica || allocParams.Replica < utils.KeyspaceGroupDefaultReplicaCount { | ||||||||
if manager.GetNodesCount() < allocParams.Replica || allocParams.Replica < utils.DefaultKeyspaceGroupReplicaCount { | ||||||||
c.AbortWithStatusJSON(http.StatusBadRequest, "invalid replica, should be in [2, nodes_num]") | ||||||||
return | ||||||||
} | ||||||||
|
@@ -347,7 +349,7 @@ | |||||||
c.JSON(http.StatusOK, nodes) | ||||||||
} | ||||||||
|
||||||||
// SetNodesForKeyspaceGroupParams defines the params for setting nodes for keyspace groups. | ||||||||
// SetNodesForKeyspaceGroupParams defines the params for setting nodes for keyspace group. | ||||||||
// Notes: it should be used carefully. | ||||||||
type SetNodesForKeyspaceGroupParams struct { | ||||||||
Nodes []string `json:"nodes"` | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also support set priorities in SetNodesForKeyspaceGroup API? if priorities []int is null, then set default priority for every node in the Nodes.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want to support it in the next pr, it's ok. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. now we can support "set-node <keyspace_group_id> <tso_node_addr> [<tso_node_addr>...]" and "set-priority <keyspace_group_id> <tso_node_addr> " in pd-ctl, if only run "set-node", it means to set default priority There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we merge these interfaces, it will be not convenient in pd-ctl |
||||||||
|
@@ -379,7 +381,7 @@ | |||||||
return | ||||||||
} | ||||||||
// check if nodes is less than default replica count | ||||||||
if len(setParams.Nodes) < utils.KeyspaceGroupDefaultReplicaCount { | ||||||||
if len(setParams.Nodes) < utils.DefaultKeyspaceGroupReplicaCount { | ||||||||
c.AbortWithStatusJSON(http.StatusBadRequest, "invalid num of nodes") | ||||||||
return | ||||||||
} | ||||||||
|
@@ -399,6 +401,53 @@ | |||||||
c.JSON(http.StatusOK, nil) | ||||||||
} | ||||||||
|
||||||||
// SetPriorityForKeyspaceGroupParams defines the params for setting priority of tso node for the keyspace group. | ||||||||
type SetPriorityForKeyspaceGroupParams struct { | ||||||||
Node string `json:"node"` | ||||||||
Priority int `json:"priority"` | ||||||||
} | ||||||||
|
||||||||
// SetPriorityForKeyspaceGroup sets priority of tso node for the keyspace group. | ||||||||
func SetPriorityForKeyspaceGroup(c *gin.Context) { | ||||||||
id, err := validateKeyspaceGroupID(c) | ||||||||
if err != nil { | ||||||||
c.AbortWithStatusJSON(http.StatusBadRequest, "invalid keyspace group id") | ||||||||
return | ||||||||
} | ||||||||
svr := c.MustGet(middlewares.ServerContextKey).(*server.Server) | ||||||||
manager := svr.GetKeyspaceGroupManager() | ||||||||
if manager == nil { | ||||||||
c.AbortWithStatusJSON(http.StatusInternalServerError, groupManagerUninitializedErr) | ||||||||
return | ||||||||
} | ||||||||
setParams := &SetPriorityForKeyspaceGroupParams{} | ||||||||
err = c.BindJSON(setParams) | ||||||||
if err != nil { | ||||||||
c.AbortWithStatusJSON(http.StatusBadRequest, errs.ErrBindJSON.Wrap(err).GenWithStackByCause()) | ||||||||
return | ||||||||
} | ||||||||
// check if keyspace group exists | ||||||||
kg, err := manager.GetKeyspaceGroupByID(id) | ||||||||
if err != nil || kg == nil { | ||||||||
c.AbortWithStatusJSON(http.StatusBadRequest, "keyspace group does not exist") | ||||||||
return | ||||||||
} | ||||||||
// check if node exists | ||||||||
members := kg.Members | ||||||||
if slice.NoneOf(members, func(i int) bool { | ||||||||
return members[i].Address == setParams.Node | ||||||||
}) { | ||||||||
c.AbortWithStatusJSON(http.StatusBadRequest, "tso node does not exist in the keyspace group") | ||||||||
} | ||||||||
// set priority | ||||||||
err = manager.SetPriorityForKeyspaceGroup(id, setParams.Node, setParams.Priority) | ||||||||
if err != nil { | ||||||||
c.AbortWithStatusJSON(http.StatusInternalServerError, err.Error()) | ||||||||
return | ||||||||
} | ||||||||
c.JSON(http.StatusOK, nil) | ||||||||
} | ||||||||
|
||||||||
func validateKeyspaceGroupID(c *gin.Context) (uint32, error) { | ||||||||
id, err := strconv.ParseUint(c.Param("id"), 10, 64) | ||||||||
if err != nil { | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just use 0 as the default priority? If we don't set the priority, it is empty which is 0 as the value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @binshi-bing