MCPcopy Create free account
hub / github.com/apache/kvrocks-controller / failoverShard

Function failoverShard

cmd/client/command/failover.go:82–105  ·  view source on GitHub ↗
(client *client, options *FailoverOptions, shardIndex int)

Source from the content-addressed store, hash-verified

80}
81
82func failoverShard(client *client, options *FailoverOptions, shardIndex int) error {
83 rsp, err := client.restyCli.R().
84 SetPathParam("namespace", options.namespace).
85 SetPathParam("cluster", options.cluster).
86 SetPathParam("shard", strconv.Itoa(shardIndex)).
87 SetBody(map[string]interface{}{
88 "preferred_node_id": options.preferred,
89 }).
90 Post("/namespaces/{namespace}/clusters/{cluster}/shards/{shard}/failover")
91 if err != nil {
92 return err
93 }
94 if rsp.IsError() {
95 return unmarshalError(rsp.Body())
96 }
97 var result struct {
98 NewMasterID string `json:"new_master_id"`
99 }
100 if err := unmarshalData(rsp.Body(), &result); err != nil {
101 return err
102 }
103 printLine("failover shard %d successfully, new master id: %s.", shardIndex, result.NewMasterID)
104 return nil
105}
106
107func init() {
108 FailoverCommand.Flags().StringVarP(&failoverOptions.namespace, "namespace", "n", "", "The namespace of the cluster")

Callers 1

failover.goFile · 0.70

Calls 3

unmarshalErrorFunction · 0.85
unmarshalDataFunction · 0.85
printLineFunction · 0.85

Tested by

no test coverage detected