Skip to content

Commit

Permalink
curvebs: curve_ops_tool support create stripe volume
Browse files Browse the repository at this point in the history
Signed-off-by: jolly-sy <757050468@qq.com>
  • Loading branch information
jolly-sy authored and ilixiaocui committed Nov 4, 2022
1 parent cb7c2dd commit 72cb758
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 120 deletions.
22 changes: 0 additions & 22 deletions src/tools/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,6 @@ COPTS = [
"-std=c++11",
]

cc_test(
name = "createFile",
srcs = ["createtool.cpp"],
copts = COPTS,
visibility = ["//visibility:public"],
deps = [
"//external:braft",
"//external:brpc",
"//external:gflags",
"//external:glog",
"//external:leveldb",
"//external:protobuf",
"//include/client:include_client",
"//proto:chunkserver-cc-protos",
"//proto:nameserver2_cc_proto",
"//src/client:curve_client",
"//src/common:curve_common",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main",
],
)

cc_binary(
name = "curve_format",
srcs = [
Expand Down
80 changes: 0 additions & 80 deletions src/tools/createtool.cpp

This file was deleted.

5 changes: 4 additions & 1 deletion src/tools/mds_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,15 @@ int MDSClient::DeleteFile(const std::string& fileName, bool forcedelete) {
return -1;
}

int MDSClient::CreateFile(const std::string& fileName, uint64_t length) {
int MDSClient::CreateFile(const std::string& fileName, uint64_t length,
uint64_t stripeUnit, uint64_t stripeCount) {
curve::mds::CreateFileRequest request;
curve::mds::CreateFileResponse response;
request.set_filename(fileName);
request.set_filetype(curve::mds::FileType::INODE_PAGEFILE);
request.set_filelength(length);
request.set_stripeunit(stripeUnit);
request.set_stripecount(stripeCount);
FillUserInfo(&request);
curve::mds::CurveFSService_Stub stub(&channel_);

Expand Down
5 changes: 4 additions & 1 deletion src/tools/mds_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,12 @@ class MDSClient {
* @brief 创建pageFile文件
* @param fileName 文件名
* @param length 文件长度
* @param stripeUnit stripe unit size
* @param stripeCount the amount of stripes
* @return 成功返回0,失败返回-1
*/
virtual int CreateFile(const std::string& fileName, uint64_t length);
virtual int CreateFile(const std::string& fileName, uint64_t length,
uint64_t stripeUnit, uint64_t stripeCount);

/**
* @brief List all volumes on copysets
Expand Down
8 changes: 6 additions & 2 deletions src/tools/namespace_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ DECLARE_string(mdsAddr);
DEFINE_bool(showAllocMap, false, "If specified, the allocated size in each"
" logical pool will be print");

DEFINE_uint64(stripeUnit, 0, "stripe unit size");
DEFINE_uint64(stripeCount, 0, "strip count");

namespace curve {
namespace tool {

Expand Down Expand Up @@ -104,8 +107,9 @@ int NameSpaceTool::RunCommand(const std::string &cmd) {
return 0;
}
} else if (cmd == kCreateCmd) {
return core_->CreateFile(fileName, FLAGS_fileLength * mds::kGB);
} else if (cmd == kExtendCmd) {
return core_->CreateFile(fileName, FLAGS_fileLength * mds::kGB,
FLAGS_stripeUnit, FLAGS_stripeCount);
} else if (cmd == kExtendCmd) {
return core_->ExtendVolume(fileName, FLAGS_newSize * mds::kGB);
} else if (cmd == kChunkLocatitonCmd) {
return PrintChunkLocation(fileName, FLAGS_offset);
Expand Down
7 changes: 5 additions & 2 deletions src/tools/namespace_tool_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ int NameSpaceToolCore::DeleteFile(const std::string& fileName,
}

int NameSpaceToolCore::CreateFile(const std::string& fileName,
uint64_t length) {
return client_->CreateFile(fileName, length);
uint64_t length,
uint64_t stripeUnit,
uint64_t stripeCount) {
return client_->CreateFile(fileName, length,
stripeUnit, stripeCount);
}
int NameSpaceToolCore::ExtendVolume(const std::string& fileName,
uint64_t newSize) {
Expand Down
5 changes: 4 additions & 1 deletion src/tools/namespace_tool_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,12 @@ class NameSpaceToolCore {
* @brief 创建pageFile文件
* @param fileName 文件名
* @param length 文件长度
* @param stripeUnit stripe unit size
* @param stripeCount the amount of stripes
* @return 成功返回0,失败返回-1
*/
virtual int CreateFile(const std::string& fileName, uint64_t length);
virtual int CreateFile(const std::string& fileName, uint64_t length,
uint64_t stripeUnit, uint64_t stripeCount);

/**
* @brief 扩容卷
Expand Down
9 changes: 6 additions & 3 deletions test/tools/mds_client_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ TEST_F(ToolMDSClientTest, CreateFile) {
dynamic_cast<brpc::Controller *>(controller);
cntl->SetFailed("test");
}));
ASSERT_EQ(-1, mdsClient.CreateFile(fileName, length));
ASSERT_EQ(-1, mdsClient.CreateFile(fileName, length,
stripeUnit, stripeCount));

// 返回码不为OK
curve::mds::CreateFileResponse response;
Expand All @@ -515,7 +516,8 @@ TEST_F(ToolMDSClientTest, CreateFile) {
Closure *done){
brpc::ClosureGuard doneGuard(done);
})));
ASSERT_EQ(-1, mdsClient.CreateFile(fileName, length));
ASSERT_EQ(-1, mdsClient.CreateFile(fileName, length,
stripeUnit, stripeCount));

// 正常情况
response.set_statuscode(curve::mds::StatusCode::kOK);
Expand All @@ -527,7 +529,8 @@ TEST_F(ToolMDSClientTest, CreateFile) {
Closure *done){
brpc::ClosureGuard doneGuard(done);
})));
ASSERT_EQ(0, mdsClient.CreateFile(fileName, length));
ASSERT_EQ(0, mdsClient.CreateFile(fileName, length,
stripeUnit, stripeCount));
}

TEST_F(ToolMDSClientTest, ExtendVolume_success) {
Expand Down
3 changes: 2 additions & 1 deletion test/tools/mock/mock_mds_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ class MockMDSClient : public MDSClient {
MOCK_METHOD3(GetSegmentInfo, GetSegmentRes(const std::string&,
uint64_t, PageFileSegment*));
MOCK_METHOD2(DeleteFile, int(const std::string&, bool));
MOCK_METHOD2(CreateFile, int(const std::string&, uint64_t));
MOCK_METHOD2(ExtendVolume, int(const std::string&, uint64_t));
MOCK_METHOD4(CreateFile, int(const std::string&, uint64_t,
uint64_t, uint64_t));
MOCK_METHOD3(GetChunkServerListInCopySet, int(const PoolIdType&,
const CopySetIdType&, std::vector<ChunkServerLocation>*));
MOCK_METHOD3(GetChunkServerListInCopySets, int(const PoolIdType&,
Expand Down
3 changes: 2 additions & 1 deletion test/tools/mock/mock_namespace_tool_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class MockNameSpaceToolCore : public NameSpaceToolCore {
const CopySetIdType&,
std::vector<ChunkServerLocation>*));
MOCK_METHOD2(DeleteFile, int(const std::string&, bool));
MOCK_METHOD2(CreateFile, int(const std::string&, uint64_t));
MOCK_METHOD4(CreateFile, int(const std::string&, uint64_t,
uint64_t, uint64_t));
MOCK_METHOD3(GetAllocatedSize, int(const std::string&,
uint64_t*, AllocMap*));
MOCK_METHOD2(GetFileSegments, int(const std::string&,
Expand Down
12 changes: 8 additions & 4 deletions test/tools/namespace_tool_core_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,22 @@ TEST_F(NameSpaceToolCoreTest, CreateFile) {
curve::tool::NameSpaceToolCore namespaceTool(client_);
std::string fileName = "/test";
uint64_t length = 5 * segmentSize;
uint64_t stripeUnit = 32 * 1024 *1024;
uint64_t stripeCount = 32;

// 1、正常情况
EXPECT_CALL(*client_, CreateFile(_, _))
EXPECT_CALL(*client_, CreateFile(_, _, _, _))
.Times(1)
.WillOnce(Return(0));
ASSERT_EQ(0, namespaceTool.CreateFile(fileName, length));
ASSERT_EQ(0, namespaceTool.CreateFile(fileName, length,
stripeUnit, stripeCount));

// 2、创建失败
EXPECT_CALL(*client_, CreateFile(_, _))
EXPECT_CALL(*client_, CreateFile(_, _, _, _))
.Times(1)
.WillOnce(Return(-1));
ASSERT_EQ(-1, namespaceTool.CreateFile(fileName, length));
ASSERT_EQ(-1, namespaceTool.CreateFile(fileName, length,
stripeUnit, stripeCount));
}

TEST_F(NameSpaceToolCoreTest, ExtendVolume) {
Expand Down
4 changes: 2 additions & 2 deletions test/tools/namespace_tool_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,13 @@ TEST_F(NameSpaceToolTest, CreateFile) {
.WillOnce(Return(0));

// 1、正常情况
EXPECT_CALL(*core_, CreateFile(_, _))
EXPECT_CALL(*core_, CreateFile(_, _, _, _))
.Times(1)
.WillOnce(Return(0));
ASSERT_EQ(0, namespaceTool.RunCommand("create"));

// 2、创建失败
EXPECT_CALL(*core_, CreateFile(_, _))
EXPECT_CALL(*core_, CreateFile(_, _, _, _))
.Times(1)
.WillOnce(Return(-1));
ASSERT_EQ(-1, namespaceTool.RunCommand("create"));
Expand Down

0 comments on commit 72cb758

Please sign in to comment.