From ff123056925981860563ed0fbc935fdc90afe092 Mon Sep 17 00:00:00 2001 From: chenwei <461432360@qq.com> Date: Mon, 12 Apr 2021 10:29:30 +0800 Subject: [PATCH] change file param from hard code to config file --- conf/mds.conf | 6 +++ .../roles/generate_config/defaults/main.yml | 3 ++ .../generate_config/templates/mds.conf.j2 | 6 +++ src/mds/common/mds_define.h | 6 +-- src/mds/main/main.cpp | 15 ++++--- src/mds/nameserver2/curvefs.cpp | 39 +++++++++++++------ src/mds/nameserver2/curvefs.h | 27 +++++++++++++ src/mds/server/mds.cpp | 6 +++ test/mds/nameserver2/chunk_allocator_test.cpp | 1 + test/mds/nameserver2/clean_core_test.cpp | 3 ++ test/mds/nameserver2/curvefs_test.cpp | 9 +++++ .../nameserver2/namespace_service_test.cpp | 15 +++++++ test/tools/mds_client_test.cpp | 2 +- test/tools/status_tool_test.cpp | 10 ++--- 14 files changed, 120 insertions(+), 28 deletions(-) diff --git a/conf/mds.conf b/conf/mds.conf index b7007b30e4..beedce08e8 100644 --- a/conf/mds.conf +++ b/conf/mds.conf @@ -165,6 +165,12 @@ mds.copyset.scatterWidthFloatingPercentage=20 # # curvefs的默认chunk size大小,16MB = 16*1024*1024 = 16777216 mds.curvefs.defaultChunkSize=16777216 +# curvefs的默认segment size大小,1GB = 1*1024*1024*1024 = 1073741824 +mds.curvefs.defaultSegmentSize=1073741824 +# curvefs的默认最小文件大小,10GB = 10*1024*1024*1024 = 10737418240 +mds.curvefs.minFileLength=10737418240 +# curvefs的默认最大文件大小,20TB = 20*1024*1024*1024*1024 = 21990232555520 +mds.curvefs.maxFileLength=21990232555520 # # chunkseverclient config diff --git a/curve-ansible/roles/generate_config/defaults/main.yml b/curve-ansible/roles/generate_config/defaults/main.yml index 01f4145b15..a6202c9ceb 100644 --- a/curve-ansible/roles/generate_config/defaults/main.yml +++ b/curve-ansible/roles/generate_config/defaults/main.yml @@ -19,6 +19,9 @@ curve_root_username: root curve_root_password: root_password chunk_size: 16777216 +segment_size: 1073741824 +min_file_length: 10737418240 +max_file_length: 21990232555520 file_expired_time_us: 5000000 # mds配置默认值 diff --git a/curve-ansible/roles/generate_config/templates/mds.conf.j2 b/curve-ansible/roles/generate_config/templates/mds.conf.j2 index d548938fc1..4fb1fa3234 100644 --- a/curve-ansible/roles/generate_config/templates/mds.conf.j2 +++ b/curve-ansible/roles/generate_config/templates/mds.conf.j2 @@ -173,6 +173,12 @@ mds.copyset.scatterWidthFloatingPercentage={{ mds_copyset_scatterwidth_floating_ # # curvefs的默认chunk size大小,16MB = 16*1024*1024 = 16777216 mds.curvefs.defaultChunkSize={{ chunk_size }} +# curvefs的默认segment size大小,1GB = 1*1024*1024*1024 = 1073741824 +mds.curvefs.defaultSegmentSize={{ segment_size }} +# curvefs的默认最小文件大小,10GB = 10*1024*1024*1024 = 10737418240 +mds.curvefs.minFileLength={{ min_file_length }} +# curvefs的默认最大文件大小,20TB = 20*1024*1024*1024*1024 = 21990232555520 +mds.curvefs.maxFileLength={{ max_file_length }} # # chunkseverclient config diff --git a/src/mds/common/mds_define.h b/src/mds/common/mds_define.h index 9e49ee6025..4e71416bc4 100644 --- a/src/mds/common/mds_define.h +++ b/src/mds/common/mds_define.h @@ -126,11 +126,7 @@ const uint64_t kMB = 1024*kKB; const uint64_t kGB = 1024*kMB; const uint64_t kTB = 1024*kGB; -extern uint64_t DefaultSegmentSize; -extern uint64_t kMiniFileLength; -const uint64_t kMaxFileLength = 4 * kTB; - -// curve默认root目录&inodeid +// curve default root path and inodeid const InodeID ROOTINODEID = 0; const char ROOTFILENAME[] = "/"; diff --git a/src/mds/main/main.cpp b/src/mds/main/main.cpp index 859338aab4..a758ff5abe 100644 --- a/src/mds/main/main.cpp +++ b/src/mds/main/main.cpp @@ -35,12 +35,12 @@ DEFINE_uint32(dummyPort, 6667, "dummy server port"); using ::curve::mds::kMB; using ::curve::mds::kGB; -using ::curve::mds::DefaultSegmentSize; -using ::curve::mds::kMiniFileLength; +using ::curve::mds::kTB; DEFINE_uint64(chunkSize, 16 * kMB, "chunk size"); DEFINE_uint64(segmentSize, 1 * kGB, "segment size"); -DEFINE_uint64(minFileLength, 10 * kGB, "min filglength"); +DEFINE_uint64(minFileLength, 10 * kGB, "min filelength"); +DEFINE_uint64(maxFileLength, 20 * kTB, "max filelength"); void LoadConfigFromCmdline(Configuration *conf) { google::CommandLineFlagInfo info; @@ -57,11 +57,16 @@ void LoadConfigFromCmdline(Configuration *conf) { } if (GetCommandLineFlagInfo("segmentSize", &info) && !info.is_default) { - DefaultSegmentSize = FLAGS_segmentSize; + conf->SetUInt64Value( + "mds.curvefs.defaultSegmentSize", FLAGS_segmentSize); } if (GetCommandLineFlagInfo("minFileLength", &info) && !info.is_default) { - kMiniFileLength = FLAGS_minFileLength; + conf->SetUInt64Value("mds.curvefs.minFileLength", FLAGS_minFileLength); + } + + if (GetCommandLineFlagInfo("maxFileLength", &info) && !info.is_default) { + conf->SetUInt64Value("mds.curvefs.maxFileLength", FLAGS_maxFileLength); } if (GetCommandLineFlagInfo("mdsDbName", &info) && !info.is_default) { diff --git a/src/mds/nameserver2/curvefs.cpp b/src/mds/nameserver2/curvefs.cpp index 76cb82b4d6..09939ac276 100644 --- a/src/mds/nameserver2/curvefs.cpp +++ b/src/mds/nameserver2/curvefs.cpp @@ -101,6 +101,9 @@ bool CurveFS::Init(std::shared_ptr storage, rootAuthOptions_ = curveFSOptions.authOptions; defaultChunkSize_ = curveFSOptions.defaultChunkSize; + defaultSegmentSize_ = curveFSOptions.defaultSegmentSize; + minFileLength_ = curveFSOptions.minFileLength; + maxFileLength_ = curveFSOptions.maxFileLength; topology_ = topology; InitRootFile(); @@ -221,24 +224,24 @@ StatusCode CurveFS::CreateFile(const std::string & fileName, // check param if (filetype == FileType::INODE_PAGEFILE) { - if (length < kMiniFileLength) { - LOG(ERROR) << "file Length < MinFileLength " << kMiniFileLength + if (length < minFileLength_) { + LOG(ERROR) << "file Length < MinFileLength " << minFileLength_ << ", length = " << length; return StatusCode::kFileLengthNotSupported; } - if (length > kMaxFileLength) { + if (length > maxFileLength_) { LOG(ERROR) << "CreateFile file length > maxFileLength, fileName = " << fileName << ", length = " << length - << ", maxFileLength = " << kMaxFileLength; + << ", maxFileLength = " << maxFileLength_; return StatusCode::kFileLengthNotSupported; } - if (length % DefaultSegmentSize != 0) { + if (length % defaultSegmentSize_ != 0) { LOG(ERROR) << "Create file length not align to segment size, " << "fileName = " << fileName << ", length = " << length - << ", segment size = " << DefaultSegmentSize; + << ", segment size = " << defaultSegmentSize_; return StatusCode::kFileLengthNotSupported; } } @@ -272,7 +275,7 @@ StatusCode CurveFS::CreateFile(const std::string & fileName, fileInfo.set_filetype(filetype); fileInfo.set_owner(owner); fileInfo.set_chunksize(defaultChunkSize_); - fileInfo.set_segmentsize(DefaultSegmentSize); + fileInfo.set_segmentsize(defaultSegmentSize_); fileInfo.set_length(length); fileInfo.set_ctime(::curve::common::TimeUtility::GetTimeofDayUs()); fileInfo.set_seqnum(kStartSeqNum); @@ -849,10 +852,10 @@ StatusCode CurveFS::ExtendFile(const std::string &filename, return StatusCode::kNotSupported; } - if (newLength > kMaxFileLength) { + if (newLength > maxFileLength_) { LOG(ERROR) << "ExtendFile newLength > maxFileLength, fileName = " << filename << ", newLength = " << newLength - << ", maxFileLength = " << kMaxFileLength; + << ", maxFileLength = " << maxFileLength_; return StatusCode::kFileLengthNotSupported; } @@ -1437,9 +1440,9 @@ StatusCode CurveFS::CreateCloneFile(const std::string &fileName, return StatusCode::kParaError; } - if (length < kMiniFileLength || seq < kStartSeqNum) { + if (length < minFileLength_ || seq < kStartSeqNum) { LOG(WARNING) << "CreateCloneFile err, filename = " << fileName - << "file Length < MinFileLength " << kMiniFileLength + << "file Length < MinFileLength " << minFileLength_ << ", length = " << length; return StatusCode::kParaError; } @@ -1480,7 +1483,7 @@ StatusCode CurveFS::CreateCloneFile(const std::string &fileName, fileInfo.set_owner(owner); fileInfo.set_chunksize(chunksize); - fileInfo.set_segmentsize(DefaultSegmentSize); + fileInfo.set_segmentsize(defaultSegmentSize_); fileInfo.set_length(length); fileInfo.set_ctime(::curve::common::TimeUtility::GetTimeofDayUs()); @@ -1910,6 +1913,18 @@ uint64_t CurveFS::GetDefaultChunkSize() { return defaultChunkSize_; } +uint64_t CurveFS::GetDefaultSegmentSize() { + return defaultSegmentSize_; +} + +uint64_t CurveFS::GetMinFileLength() { + return minFileLength_; +} + +uint64_t CurveFS::GetMaxFileLength() { + return maxFileLength_; +} + CurveFS &kCurveFS = CurveFS::GetInstance(); uint64_t GetOpenFileNum(void *varg) { diff --git a/src/mds/nameserver2/curvefs.h b/src/mds/nameserver2/curvefs.h index d49dcc6b16..9ccadc0dba 100644 --- a/src/mds/nameserver2/curvefs.h +++ b/src/mds/nameserver2/curvefs.h @@ -52,6 +52,9 @@ struct RootAuthOption { struct CurveFSOption { uint64_t defaultChunkSize; + uint64_t defaultSegmentSize; + uint64_t minFileLength; + uint64_t maxFileLength; RootAuthOption authOptions; FileRecordOptions fileRecordOptions; }; @@ -466,6 +469,27 @@ class CurveFS { */ uint64_t GetDefaultChunkSize(); + /** + * @brief get the defaultSegmentSize info of curvefs + * @param: + * @return return defaultSegmentSize info obtained + */ + uint64_t GetDefaultSegmentSize(); + + /** + * @brief get the minFileLength info of curvefs + * @param: + * @return return minFileLength info obtained + */ + uint64_t GetMinFileLength(); + + /** + * @brief get the maxFileLength info of curvefs + * @param: + * @return return maxFileLength info obtained + */ + uint64_t GetMaxFileLength(); + private: CurveFS() = default; @@ -628,6 +652,9 @@ class CurveFS { struct RootAuthOption rootAuthOptions_; uint64_t defaultChunkSize_; + uint64_t defaultSegmentSize_; + uint64_t minFileLength_; + uint64_t maxFileLength_; std::chrono::steady_clock::time_point startTime_; }; extern CurveFS &kCurveFS; diff --git a/src/mds/server/mds.cpp b/src/mds/server/mds.cpp index 48a7beecce..19f069d1be 100644 --- a/src/mds/server/mds.cpp +++ b/src/mds/server/mds.cpp @@ -458,6 +458,12 @@ void MDS::InitAuthOptions(RootAuthOption *authOptions) { void MDS::InitCurveFSOptions(CurveFSOption *curveFSOptions) { conf_->GetValueFatalIfFail( "mds.curvefs.defaultChunkSize", &curveFSOptions->defaultChunkSize); + conf_->GetValueFatalIfFail( + "mds.curvefs.defaultSegmentSize", &curveFSOptions->defaultSegmentSize); + conf_->GetValueFatalIfFail( + "mds.curvefs.minFileLength", &curveFSOptions->minFileLength); + conf_->GetValueFatalIfFail( + "mds.curvefs.maxFileLength", &curveFSOptions->maxFileLength); FileRecordOptions fileRecordOptions; InitFileRecordOptions(&curveFSOptions->fileRecordOptions); diff --git a/test/mds/nameserver2/chunk_allocator_test.cpp b/test/mds/nameserver2/chunk_allocator_test.cpp index 680a8eb05c..780cb090d9 100644 --- a/test/mds/nameserver2/chunk_allocator_test.cpp +++ b/test/mds/nameserver2/chunk_allocator_test.cpp @@ -40,6 +40,7 @@ namespace curve { namespace mds { const uint64_t DefaultChunkSize = 16 * kMB; +const uint64_t DefaultSegmentSize = kGB * 1; class ChunkAllocatorTest: public ::testing::Test { protected: diff --git a/test/mds/nameserver2/clean_core_test.cpp b/test/mds/nameserver2/clean_core_test.cpp index 47cefd8595..a3831307ea 100644 --- a/test/mds/nameserver2/clean_core_test.cpp +++ b/test/mds/nameserver2/clean_core_test.cpp @@ -37,6 +37,9 @@ using ::curve::mds::chunkserverclient::ChunkServerClientOption; namespace curve { namespace mds { +const uint64_t DefaultSegmentSize = kGB * 1; +const uint64_t kMiniFileLength = 10 * kGB; + TEST(CleanCore, testcleansnapshotfile) { auto storage = std::make_shared(); auto topology = std::make_shared(); diff --git a/test/mds/nameserver2/curvefs_test.cpp b/test/mds/nameserver2/curvefs_test.cpp index 7e60185f04..f93f01c367 100644 --- a/test/mds/nameserver2/curvefs_test.cpp +++ b/test/mds/nameserver2/curvefs_test.cpp @@ -70,6 +70,9 @@ class CurveFSTest: public ::testing::Test { authOptions_.rootPassword = "root_password"; curveFSOptions_.defaultChunkSize = 16 * kMB; + curveFSOptions_.defaultSegmentSize = 1 * kGB; + curveFSOptions_.minFileLength = 10 * kGB; + curveFSOptions_.maxFileLength = 20 * kTB; curveFSOptions_.authOptions = authOptions_; curveFSOptions_.fileRecordOptions = fileRecordOptions_; @@ -93,6 +96,9 @@ class CurveFSTest: public ::testing::Test { allocStatistic_, curveFSOptions_, topology_); + DefaultSegmentSize = curvefs_->GetDefaultSegmentSize(); + kMiniFileLength = curvefs_->GetMinFileLength(); + kMaxFileLength = curvefs_->GetMaxFileLength(); curvefs_->Run(); } @@ -112,6 +118,9 @@ class CurveFSTest: public ::testing::Test { struct FileRecordOptions fileRecordOptions_; struct RootAuthOption authOptions_; struct CurveFSOption curveFSOptions_; + uint64_t DefaultSegmentSize; + uint64_t kMiniFileLength; + uint64_t kMaxFileLength; }; TEST_F(CurveFSTest, testCreateFile1) { diff --git a/test/mds/nameserver2/namespace_service_test.cpp b/test/mds/nameserver2/namespace_service_test.cpp index 11befe1b64..20651174b7 100644 --- a/test/mds/nameserver2/namespace_service_test.cpp +++ b/test/mds/nameserver2/namespace_service_test.cpp @@ -95,6 +95,9 @@ class NameSpaceServiceTest : public ::testing::Test { authOptions.rootPassword = "root_password"; curveFSOptions.defaultChunkSize = 16 * kMB; + curveFSOptions.defaultSegmentSize = 1 * kGB; + curveFSOptions.minFileLength = 10 * kGB; + curveFSOptions.maxFileLength = 20 * kTB; curveFSOptions.fileRecordOptions = fileRecordOptions; curveFSOptions.authOptions = authOptions; @@ -103,6 +106,16 @@ class NameSpaceServiceTest : public ::testing::Test { fileRecordManager_, allocStatistic_, curveFSOptions, topology_); + + ASSERT_EQ(curveFSOptions.defaultChunkSize, + kCurveFS.GetDefaultChunkSize()); + ASSERT_EQ(curveFSOptions.defaultSegmentSize, + kCurveFS.GetDefaultSegmentSize()); + ASSERT_EQ(curveFSOptions.minFileLength, kCurveFS.GetMinFileLength()); + ASSERT_EQ(curveFSOptions.maxFileLength, kCurveFS.GetMaxFileLength()); + DefaultSegmentSize = kCurveFS.GetDefaultSegmentSize(); + kMiniFileLength = kCurveFS.GetMinFileLength(); + kCurveFS.Run(); std::this_thread::sleep_for(std::chrono::microseconds( @@ -131,6 +144,8 @@ class NameSpaceServiceTest : public ::testing::Test { struct FileRecordOptions fileRecordOptions; struct RootAuthOption authOptions; struct CurveFSOption curveFSOptions; + uint64_t DefaultSegmentSize; + uint64_t kMiniFileLength; }; TEST_F(NameSpaceServiceTest, test1) { diff --git a/test/tools/mds_client_test.cpp b/test/tools/mds_client_test.cpp index ae64fad841..7393a9ef86 100644 --- a/test/tools/mds_client_test.cpp +++ b/test/tools/mds_client_test.cpp @@ -43,7 +43,6 @@ using curve::mds::topology::GetCopySetsInChunkServerResponse; using curve::mds::schedule::RapidLeaderScheduleResponse; using curve::mds::schedule::QueryChunkServerRecoverStatusRequest; using curve::mds::schedule::QueryChunkServerRecoverStatusResponse; -using curve::mds::DefaultSegmentSize; using ::testing::_; using ::testing::Return; @@ -196,6 +195,7 @@ class ToolMDSClientTest : public ::testing::Test { curve::mds::schedule::MockScheduleService* scheduleService; MDSClient mdsClient; const uint64_t kChunkSize = 16777216; + const uint64_t DefaultSegmentSize = 1024 * 1024 * 1024; }; TEST(MDSClientInitTest, Init) { diff --git a/test/tools/status_tool_test.cpp b/test/tools/status_tool_test.cpp index ec8ff0d5dd..3693c600dd 100644 --- a/test/tools/status_tool_test.cpp +++ b/test/tools/status_tool_test.cpp @@ -37,7 +37,6 @@ using ::testing::SetArgPointee; using ::testing::An; using curve::mds::topology::LogicalPoolType; using curve::mds::topology::AllocateStatus; -using curve::mds::DefaultSegmentSize; DECLARE_bool(offline); DECLARE_bool(unhealthy); @@ -133,6 +132,7 @@ class StatusToolTest : public ::testing::Test { std::shared_ptr versionTool_; std::shared_ptr metricClient_; std::shared_ptr snapshotClient_; + const uint64_t DefaultSegmentSize = 1024 * 1024 * 1024; }; TEST_F(StatusToolTest, InitAndSupportCommand) { @@ -281,7 +281,7 @@ TEST_F(StatusToolTest, SpaceCmd) { Return(0))); EXPECT_CALL(*mdsClient_, GetMetric(_, _)) .WillOnce(Return(-1)) - .WillOnce(DoAll(SetArgPointee<1>(300 * curve::mds::DefaultSegmentSize), + .WillOnce(DoAll(SetArgPointee<1>(300 * DefaultSegmentSize), Return(0))) .WillOnce(Return(-1)); ASSERT_EQ(-1, statusTool.RunCommand("space")); @@ -294,7 +294,7 @@ TEST_F(StatusToolTest, SpaceCmd) { Return(0))); EXPECT_CALL(*mdsClient_, GetFileSize(_, _)) .Times(1) - .WillOnce(DoAll(SetArgPointee<1>(150 * curve::mds::DefaultSegmentSize), + .WillOnce(DoAll(SetArgPointee<1>(150 * DefaultSegmentSize), Return(0))); EXPECT_CALL(*mdsClient_, GetMetric(_, _)) .Times(4) @@ -468,7 +468,7 @@ TEST_F(StatusToolTest, StatusCmdCommon) { Return(0))); EXPECT_CALL(*mdsClient_, GetFileSize(_, _)) .Times(1) - .WillOnce(DoAll(SetArgPointee<1>(150 * curve::mds::DefaultSegmentSize), + .WillOnce(DoAll(SetArgPointee<1>(150 * DefaultSegmentSize), Return(0))); EXPECT_CALL(*mdsClient_, GetMetric(_, _)) .Times(4) @@ -482,7 +482,7 @@ TEST_F(StatusToolTest, StatusCmdCommon) { Return(0))); EXPECT_CALL(*mdsClient_, GetAllocatedSize(_, _, _)) .Times(1) - .WillOnce(DoAll(SetArgPointee<1>(10 * curve::mds::DefaultSegmentSize), + .WillOnce(DoAll(SetArgPointee<1>(10 * DefaultSegmentSize), Return(0))); // 设置client status的输出