From 1041ceb026cb61aade8b20ebb73cfac34d57ceb7 Mon Sep 17 00:00:00 2001 From: liuminjian Date: Thu, 9 Nov 2023 13:38:27 +0800 Subject: [PATCH] add delete broken copyset in chunkserver cli Signed-off-by: liuminjian --- proto/heartbeat.proto | 2 - src/chunkserver/heartbeat.cpp | 11 +- src/mds/heartbeat/copyset_conf_generator.cpp | 3 - .../command/curvebs/delete/copyset/copyset.go | 102 ++++++++++++++++++ .../pkg/cli/command/curvebs/delete/delete.go | 2 + tools-v2/pkg/cli/command/curvebs/list/list.go | 2 + .../list/unavailcopysets/unavailcopysets.go | 26 ++++- 7 files changed, 139 insertions(+), 9 deletions(-) create mode 100644 tools-v2/pkg/cli/command/curvebs/delete/copyset/copyset.go diff --git a/proto/heartbeat.proto b/proto/heartbeat.proto index 693bb6a9c5..77adadb293 100644 --- a/proto/heartbeat.proto +++ b/proto/heartbeat.proto @@ -150,8 +150,6 @@ message CopySetConf { // 表示待删除节点。 // chunkserver收到CHANGE_PEER,根据peers,configchangeItem,oldPeer拼出新的conf optional common.Peer oldPeer = 7; - // copyset availflag - optional bool availflag = 8; }; enum HeartbeatStatusCode { diff --git a/src/chunkserver/heartbeat.cpp b/src/chunkserver/heartbeat.cpp index 8db742ab62..4970bd7b81 100644 --- a/src/chunkserver/heartbeat.cpp +++ b/src/chunkserver/heartbeat.cpp @@ -307,6 +307,14 @@ int Heartbeat::BuildRequest(HeartbeatRequest* req) { int leaders = 0; for (CopysetNodePtr copyset : copysets) { + + // 如果磁盘空间不足设为readonly + if (diskState->errtype() == curve::mds::heartbeat::DISKFULL) { + copyset->SetReadOnly(true); + }else { + copyset->SetReadOnly(false); + } + curve::mds::heartbeat::CopySetInfo* info = req->add_copysetinfos(); ret = BuildCopysetInfo(info, copyset); @@ -439,9 +447,6 @@ int Heartbeat::ExecTask(const HeartbeatResponse& response) { continue; } - // 判断copyset是否avail,否则设置readonly - copyset->SetReadOnly(!conf.availflag()); - // 解析该chunkserver上的copyset是否需要删除 // 需要删除则清理copyset if (HeartbeatHelper::NeedPurge(csEp_, conf, copyset)) { diff --git a/src/mds/heartbeat/copyset_conf_generator.cpp b/src/mds/heartbeat/copyset_conf_generator.cpp index a056da1eb1..9139275e4e 100644 --- a/src/mds/heartbeat/copyset_conf_generator.cpp +++ b/src/mds/heartbeat/copyset_conf_generator.cpp @@ -52,9 +52,6 @@ bool CopysetConfGenerator::GenCopysetConf( return true; } - // set copyset availflag - copysetConf->set_availflag(recordCopySetInfo.IsAvailable()); - if (reportCopySetInfo.GetLeader() == reportId) { ChunkServerIdType candidate = LeaderGenCopysetConf(reportCopySetInfo, configChInfo, copysetConf); diff --git a/tools-v2/pkg/cli/command/curvebs/delete/copyset/copyset.go b/tools-v2/pkg/cli/command/curvebs/delete/copyset/copyset.go new file mode 100644 index 0000000000..70c06cc2b6 --- /dev/null +++ b/tools-v2/pkg/cli/command/curvebs/delete/copyset/copyset.go @@ -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) +} diff --git a/tools-v2/pkg/cli/command/curvebs/delete/delete.go b/tools-v2/pkg/cli/command/curvebs/delete/delete.go index fe57b58ef0..83c2b1e57a 100644 --- a/tools-v2/pkg/cli/command/curvebs/delete/delete.go +++ b/tools-v2/pkg/cli/command/curvebs/delete/delete.go @@ -7,6 +7,7 @@ package delete import ( + "github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/delete/copyset" "github.com/spf13/cobra" basecmd "github.com/opencurve/curve/tools-v2/pkg/cli/command" @@ -26,6 +27,7 @@ func (dCmd *DeleteCommand) AddSubCommands() { file.NewFileCommand(), peer.NewCommand(), volume.NewVolumeCommand(), + copyset.NewDeleteCommand(), ) } diff --git a/tools-v2/pkg/cli/command/curvebs/list/list.go b/tools-v2/pkg/cli/command/curvebs/list/list.go index 44472a01a9..61d269b790 100644 --- a/tools-v2/pkg/cli/command/curvebs/list/list.go +++ b/tools-v2/pkg/cli/command/curvebs/list/list.go @@ -34,6 +34,7 @@ import ( "github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/list/server" "github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/list/snapshot" "github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/list/space" + "github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/list/unavailcopysets" "github.com/spf13/cobra" ) @@ -55,6 +56,7 @@ func (listCmd *ListCommand) AddSubCommands() { may_broken_vol.NewMayBrokenVolCommand(), formatstatus.NewFormatStatusCommand(), snapshot.NewSnapShotCommand(), + unavailcopysets.NewUnAvailCopySetsCommand(), ) } diff --git a/tools-v2/pkg/cli/command/curvebs/list/unavailcopysets/unavailcopysets.go b/tools-v2/pkg/cli/command/curvebs/list/unavailcopysets/unavailcopysets.go index f9e9f5a103..ffa50c4c36 100644 --- a/tools-v2/pkg/cli/command/curvebs/list/unavailcopysets/unavailcopysets.go +++ b/tools-v2/pkg/cli/command/curvebs/list/unavailcopysets/unavailcopysets.go @@ -24,6 +24,8 @@ package unavailcopysets import ( "context" + "fmt" + cobrautil "github.com/opencurve/curve/tools-v2/internal/utils" cmderror "github.com/opencurve/curve/tools-v2/internal/error" basecmd "github.com/opencurve/curve/tools-v2/pkg/cli/command" @@ -36,6 +38,10 @@ import ( "google.golang.org/grpc" ) +const ( + listUnAvailCopySetExample = `$ curve bs list unavail-copyset` +) + type ListUnAvailCopySets struct { Info *basecmd.Rpc Request *topology.ListUnAvailCopySetsRequest @@ -66,7 +72,11 @@ func NewUnAvailCopySetsCommand() *cobra.Command { func NewListUnAvailCopySetsCommand() *UnAvailCopySetsCommand { uCmd := &UnAvailCopySetsCommand{ - FinalCurveCmd: basecmd.FinalCurveCmd{}, + FinalCurveCmd: basecmd.FinalCurveCmd{ + Use: "unavail-copyset", + Short: "list unavail copyset", + Example: listUnAvailCopySetExample, + }, } basecmd.NewFinalCurveCli(&uCmd.FinalCurveCmd, uCmd) @@ -90,6 +100,8 @@ func (uCmd *UnAvailCopySetsCommand) Init(cmd *cobra.Command, args []string) erro Request: &topology.ListUnAvailCopySetsRequest{}, Info: basecmd.NewRpc(mdsAddrs, timeout, retrytimes, "ListUnAvailCopySets"), } + header := []string{cobrautil.ROW_LOGICALPOOL, cobrautil.ROW_COPYSET} + uCmd.SetHeader(header) return nil } @@ -109,6 +121,18 @@ func (uCmd *UnAvailCopySetsCommand) RunCommand(cmd *cobra.Command, args []string return cmderror.ErrBsListPhysicalPoolRpc(code).ToError() } uCmd.response = response.Copysets + uCmd.Result = response.Copysets + rows := make([]map[string]string, 0) + for _, info := range response.Copysets { + row := make(map[string]string) + row[cobrautil.ROW_LOGICALPOOL] = fmt.Sprintf("%d", info.GetLogicalPoolId()) + row[cobrautil.ROW_COPYSET] = fmt.Sprintf("%d", info.GetCopysetId()) + rows = append(rows, row) + } + list := cobrautil.ListMap2ListSortByKeys(rows, uCmd.Header, []string{ + cobrautil.ROW_LOGICALPOOL, cobrautil.ROW_COPYSET, + }) + uCmd.TableNew.AppendBulk(list) return nil }