Skip to content

Commit

Permalink
add delete broken copyset in chunkserver cli
Browse files Browse the repository at this point in the history
Signed-off-by: liuminjian <liuminjian@chinatelecom.cn>
  • Loading branch information
liuminjian committed Nov 10, 2023
1 parent 01e9dc4 commit 1041ceb
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 9 deletions.
2 changes: 0 additions & 2 deletions proto/heartbeat.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 8 additions & 3 deletions src/chunkserver/heartbeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
Expand Down
3 changes: 0 additions & 3 deletions src/mds/heartbeat/copyset_conf_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
102 changes: 102 additions & 0 deletions tools-v2/pkg/cli/command/curvebs/delete/copyset/copyset.go
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)
}
2 changes: 2 additions & 0 deletions tools-v2/pkg/cli/command/curvebs/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -26,6 +27,7 @@ func (dCmd *DeleteCommand) AddSubCommands() {
file.NewFileCommand(),
peer.NewCommand(),
volume.NewVolumeCommand(),
copyset.NewDeleteCommand(),
)
}

Expand Down
2 changes: 2 additions & 0 deletions tools-v2/pkg/cli/command/curvebs/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -55,6 +56,7 @@ func (listCmd *ListCommand) AddSubCommands() {
may_broken_vol.NewMayBrokenVolCommand(),
formatstatus.NewFormatStatusCommand(),
snapshot.NewSnapShotCommand(),
unavailcopysets.NewUnAvailCopySetsCommand(),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
}

Expand All @@ -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
}

Expand Down

0 comments on commit 1041ceb

Please sign in to comment.