-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add delete broken copyset in chunkserver cli
Signed-off-by: liuminjian <[email protected]>
- Loading branch information
liuminjian
committed
Nov 9, 2023
1 parent
01e9dc4
commit dc1cee6
Showing
7 changed files
with
139 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
tools-v2/pkg/cli/command/curvebs/delete/copyset/copyset.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package copyset | ||
|
||
import ( | ||
"context" | ||
cmderror "github.com/opencurve/curve/tools-v2/internal/error" | ||
basecmd "github.com/opencurve/curve/tools-v2/pkg/cli/command" | ||
"github.com/opencurve/curve/tools-v2/pkg/config" | ||
"github.com/opencurve/curve/tools-v2/pkg/output" | ||
"github.com/opencurve/curve/tools-v2/proto/proto/topology" | ||
"github.com/spf13/cobra" | ||
"google.golang.org/grpc" | ||
"strconv" | ||
) | ||
|
||
const ( | ||
deleteBrokenCopySetExample = `$ curve bs delete broken-copyset --chunkserverid=1` | ||
) | ||
|
||
type DeleteBrokenCopySetInChunkServerRpc struct { | ||
Info *basecmd.Rpc | ||
Request *topology.DeleteBrokenCopysetInChunkServerRequest | ||
topologyClient topology.TopologyServiceClient | ||
} | ||
|
||
var _ basecmd.RpcFunc = (*DeleteBrokenCopySetInChunkServerRpc)(nil) // check interface | ||
|
||
type DeleteBrokenCopySetCommand struct { | ||
basecmd.FinalCurveCmd | ||
Rpc *DeleteBrokenCopySetInChunkServerRpc | ||
Servers []*topology.ServerInfo | ||
chunkserverid uint32 | ||
} | ||
|
||
func (d *DeleteBrokenCopySetInChunkServerRpc) Stub_Func(ctx context.Context) (interface{}, error) { | ||
return d.topologyClient.DeleteBrokenCopysetInChunkServer(ctx, d.Request) | ||
} | ||
|
||
func NewDeleteCommand() *cobra.Command { | ||
return NewDeleteBrokenCopySetCommand().Cmd | ||
} | ||
|
||
func NewDeleteBrokenCopySetCommand() *DeleteBrokenCopySetCommand { | ||
cmd := &DeleteBrokenCopySetCommand{ | ||
FinalCurveCmd: basecmd.FinalCurveCmd{ | ||
Use: "broken-copyset", | ||
Short: "delete broken copyset in chunkserver", | ||
Example: deleteBrokenCopySetExample, | ||
}, | ||
} | ||
|
||
basecmd.NewFinalCurveCli(&cmd.FinalCurveCmd, cmd) | ||
return cmd | ||
} | ||
|
||
func (d *DeleteBrokenCopySetCommand) AddFlags() { | ||
config.AddBsMdsFlagOption(d.Cmd) | ||
config.AddRpcRetryTimesFlag(d.Cmd) | ||
config.AddRpcTimeoutFlag(d.Cmd) | ||
config.AddBsChunkServerIdFlag(d.Cmd) | ||
} | ||
|
||
func (d *DeleteBrokenCopySetInChunkServerRpc) NewRpcClient(cc grpc.ClientConnInterface) { | ||
d.topologyClient = topology.NewTopologyServiceClient(cc) | ||
} | ||
|
||
func (d *DeleteBrokenCopySetCommand) Init(cmd *cobra.Command, args []string) error { | ||
mdsAddrs, err := config.GetBsMdsAddrSlice(d.Cmd) | ||
if err.TypeCode() != cmderror.CODE_SUCCESS { | ||
return err.ToError() | ||
} | ||
timeout := config.GetFlagDuration(d.Cmd, config.RPCTIMEOUT) | ||
retrytimes := config.GetFlagInt32(d.Cmd, config.RPCRETRYTIMES) | ||
strid, e := strconv.Atoi(config.GetBsFlagString(d.Cmd, config.CURVEBS_CHUNKSERVER_ID)) | ||
if e != nil { | ||
return e | ||
} | ||
d.chunkserverid = uint32(strid) | ||
d.Rpc = &DeleteBrokenCopySetInChunkServerRpc{ | ||
Info: basecmd.NewRpc(mdsAddrs, timeout, retrytimes, "DeleteBrokenCopysetInChunkServer"), | ||
Request: &topology.DeleteBrokenCopysetInChunkServerRequest{ | ||
ChunkServerID: &d.chunkserverid, | ||
}, | ||
} | ||
return nil | ||
} | ||
|
||
func (d *DeleteBrokenCopySetCommand) RunCommand(cmd *cobra.Command, args []string) error { | ||
result, errCmd := basecmd.GetRpcResponse(d.Rpc.Info, d.Rpc) | ||
if errCmd.TypeCode() != cmderror.CODE_SUCCESS { | ||
return errCmd.ToError() | ||
} | ||
d.Result = result | ||
return nil | ||
} | ||
|
||
func (d *DeleteBrokenCopySetCommand) Print(cmd *cobra.Command, args []string) error { | ||
return output.FinalCmdOutput(&d.FinalCurveCmd, d) | ||
} | ||
|
||
func (d *DeleteBrokenCopySetCommand) ResultPlainOutput() error { | ||
return output.FinalCmdOutputPlain(&d.FinalCurveCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters