Skip to content

Commit

Permalink
change file param from hard code to config file
Browse files Browse the repository at this point in the history
  • Loading branch information
cw123 authored and ilixiaocui committed Apr 21, 2021
1 parent 9a39ffa commit ff12305
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 28 deletions.
6 changes: 6 additions & 0 deletions conf/mds.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions curve-ansible/roles/generate_config/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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配置默认值
Expand Down
6 changes: 6 additions & 0 deletions curve-ansible/roles/generate_config/templates/mds.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions src/mds/common/mds_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = "/";

Expand Down
15 changes: 10 additions & 5 deletions src/mds/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
39 changes: 27 additions & 12 deletions src/mds/nameserver2/curvefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ bool CurveFS::Init(std::shared_ptr<NameServerStorage> storage,
rootAuthOptions_ = curveFSOptions.authOptions;

defaultChunkSize_ = curveFSOptions.defaultChunkSize;
defaultSegmentSize_ = curveFSOptions.defaultSegmentSize;
minFileLength_ = curveFSOptions.minFileLength;
maxFileLength_ = curveFSOptions.maxFileLength;
topology_ = topology;

InitRootFile();
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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) {
Expand Down
27 changes: 27 additions & 0 deletions src/mds/nameserver2/curvefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ struct RootAuthOption {

struct CurveFSOption {
uint64_t defaultChunkSize;
uint64_t defaultSegmentSize;
uint64_t minFileLength;
uint64_t maxFileLength;
RootAuthOption authOptions;
FileRecordOptions fileRecordOptions;
};
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/mds/server/mds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions test/mds/nameserver2/chunk_allocator_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions test/mds/nameserver2/clean_core_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<MockNameServerStorage>();
auto topology = std::make_shared<MockTopology>();
Expand Down
9 changes: 9 additions & 0 deletions test/mds/nameserver2/curvefs_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;

Expand All @@ -93,6 +96,9 @@ class CurveFSTest: public ::testing::Test {
allocStatistic_,
curveFSOptions_,
topology_);
DefaultSegmentSize = curvefs_->GetDefaultSegmentSize();
kMiniFileLength = curvefs_->GetMinFileLength();
kMaxFileLength = curvefs_->GetMaxFileLength();
curvefs_->Run();
}

Expand All @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions test/mds/nameserver2/namespace_service_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/tools/mds_client_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions test/tools/status_tool_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -133,6 +132,7 @@ class StatusToolTest : public ::testing::Test {
std::shared_ptr<MockVersionTool> versionTool_;
std::shared_ptr<MockMetricClient> metricClient_;
std::shared_ptr<MockSnapshotCloneClient> snapshotClient_;
const uint64_t DefaultSegmentSize = 1024 * 1024 * 1024;
};

TEST_F(StatusToolTest, InitAndSupportCommand) {
Expand Down Expand Up @@ -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"));
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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的输出
Expand Down

0 comments on commit ff12305

Please sign in to comment.