Skip to content

Commit 1041ceb

Browse files
author
liuminjian
committed
add delete broken copyset in chunkserver cli
Signed-off-by: liuminjian <[email protected]>
1 parent 01e9dc4 commit 1041ceb

File tree

7 files changed

+139
-9
lines changed

7 files changed

+139
-9
lines changed

proto/heartbeat.proto

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ message CopySetConf {
150150
// 表示待删除节点。
151151
// chunkserver收到CHANGE_PEER,根据peers,configchangeItem,oldPeer拼出新的conf
152152
optional common.Peer oldPeer = 7;
153-
// copyset availflag
154-
optional bool availflag = 8;
155153
};
156154

157155
enum HeartbeatStatusCode {

src/chunkserver/heartbeat.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,14 @@ int Heartbeat::BuildRequest(HeartbeatRequest* req) {
307307
int leaders = 0;
308308

309309
for (CopysetNodePtr copyset : copysets) {
310+
311+
// 如果磁盘空间不足设为readonly
312+
if (diskState->errtype() == curve::mds::heartbeat::DISKFULL) {
313+
copyset->SetReadOnly(true);
314+
}else {
315+
copyset->SetReadOnly(false);
316+
}
317+
310318
curve::mds::heartbeat::CopySetInfo* info = req->add_copysetinfos();
311319

312320
ret = BuildCopysetInfo(info, copyset);
@@ -439,9 +447,6 @@ int Heartbeat::ExecTask(const HeartbeatResponse& response) {
439447
continue;
440448
}
441449

442-
// 判断copyset是否avail,否则设置readonly
443-
copyset->SetReadOnly(!conf.availflag());
444-
445450
// 解析该chunkserver上的copyset是否需要删除
446451
// 需要删除则清理copyset
447452
if (HeartbeatHelper::NeedPurge(csEp_, conf, copyset)) {

src/mds/heartbeat/copyset_conf_generator.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ bool CopysetConfGenerator::GenCopysetConf(
5252
return true;
5353
}
5454

55-
// set copyset availflag
56-
copysetConf->set_availflag(recordCopySetInfo.IsAvailable());
57-
5855
if (reportCopySetInfo.GetLeader() == reportId) {
5956
ChunkServerIdType candidate =
6057
LeaderGenCopysetConf(reportCopySetInfo, configChInfo, copysetConf);
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package copyset
2+
3+
import (
4+
"context"
5+
cmderror "github.com/opencurve/curve/tools-v2/internal/error"
6+
basecmd "github.com/opencurve/curve/tools-v2/pkg/cli/command"
7+
"github.com/opencurve/curve/tools-v2/pkg/config"
8+
"github.com/opencurve/curve/tools-v2/pkg/output"
9+
"github.com/opencurve/curve/tools-v2/proto/proto/topology"
10+
"github.com/spf13/cobra"
11+
"google.golang.org/grpc"
12+
"strconv"
13+
)
14+
15+
const (
16+
deleteBrokenCopySetExample = `$ curve bs delete broken-copyset --chunkserverid=1`
17+
)
18+
19+
type DeleteBrokenCopySetInChunkServerRpc struct {
20+
Info *basecmd.Rpc
21+
Request *topology.DeleteBrokenCopysetInChunkServerRequest
22+
topologyClient topology.TopologyServiceClient
23+
}
24+
25+
var _ basecmd.RpcFunc = (*DeleteBrokenCopySetInChunkServerRpc)(nil) // check interface
26+
27+
type DeleteBrokenCopySetCommand struct {
28+
basecmd.FinalCurveCmd
29+
Rpc *DeleteBrokenCopySetInChunkServerRpc
30+
Servers []*topology.ServerInfo
31+
chunkserverid uint32
32+
}
33+
34+
func (d *DeleteBrokenCopySetInChunkServerRpc) Stub_Func(ctx context.Context) (interface{}, error) {
35+
return d.topologyClient.DeleteBrokenCopysetInChunkServer(ctx, d.Request)
36+
}
37+
38+
func NewDeleteCommand() *cobra.Command {
39+
return NewDeleteBrokenCopySetCommand().Cmd
40+
}
41+
42+
func NewDeleteBrokenCopySetCommand() *DeleteBrokenCopySetCommand {
43+
cmd := &DeleteBrokenCopySetCommand{
44+
FinalCurveCmd: basecmd.FinalCurveCmd{
45+
Use: "broken-copyset",
46+
Short: "delete broken copyset in chunkserver",
47+
Example: deleteBrokenCopySetExample,
48+
},
49+
}
50+
51+
basecmd.NewFinalCurveCli(&cmd.FinalCurveCmd, cmd)
52+
return cmd
53+
}
54+
55+
func (d *DeleteBrokenCopySetCommand) AddFlags() {
56+
config.AddBsMdsFlagOption(d.Cmd)
57+
config.AddRpcRetryTimesFlag(d.Cmd)
58+
config.AddRpcTimeoutFlag(d.Cmd)
59+
config.AddBsChunkServerIdFlag(d.Cmd)
60+
}
61+
62+
func (d *DeleteBrokenCopySetInChunkServerRpc) NewRpcClient(cc grpc.ClientConnInterface) {
63+
d.topologyClient = topology.NewTopologyServiceClient(cc)
64+
}
65+
66+
func (d *DeleteBrokenCopySetCommand) Init(cmd *cobra.Command, args []string) error {
67+
mdsAddrs, err := config.GetBsMdsAddrSlice(d.Cmd)
68+
if err.TypeCode() != cmderror.CODE_SUCCESS {
69+
return err.ToError()
70+
}
71+
timeout := config.GetFlagDuration(d.Cmd, config.RPCTIMEOUT)
72+
retrytimes := config.GetFlagInt32(d.Cmd, config.RPCRETRYTIMES)
73+
strid, e := strconv.Atoi(config.GetBsFlagString(d.Cmd, config.CURVEBS_CHUNKSERVER_ID))
74+
if e != nil {
75+
return e
76+
}
77+
d.chunkserverid = uint32(strid)
78+
d.Rpc = &DeleteBrokenCopySetInChunkServerRpc{
79+
Info: basecmd.NewRpc(mdsAddrs, timeout, retrytimes, "DeleteBrokenCopysetInChunkServer"),
80+
Request: &topology.DeleteBrokenCopysetInChunkServerRequest{
81+
ChunkServerID: &d.chunkserverid,
82+
},
83+
}
84+
return nil
85+
}
86+
87+
func (d *DeleteBrokenCopySetCommand) RunCommand(cmd *cobra.Command, args []string) error {
88+
result, errCmd := basecmd.GetRpcResponse(d.Rpc.Info, d.Rpc)
89+
if errCmd.TypeCode() != cmderror.CODE_SUCCESS {
90+
return errCmd.ToError()
91+
}
92+
d.Result = result
93+
return nil
94+
}
95+
96+
func (d *DeleteBrokenCopySetCommand) Print(cmd *cobra.Command, args []string) error {
97+
return output.FinalCmdOutput(&d.FinalCurveCmd, d)
98+
}
99+
100+
func (d *DeleteBrokenCopySetCommand) ResultPlainOutput() error {
101+
return output.FinalCmdOutputPlain(&d.FinalCurveCmd)
102+
}

tools-v2/pkg/cli/command/curvebs/delete/delete.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package delete
88

99
import (
10+
"github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/delete/copyset"
1011
"github.com/spf13/cobra"
1112

1213
basecmd "github.com/opencurve/curve/tools-v2/pkg/cli/command"
@@ -26,6 +27,7 @@ func (dCmd *DeleteCommand) AddSubCommands() {
2627
file.NewFileCommand(),
2728
peer.NewCommand(),
2829
volume.NewVolumeCommand(),
30+
copyset.NewDeleteCommand(),
2931
)
3032
}
3133

tools-v2/pkg/cli/command/curvebs/list/list.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/list/server"
3535
"github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/list/snapshot"
3636
"github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/list/space"
37+
"github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/list/unavailcopysets"
3738
"github.com/spf13/cobra"
3839
)
3940

@@ -55,6 +56,7 @@ func (listCmd *ListCommand) AddSubCommands() {
5556
may_broken_vol.NewMayBrokenVolCommand(),
5657
formatstatus.NewFormatStatusCommand(),
5758
snapshot.NewSnapShotCommand(),
59+
unavailcopysets.NewUnAvailCopySetsCommand(),
5860
)
5961
}
6062

tools-v2/pkg/cli/command/curvebs/list/unavailcopysets/unavailcopysets.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ package unavailcopysets
2424

2525
import (
2626
"context"
27+
"fmt"
28+
cobrautil "github.com/opencurve/curve/tools-v2/internal/utils"
2729

2830
cmderror "github.com/opencurve/curve/tools-v2/internal/error"
2931
basecmd "github.com/opencurve/curve/tools-v2/pkg/cli/command"
@@ -36,6 +38,10 @@ import (
3638
"google.golang.org/grpc"
3739
)
3840

41+
const (
42+
listUnAvailCopySetExample = `$ curve bs list unavail-copyset`
43+
)
44+
3945
type ListUnAvailCopySets struct {
4046
Info *basecmd.Rpc
4147
Request *topology.ListUnAvailCopySetsRequest
@@ -66,7 +72,11 @@ func NewUnAvailCopySetsCommand() *cobra.Command {
6672

6773
func NewListUnAvailCopySetsCommand() *UnAvailCopySetsCommand {
6874
uCmd := &UnAvailCopySetsCommand{
69-
FinalCurveCmd: basecmd.FinalCurveCmd{},
75+
FinalCurveCmd: basecmd.FinalCurveCmd{
76+
Use: "unavail-copyset",
77+
Short: "list unavail copyset",
78+
Example: listUnAvailCopySetExample,
79+
},
7080
}
7181

7282
basecmd.NewFinalCurveCli(&uCmd.FinalCurveCmd, uCmd)
@@ -90,6 +100,8 @@ func (uCmd *UnAvailCopySetsCommand) Init(cmd *cobra.Command, args []string) erro
90100
Request: &topology.ListUnAvailCopySetsRequest{},
91101
Info: basecmd.NewRpc(mdsAddrs, timeout, retrytimes, "ListUnAvailCopySets"),
92102
}
103+
header := []string{cobrautil.ROW_LOGICALPOOL, cobrautil.ROW_COPYSET}
104+
uCmd.SetHeader(header)
93105
return nil
94106
}
95107

@@ -109,6 +121,18 @@ func (uCmd *UnAvailCopySetsCommand) RunCommand(cmd *cobra.Command, args []string
109121
return cmderror.ErrBsListPhysicalPoolRpc(code).ToError()
110122
}
111123
uCmd.response = response.Copysets
124+
uCmd.Result = response.Copysets
125+
rows := make([]map[string]string, 0)
126+
for _, info := range response.Copysets {
127+
row := make(map[string]string)
128+
row[cobrautil.ROW_LOGICALPOOL] = fmt.Sprintf("%d", info.GetLogicalPoolId())
129+
row[cobrautil.ROW_COPYSET] = fmt.Sprintf("%d", info.GetCopysetId())
130+
rows = append(rows, row)
131+
}
132+
list := cobrautil.ListMap2ListSortByKeys(rows, uCmd.Header, []string{
133+
cobrautil.ROW_LOGICALPOOL, cobrautil.ROW_COPYSET,
134+
})
135+
uCmd.TableNew.AppendBulk(list)
112136
return nil
113137
}
114138

0 commit comments

Comments
 (0)