From e0eb79fe72afffdaa422468f885f7eddb1f5aad7 Mon Sep 17 00:00:00 2001 From: tianpingan Date: Fri, 22 Dec 2023 02:38:15 +0000 Subject: [PATCH] update tools to support storage class Signed-off-by: tianpingan --- curvefs/proto/common.proto | 1 + .../src/tools/create/curvefs_create_fs.cpp | 11 ++++++ curvefs/src/tools/curvefs_tool_define.cpp | 7 ++++ curvefs/src/tools/curvefs_tool_define.h | 4 +++ tools-v2/internal/error/error.go | 4 ++- tools-v2/internal/utils/proto.go | 10 ++++++ .../pkg/cli/command/curvefs/create/fs/fs.go | 24 ++++++++----- tools-v2/pkg/config/fs.go | 34 ++++++++++++------- 8 files changed, 73 insertions(+), 22 deletions(-) diff --git a/curvefs/proto/common.proto b/curvefs/proto/common.proto index 84d351dd09..e9b6359a35 100644 --- a/curvefs/proto/common.proto +++ b/curvefs/proto/common.proto @@ -112,6 +112,7 @@ message CopysetInfo { } enum StorageClass { + NOT_SET = 0; STANDARD = 1; REDUCED_REDUNDANCY = 2; STANDARD_IA = 3; diff --git a/curvefs/src/tools/create/curvefs_create_fs.cpp b/curvefs/src/tools/create/curvefs_create_fs.cpp index d8fd0641fd..1a562810a4 100644 --- a/curvefs/src/tools/create/curvefs_create_fs.cpp +++ b/curvefs/src/tools/create/curvefs_create_fs.cpp @@ -58,6 +58,7 @@ DECLARE_string(s3_bucket_name); DECLARE_uint64(s3_blocksize); DECLARE_uint64(s3_chunksize); DECLARE_uint32(s3_objectPrefix); +DECLARE_string(s3_storageClass); DECLARE_uint32(rpcTimeoutMs); DECLARE_uint32(rpcRetryTimes); DECLARE_bool(enableSumInDir); @@ -100,6 +101,7 @@ void CreateFsTool::PrintHelp() { << " -s3_blocksize=" << FLAGS_s3_blocksize << " -s3_chunksize=" << FLAGS_s3_chunksize << " -s3_objectPrefix=" << FLAGS_s3_objectPrefix + << " -s3_storageClass=NOT_SET|STANDARD|REDUCED_REDUNDANCY|STANDARD_IA|ONEZONE_IA|INTELLIGENT_TIERING|GLACIER|DEEP_ARCHIVE" << "]\n[-fsType=hybrid -volumeBlockGroupSize=" << FLAGS_volumeBlockGroupSize << " -volumeBlockSize=" << FLAGS_volumeBlockSize @@ -113,6 +115,7 @@ void CreateFsTool::PrintHelp() { << " -s3_blocksize=" << FLAGS_s3_blocksize << " -s3_chunksize=" << FLAGS_s3_chunksize << " -s3_objectPrefix=" << FLAGS_s3_objectPrefix + << " -s3_storageClass=NOT_SET|STANDARD|REDUCED_REDUNDANCY|STANDARD_IA|ONEZONE_IA|INTELLIGENT_TIERING|GLACIER|DEEP_ARCHIVE" << "]" << std::endl; } @@ -134,6 +137,7 @@ void CreateFsTool::AddUpdateFlags() { AddUpdateFlagsFunc(curvefs::tools::SetS3_blocksize); AddUpdateFlagsFunc(curvefs::tools::SetS3_chunksize); AddUpdateFlagsFunc(curvefs::tools::SetS3_objectPrefix); + AddUpdateFlagsFunc(curvefs::tools::SetS3_storageClass); AddUpdateFlagsFunc(curvefs::tools::SetRpcTimeoutMs); AddUpdateFlagsFunc(curvefs::tools::SetRpcRetryTimes); AddUpdateFlagsFunc(curvefs::tools::SetEnableSumInDir); @@ -179,6 +183,13 @@ int CreateFsTool::Init() { s3->set_blocksize(FLAGS_s3_blocksize); s3->set_chunksize(FLAGS_s3_chunksize); s3->set_objectprefix(FLAGS_s3_objectPrefix); + curvefs::common::StorageClass storageClass; + if (!StorageClass_Parse(FLAGS_s3_storageClass, &storageClass)) { + std::cerr << "Parse storageClass error, only support " + "NOT_SET|STANDARD|REDUCED_REDUNDANCY|STANDARD_IA|ONEZONE_IA|INTELLIGENT_TIERING|GLACIER|DEEP_ARCHIVE"; + return -1; + } + s3->set_storageclass(storageClass); request.mutable_fsdetail()->set_allocated_s3info(s3); return 0; }; diff --git a/curvefs/src/tools/curvefs_tool_define.cpp b/curvefs/src/tools/curvefs_tool_define.cpp index 383479fba5..3512b6151f 100644 --- a/curvefs/src/tools/curvefs_tool_define.cpp +++ b/curvefs/src/tools/curvefs_tool_define.cpp @@ -75,6 +75,7 @@ DEFINE_string(s3_bucket_name, "bucketname", "s3 bucket name"); DEFINE_uint64(s3_blocksize, 1048576, "s3 block size"); DEFINE_uint64(s3_chunksize, 4194304, "s3 chunk size"); DEFINE_uint32(s3_objectPrefix, 0, "object prefix"); +DEFINE_string(s3_storageClass, "NOT_SET", "s3 storage classes"); DEFINE_bool(enableSumInDir, false, "statistic info in xattr"); DEFINE_uint64(capacity, (uint64_t)0, "capacity of fs, unit is bytes, default 0 to disable quota"); @@ -256,6 +257,12 @@ std::function std::placeholders::_2, "s3_objectPrefix", "s3.objectPrefix", &FLAGS_s3_objectPrefix); +std::function + SetS3_storageClass = + std::bind(&SetDiffFlagInfo, std::placeholders::_1, + std::placeholders::_2, "s3_storageClass", "s3.storageClass", + &FLAGS_s3_storageClass); + std::function SetEnableSumInDir = std::bind(&SetFlagInfo, std::placeholders::_1, std::placeholders::_2, "enableSumInDir", diff --git a/curvefs/src/tools/curvefs_tool_define.h b/curvefs/src/tools/curvefs_tool_define.h index 819588a539..9a5d234e5b 100644 --- a/curvefs/src/tools/curvefs_tool_define.h +++ b/curvefs/src/tools/curvefs_tool_define.h @@ -274,6 +274,10 @@ extern std::function SetS3_objectPrefix; +extern std::function + SetS3_storageClass; + extern std::function SetEnableSumInDir; diff --git a/tools-v2/internal/error/error.go b/tools-v2/internal/error/error.go index aea8ad92d3..9a34f80d66 100644 --- a/tools-v2/internal/error/error.go +++ b/tools-v2/internal/error/error.go @@ -500,7 +500,9 @@ var ( ErrInvalidMetaServerAddr = func() *CmdError { return NewInternalCmdError(80, "invalid metaserver external addr: %s") } - + ErrUnknownStorageClass = func() *CmdError { + return NewInternalCmdError(81, "unknown storage class: %s") + } // http error ErrHttpUnreadableResult = func() *CmdError { return NewHttpResultCmdError(1, "http response is unreadable, the uri is: %s, the error is: %s") diff --git a/tools-v2/internal/utils/proto.go b/tools-v2/internal/utils/proto.go index fc53053a9e..1ea6529561 100644 --- a/tools-v2/internal/utils/proto.go +++ b/tools-v2/internal/utils/proto.go @@ -223,3 +223,13 @@ func ParseThrottleType(typeStr string) (nameserver2.ThrottleType, *cmderror.CmdE } return nameserver2.ThrottleType(throttleType), retErr } + +func TranslateStorageClass(storageclass string) (common.StorageClass, *cmderror.CmdError) { + value, found := common.StorageClass_value[storageclass] + var retErr cmderror.CmdError + if !found { + retErr = *cmderror.ErrUnknownStorageClass() + retErr.Format(storageclass) + } + return common.StorageClass(value), &retErr +} diff --git a/tools-v2/pkg/cli/command/curvefs/create/fs/fs.go b/tools-v2/pkg/cli/command/curvefs/create/fs/fs.go index 9c28858133..d6aab1079a 100644 --- a/tools-v2/pkg/cli/command/curvefs/create/fs/fs.go +++ b/tools-v2/pkg/cli/command/curvefs/create/fs/fs.go @@ -41,9 +41,9 @@ import ( const ( fsExample = `$ curve fs create fs --fsname test1 -$ curve fs create fs --fsname test1 --fstype s3 --s3.ak AK --s3.sk SK --s3.endpoint http://localhost:9000 --s3.bucketname test1 --s3.blocksize 4MiB --s3.chunksize 4MiB +$ curve fs create fs --fsname test1 --fstype s3 --s3.ak AK --s3.sk SK --s3.endpoint http://localhost:9000 --s3.bucketname test1 --s3.blocksize 4MiB --s3.chunksize 4MiB --s3.storageclass STANDARD $ curve fs create fs --fsname test1 --fstype volume --volume.bitmaplocation AtStart --volume.blockgroupsize 128MiB --volume.blocksize 4KiB --volume.name volume --volume.password password --volume.size 1MiB --volume.slicesize 1MiB --volume.user user -$ curve fs create fs --fsname test1 --fstype hybrid --s3.ak AK --s3.sk SK --s3.endpoint http://localhost:9000 --s3.bucketname test1 --s3.blocksize 4MiB --s3.chunksize 4MiB --volume.bitmaplocation AtStart --volume.blockgroupsize 128MiB --volume.blocksize 4KiB --volume.name volume --volume.password password --volume.size 1MiB --volume.slicesize 1MiB --volume.user user` +$ curve fs create fs --fsname test1 --fstype hybrid --s3.ak AK --s3.sk SK --s3.endpoint http://localhost:9000 --s3.bucketname test1 --s3.blocksize 4MiB --s3.chunksize 4MiB --s3.storageclass STANDARD --volume.bitmaplocation AtStart --volume.blockgroupsize 128MiB --volume.blocksize 4KiB --volume.name volume --volume.password password --volume.size 1MiB --volume.slicesize 1MiB --volume.user user` ) type CreateFsRpc struct { @@ -98,6 +98,7 @@ func (fCmd *FsCommand) AddFlags() { config.AddS3BucknameOptionFlag(fCmd.Cmd) config.AddS3BlocksizeOptionFlag(fCmd.Cmd) config.AddS3ChunksizeOptionFlag(fCmd.Cmd) + config.AddS3StorageclassOptionFlag(fCmd.Cmd) // volume config.AddVolumeSizeOptionFlag(fCmd.Cmd) config.AddVolumeBlockgroupsizeOptionFlag(fCmd.Cmd) @@ -209,14 +210,19 @@ func setS3Info(detail *mds.FsDetail, cmd *cobra.Command) *cmderror.CmdError { errParse.Format(config.CURVEFS_S3_CHUNKSIZE, chunksizeStr) return errParse } - + storageclassStr := config.GetFlagString(cmd, config.CURVEFS_S3_STORAGECLASS) + storageclass, errStorageclass := cobrautil.TranslateStorageClass(storageclassStr) + if errStorageclass.TypeCode() != cmderror.CODE_SUCCESS { + return errStorageclass + } info := &common.S3Info{ - Ak: &ak, - Sk: &sk, - Endpoint: &endpoint, - Bucketname: &bucketname, - BlockSize: &blocksize, - ChunkSize: &chunksize, + Ak: &ak, + Sk: &sk, + Endpoint: &endpoint, + Bucketname: &bucketname, + BlockSize: &blocksize, + ChunkSize: &chunksize, + StorageClass: &storageclass, } detail.S3Info = info return cmderror.ErrSuccess() diff --git a/tools-v2/pkg/config/fs.go b/tools-v2/pkg/config/fs.go index 304400db1c..b76d8f0cc0 100644 --- a/tools-v2/pkg/config/fs.go +++ b/tools-v2/pkg/config/fs.go @@ -115,6 +115,9 @@ const ( CURVEFS_S3_CHUNKSIZE = "s3.chunksize" VIPER_CURVEFS_S3CHUNKSIZE = "curvefs.s3.chunksize" CURVEFS_DEFAULT_S3_CHUNKSIZE = "64 MiB" + CURVEFS_S3_STORAGECLASS = "s3.storageclass" + VIPER_CURVEFS_S3_STORAGECLASS = "curvefs.s3.storageclass" + CURVEFS_DEFAULT_STORAGECLASS = "NOT_SET" // Volume CURVEFS_VOLUME_SIZE = "volume.size" VIPER_CURVEFS_VOLUME_SIZE = "curvefs.volume.size" @@ -174,12 +177,13 @@ var ( CURVEFS_STORAGE: VIPER_CURVEFS_STORAGE, // S3 - CURVEFS_S3_AK: VIPER_CURVEFS_S3_AK, - CURVEFS_S3_SK: VIPER_CURVEFS_S3_SK, - CURVEFS_S3_ENDPOINT: VIPER_CURVEFS_S3_ENDPOINT, - CURVEFS_S3_BUCKETNAME: VIPER_CURVEFS_S3_BUCKETNAME, - CURVEFS_S3_BLOCKSIZE: VIPER_CURVEFS_S3_BLOCKSIZE, - CURVEFS_S3_CHUNKSIZE: VIPER_CURVEFS_S3CHUNKSIZE, + CURVEFS_S3_AK: VIPER_CURVEFS_S3_AK, + CURVEFS_S3_SK: VIPER_CURVEFS_S3_SK, + CURVEFS_S3_ENDPOINT: VIPER_CURVEFS_S3_ENDPOINT, + CURVEFS_S3_BUCKETNAME: VIPER_CURVEFS_S3_BUCKETNAME, + CURVEFS_S3_BLOCKSIZE: VIPER_CURVEFS_S3_BLOCKSIZE, + CURVEFS_S3_CHUNKSIZE: VIPER_CURVEFS_S3CHUNKSIZE, + CURVEFS_S3_STORAGECLASS: VIPER_CURVEFS_S3_STORAGECLASS, // Volume CURVEFS_VOLUME_SIZE: VIPER_CURVEFS_VOLUME_SIZE, @@ -204,12 +208,13 @@ var ( CURVEFS_STORAGE: CURVEFS_DEFAULT_STORAGE, // S3 - CURVEFS_S3_AK: CURVEFS_DEFAULT_S3_AK, - CURVEFS_S3_SK: CURVEFS_DEFAULT_S3_SK, - CURVEFS_S3_ENDPOINT: CURVEFS_DEFAULT_ENDPOINT, - CURVEFS_S3_BUCKETNAME: CURVEFS_DEFAULT_S3_BUCKETNAME, - CURVEFS_S3_BLOCKSIZE: CURVEFS_DEFAULT_S3_BLOCKSIZE, - CURVEFS_S3_CHUNKSIZE: CURVEFS_DEFAULT_S3_CHUNKSIZE, + CURVEFS_S3_AK: CURVEFS_DEFAULT_S3_AK, + CURVEFS_S3_SK: CURVEFS_DEFAULT_S3_SK, + CURVEFS_S3_ENDPOINT: CURVEFS_DEFAULT_ENDPOINT, + CURVEFS_S3_BUCKETNAME: CURVEFS_DEFAULT_S3_BUCKETNAME, + CURVEFS_S3_BLOCKSIZE: CURVEFS_DEFAULT_S3_BLOCKSIZE, + CURVEFS_S3_CHUNKSIZE: CURVEFS_DEFAULT_S3_CHUNKSIZE, + CURVEFS_S3_STORAGECLASS: CURVEFS_DEFAULT_STORAGECLASS, // Volume CURVEFS_VOLUME_SIZE: CURVEFS_DEFAULT_VOLUME_SIZE, @@ -676,6 +681,11 @@ func AddS3ChunksizeOptionFlag(cmd *cobra.Command) { AddStringOptionFlag(cmd, CURVEFS_S3_CHUNKSIZE, "s3 chunksize") } +// S3.StorageClass [option] +func AddS3StorageclassOptionFlag(cmd *cobra.Command) { + AddStringOptionFlag(cmd, CURVEFS_S3_STORAGECLASS, "s3 storageclass") +} + // volume.size [option] func AddVolumeSizeOptionFlag(cmd *cobra.Command) { AddStringOptionFlag(cmd, CURVEFS_VOLUME_SIZE, "volume size")