This is an automated email from the ASF dual-hosted git repository.

xikai pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-horaedb-meta.git

commit 7e5268a39fc73f047a383490c971d3aa249aa76b
Author: CooooolFrog <[email protected]>
AuthorDate: Thu Dec 28 17:11:41 2023 +0800

    feat: add drop shard node api (#295)
    
    ## Rationale
    In some extreme cases (for this situation, please refer to
    https://github.com/apache/incubator-horaedb-meta/issues/296), the shard
    node cannot be cleaned normally, and we need to add an operation and
    maintenance interface to complete manual cleaning.
    
    ## Detailed Changes
    * Add drop shard node api.
    
    ## Test Plan
    Pass CI.
---
 server/service/http/api.go   | 32 ++++++++++++++++++++++++++++++++
 server/service/http/error.go |  1 +
 server/service/http/types.go |  5 +++++
 3 files changed, 38 insertions(+)

diff --git a/server/service/http/api.go b/server/service/http/api.go
index 36412ca..4476e81 100644
--- a/server/service/http/api.go
+++ b/server/service/http/api.go
@@ -64,6 +64,7 @@ func (a *API) NewAPIRouter() *Router {
        router.Post("/route", wrap(a.route, true, a.forwardClient))
        router.Del("/table", wrap(a.dropTable, true, a.forwardClient))
        router.Post("/getNodeShards", wrap(a.getNodeShards, true, 
a.forwardClient))
+       router.Del("/nodeShards", wrap(a.dropNodeShards, true, a.forwardClient))
        router.Get("/flowLimiter", wrap(a.getFlowLimiter, true, 
a.forwardClient))
        router.Put("/flowLimiter", wrap(a.updateFlowLimiter, true, 
a.forwardClient))
        router.Get("/health", wrap(a.health, false, a.forwardClient))
@@ -206,6 +207,37 @@ func (a *API) getNodeShards(req *http.Request) 
apiFuncResult {
        return okResult(result)
 }
 
+func (a *API) dropNodeShards(req *http.Request) apiFuncResult {
+       var dropNodeShardsRequest DropNodeShardsRequest
+       err := json.NewDecoder(req.Body).Decode(&dropNodeShardsRequest)
+       if err != nil {
+               return errResult(ErrParseRequest, err.Error())
+       }
+
+       c, err := a.clusterManager.GetCluster(req.Context(), 
dropNodeShardsRequest.ClusterName)
+       if err != nil {
+               log.Error("get cluster failed", zap.String("clusterName", 
dropNodeShardsRequest.ClusterName), zap.Error(err))
+               return errResult(ErrGetCluster, fmt.Sprintf("clusterName: %s, 
err: %s", dropNodeShardsRequest.ClusterName, err.Error()))
+       }
+
+       targetShardNodes := make([]storage.ShardNode, 0, 
len(dropNodeShardsRequest.ShardIDs))
+       getShardNodeResult := c.GetMetadata().GetShardNodes()
+       for _, shardNode := range getShardNodeResult.ShardNodes {
+               for _, shardID := range dropNodeShardsRequest.ShardIDs {
+                       if shardNode.ID == storage.ShardID(shardID) {
+                               targetShardNodes = append(targetShardNodes, 
shardNode)
+                       }
+               }
+       }
+
+       if err := c.GetMetadata().DropShardNode(req.Context(), 
targetShardNodes); err != nil {
+               log.Error("drop node shards failed", zap.Error(err))
+               return errResult(ErrDropNodeShards, err.Error())
+       }
+
+       return okResult(targetShardNodes)
+}
+
 func (a *API) dropTable(req *http.Request) apiFuncResult {
        var dropTableRequest DropTableRequest
        err := json.NewDecoder(req.Body).Decode(&dropTableRequest)
diff --git a/server/service/http/error.go b/server/service/http/error.go
index 0fbafae..70cc83c 100644
--- a/server/service/http/error.go
+++ b/server/service/http/error.go
@@ -27,6 +27,7 @@ var (
        ErrTable                         = coderr.NewCodeError(coderr.Internal, 
"table")
        ErrRoute                         = coderr.NewCodeError(coderr.Internal, 
"route table")
        ErrGetNodeShards                 = coderr.NewCodeError(coderr.Internal, 
"get node shards")
+       ErrDropNodeShards                = coderr.NewCodeError(coderr.Internal, 
"drop node shards")
        ErrCreateProcedure               = coderr.NewCodeError(coderr.Internal, 
"create procedure")
        ErrSubmitProcedure               = coderr.NewCodeError(coderr.Internal, 
"submit procedure")
        ErrGetCluster                    = coderr.NewCodeError(coderr.Internal, 
"get cluster")
diff --git a/server/service/http/types.go b/server/service/http/types.go
index 9010481..2d17652 100644
--- a/server/service/http/types.go
+++ b/server/service/http/types.go
@@ -119,6 +119,11 @@ type NodeShardsRequest struct {
        ClusterName string `json:"clusterName"`
 }
 
+type DropNodeShardsRequest struct {
+       ClusterName string   `json:"clusterName"`
+       ShardIDs    []uint32 `json:"shardIDs"`
+}
+
 type DropTableRequest struct {
        ClusterName string `json:"clusterName"`
        SchemaName  string `json:"schemaName"`


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to