diff --git a/tools-v2/README.md b/tools-v2/README.md index 51c18a6684..83ee62cd27 100644 --- a/tools-v2/README.md +++ b/tools-v2/README.md @@ -54,9 +54,10 @@ A tool for CurveFS & CurveBs. - [query chunk](#query-chunk) - [query segment](#query-segment) - [status](#status-1) - - [staus etcd](#staus-etcd) - - [staus mds](#staus-mds) + - [status etcd](#status-etcd-1) + - [status mds](#status-mds-1) - [status client](#status-client) + - [status snapshotserver](#status-snapshotserver) - [delete](#delete-1) - [delete peer](#delete-peer) - [update](#update) @@ -1011,7 +1012,7 @@ Output: ### status -#### staus etcd +#### status etcd get the etcd status of curvebs @@ -1035,7 +1036,7 @@ Output: +---------------------+---------+----------+ ``` -#### staus mds +#### status mds get the mds status of curvebs @@ -1059,6 +1060,7 @@ Output: +-------------------+-------------------+-------------------+----------+ ``` + #### status client get the client status of curvebs @@ -1081,6 +1083,31 @@ Output: +-------------+----------------+---------------------+-----+ ``` +#### status snapshotserver + +get the mds status of curvebs + +Usage: + +```bash +curve bs status snapshotserver +``` + +Output: + +```bash ++---------------------+---------------------+-------------------+----------+ +| ADDR | DUMMYADDR | VERSION | STATUS | ++---------------------+---------------------+-------------------+----------+ +| ***.***.**.***:**** | ***.***.**.***:**** | ci+562296c7+debug | follower | ++---------------------+---------------------+ + + +| ***.***.**.***:**** | ***.***.**.***:**** | | | ++---------------------+---------------------+ +----------+ +| ***.***.**.***:**** | ***.***.**.***:**** | | leader | ++---------------------+---------------------+-------------------+----------+ +``` + + ### delete #### delete peer @@ -1273,6 +1300,8 @@ Output: | status | | | chunkserver-status | | | snapshot-clone-status | | +| client-status | curve bs status client | +| snapshot-clone-status | curve bs status snapshotserver | | copysets-status | | | chunkserver-list | | | cluster-status | | diff --git a/tools-v2/docs/zh/develop.md b/tools-v2/docs/zh/develop.md index e030712a8e..e2e42f7d2a 100644 --- a/tools-v2/docs/zh/develop.md +++ b/tools-v2/docs/zh/develop.md @@ -386,7 +386,7 @@ docker cp ./sbin/curve de7603f17cf9:/ 4. 准备配置文件,将之拷贝进 playground 容器内: ```shell -docker cp ./pkg/config/template.yaml de7603f17cf9:/etc/curve/curve.yaml +docker cp ./pkg/config/curve.yaml de7603f17cf9:/etc/curve/curve.yaml ``` 5. 进入对应的容器: @@ -558,10 +558,10 @@ curveadm status make ``` -3. 准备配置文件,将项目目录下的 `tools-v2/pkg/config/template.yaml` 复制到 `$(HOME)/.curve/curve.yaml`: +3. 准备配置文件,将项目目录下的 `tools-v2/pkg/config/curve.yaml` 复制到 `$(HOME)/.curve/curve.yaml`: ```shell -cp ./pkg/config/template.yaml ~/.curve/curve.yaml +cp ./pkg/config/curve.yaml ~/.curve/curve.yaml ``` 4. 在项目目录(`curve/tools-v2`) 下执行命令/调试: diff --git a/tools-v2/pkg/cli/command/curvebs/status/etcd/etcd.go b/tools-v2/pkg/cli/command/curvebs/status/etcd/etcd.go index b9d70ed03c..c3c5aa7e90 100644 --- a/tools-v2/pkg/cli/command/curvebs/status/etcd/etcd.go +++ b/tools-v2/pkg/cli/command/curvebs/status/etcd/etcd.go @@ -68,12 +68,13 @@ func NewEtcdCommand() *cobra.Command { } func (eCmd *EtcdCommand) AddFlags() { - config.AddBsEtcdAddrFlag(eCmd.Cmd) config.AddHttpTimeoutFlag(eCmd.Cmd) + config.AddBsEtcdAddrFlag(eCmd.Cmd) } func (eCmd *EtcdCommand) Init(cmd *cobra.Command, args []string) error { eCmd.health = cobrautil.HEALTH_ERROR + header := []string{cobrautil.ROW_ADDR, cobrautil.ROW_VERSION, cobrautil.ROW_STATUS} eCmd.SetHeader(header) eCmd.TableNew.SetAutoMergeCellsByColumnIndex(cobrautil.GetIndexSlice( @@ -85,6 +86,7 @@ func (eCmd *EtcdCommand) Init(cmd *cobra.Command, args []string) error { if addrErr.TypeCode() != cmderror.CODE_SUCCESS { return fmt.Errorf(addrErr.Message) } + for _, addr := range etcdAddrs { // set metric timeout := viper.GetDuration(config.VIPER_GLOBALE_HTTPTIMEOUT) @@ -117,6 +119,7 @@ func (eCmd *EtcdCommand) RunCommand(cmd *cobra.Command, args []string) error { size++ go func(m *basecmd.Metric) { result, err := basecmd.QueryMetric(m) + var key string var metricKey string if m.SubUri == STATUS_SUBURI { @@ -126,6 +129,7 @@ func (eCmd *EtcdCommand) RunCommand(cmd *cobra.Command, args []string) error { key = "version" metricKey = VARSION_METRIC_KEY } + var value string if err.TypeCode() == cmderror.CODE_SUCCESS { value, err = basecmd.GetKeyValueFromJsonMetric(result, metricKey) @@ -133,6 +137,7 @@ func (eCmd *EtcdCommand) RunCommand(cmd *cobra.Command, args []string) error { errs = append(errs, err) } } + results <- basecmd.MetricResult{ Addr: m.Addrs[0], Key: key, @@ -166,8 +171,6 @@ func (eCmd *EtcdCommand) RunCommand(cmd *cobra.Command, args []string) error { break } } - mergeErr := cmderror.MergeCmdErrorExceptSuccess(errs) - eCmd.Error = mergeErr if len(errs) > 0 && len(errs) < len(eCmd.rows) { eCmd.health = cobrautil.HEALTH_WARN @@ -175,12 +178,14 @@ func (eCmd *EtcdCommand) RunCommand(cmd *cobra.Command, args []string) error { eCmd.health = cobrautil.HEALTH_OK } + mergeErr := cmderror.MergeCmdErrorExceptSuccess(errs) + eCmd.Error = mergeErr list := cobrautil.ListMap2ListSortByKeys(eCmd.rows, eCmd.Header, []string{ cobrautil.ROW_STATUS, cobrautil.ROW_VERSION, }) eCmd.TableNew.AppendBulk(list) - eCmd.Result = eCmd.rows + return nil } @@ -206,7 +211,7 @@ func GetEtcdStatus(caller *cobra.Command) (*interface{}, *tablewriter.Table, *cm fmt.Sprintf("--%s", config.FORMAT), config.FORMAT_NOOUT, }) config.AlignFlagsValue(caller, etcdCmd.Cmd, []string{ - config.RPCRETRYTIMES, config.RPCTIMEOUT, config.CURVEFS_MDSADDR, + config.RPCRETRYTIMES, config.RPCTIMEOUT, config.CURVEFS_ETCDADDR, }) etcdCmd.Cmd.SilenceErrors = true etcdCmd.Cmd.Execute() diff --git a/tools-v2/pkg/cli/command/curvebs/status/mds/mds.go b/tools-v2/pkg/cli/command/curvebs/status/mds/mds.go index 06ad73afa6..a50c4407d7 100644 --- a/tools-v2/pkg/cli/command/curvebs/status/mds/mds.go +++ b/tools-v2/pkg/cli/command/curvebs/status/mds/mds.go @@ -59,8 +59,8 @@ func NewMdsCommand() *cobra.Command { } func (mCmd *MdsCommand) AddFlags() { - config.AddBsMdsFlagOption(mCmd.Cmd) config.AddHttpTimeoutFlag(mCmd.Cmd) + config.AddBsMdsFlagOption(mCmd.Cmd) config.AddBsMdsDummyFlagOption(mCmd.Cmd) } @@ -84,6 +84,7 @@ func (mCmd *MdsCommand) Init(cmd *cobra.Command, args []string) error { if addrErr.TypeCode() != cmderror.CODE_SUCCESS { return fmt.Errorf(addrErr.Message) } + for _, addr := range dummyAddrs { // Use the dummy port to access the metric service timeout := viper.GetDuration(config.VIPER_GLOBALE_HTTPTIMEOUT) @@ -118,16 +119,20 @@ func (mCmd *MdsCommand) RunCommand(cmd *cobra.Command, args []string) error { size++ go func(m *basecmd.Metric) { result, err := basecmd.QueryMetric(m) + var key string + if m.SubUri == STATUS_SUBURI { key = "status" } else { key = "version" } + var value string if err.TypeCode() == cmderror.CODE_SUCCESS { value, err = basecmd.GetMetricValue(result) } + results <- basecmd.MetricResult{ Addr: m.Addrs[0], Key: key, @@ -157,11 +162,13 @@ func (mCmd *MdsCommand) RunCommand(cmd *cobra.Command, args []string) error { break } } + if len(errs) > 0 && len(errs) < len(mCmd.rows) { mCmd.health = cobrautil.HEALTH_WARN } else if len(errs) == 0 { mCmd.health = cobrautil.HEALTH_OK } + mergeErr := cmderror.MergeCmdErrorExceptSuccess(errs) mCmd.Error = mergeErr list := cobrautil.ListMap2ListSortByKeys(mCmd.rows, mCmd.Header, []string{ @@ -169,6 +176,7 @@ func (mCmd *MdsCommand) RunCommand(cmd *cobra.Command, args []string) error { }) mCmd.TableNew.AppendBulk(list) mCmd.Result = mCmd.rows + return nil } diff --git a/tools-v2/pkg/cli/command/curvebs/status/snapshot/snapshot.go b/tools-v2/pkg/cli/command/curvebs/status/snapshot/snapshot.go new file mode 100644 index 0000000000..d88b6b8be7 --- /dev/null +++ b/tools-v2/pkg/cli/command/curvebs/status/snapshot/snapshot.go @@ -0,0 +1,220 @@ +/* + * 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-25 + * Author: Xinlong-Chen + */ + +package snapshot + +import ( + "fmt" + + "github.com/olekukonko/tablewriter" + 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" + config "github.com/opencurve/curve/tools-v2/pkg/config" + "github.com/opencurve/curve/tools-v2/pkg/output" + "github.com/spf13/cobra" + "github.com/spf13/viper" + "golang.org/x/exp/slices" +) + +const ( + snapshotExample = `$ curve bs status snapshotserver` +) + +type SnapshotCommand struct { + basecmd.FinalCurveCmd + metrics []*basecmd.Metric + rows []map[string]string + health cobrautil.ClUSTER_HEALTH_STATUS +} + +const ( + STATUS_SUBURI = "/vars/snapshotcloneserver_status" + VERSION_SUBURI = "/vars/curve_version" +) + +var ( + SnapshotCloneStatusMap = map[string]string{ + "active": "leader", + "standby": "follower", + } +) + +var _ basecmd.FinalCurveCmdFunc = (*SnapshotCommand)(nil) // check interface + +func NewSnapshotCommand() *cobra.Command { + return NewStatusSnapshotCommand().Cmd +} + +func (sCmd *SnapshotCommand) AddFlags() { + config.AddHttpTimeoutFlag(sCmd.Cmd) + config.AddBsSnapshotCloneFlagOption(sCmd.Cmd) + config.AddBsSnapshotCloneDummyFlagOption(sCmd.Cmd) +} + +func (sCmd *SnapshotCommand) Init(cmd *cobra.Command, args []string) error { + sCmd.health = cobrautil.HEALTH_ERROR + + header := []string{cobrautil.ROW_ADDR, cobrautil.ROW_DUMMY_ADDR, cobrautil.ROW_VERSION, cobrautil.ROW_STATUS} + sCmd.SetHeader(header) + sCmd.TableNew.SetAutoMergeCellsByColumnIndex(cobrautil.GetIndexSlice( + sCmd.Header, []string{cobrautil.ROW_STATUS, cobrautil.ROW_VERSION}, + )) + + // set main addr + mainAddrs, addrErr := config.GetBsSnapshotAddrSlice(sCmd.Cmd) + if addrErr.TypeCode() != cmderror.CODE_SUCCESS { + return fmt.Errorf(addrErr.Message) + } + + // set dummy addr + dummyAddrs, addrErr := config.GetBsSnapshotDummyAddrSlice(sCmd.Cmd) + if addrErr.TypeCode() != cmderror.CODE_SUCCESS { + return fmt.Errorf(addrErr.Message) + } + + for _, addr := range dummyAddrs { + // Use the dummy port to access the metric service + timeout := viper.GetDuration(config.VIPER_GLOBALE_HTTPTIMEOUT) + + addrs := []string{addr} + statusMetric := basecmd.NewMetric(addrs, STATUS_SUBURI, timeout) + sCmd.metrics = append(sCmd.metrics, statusMetric) + versionMetric := basecmd.NewMetric(addrs, VERSION_SUBURI, timeout) + sCmd.metrics = append(sCmd.metrics, versionMetric) + } + + for i := range mainAddrs { + row := make(map[string]string) + row[cobrautil.ROW_ADDR] = mainAddrs[i] + row[cobrautil.ROW_DUMMY_ADDR] = dummyAddrs[i] + row[cobrautil.ROW_STATUS] = cobrautil.ROW_VALUE_OFFLINE + row[cobrautil.ROW_VERSION] = cobrautil.ROW_VALUE_UNKNOWN + sCmd.rows = append(sCmd.rows, row) + } + + return nil +} + +func (sCmd *SnapshotCommand) Print(cmd *cobra.Command, args []string) error { + return output.FinalCmdOutput(&sCmd.FinalCurveCmd, sCmd) +} + +func (sCmd *SnapshotCommand) RunCommand(cmd *cobra.Command, args []string) error { + results := make(chan basecmd.MetricResult, config.MaxChannelSize()) + size := 0 + for _, metric := range sCmd.metrics { + size++ + go func(m *basecmd.Metric) { + result, err := basecmd.QueryMetric(m) + + var key string + if m.SubUri == STATUS_SUBURI { + key = "status" + } else { + key = "version" + } + + var value string + if err.TypeCode() == cmderror.CODE_SUCCESS { + value, err = basecmd.GetMetricValue(result) + } + + results <- basecmd.MetricResult{ + Addr: m.Addrs[0], + Key: key, + Value: value, + Err: err, + } + }(metric) + } + + count := 0 + var errs []*cmderror.CmdError + var recordAddrs []string + for res := range results { + for _, row := range sCmd.rows { + if res.Err.TypeCode() == cmderror.CODE_SUCCESS && row[cobrautil.ROW_DUMMY_ADDR] == res.Addr { + if res.Key == "status" { + row[res.Key] = SnapshotCloneStatusMap[res.Value] + } else { + row[res.Key] = res.Value + } + } else if res.Err.TypeCode() != cmderror.CODE_SUCCESS { + index := slices.Index(recordAddrs, res.Addr) + if index == -1 { + errs = append(errs, res.Err) + recordAddrs = append(recordAddrs, res.Addr) + } + } + } + count++ + if count >= size { + break + } + } + + if len(errs) > 0 && len(errs) < len(sCmd.rows) { + sCmd.health = cobrautil.HEALTH_WARN + } else if len(errs) == 0 { + sCmd.health = cobrautil.HEALTH_OK + } + + mergeErr := cmderror.MergeCmdErrorExceptSuccess(errs) + sCmd.Error = mergeErr + list := cobrautil.ListMap2ListSortByKeys(sCmd.rows, sCmd.Header, []string{ + cobrautil.ROW_STATUS, cobrautil.ROW_VERSION, + }) + sCmd.TableNew.AppendBulk(list) + sCmd.Result = sCmd.rows + + return nil +} + +func (sCmd *SnapshotCommand) ResultPlainOutput() error { + return output.FinalCmdOutputPlain(&sCmd.FinalCurveCmd) +} + +func NewStatusSnapshotCommand() *SnapshotCommand { + snapshotCmd := &SnapshotCommand{ + FinalCurveCmd: basecmd.FinalCurveCmd{ + Use: "snapshotserver", + Short: "get the snapshot clone status of curvebs", + Example: snapshotExample, + }, + } + basecmd.NewFinalCurveCli(&snapshotCmd.FinalCurveCmd, snapshotCmd) + return snapshotCmd +} + +func GetSnapshotStatus(caller *cobra.Command) (*interface{}, *tablewriter.Table, *cmderror.CmdError, cobrautil.ClUSTER_HEALTH_STATUS) { + snapshotCmd := NewStatusSnapshotCommand() + snapshotCmd.Cmd.SetArgs([]string{ + fmt.Sprintf("--%s", config.FORMAT), config.FORMAT_NOOUT, + }) + config.AlignFlagsValue(caller, snapshotCmd.Cmd, []string{ + config.RPCRETRYTIMES, config.RPCTIMEOUT, config.CURVEBS_SNAPSHOTADDR, + }) + snapshotCmd.Cmd.SilenceErrors = true + snapshotCmd.Cmd.Execute() + return &snapshotCmd.Result, snapshotCmd.TableNew, snapshotCmd.Error, snapshotCmd.health +} diff --git a/tools-v2/pkg/cli/command/curvebs/status/status.go b/tools-v2/pkg/cli/command/curvebs/status/status.go index 4a3f6eea01..f7484b4a00 100644 --- a/tools-v2/pkg/cli/command/curvebs/status/status.go +++ b/tools-v2/pkg/cli/command/curvebs/status/status.go @@ -27,6 +27,7 @@ import ( "github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/status/client" "github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/status/etcd" "github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/status/mds" + "github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/status/snapshot" "github.com/spf13/cobra" ) @@ -41,6 +42,7 @@ func (statusCmd *StatusCommand) AddSubCommands() { etcd.NewEtcdCommand(), mds.NewMdsCommand(), client.NewClientCommand(), + snapshot.NewSnapshotCommand(), ) } diff --git a/tools-v2/pkg/config/bs.go b/tools-v2/pkg/config/bs.go index 760a7b6118..bde06dfd89 100644 --- a/tools-v2/pkg/config/bs.go +++ b/tools-v2/pkg/config/bs.go @@ -36,66 +36,70 @@ import ( const ( // curvebs - CURVEBS_MDSADDR = "mdsaddr" - VIPER_CURVEBS_MDSADDR = "curvebs.mdsAddr" - CURVEBS_MDSDUMMYADDR = "mdsdummyaddr" - VIPER_CURVEBS_MDSDUMMYADDR = "curvebs.mdsDummyAddr" - CURVEBS_ETCDADDR = "etcdaddr" - VIPER_CURVEBS_ETCDADDR = "curvebs.etcdAddr" - CURVEBS_PATH = "path" - VIPER_CURVEBS_PATH = "curvebs.path" - CURVEBS_DEFAULT_PATH = "/test" - CURVEBS_USER = "user" - VIPER_CURVEBS_USER = "curvebs.root.user" - CURVEBS_DEFAULT_USER = "root" - CURVEBS_PASSWORD = "password" - VIPER_CURVEBS_PASSWORD = "curvebs.root.password" - CURVEBS_DEFAULT_PASSWORD = "root_password" - CURVEBS_CLUSTERMAP = "clustermap" - VIPER_CURVEBS_CLUSTERMAP = "curvebs.clustermap" - CURVEBS_FORCE = "force" - VIPER_CURVEBS_FORCE = "curvebs.force" - CURVEBS_DEFAULT_FORCE = false - CURVEBS_LOGIC_POOL_ID = "logicalpoolid" - VIPER_CURVEBS_LOGIC_POOL_ID = "curvebs.logicalpoolid" - CURVEBS_COPYSET_ID = "copysetid" - VIPER_CURVEBS_COPYSET_ID = "curvebs.copysetid" - CURVEBS_PEERS_ADDRESS = "peers" - VIPER_CURVEBS_PEERS_ADDRESS = "curvebs.peers" - CURVEBS_OFFSET = "offset" - VIPER_CURVEBS_OFFSET = "curvebs.offset" - CURVEBS_SIZE = "size" - VIPER_CURVEBS_SIZE = "curvebs.size" - CURVEBS_DEFAULT_SIZE = uint64(10) - CURVEBS_TYPE = "type" - VIPER_CURVEBS_TYPE = "curvebs.type" - CURVEBS_STRIPE_UNIT = "stripeunit" - VIPER_CURVEBS_STRIPE_UNIT = "curvebs.stripeunit" - CURVEBS_DEFAULT_STRIPE_UNIT = "32 KiB" - CURVEBS_STRIPE_COUNT = "stripecount" - VIPER_CURVEBS_STRIPE_COUNT = "curvebs.stripecount" - CURVEBS_DEFAULT_STRIPE_COUNT = uint64(32) - CURVEBS_RECYCLE_PREFIX = "recycleprefix" - VIPER_RECYCLE_PREFIX = "curvebs.recycleprefix" - CURVEBS_EXPIRED_TIME = "expiredtime" - VIPER_CURVEBS_EXPIRED_TIME = "curvebs.expiredtime" - CURVEBS_LIMIT = "limit" - VIPER_CURVEBS_LIMIT = "curvebs.limit" - CURVEBS_BURST = "burst" - VIPER_CURVEBS_BURST = "curvebs.burst" - CURVEBS_DEFAULT_BURST = uint64(30000) - CURVEBS_BURST_LENGTH = "burstlength" - VIPER_CURVEBS_BURST_LENGTH = "curvebs.burstlength" - CURVEBS_DEFAULT_BURST_LENGTH = uint64(10) - CURVEBS_OP = "op" - VIPER_CURVEBS_OP = "curvebs.op" - CURVEBS_DEFAULT_OP = "operator" - CURVEBS_CHECK_TIME = "checktime" - VIPER_CURVEBS_CHECK_TIME = "curvebs.checktime" - CURVEBS_DEFAULT_CHECK_TIME = 30 * time.Second - CURVEBS_MARGIN = "margin" - VIPER_CURVEBS_MARGIN = "curvebs.margin" - CURVEBS_DEFAULT_MARGIN = uint64(1000) + CURVEBS_MDSADDR = "mdsaddr" + VIPER_CURVEBS_MDSADDR = "curvebs.mdsAddr" + CURVEBS_MDSDUMMYADDR = "mdsdummyaddr" + VIPER_CURVEBS_MDSDUMMYADDR = "curvebs.mdsDummyAddr" + CURVEBS_ETCDADDR = "etcdaddr" + VIPER_CURVEBS_ETCDADDR = "curvebs.etcdAddr" + CURVEBS_PATH = "path" + VIPER_CURVEBS_PATH = "curvebs.path" + CURVEBS_DEFAULT_PATH = "/test" + CURVEBS_USER = "user" + VIPER_CURVEBS_USER = "curvebs.root.user" + CURVEBS_DEFAULT_USER = "root" + CURVEBS_PASSWORD = "password" + VIPER_CURVEBS_PASSWORD = "curvebs.root.password" + CURVEBS_DEFAULT_PASSWORD = "root_password" + CURVEBS_CLUSTERMAP = "clustermap" + VIPER_CURVEBS_CLUSTERMAP = "curvebs.clustermap" + CURVEBS_FORCE = "force" + VIPER_CURVEBS_FORCE = "curvebs.force" + CURVEBS_DEFAULT_FORCE = false + CURVEBS_LOGIC_POOL_ID = "logicalpoolid" + VIPER_CURVEBS_LOGIC_POOL_ID = "curvebs.logicalpoolid" + CURVEBS_COPYSET_ID = "copysetid" + VIPER_CURVEBS_COPYSET_ID = "curvebs.copysetid" + CURVEBS_PEERS_ADDRESS = "peers" + VIPER_CURVEBS_PEERS_ADDRESS = "curvebs.peers" + CURVEBS_OFFSET = "offset" + VIPER_CURVEBS_OFFSET = "curvebs.offset" + CURVEBS_SIZE = "size" + VIPER_CURVEBS_SIZE = "curvebs.size" + CURVEBS_DEFAULT_SIZE = uint64(10) + CURVEBS_TYPE = "type" + VIPER_CURVEBS_TYPE = "curvebs.type" + CURVEBS_STRIPE_UNIT = "stripeunit" + VIPER_CURVEBS_STRIPE_UNIT = "curvebs.stripeunit" + CURVEBS_DEFAULT_STRIPE_UNIT = "32 KiB" + CURVEBS_STRIPE_COUNT = "stripecount" + VIPER_CURVEBS_STRIPE_COUNT = "curvebs.stripecount" + CURVEBS_DEFAULT_STRIPE_COUNT = uint64(32) + CURVEBS_RECYCLE_PREFIX = "recycleprefix" + VIPER_RECYCLE_PREFIX = "curvebs.recycleprefix" + CURVEBS_EXPIRED_TIME = "expiredtime" + VIPER_CURVEBS_EXPIRED_TIME = "curvebs.expiredtime" + CURVEBS_LIMIT = "limit" + VIPER_CURVEBS_LIMIT = "curvebs.limit" + CURVEBS_BURST = "burst" + VIPER_CURVEBS_BURST = "curvebs.burst" + CURVEBS_DEFAULT_BURST = uint64(30000) + CURVEBS_BURST_LENGTH = "burstlength" + VIPER_CURVEBS_BURST_LENGTH = "curvebs.burstlength" + CURVEBS_DEFAULT_BURST_LENGTH = uint64(10) + CURVEBS_OP = "op" + VIPER_CURVEBS_OP = "curvebs.op" + CURVEBS_DEFAULT_OP = "operator" + CURVEBS_CHECK_TIME = "checktime" + VIPER_CURVEBS_CHECK_TIME = "curvebs.checktime" + CURVEBS_DEFAULT_CHECK_TIME = 30 * time.Second + CURVEBS_MARGIN = "margin" + VIPER_CURVEBS_MARGIN = "curvebs.margin" + CURVEBS_DEFAULT_MARGIN = uint64(1000) + CURVEBS_SNAPSHOTADDR = "snapshotaddr" + VIPER_CURVEBS_SNAPSHOTADDR = "curvebs.snapshotAddr" + CURVEBS_SNAPSHOTDUMMYADDR = "snapshotdummyaddr" + VIPER_CURVEBS_SNAPSHOTDUMMYADDR = "curvebs.snapshotDummyAddr" ) var ( @@ -105,30 +109,32 @@ var ( RPCRETRYTIMES: VIPER_GLOBALE_RPCRETRYTIMES, // bs - CURVEBS_MDSADDR: VIPER_CURVEBS_MDSADDR, - CURVEBS_MDSDUMMYADDR: VIPER_CURVEBS_MDSDUMMYADDR, - CURVEBS_PATH: VIPER_CURVEBS_PATH, - CURVEBS_USER: VIPER_CURVEBS_USER, - CURVEBS_PASSWORD: VIPER_CURVEBS_PASSWORD, - CURVEBS_ETCDADDR: VIPER_CURVEBS_ETCDADDR, - CURVEBS_LOGIC_POOL_ID: VIPER_CURVEBS_LOGIC_POOL_ID, - CURVEBS_COPYSET_ID: VIPER_CURVEBS_COPYSET_ID, - CURVEBS_PEERS_ADDRESS: VIPER_CURVEBS_PEERS_ADDRESS, - CURVEBS_CLUSTERMAP: VIPER_CURVEBS_CLUSTERMAP, - CURVEBS_OFFSET: VIPER_CURVEBS_OFFSET, - CURVEBS_SIZE: VIPER_CURVEBS_SIZE, - CURVEBS_STRIPE_UNIT: VIPER_CURVEBS_STRIPE_UNIT, - CURVEBS_STRIPE_COUNT: VIPER_CURVEBS_STRIPE_COUNT, - CURVEBS_LIMIT: VIPER_CURVEBS_LIMIT, - CURVEBS_BURST: VIPER_CURVEBS_BURST, - CURVEBS_BURST_LENGTH: VIPER_CURVEBS_BURST_LENGTH, - CURVEBS_FORCE: VIPER_CURVEBS_FORCE, - CURVEBS_TYPE: VIPER_CURVEBS_TYPE, - CURVEBS_EXPIRED_TIME: VIPER_CURVEBS_EXPIRED_TIME, - CURVEBS_RECYCLE_PREFIX: VIPER_RECYCLE_PREFIX, - CURVEBS_MARGIN: VIPER_CURVEBS_MARGIN, - CURVEBS_OP: VIPER_CURVEBS_OP, - CURVEBS_CHECK_TIME: VIPER_CURVEBS_CHECK_TIME, + CURVEBS_MDSADDR: VIPER_CURVEBS_MDSADDR, + CURVEBS_MDSDUMMYADDR: VIPER_CURVEBS_MDSDUMMYADDR, + CURVEBS_PATH: VIPER_CURVEBS_PATH, + CURVEBS_USER: VIPER_CURVEBS_USER, + CURVEBS_PASSWORD: VIPER_CURVEBS_PASSWORD, + CURVEBS_ETCDADDR: VIPER_CURVEBS_ETCDADDR, + CURVEBS_LOGIC_POOL_ID: VIPER_CURVEBS_LOGIC_POOL_ID, + CURVEBS_COPYSET_ID: VIPER_CURVEBS_COPYSET_ID, + CURVEBS_PEERS_ADDRESS: VIPER_CURVEBS_PEERS_ADDRESS, + CURVEBS_CLUSTERMAP: VIPER_CURVEBS_CLUSTERMAP, + CURVEBS_OFFSET: VIPER_CURVEBS_OFFSET, + CURVEBS_SIZE: VIPER_CURVEBS_SIZE, + CURVEBS_STRIPE_UNIT: VIPER_CURVEBS_STRIPE_UNIT, + CURVEBS_STRIPE_COUNT: VIPER_CURVEBS_STRIPE_COUNT, + CURVEBS_LIMIT: VIPER_CURVEBS_LIMIT, + CURVEBS_BURST: VIPER_CURVEBS_BURST, + CURVEBS_BURST_LENGTH: VIPER_CURVEBS_BURST_LENGTH, + CURVEBS_FORCE: VIPER_CURVEBS_FORCE, + CURVEBS_TYPE: VIPER_CURVEBS_TYPE, + CURVEBS_EXPIRED_TIME: VIPER_CURVEBS_EXPIRED_TIME, + CURVEBS_RECYCLE_PREFIX: VIPER_RECYCLE_PREFIX, + CURVEBS_MARGIN: VIPER_CURVEBS_MARGIN, + CURVEBS_OP: VIPER_CURVEBS_OP, + CURVEBS_CHECK_TIME: VIPER_CURVEBS_CHECK_TIME, + CURVEBS_SNAPSHOTADDR: VIPER_CURVEBS_SNAPSHOTADDR, + CURVEBS_SNAPSHOTDUMMYADDR: VIPER_CURVEBS_SNAPSHOTDUMMYADDR, } BSFLAG2DEFAULT = map[string]interface{}{ @@ -311,10 +317,20 @@ func AddBsDurationRequiredFlag(cmd *cobra.Command, name string, usage string) { func AddBsMdsFlagOption(cmd *cobra.Command) { AddBsStringOptionFlag(cmd, CURVEBS_MDSADDR, "mds address, should be like 127.0.0.1:6700,127.0.0.1:6701,127.0.0.1:6702") } + func AddBsMdsDummyFlagOption(cmd *cobra.Command) { AddBsStringOptionFlag(cmd, CURVEBS_MDSDUMMYADDR, "mds dummy address, should be like 127.0.0.1:6700,127.0.0.1:6701,127.0.0.1:6702") } +// snapshot clone +func AddBsSnapshotCloneFlagOption(cmd *cobra.Command) { + AddBsStringOptionFlag(cmd, CURVEBS_SNAPSHOTADDR, "snapshot clone address, should be like 127.0.0.1:5550,127.0.0.1:5551,127.0.0.1:5552") +} + +func AddBsSnapshotCloneDummyFlagOption(cmd *cobra.Command) { + AddBsStringOptionFlag(cmd, CURVEBS_SNAPSHOTDUMMYADDR, "snapshot clone dummy address, should be like 127.0.0.1:8100,127.0.0.1:8101,127.0.0.1:8102") +} + // user func AddBsUserOptionFlag(cmd *cobra.Command) { AddBsStringOptionFlag(cmd, CURVEBS_USER, "user name") @@ -502,6 +518,7 @@ func GetBsAddrSlice(cmd *cobra.Command, addrType string) ([]string, *cmderror.Cm func GetBsEtcdAddrSlice(cmd *cobra.Command) ([]string, *cmderror.CmdError) { return GetBsAddrSlice(cmd, CURVEBS_ETCDADDR) } + func GetBsMdsAddrSlice(cmd *cobra.Command) ([]string, *cmderror.CmdError) { return GetBsAddrSlice(cmd, CURVEBS_MDSADDR) } @@ -510,6 +527,14 @@ func GetBsMdsDummyAddrSlice(cmd *cobra.Command) ([]string, *cmderror.CmdError) { return GetBsAddrSlice(cmd, CURVEBS_MDSDUMMYADDR) } +func GetBsSnapshotAddrSlice(cmd *cobra.Command) ([]string, *cmderror.CmdError) { + return GetBsAddrSlice(cmd, CURVEBS_SNAPSHOTADDR) +} + +func GetBsSnapshotDummyAddrSlice(cmd *cobra.Command) ([]string, *cmderror.CmdError) { + return GetBsAddrSlice(cmd, CURVEBS_SNAPSHOTDUMMYADDR) +} + func GetBsFlagBool(cmd *cobra.Command, flagName string) bool { var value bool if cmd.Flag(flagName).Changed { diff --git a/tools-v2/pkg/config/curve.yaml b/tools-v2/pkg/config/curve.yaml index 96ccc637db..e791239685 100644 --- a/tools-v2/pkg/config/curve.yaml +++ b/tools-v2/pkg/config/curve.yaml @@ -20,6 +20,8 @@ curvebs: mdsAddr: 127.0.0.1:6700,127.0.0.1:6701,127.0.0.1:6702 # __CURVEADM_TEMPLATE__ ${cluster_mds_addr} __CURVEADM_TEMPLATE__ mdsDummyAddr: 127.0.0.1:7700,127.0.0.1:7701,127.0.0.1:7702 # __CURVEADM_TEMPLATE__ ${cluster_mds_dummy_addr} __CURVEADM_TEMPLATE__ etcdAddr: 127.0.0.1:23790,127.0.0.1:23791,127.0.0.1:23792 # __CURVEADM_TEMPLATE__ ${cluster_etcd_addr} __CURVEADM_TEMPLATE__ + snapshotAddr: 127.0.0.1:5550,127.0.0.1:5551,127.0.0.1:5552 # __CURVEADM_TEMPLATE__ ${cluster_snapshot_addr} __CURVEADM_TEMPLATE__ + snapshotDummyAddr: 127.0.0.1:8100,127.0.0.1:8101,127.0.0.1:8102 # __CURVEADM_TEMPLATE__ ${cluster_snapshot_dummy_addr} __CURVEADM_TEMPLATE__ root: user: root password: root_password