Skip to content

Commit 895e6ba

Browse files
jolly-sywu-hanqing
authored andcommitted
curvebs: curve_ops_tool support create stripe volume
Signed-off-by: jolly-sy <[email protected]>
1 parent 25529b5 commit 895e6ba

11 files changed

+44
-98
lines changed

src/tools/createtool.cpp

-80
This file was deleted.

src/tools/mds_client.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,15 @@ int MDSClient::DeleteFile(const std::string& fileName, bool forcedelete) {
271271
return -1;
272272
}
273273

274-
int MDSClient::CreateFile(const std::string& fileName, uint64_t length) {
274+
int MDSClient::CreateFile(const std::string& fileName, uint64_t length,
275+
uint64_t stripeUnit, uint64_t stripeCount) {
275276
curve::mds::CreateFileRequest request;
276277
curve::mds::CreateFileResponse response;
277278
request.set_filename(fileName);
278279
request.set_filetype(curve::mds::FileType::INODE_PAGEFILE);
279280
request.set_filelength(length);
281+
request.set_stripeunit(stripeUnit);
282+
request.set_stripecount(stripeCount);
280283
FillUserInfo(&request);
281284
curve::mds::CurveFSService_Stub stub(&channel_);
282285

src/tools/mds_client.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,12 @@ class MDSClient {
170170
* @brief 创建pageFile文件
171171
* @param fileName 文件名
172172
* @param length 文件长度
173+
* @param stripeUnit stripe unit size
174+
* @param stripeCount the amount of stripes
173175
* @return 成功返回0,失败返回-1
174176
*/
175-
virtual int CreateFile(const std::string& fileName, uint64_t length);
177+
virtual int CreateFile(const std::string& fileName, uint64_t length,
178+
uint64_t stripeUnit, uint64_t stripeCount);
176179

177180
/**
178181
* @brief List all volumes on copysets

src/tools/namespace_tool.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ DEFINE_string(throttleType, "", "throttle type");
4040
DEFINE_uint64(limit, 0, "throttle limit");
4141
DEFINE_int64(burst, -1, "throttle burst");
4242
DEFINE_int64(burstLength, -1, "throttle burst length");
43+
DEFINE_uint64(stripeUnit, 0, "stripe unit size");
44+
DEFINE_uint64(stripeCount, 0, "strip count");
4345

4446
namespace curve {
4547
namespace tool {
@@ -118,7 +120,8 @@ int NameSpaceTool::RunCommand(const std::string &cmd) {
118120
return 0;
119121
}
120122
} else if (cmd == kCreateCmd) {
121-
return core_->CreateFile(fileName, FLAGS_fileLength * mds::kGB);
123+
return core_->CreateFile(fileName, FLAGS_fileLength * mds::kGB,
124+
FLAGS_stripeUnit, FLAGS_stripeCount);
122125
} else if (cmd == kChunkLocatitonCmd) {
123126
return PrintChunkLocation(fileName, FLAGS_offset);
124127
} else if (cmd == kUpdateThrottle) {
@@ -143,7 +146,7 @@ void NameSpaceTool::PrintHelp(const std::string &cmd) {
143146
std::cout << "If -fileName is specified, delete the files in recyclebin that the original directory is fileName" << std::endl; // NOLINT
144147
std::cout << "expireTime: s=second, m=minute, h=hour, d=day, M=month, y=year" << std::endl; // NOLINT
145148
} else if (cmd == kCreateCmd) {
146-
std::cout << "curve_ops_tool " << cmd << " -fileName=/test -userName=test -password=123 -fileLength=20 [-mdsAddr=127.0.0.1:6666] [-confPath=/etc/curve/tools.conf]" << std::endl; // NOLINT
149+
std::cout << "curve_ops_tool " << cmd << " -fileName=/test -userName=test -password=123 -filelength=20 -stripeUnit=32768 -stripeCount=32 [-mdsAddr=127.0.0.1:6666] [-confPath=/etc/curve/tools.conf]" << std::endl; // NOLINT
147150
} else if (cmd == kDeleteCmd) {
148151
std::cout << "curve_ops_tool " << cmd << " -fileName=/test -userName=test -password=123 -forcedelete=true [-mdsAddr=127.0.0.1:6666] [-confPath=/etc/curve/tools.conf]" << std::endl; // NOLINT
149152
} else if (cmd == kChunkLocatitonCmd) {

src/tools/namespace_tool_core.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,11 @@ int NameSpaceToolCore::DeleteFile(const std::string& fileName,
6161
}
6262

6363
int NameSpaceToolCore::CreateFile(const std::string& fileName,
64-
uint64_t length) {
65-
return client_->CreateFile(fileName, length);
64+
uint64_t length,
65+
uint64_t stripeUnit,
66+
uint64_t stripeCount) {
67+
return client_->CreateFile(fileName, length,
68+
stripeUnit, stripeCount);
6669
}
6770

6871
int NameSpaceToolCore::GetAllocatedSize(const std::string& fileName,

src/tools/namespace_tool_core.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,12 @@ class NameSpaceToolCore {
105105
* @brief 创建pageFile文件
106106
* @param fileName 文件名
107107
* @param length 文件长度
108+
* @param stripeUnit stripe unit size
109+
* @param stripeCount the amount of stripes
108110
* @return 成功返回0,失败返回-1
109111
*/
110-
virtual int CreateFile(const std::string& fileName, uint64_t length);
112+
virtual int CreateFile(const std::string& fileName, uint64_t length,
113+
uint64_t stripeUnit, uint64_t stripeCount);
111114

112115
/**
113116
* @brief 计算文件或目录实际分配的空间

test/tools/mds_client_test.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,8 @@ TEST_F(ToolMDSClientTest, DeleteFile) {
504504
TEST_F(ToolMDSClientTest, CreateFile) {
505505
std::string fileName = "/test";
506506
uint64_t length = 10 * DefaultSegmentSize;
507+
uint64_t stripeUnit = 32 * 1024 *1024;
508+
uint64_t stripeCount = 32;
507509

508510
// 发送RPC失败
509511
EXPECT_CALL(*nameService, CreateFile(_, _, _, _))
@@ -517,7 +519,8 @@ TEST_F(ToolMDSClientTest, CreateFile) {
517519
dynamic_cast<brpc::Controller *>(controller);
518520
cntl->SetFailed("test");
519521
}));
520-
ASSERT_EQ(-1, mdsClient.CreateFile(fileName, length));
522+
ASSERT_EQ(-1, mdsClient.CreateFile(fileName, length,
523+
stripeUnit, stripeCount));
521524

522525
// 返回码不为OK
523526
curve::mds::CreateFileResponse response;
@@ -530,7 +533,8 @@ TEST_F(ToolMDSClientTest, CreateFile) {
530533
Closure *done){
531534
brpc::ClosureGuard doneGuard(done);
532535
})));
533-
ASSERT_EQ(-1, mdsClient.CreateFile(fileName, length));
536+
ASSERT_EQ(-1, mdsClient.CreateFile(fileName, length,
537+
stripeUnit, stripeCount));
534538

535539
// 正常情况
536540
response.set_statuscode(curve::mds::StatusCode::kOK);
@@ -542,7 +546,8 @@ TEST_F(ToolMDSClientTest, CreateFile) {
542546
Closure *done){
543547
brpc::ClosureGuard doneGuard(done);
544548
})));
545-
ASSERT_EQ(0, mdsClient.CreateFile(fileName, length));
549+
ASSERT_EQ(0, mdsClient.CreateFile(fileName, length,
550+
stripeUnit, stripeCount));
546551
}
547552

548553
TEST_F(ToolMDSClientTest, GetChunkServerListInCopySets) {

test/tools/mock/mock_mds_client.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class MockMDSClient : public MDSClient {
4848
MOCK_METHOD3(GetSegmentInfo, GetSegmentRes(const std::string&,
4949
uint64_t, PageFileSegment*));
5050
MOCK_METHOD2(DeleteFile, int(const std::string&, bool));
51-
MOCK_METHOD2(CreateFile, int(const std::string&, uint64_t));
51+
MOCK_METHOD4(CreateFile, int(const std::string&, uint64_t,
52+
uint64_t, uint64_t));
5253
MOCK_METHOD3(GetChunkServerListInCopySet, int(const PoolIdType&,
5354
const CopySetIdType&, std::vector<ChunkServerLocation>*));
5455
MOCK_METHOD3(GetChunkServerListInCopySets, int(const PoolIdType&,

test/tools/mock/mock_namespace_tool_core.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class MockNameSpaceToolCore : public NameSpaceToolCore {
4747
const CopySetIdType&,
4848
std::vector<ChunkServerLocation>*));
4949
MOCK_METHOD2(DeleteFile, int(const std::string&, bool));
50-
MOCK_METHOD2(CreateFile, int(const std::string&, uint64_t));
50+
MOCK_METHOD4(CreateFile, int(const std::string&, uint64_t,
51+
uint64_t, uint64_t));
5152
MOCK_METHOD3(GetAllocatedSize, int(const std::string&,
5253
uint64_t*, AllocMap*));
5354
MOCK_METHOD2(GetFileSegments, int(const std::string&,

test/tools/namespace_tool_core_test.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,22 @@ TEST_F(NameSpaceToolCoreTest, CreateFile) {
139139
curve::tool::NameSpaceToolCore namespaceTool(client_);
140140
std::string fileName = "/test";
141141
uint64_t length = 5 * segmentSize;
142+
uint64_t stripeUnit = 32 * 1024 *1024;
143+
uint64_t stripeCount = 32;
142144

143145
// 1、正常情况
144-
EXPECT_CALL(*client_, CreateFile(_, _))
146+
EXPECT_CALL(*client_, CreateFile(_, _, _, _))
145147
.Times(1)
146148
.WillOnce(Return(0));
147-
ASSERT_EQ(0, namespaceTool.CreateFile(fileName, length));
149+
ASSERT_EQ(0, namespaceTool.CreateFile(fileName, length,
150+
stripeUnit, stripeCount));
148151

149152
// 2、创建失败
150-
EXPECT_CALL(*client_, CreateFile(_, _))
153+
EXPECT_CALL(*client_, CreateFile(_, _, _, _))
151154
.Times(1)
152155
.WillOnce(Return(-1));
153-
ASSERT_EQ(-1, namespaceTool.CreateFile(fileName, length));
156+
ASSERT_EQ(-1, namespaceTool.CreateFile(fileName, length,
157+
stripeUnit, stripeCount));
154158
}
155159

156160
TEST_F(NameSpaceToolCoreTest, DeleteFile) {

test/tools/namespace_tool_test.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,13 @@ TEST_F(NameSpaceToolTest, CreateFile) {
298298
.WillOnce(Return(0));
299299

300300
// 1、正常情况
301-
EXPECT_CALL(*core_, CreateFile(_, _))
301+
EXPECT_CALL(*core_, CreateFile(_, _, _, _))
302302
.Times(1)
303303
.WillOnce(Return(0));
304304
ASSERT_EQ(0, namespaceTool.RunCommand("create"));
305305

306306
// 2、创建失败
307-
EXPECT_CALL(*core_, CreateFile(_, _))
307+
EXPECT_CALL(*core_, CreateFile(_, _, _, _))
308308
.Times(1)
309309
.WillOnce(Return(-1));
310310
ASSERT_EQ(-1, namespaceTool.RunCommand("create"));

0 commit comments

Comments
 (0)