diff --git a/README.md b/README.md index 0296f61b3c..5424c71cb4 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ **A cloud-native distributed storage system** +**A sandbox project hosted by the CNCF Foundation** + #### English | [简体中文](README_cn.md) ### 📄 [Documents](https://github.com/opencurve/curve/tree/master/docs) || 🌐 [Official Website](https://www.opencurve.io/Curve/HOME) || 🏠 [Forum](https://ask.opencurve.io/t/topic/7)
diff --git a/README_cn.md b/README_cn.md index b9aa22b211..8e44ca38df 100644 --- a/README_cn.md +++ b/README_cn.md @@ -4,7 +4,9 @@
-**A cloud-native distributed storage system** +**云原生高性能分布式存储系统** + +**CNCF基金会的沙箱托管项目** #### [English](README.md) | 简体中文 ### 📄 [文档](https://github.com/opencurve/curve/tree/master/docs) || 🌐 [官网](https://www.opencurve.io/Curve/HOME) || 🏠 [论坛](https://ask.opencurve.io/t/topic/7) diff --git a/tools-v2/README.md b/tools-v2/README.md index 89085428a6..37ed791043 100644 --- a/tools-v2/README.md +++ b/tools-v2/README.md @@ -71,6 +71,9 @@ A tool for CurveFS & CurveBs. - [create dir](#create-dir) - [check](#check-1) - [check copyset](#check-copyset-1) + - [snapshot](#snapshot) + - [snapshot copyset](#snapshot-copyset) + - [clean-recycle](#clean-recycle) - [Comparison of old and new commands](#comparison-of-old-and-new-commands) - [curve fs](#curve-fs) - [curve bs](#curve-bs) @@ -1288,6 +1291,26 @@ Output: +------------+-----------+--------+--------+--------+---------+ ``` +### snapshot + +#### snapshot copyset + +take snapshot for copyset + +Usage: +```bash +curve bs snapshot copyset 127.0.0.0:8200:0 --logicalpoolid=1 --copysetid=1 +``` + +Output: +``` ++-----------------------+---------+---------+ +| PEER | COPYSET | RESULT | ++-----------------------+---------+---------+ +| ***.***.**.***:****:* | (**:**) | success | ++-----------------------+---------+---------+ +``` + ## Comparison of old and new commands ### curve fs @@ -1318,7 +1341,6 @@ Output: ### curve bs -<<<<<<< HEAD | old | new | | ------------------------------------ | ------------------------------ | | curve_ops_tool logical-pool-list | curve bs list logical-pool | @@ -1340,7 +1362,8 @@ Output: | curve_ops_tool client-status | curve bs status client | | curve_ops_tool check-operator | curve bs check operator | | curve_ops_tool snapshot-clone-status | curve bs status snapshotserver | -| transfer-leader | curve bs update leader | +| curve_ops_tool transfer-leader | curve bs update leader | +| curve_ops_tool do-snapshot | curve bs snapshot copyset | | curve_ops_tool set-scan-state | curve bs update scan-state | | curve_ops_tool status | | | curve_ops_tool chunkserver-status | | @@ -1348,7 +1371,6 @@ Output: | curve_ops_tool chunkserver-list | | | curve_ops_tool clean-recycle | | | curve_ops_tool check-consistency | | -| curve_ops_tool do-snapshot | | | curve_ops_tool do-snapshot-all | | | curve_ops_tool check-chunkserver | | | curve_ops_tool check-server | | diff --git a/tools-v2/pkg/cli/command/curvebs/bs.go b/tools-v2/pkg/cli/command/curvebs/bs.go index 38ff6fcf29..3fa7fa86c6 100644 --- a/tools-v2/pkg/cli/command/curvebs/bs.go +++ b/tools-v2/pkg/cli/command/curvebs/bs.go @@ -32,6 +32,7 @@ import ( "github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/delete" "github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/list" "github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/query" + "github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/snapshot" "github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/status" "github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/update" ) @@ -52,6 +53,7 @@ func (bsCmd *CurveBsCommand) AddSubCommands() { update.NewUpdateCommand(), clean_recycle.NewCleanRecycleCommand(), check.NewCheckCommand(), + snapshot.NewSnapshotCommand(), ) } diff --git a/tools-v2/pkg/cli/command/curvebs/snapshot/copyset/copyset.go b/tools-v2/pkg/cli/command/curvebs/snapshot/copyset/copyset.go new file mode 100644 index 0000000000..1fc0eed014 --- /dev/null +++ b/tools-v2/pkg/cli/command/curvebs/snapshot/copyset/copyset.go @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2023 NetEase Inc. + * + * 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. + */ + +/* + * Project: CurveCli + * Created Date: 2023-04-28 + * Author: Xinlong-Chen + */ + +package copyset + +import ( + "context" + "fmt" + + "github.com/spf13/cobra" + "google.golang.org/grpc" + + cmderror "github.com/opencurve/curve/tools-v2/internal/error" + cobrautil "github.com/opencurve/curve/tools-v2/internal/utils" + basecmd "github.com/opencurve/curve/tools-v2/pkg/cli/command" + "github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/delete/peer" + "github.com/opencurve/curve/tools-v2/pkg/config" + "github.com/opencurve/curve/tools-v2/pkg/output" + "github.com/opencurve/curve/tools-v2/proto/proto/cli2" +) + +const ( + updateExample = `$ curve bs snapshot copyset 127.0.0.0:8200:0 --logicalpoolid=1 --copysetid=1` +) + +type SnapshotRpc struct { + Info *basecmd.Rpc + Request *cli2.SnapshotRequest2 + Client cli2.CliService2Client +} + +func (sRpc *SnapshotRpc) NewRpcClient(cc grpc.ClientConnInterface) { + sRpc.Client = cli2.NewCliService2Client(cc) +} + +func (sRpc *SnapshotRpc) Stub_Func(ctx context.Context) (interface{}, error) { + return sRpc.Client.Snapshot(ctx, sRpc.Request) +} + +type SnapshotOneCommand struct { + basecmd.FinalCurveCmd + + Rpc *SnapshotRpc + Response *cli2.SnapshotResponse2 + row map[string]string +} + +var _ basecmd.FinalCurveCmdFunc = (*SnapshotOneCommand)(nil) // check interface + +// NewCommand ... +func NewSnapshotOneCommand() *cobra.Command { + peerCmd := &SnapshotOneCommand{ + FinalCurveCmd: basecmd.FinalCurveCmd{ + Use: "copyset", + Short: "take snapshot for copyset", + Example: updateExample, + }, + } + basecmd.NewFinalCurveCli(&peerCmd.FinalCurveCmd, peerCmd) + return peerCmd.Cmd +} + +func (sCmd *SnapshotOneCommand) AddFlags() { + config.AddRpcRetryTimesFlag(sCmd.Cmd) + config.AddRpcTimeoutFlag(sCmd.Cmd) + + config.AddBSLogicalPoolIdRequiredFlag(sCmd.Cmd) + config.AddBSCopysetIdRequiredFlag(sCmd.Cmd) +} + +func (sCmd *SnapshotOneCommand) Init(cmd *cobra.Command, args []string) error { + sCmd.SetHeader([]string{cobrautil.ROW_PEER, cobrautil.ROW_COPYSET, cobrautil.ROW_RESULT}) + sCmd.TableNew.SetAutoMergeCellsByColumnIndex(cobrautil.GetIndexSlice( + sCmd.Header, []string{}, + )) + + timeout := config.GetFlagDuration(sCmd.Cmd, config.RPCTIMEOUT) + retryTimes := config.GetFlagInt32(sCmd.Cmd, config.RPCRETRYTIMES) + + copysetID := config.GetBsFlagUint32(sCmd.Cmd, config.CURVEBS_COPYSET_ID) + + logicalPoolID := config.GetBsFlagUint32(sCmd.Cmd, config.CURVEBS_LOGIC_POOL_ID) + + // parse peer conf + if len(args) < 1 { + pErr := cmderror.ErrGetPeer() + pErr.Format("should specified the peer address") + return pErr.ToError() + } + snapshotPeer, err := peer.ParsePeer(args[0]) + if err != nil { + return err.ToError() + } + + out := make(map[string]string) + out[cobrautil.ROW_PEER] = fmt.Sprintf("%s:%d", snapshotPeer.GetAddress(), snapshotPeer.GetId()) + out[cobrautil.ROW_COPYSET] = fmt.Sprintf("(%d:%d)", logicalPoolID, copysetID) + sCmd.row = out + + sCmd.Rpc = &SnapshotRpc{ + Info: basecmd.NewRpc([]string{snapshotPeer.GetAddress()}, timeout, retryTimes, "Snapshot"), + Request: &cli2.SnapshotRequest2{ + LogicPoolId: &logicalPoolID, + CopysetId: ©setID, + Peer: snapshotPeer, + }, + } + + return nil +} + +func (sCmd *SnapshotOneCommand) Print(cmd *cobra.Command, args []string) error { + return output.FinalCmdOutput(&sCmd.FinalCurveCmd, sCmd) +} + +func (sCmd *SnapshotOneCommand) RunCommand(cmd *cobra.Command, args []string) error { + response, err := basecmd.GetRpcResponse(sCmd.Rpc.Info, sCmd.Rpc) + sCmd.Error = err + if err.TypeCode() != cmderror.CODE_SUCCESS { + return err.ToError() + } + + sCmd.row[cobrautil.ROW_RESULT] = "success" + sCmd.Response = response.(*cli2.SnapshotResponse2) + + list := cobrautil.Map2List(sCmd.row, sCmd.Header) + sCmd.TableNew.Append(list) + return nil +} + +func (sCmd *SnapshotOneCommand) ResultPlainOutput() error { + return output.FinalCmdOutputPlain(&sCmd.FinalCurveCmd) +} diff --git a/tools-v2/pkg/cli/command/curvebs/snapshot/snapshot.go b/tools-v2/pkg/cli/command/curvebs/snapshot/snapshot.go new file mode 100644 index 0000000000..5d240432b4 --- /dev/null +++ b/tools-v2/pkg/cli/command/curvebs/snapshot/snapshot.go @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023 NetEase Inc. + * + * 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. + */ + +/* + * Project: CurveCli + * Created Date: 2023-04-28 + * Author: Xinlong-Chen + */ + +package snapshot + +import ( + basecmd "github.com/opencurve/curve/tools-v2/pkg/cli/command" + "github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/snapshot/copyset" + "github.com/spf13/cobra" +) + +type SnapshotCommand struct { + basecmd.MidCurveCmd +} + +var _ basecmd.MidCurveCmdFunc = (*SnapshotCommand)(nil) // check interface + +func (statusCmd *SnapshotCommand) AddSubCommands() { + statusCmd.Cmd.AddCommand( + copyset.NewSnapshotOneCommand(), + ) +} + +func NewSnapshotCommand() *cobra.Command { + statusCmd := &SnapshotCommand{ + basecmd.MidCurveCmd{ + Use: "snapshot", + Short: "take snapshot for curvebs resource", + }, + } + return basecmd.NewMidCurveCli(&statusCmd.MidCurveCmd, statusCmd) +}