/
shard.go
86 lines (80 loc) · 2.42 KB
/
shard.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2022 The CubeFS Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
package blobnode
import (
"github.com/cubefs/cubefs/blobstore/api/blobnode"
"github.com/cubefs/cubefs/blobstore/cli/common"
"github.com/cubefs/cubefs/blobstore/cli/common/fmt"
"github.com/cubefs/cubefs/blobstore/common/proto"
"github.com/desertbit/grumble"
)
func addCmdShard(cmd *grumble.Command) {
chunkCommand := &grumble.Command{
Name: "shard",
Help: "shard tools",
LongHelp: "shard tools for blobnode",
}
cmd.AddCommand(chunkCommand)
chunkCommand.AddCommand(&grumble.Command{
Name: "stat",
Help: "shard stat",
Flags: func(f *grumble.Flags) {
blobnodeFlags(f)
f.UintL("diskid", 1, "disk id")
f.UintL("vuid", 1, "vuid")
f.UintL("bid", 1, "bid")
},
Run: func(c *grumble.Context) error {
cli := blobnode.New(&blobnode.Config{})
host := c.Flags.String("host")
args := blobnode.StatShardArgs{
DiskID: proto.DiskID(c.Flags.Uint("diskid")),
Vuid: proto.Vuid(c.Flags.Uint("vuid")),
Bid: proto.BlobID(c.Flags.Uint("bid")),
}
stat, err := cli.StatShard(common.CmdContext(), host, &args)
if err != nil {
return err
}
fmt.Println(common.Readable(stat))
return nil
},
})
chunkCommand.AddCommand(&grumble.Command{
Name: "get",
Help: "get shard",
Flags: func(f *grumble.Flags) {
blobnodeFlags(f)
f.UintL("diskid", 1, "disk id")
f.UintL("vuid", 1, "vuid")
f.UintL("bid", 1, "bid")
},
Run: func(c *grumble.Context) error {
cli := blobnode.New(&blobnode.Config{})
host := c.Flags.String("host")
args := blobnode.GetShardArgs{
DiskID: proto.DiskID(c.Flags.Uint("diskid")),
Vuid: proto.Vuid(c.Flags.Uint("vuid")),
Bid: proto.BlobID(c.Flags.Uint("bid")),
Type: blobnode.IOType(0),
}
body, _, err := cli.GetShard(common.CmdContext(), host, &args)
if err != nil {
return err
}
fmt.Println(body)
return nil
},
})
}