From 72cb75823de68d8eeea18566bb4be67c78df82e2 Mon Sep 17 00:00:00 2001 From: jolly-sy <757050468@qq.com> Date: Fri, 14 Oct 2022 16:41:40 +0800 Subject: [PATCH] curvebs: curve_ops_tool support create stripe volume Signed-off-by: jolly-sy <757050468@qq.com> --- src/tools/BUILD | 22 ------ src/tools/createtool.cpp | 80 ---------------------- src/tools/mds_client.cpp | 5 +- src/tools/mds_client.h | 5 +- src/tools/namespace_tool.cpp | 8 ++- src/tools/namespace_tool_core.cpp | 7 +- src/tools/namespace_tool_core.h | 5 +- test/tools/mds_client_test.cpp | 9 ++- test/tools/mock/mock_mds_client.h | 3 +- test/tools/mock/mock_namespace_tool_core.h | 3 +- test/tools/namespace_tool_core_test.cpp | 12 ++-- test/tools/namespace_tool_test.cpp | 4 +- 12 files changed, 43 insertions(+), 120 deletions(-) delete mode 100644 src/tools/createtool.cpp diff --git a/src/tools/BUILD b/src/tools/BUILD index 6aa8dbe3df..dcf1a44ede 100644 --- a/src/tools/BUILD +++ b/src/tools/BUILD @@ -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 = [ diff --git a/src/tools/createtool.cpp b/src/tools/createtool.cpp deleted file mode 100644 index 7d90128bb7..0000000000 --- a/src/tools/createtool.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2020 NetEase Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Project: curve - * File Created: Wednesday, 3rd October 2018 5:08:08 pm - * Author: tongguangxun - */ - -#include -#include -#include - -#include "proto/nameserver2.pb.h" -#include "proto/topology.pb.h" - -#include "include/client/libcurve.h" -#include "src/client/client_common.h" - -DEFINE_string(mds_addr, "127.0.0.1:9000", "mds addr"); -DEFINE_string(file_name, "vdisk_001", "file name"); -DEFINE_uint64(file_size, 1 * 1024 * 1024 * 1024, "file size"); - -using curve::mds::CurveFSService; -using curve::mds::topology::TopologyService; - -int main(int argc, char** argv) { - google::InitGoogleLogging(argv[0]); - google::ParseCommandLineFlags(&argc, &argv, false); - - brpc::Channel channel; - if (channel.Init(FLAGS_mds_addr.c_str(), nullptr) != 0) { - LOG(FATAL) << "Init channel failed!"; - return LIBCURVE_ERROR::FAILED; - } - curve::mds::CurveFSService_Stub stub(&channel); - - // CreateFile - curve::mds::CreateFileRequest request; - curve::mds::CreateFileResponse response; - brpc::Controller cntl; - - request.set_filename(FLAGS_file_name); - request.set_filetype(curve::mds::FileType::INODE_PAGEFILE); - request.set_filelength(FLAGS_file_size); - - cntl.set_log_id(1); // TODO(tongguangxun) : specify the log id usage - stub.CreateFile(&cntl, &request, &response, NULL); - - if (cntl.Failed()) { - LOG(ERROR) << "Create file failed, errcorde = " - << response.statuscode() - << ", error content:" - << cntl.ErrorText(); - } - if (response.has_statuscode()) { - if (response.statuscode() == curve::mds::StatusCode::kFileExists) { - LOG(INFO) << "file already exists!"; - } else if (response.statuscode() == curve::mds::StatusCode::kOK) { - LOG(INFO) << "Create file success!"; - } else { - LOG(INFO) << "Create file failed, " - << cntl.ErrorText(); - } - } - return 0; -} diff --git a/src/tools/mds_client.cpp b/src/tools/mds_client.cpp index ff443b74c8..f31579096b 100644 --- a/src/tools/mds_client.cpp +++ b/src/tools/mds_client.cpp @@ -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_); diff --git a/src/tools/mds_client.h b/src/tools/mds_client.h index 9333cd4682..2af5d0c86b 100644 --- a/src/tools/mds_client.h +++ b/src/tools/mds_client.h @@ -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 diff --git a/src/tools/namespace_tool.cpp b/src/tools/namespace_tool.cpp index d4bbfd8916..a10b58e4d6 100644 --- a/src/tools/namespace_tool.cpp +++ b/src/tools/namespace_tool.cpp @@ -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 { @@ -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); diff --git a/src/tools/namespace_tool_core.cpp b/src/tools/namespace_tool_core.cpp index e1408e5f73..99615ce17d 100644 --- a/src/tools/namespace_tool_core.cpp +++ b/src/tools/namespace_tool_core.cpp @@ -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) { diff --git a/src/tools/namespace_tool_core.h b/src/tools/namespace_tool_core.h index 4ffb72cc92..6a89d281ac 100644 --- a/src/tools/namespace_tool_core.h +++ b/src/tools/namespace_tool_core.h @@ -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 扩容卷 diff --git a/test/tools/mds_client_test.cpp b/test/tools/mds_client_test.cpp index 13e62d0b2a..75342bb3e7 100644 --- a/test/tools/mds_client_test.cpp +++ b/test/tools/mds_client_test.cpp @@ -502,7 +502,8 @@ TEST_F(ToolMDSClientTest, CreateFile) { dynamic_cast(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; @@ -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); @@ -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) { diff --git a/test/tools/mock/mock_mds_client.h b/test/tools/mock/mock_mds_client.h index a5a4e8cc61..0d1bf37d2a 100644 --- a/test/tools/mock/mock_mds_client.h +++ b/test/tools/mock/mock_mds_client.h @@ -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*)); MOCK_METHOD3(GetChunkServerListInCopySets, int(const PoolIdType&, diff --git a/test/tools/mock/mock_namespace_tool_core.h b/test/tools/mock/mock_namespace_tool_core.h index e001d62eea..aa5357b64d 100644 --- a/test/tools/mock/mock_namespace_tool_core.h +++ b/test/tools/mock/mock_namespace_tool_core.h @@ -47,7 +47,8 @@ class MockNameSpaceToolCore : public NameSpaceToolCore { const CopySetIdType&, std::vector*)); 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&, diff --git a/test/tools/namespace_tool_core_test.cpp b/test/tools/namespace_tool_core_test.cpp index ebbbff5980..03ac5d600f 100644 --- a/test/tools/namespace_tool_core_test.cpp +++ b/test/tools/namespace_tool_core_test.cpp @@ -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) { diff --git a/test/tools/namespace_tool_test.cpp b/test/tools/namespace_tool_test.cpp index 464e528acb..069b533bc9 100644 --- a/test/tools/namespace_tool_test.cpp +++ b/test/tools/namespace_tool_test.cpp @@ -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"));