diff --git a/proto/nameserver2.proto b/proto/nameserver2.proto index c94281ffdd..79c72f41de 100644 --- a/proto/nameserver2.proto +++ b/proto/nameserver2.proto @@ -439,7 +439,11 @@ message GetAllocatedSizeRequest { message GetAllocatedSizeResponse { required StatusCode statusCode = 1; + // 文件或目录的分配大小 optional uint64 allocatedSize = 2; + // 物理上分配的时间,因为对分配了1GB空间的文件来说 + // 如果是三副本,实际上相当于分配了3GB物理空间 + optional uint64 physicalAllocatedSize = 3; } message ClientInfo { diff --git a/src/mds/nameserver2/curvefs.cpp b/src/mds/nameserver2/curvefs.cpp index c80574a32c..c530b0f093 100644 --- a/src/mds/nameserver2/curvefs.cpp +++ b/src/mds/nameserver2/curvefs.cpp @@ -20,6 +20,7 @@ using curve::common::TimeUtility; using ::std::chrono::steady_clock; using ::std::chrono::microseconds; +using curve::mds::topology::LogicalPool; namespace curve { namespace mds { @@ -73,7 +74,8 @@ bool CurveFS::Init(std::shared_ptr storage, std::shared_ptr fileRecordManager, std::shared_ptr allocStatistic, const struct CurveFSOption &curveFSOptions, - std::shared_ptr repo) { + std::shared_ptr repo, + std::shared_ptr topology) { startTime_ = steady_clock::now(); storage_ = storage; InodeIDGenerator_ = InodeIDGenerator; @@ -85,6 +87,7 @@ bool CurveFS::Init(std::shared_ptr storage, defaultChunkSize_ = curveFSOptions.defaultChunkSize; repo_ = repo; + topology_ = topology; InitRootFile(); @@ -282,9 +285,17 @@ StatusCode CurveFS::GetFileInfo(const std::string & filename, } } +AllocatedSize& AllocatedSize::operator+=(const AllocatedSize& rhs) { + allocatedSize += rhs.allocatedSize; + physicalAllocatedSize += rhs.physicalAllocatedSize; + return *this; +} + StatusCode CurveFS::GetAllocatedSize(const std::string& fileName, - uint64_t* allocatedSize) { + AllocatedSize* allocatedSize) { assert(allocatedSize != nullptr); + allocatedSize->allocatedSize = 0; + allocatedSize->physicalAllocatedSize = 0; FileInfo fileInfo; auto ret = GetFileInfo(fileName, &fileInfo); if (ret != StatusCode::kOK) { @@ -303,8 +314,7 @@ StatusCode CurveFS::GetAllocatedSize(const std::string& fileName, StatusCode CurveFS::GetAllocatedSize(const std::string& fileName, const FileInfo& fileInfo, - uint64_t* allocSize) { - *allocSize = 0; + AllocatedSize* allocSize) { if (fileInfo.filetype() != curve::mds::FileType::INODE_DIRECTORY) { return GetFileAllocSize(fileName, fileInfo, allocSize); } else { // 如果是目录,则list dir,并递归计算每个文件的大小最后加起来 @@ -314,20 +324,32 @@ StatusCode CurveFS::GetAllocatedSize(const std::string& fileName, StatusCode CurveFS::GetFileAllocSize(const std::string& fileName, const FileInfo& fileInfo, - uint64_t* allocSize) { + AllocatedSize* allocSize) { std::vector segments; auto listSegmentRet = storage_->ListSegment(fileInfo.id(), &segments); if (listSegmentRet != StoreStatus::OK) { return StatusCode::kStorageError; } - *allocSize = fileInfo.segmentsize() * segments.size(); + for (const auto& segment : segments) { + const auto & logicPoolId = segment.logicalpoolid(); + LogicalPool logicPool; + if (!topology_->GetLogicalPool(logicPoolId, &logicPool)) { + LOG(ERROR) << "Get logical pool " << logicPoolId + << " from topology failed!"; + return StatusCode::KInternalError; + } + uint64_t replicasNum = logicPool.GetReplicaNum(); + allocSize->physicalAllocatedSize += + fileInfo.segmentsize() * replicasNum; + } + allocSize->allocatedSize = fileInfo.segmentsize() * segments.size(); return StatusCode::kOK; } StatusCode CurveFS::GetDirAllocSize(const std::string& fileName, const FileInfo& fileInfo, - uint64_t* allocSize) { + AllocatedSize* allocSize) { std::vector files; StatusCode ret = ReadDir(fileName, &files); if (ret != StatusCode::kOK) { @@ -341,7 +363,7 @@ StatusCode CurveFS::GetDirAllocSize(const std::string& fileName, } else { fullPathName = fileName + "/" + file.filename(); } - uint64_t size; + AllocatedSize size; if (GetAllocatedSize(fullPathName, file, &size) != 0) { std::cout << "Get allocated size of " << fullPathName << " fail!" << std::endl; diff --git a/src/mds/nameserver2/curvefs.h b/src/mds/nameserver2/curvefs.h index 5c8536899f..89940cfab8 100644 --- a/src/mds/nameserver2/curvefs.h +++ b/src/mds/nameserver2/curvefs.h @@ -41,6 +41,15 @@ struct CurveFSOption { FileRecordOptions fileRecordOptions; }; +struct AllocatedSize { + // mds给文件分配的segment的大小 + uint64_t allocatedSize; + // 实际会占用的底层空间 + uint64_t physicalAllocatedSize; + AllocatedSize() : allocatedSize(0), physicalAllocatedSize(0) {} + AllocatedSize& operator+=(const AllocatedSize& rhs); +}; + using ::curve::mds::DeleteSnapShotResponse; bool InitRecycleBinDir(std::shared_ptr storage); @@ -72,7 +81,8 @@ class CurveFS { std::shared_ptr fileRecordManager, std::shared_ptr allocStatistic, const struct CurveFSOption &curveFSOptions, - std::shared_ptr repo); + std::shared_ptr repo, + std::shared_ptr topology); /** * @brief Run session manager @@ -119,7 +129,7 @@ class CurveFS { * @return 是否成功,成功返回StatusCode::kOK */ StatusCode GetAllocatedSize(const std::string& fileName, - uint64_t* allocatedSize); + AllocatedSize* allocatedSize); /** * @brief 删除文件 @@ -536,7 +546,7 @@ class CurveFS { */ StatusCode GetAllocatedSize(const std::string& fileName, const FileInfo& fileInfo, - uint64_t* allocSize); + AllocatedSize* allocSize); /** * @brief 获取文件分配大小 @@ -547,7 +557,7 @@ class CurveFS { */ StatusCode GetFileAllocSize(const std::string& fileName, const FileInfo& fileInfo, - uint64_t* allocSize); + AllocatedSize* allocSize); /** * @brief 获取目录分配大小 @@ -558,7 +568,7 @@ class CurveFS { */ StatusCode GetDirAllocSize(const std::string& fileName, const FileInfo& fileInfo, - uint64_t* allocSize); + AllocatedSize* allocSize); private: FileInfo rootFileInfo_; @@ -568,6 +578,7 @@ class CurveFS { std::shared_ptr fileRecordManager_; std::shared_ptr cleanManager_; std::shared_ptr allocStatistic_; + std::shared_ptr topology_; struct RootAuthOption rootAuthOptions_; uint64_t defaultChunkSize_; diff --git a/src/mds/nameserver2/namespace_service.cpp b/src/mds/nameserver2/namespace_service.cpp index 02cd6c5a9e..7d50f73aec 100644 --- a/src/mds/nameserver2/namespace_service.cpp +++ b/src/mds/nameserver2/namespace_service.cpp @@ -1614,8 +1614,8 @@ void NameSpaceService::GetAllocatedSize( << ", GetAllocatedSize request, fileName = " << request->filename(); StatusCode retCode; - uint64_t allocatedSize; - retCode = kCurveFS.GetAllocatedSize(request->filename(), &allocatedSize); + AllocatedSize allocSize; + retCode = kCurveFS.GetAllocatedSize(request->filename(), &allocSize); if (retCode != StatusCode::kOK) { response->set_statuscode(retCode); LOG(ERROR) << "logid = " << cntl->log_id() @@ -1625,7 +1625,8 @@ void NameSpaceService::GetAllocatedSize( return; } else { response->set_statuscode(StatusCode::kOK); - response->set_allocatedsize(allocatedSize); + response->set_allocatedsize(allocSize.allocatedSize); + response->set_physicalallocatedsize(allocSize.physicalAllocatedSize); LOG(INFO) << "logid = " << cntl->log_id() << ", GetAllocatedSize ok, fileName = " << request->filename() << ", allocatedSize = " << response->allocatedsize() / kGB << "GB"; diff --git a/src/mds/server/mds.cpp b/src/mds/server/mds.cpp index a604c421df..198ed7a288 100644 --- a/src/mds/server/mds.cpp +++ b/src/mds/server/mds.cpp @@ -446,7 +446,7 @@ void MDS::InitCurveFS(const CurveFSOption& curveFSOptions) { chunkSegmentAllocate, cleanManager_, fileRecordManager, segmentAllocStatistic_, - curveFSOptions, mdsRepo_)) + curveFSOptions, mdsRepo_, topology_)) << "init FileRecordManager fail"; LOG(INFO) << "init FileRecordManager success."; diff --git a/src/tools/mds_client.cpp b/src/tools/mds_client.cpp index e5d5e9b91c..b479b45cc6 100644 --- a/src/tools/mds_client.cpp +++ b/src/tools/mds_client.cpp @@ -124,7 +124,8 @@ int MDSClient::GetFileInfo(const std::string &fileName, } int MDSClient::GetAllocatedSize(const std::string& fileName, - uint64_t* allocSize) { + uint64_t* allocSize, + uint64_t* physicalAllocSize) { if (!allocSize) { std::cout << "The argument is a null pointer!" << std::endl; return -1; @@ -146,6 +147,9 @@ int MDSClient::GetAllocatedSize(const std::string& fileName, } if (response.statuscode() == StatusCode::kOK) { *allocSize = response.allocatedsize(); + if (physicalAllocSize) { + *physicalAllocSize = response.physicalallocatedsize(); + } return 0; } std::cout << "GetAllocatedSize fail with errCode: " diff --git a/src/tools/mds_client.h b/src/tools/mds_client.h index 2928ea3d5f..88baf82421 100644 --- a/src/tools/mds_client.h +++ b/src/tools/mds_client.h @@ -106,10 +106,12 @@ class MDSClient { * @brief 获取文件或目录分配大小 * @param fileName 文件名 * @param[out] allocSize 文件或目录分配大小,返回值为0时有效 + * @param[out] physicalAllocSize 文件或目录底层分配大小,返回值为0时有效 * @return 成功返回0,失败返回-1 */ virtual int GetAllocatedSize(const std::string& fileName, - uint64_t* allocSize); + uint64_t* allocSize, + uint64_t* physicalAllocSize = nullptr); /** * @brief 将目录下所有的fileInfo列出来 diff --git a/src/tools/namespace_tool_core.cpp b/src/tools/namespace_tool_core.cpp index a7df266855..f563280cd6 100644 --- a/src/tools/namespace_tool_core.cpp +++ b/src/tools/namespace_tool_core.cpp @@ -51,8 +51,9 @@ int NameSpaceToolCore::CreateFile(const std::string& fileName, } int NameSpaceToolCore::GetAllocatedSize(const std::string& fileName, - uint64_t* size) { - return client_->GetAllocatedSize(fileName, size); + uint64_t* allocSize, + uint64_t* phyAllocSize) { + return client_->GetAllocatedSize(fileName, allocSize, phyAllocSize); } int NameSpaceToolCore::GetFileSize(const std::string& fileName, diff --git a/src/tools/namespace_tool_core.h b/src/tools/namespace_tool_core.h index f699fe9e7e..ea7a212c40 100644 --- a/src/tools/namespace_tool_core.h +++ b/src/tools/namespace_tool_core.h @@ -96,10 +96,12 @@ class NameSpaceToolCore { * @brief 计算文件或目录实际分配的空间 * @param fileName 文件名 * @param[out] allocSize 文件或目录已分配大小,返回值为0是有效 + * @param[out] phyAllocSize 文件或目录底层实际分配的大小,返回值0时有效 * @return 成功返回0,失败返回-1 */ virtual int GetAllocatedSize(const std::string& fileName, - uint64_t* allocSize); + uint64_t* allocSize, + uint64_t* phyAllocSize = nullptr); /** * @brief 返回文件或目录的中的文件的用户申请的大小 diff --git a/src/tools/status_tool.cpp b/src/tools/status_tool.cpp index c69fbef7d0..0e55110b19 100644 --- a/src/tools/status_tool.cpp +++ b/src/tools/status_tool.cpp @@ -133,14 +133,21 @@ int StatusTool::SpaceCmd() { std::cout << "GetSpaceInfo fail!" << std::endl; return -1; } - double logicalUsedRatio = static_cast(spaceInfo.logicalUsed) / + double logicalUsedRatio = 0; + double physicalUsedRatio = 0; + double canBeRecycledRatio = 0; + if (spaceInfo.total != 0) { + logicalUsedRatio = static_cast(spaceInfo.logicalUsed) / spaceInfo.total; - double physicalUsedRatio = static_cast(spaceInfo.physicalUsed) / + physicalUsedRatio = static_cast(spaceInfo.physicalUsed) / spaceInfo.total; - double canBeRecycledRatio = static_cast(spaceInfo.canBeRecycled) / + } + if (spaceInfo.logicalUsed != 0) { + canBeRecycledRatio = static_cast(spaceInfo.canBeRecycled) / spaceInfo.logicalUsed; + } std:: cout.setf(std::ios::fixed); - std::cout<< std::setprecision(2); + std::cout << std::setprecision(2); std::cout << "total space = " << spaceInfo.total / mds::kGB << "GB" << ", logical used = " << spaceInfo.logicalUsed / mds::kGB << "GB" << "(" << logicalUsedRatio * 100 << "%, can be recycled = " @@ -719,7 +726,9 @@ int StatusTool::GetSpaceInfo(SpaceInfo* spaceInfo) { spaceInfo->physicalUsed += size; } // 通过NameSpace工具获取RecycleBin的大小 + uint64_t allocSize; res = nameSpaceToolCore_->GetAllocatedSize(curve::mds::RECYCLEBINDIR, + &allocSize, &spaceInfo->canBeRecycled); if (res != 0) { std::cout << "GetAllocatedSize of RecycleBin fail!" << std::endl; diff --git a/test/mds/nameserver2/curvefs_test.cpp b/test/mds/nameserver2/curvefs_test.cpp index 20c47b5f41..72c23ecb21 100644 --- a/test/mds/nameserver2/curvefs_test.cpp +++ b/test/mds/nameserver2/curvefs_test.cpp @@ -19,6 +19,7 @@ #include "test/mds/nameserver2/mock/mock_clean_manager.h" #include "test/mds/mock/mock_repo.h" #include "test/mds/mock/mock_alloc_statistic.h" +#include "test/mds/mock/mock_topology.h" using ::testing::AtLeast; @@ -31,6 +32,7 @@ using ::testing::SetArgPointee; using curve::common::Authenticator; using curve::common::TimeUtility; +using curve::mds::topology::MockTopology; namespace curve { namespace mds { @@ -45,6 +47,7 @@ class CurveFSTest: public ::testing::Test { mockcleanManager_ = std::make_shared(); mockRepo_ = std::make_shared(); + topology_ = std::make_shared(); fileRecordManager_ = std::make_shared(); // session repo已经mock,数据库相关参数不需要 @@ -66,7 +69,8 @@ class CurveFSTest: public ::testing::Test { fileRecordManager_, allocStatistic_, curveFSOptions_, - mockRepo_); + mockRepo_, + topology_); curvefs_->Run(); } @@ -83,6 +87,7 @@ class CurveFSTest: public ::testing::Test { std::shared_ptr fileRecordManager_; std::shared_ptr allocStatistic_; std::shared_ptr mockRepo_; + std::shared_ptr topology_; struct FileRecordOptions fileRecordOptions_; struct RootAuthOption authOptions_; struct CurveFSOption curveFSOptions_; @@ -554,14 +559,14 @@ TEST_F(CurveFSTest, testDeleteFile) { } TEST_F(CurveFSTest, testGetAllocatedSize) { - uint64_t allocSize; + AllocatedSize allocSize; FileInfo fileInfo; uint64_t segmentSize = 1 * 1024 * 1024 * 1024ul; fileInfo.set_id(0); fileInfo.set_filetype(FileType::INODE_PAGEFILE); fileInfo.set_segmentsize(segmentSize); std::vector segments; - for (int i = 0; i < 5; ++i) { + for (int i = 0; i < 3; ++i) { PageFileSegment segment; segment.set_logicalpoolid(1); segment.set_segmentsize(segmentSize); @@ -570,6 +575,15 @@ TEST_F(CurveFSTest, testGetAllocatedSize) { segments.emplace_back(segment); } + LogicalPool lgPool1; + LogicalPool::RedundanceAndPlaceMentPolicy rap1; + rap1.pageFileRAP.replicaNum = 4; + lgPool1.SetRedundanceAndPlaceMentPolicy(rap1); + LogicalPool lgPool2; + LogicalPool::RedundanceAndPlaceMentPolicy rap2; + rap2.pageFileRAP.replicaNum = 3; + lgPool2.SetRedundanceAndPlaceMentPolicy(rap2); + // test page file normal { EXPECT_CALL(*storage_, GetFile(_, _, _)) @@ -580,9 +594,15 @@ TEST_F(CurveFSTest, testGetAllocatedSize) { .Times(1) .WillOnce(DoAll(SetArgPointee<1>(segments), Return(StoreStatus::OK))); + EXPECT_CALL(*topology_, GetLogicalPool(_, _)).Times(3) + .WillOnce( + DoAll(SetArgPointee<1>(lgPool1), Return(true))) + .WillRepeatedly( + DoAll(SetArgPointee<1>(lgPool2), Return(true))); ASSERT_EQ(StatusCode::kOK, curvefs_->GetAllocatedSize("/tests", &allocSize)); - ASSERT_EQ(5 * segmentSize, allocSize); + ASSERT_EQ(3 * segmentSize, allocSize.allocatedSize); + ASSERT_EQ(10 * segmentSize, allocSize.physicalAllocatedSize); } // test directory normal { @@ -604,9 +624,14 @@ TEST_F(CurveFSTest, testGetAllocatedSize) { .Times(3) .WillRepeatedly(DoAll(SetArgPointee<1>(segments), Return(StoreStatus::OK))); + EXPECT_CALL(*topology_, GetLogicalPool(_, _)).Times(9) + .WillOnce(DoAll(SetArgPointee<1>(lgPool1), Return(true))) + .WillRepeatedly( + DoAll(SetArgPointee<1>(lgPool2), Return(true))); ASSERT_EQ(StatusCode::kOK, curvefs_->GetAllocatedSize("/tests", &allocSize)); - ASSERT_EQ(15 * segmentSize, allocSize); + ASSERT_EQ(9 * segmentSize, allocSize.allocatedSize); + ASSERT_EQ(28 * segmentSize, allocSize.physicalAllocatedSize); } // test GetFile fail { @@ -653,6 +678,21 @@ TEST_F(CurveFSTest, testGetAllocatedSize) { ASSERT_EQ(StatusCode::kStorageError, curvefs_->GetAllocatedSize("/tests", &allocSize)); } + // test get logical pool fail + { + EXPECT_CALL(*storage_, GetFile(_, _, _)) + .Times(1) + .WillOnce(DoAll(SetArgPointee<2>(fileInfo), + Return(StoreStatus::OK))); + EXPECT_CALL(*storage_, ListSegment(_, _)) + .Times(1) + .WillOnce(DoAll(SetArgPointee<1>(segments), + Return(StoreStatus::OK))); + EXPECT_CALL(*topology_, GetLogicalPool(_, _)).Times(1) + .WillOnce(Return(false)); + ASSERT_EQ(StatusCode::KInternalError, + curvefs_->GetAllocatedSize("/tests", &allocSize)); + } } TEST_F(CurveFSTest, testReadDir) { diff --git a/test/mds/nameserver2/namespace_service_test.cpp b/test/mds/nameserver2/namespace_service_test.cpp index a450023d57..d0dd407278 100644 --- a/test/mds/nameserver2/namespace_service_test.cpp +++ b/test/mds/nameserver2/namespace_service_test.cpp @@ -29,6 +29,12 @@ using curve::common::TimeUtility; using curve::common::Authenticator; using curve::mds::topology::MockTopology; using ::curve::mds::chunkserverclient::ChunkServerClientOption; +using ::testing::_; +using ::testing::Return; +using ::testing::AtLeast; +using ::testing::SetArgPointee; +using ::testing::DoAll; +using ::testing::Invoke; namespace curve { namespace mds { @@ -85,7 +91,7 @@ class NameSpaceServiceTest : public ::testing::Test { cleanManager_, fileRecordManager_, allocStatistic_, - curveFSOptions, repo); + curveFSOptions, repo, topology_); kCurveFS.Run(); std::this_thread::sleep_for(std::chrono::microseconds( @@ -502,10 +508,18 @@ TEST_F(NameSpaceServiceTest, test1) { // normal cntl.Reset(); request.set_filename("/file1"); + LogicalPool lgPool; + LogicalPool::RedundanceAndPlaceMentPolicy rap; + rap.pageFileRAP.replicaNum = 3; + lgPool.SetRedundanceAndPlaceMentPolicy(rap); + EXPECT_CALL(*topology_, GetLogicalPool(_, _)) + .WillRepeatedly( + DoAll(SetArgPointee<1>(lgPool), Return(true))); stub.GetAllocatedSize(&cntl, &request, &response, NULL); ASSERT_FALSE(cntl.Failed()); ASSERT_EQ(StatusCode::kOK, response.statuscode()); ASSERT_EQ(DefaultSegmentSize, response.allocatedsize()); + ASSERT_EQ(DefaultSegmentSize * 3, response.physicalallocatedsize()); } // test change owner @@ -1541,12 +1555,6 @@ TEST_F(NameSpaceServiceTest, deletefiletests) { using ::curve::chunkserver::ChunkRequest; using ::curve::chunkserver::ChunkResponse; using ::curve::chunkserver::CHUNK_OP_STATUS; - using ::testing::_; - using ::testing::Return; - using ::testing::AtLeast; - using ::testing::SetArgPointee; - using ::testing::DoAll; - using ::testing::Invoke; CopySetInfo copyset(1, 1); copyset.SetLeader(1); diff --git a/test/tools/mds_client_test.cpp b/test/tools/mds_client_test.cpp index 879fcf04b7..463def5cb4 100644 --- a/test/tools/mds_client_test.cpp +++ b/test/tools/mds_client_test.cpp @@ -220,10 +220,17 @@ TEST_F(ToolMDSClientTest, GetAllocatedSize) { ASSERT_EQ(-1, mdsClient.GetAllocatedSize(filename, &allocSize)); // 正常情况 - response->set_allocatedsize(1073741824); + uint64_t expectedSize1 = 1073741824; + uint64_t expectedSize2 = allocSize * 3; + response->set_allocatedsize(expectedSize1); + response->set_physicalallocatedsize(expectedSize2); + response->set_statuscode(curve::mds::StatusCode::kOK); - ASSERT_EQ(0, mdsClient.GetAllocatedSize(filename, &allocSize)); - ASSERT_EQ(1073741824, allocSize); + uint64_t physicAllocSize; + ASSERT_EQ(0, mdsClient.GetAllocatedSize(filename, &allocSize, + &physicAllocSize)); + ASSERT_EQ(expectedSize1, allocSize); + ASSERT_EQ(expectedSize2, physicAllocSize); } TEST_F(ToolMDSClientTest, ListDir) { diff --git a/test/tools/mock_mds_client.h b/test/tools/mock_mds_client.h index 5b78fb0460..72461e07b8 100644 --- a/test/tools/mock_mds_client.h +++ b/test/tools/mock_mds_client.h @@ -26,7 +26,8 @@ class MockMDSClient : public MDSClient { MOCK_METHOD1(Init, int(const std::string&)); MOCK_METHOD2(Init, int(const std::string&, const std::string&)); MOCK_METHOD2(GetFileInfo, int(const std::string&, FileInfo*)); - MOCK_METHOD2(GetAllocatedSize, int(const std::string&, uint64_t*)); + MOCK_METHOD3(GetAllocatedSize, int(const std::string&, + uint64_t*, uint64_t*)); MOCK_METHOD2(ListDir, int(const std::string&, std::vector*)); MOCK_METHOD3(GetSegmentInfo, GetSegmentRes(const std::string&, uint64_t, PageFileSegment*)); diff --git a/test/tools/mock_namespace_tool_core.h b/test/tools/mock_namespace_tool_core.h index 68d4cad05e..fb4ef4826f 100644 --- a/test/tools/mock_namespace_tool_core.h +++ b/test/tools/mock_namespace_tool_core.h @@ -33,7 +33,8 @@ class MockNameSpaceToolCore : public NameSpaceToolCore { std::vector*)); MOCK_METHOD2(DeleteFile, int(const std::string&, bool)); MOCK_METHOD2(CreateFile, int(const std::string&, uint64_t)); - MOCK_METHOD2(GetAllocatedSize, int(const std::string&, uint64_t*)); + MOCK_METHOD3(GetAllocatedSize, int(const std::string&, uint64_t*, + uint64_t*)); MOCK_METHOD2(GetFileSegments, int(const std::string&, std::vector*)); MOCK_METHOD4(QueryChunkCopyset, int(const std::string&, uint64_t, diff --git a/test/tools/namespace_tool_core_test.cpp b/test/tools/namespace_tool_core_test.cpp index 5271d1a7cf..509f4859de 100644 --- a/test/tools/namespace_tool_core_test.cpp +++ b/test/tools/namespace_tool_core_test.cpp @@ -230,7 +230,7 @@ TEST_F(NameSpaceToolCoreTest, GetAllocatedSize) { curve::tool::NameSpaceToolCore namespaceTool(client_); // 1、正常情况 uint64_t allocSize; - EXPECT_CALL(*client_, GetAllocatedSize(_, _)) + EXPECT_CALL(*client_, GetAllocatedSize(_, _, _)) .Times(1) .WillOnce(Return(0)); ASSERT_EQ(0, namespaceTool.GetAllocatedSize("/test", &allocSize)); diff --git a/test/tools/namespace_tool_test.cpp b/test/tools/namespace_tool_test.cpp index c6107bc2aa..9621a21bfb 100644 --- a/test/tools/namespace_tool_test.cpp +++ b/test/tools/namespace_tool_test.cpp @@ -104,7 +104,7 @@ TEST_F(NameSpaceToolTest, GetFile) { .Times(1) .WillOnce(DoAll(SetArgPointee<1>(fileInfo), Return(0))); - EXPECT_CALL(*core_, GetAllocatedSize(_, _)) + EXPECT_CALL(*core_, GetAllocatedSize(_, _, _)) .Times(1) .WillOnce(DoAll(SetArgPointee<1>(10 * segmentSize), Return(0))); @@ -121,7 +121,7 @@ TEST_F(NameSpaceToolTest, GetFile) { .Times(1) .WillOnce(DoAll(SetArgPointee<1>(fileInfo), Return(0))); - EXPECT_CALL(*core_, GetAllocatedSize(_, _)) + EXPECT_CALL(*core_, GetAllocatedSize(_, _, _)) .Times(1) .WillOnce(Return(-1)); ASSERT_EQ(-1, namespaceTool.RunCommand("get")); @@ -134,7 +134,7 @@ TEST_F(NameSpaceToolTest, GetFile) { .Times(1) .WillOnce(DoAll(SetArgPointee<1>(fileInfo2), Return(0))); - EXPECT_CALL(*core_, GetAllocatedSize(_, _)) + EXPECT_CALL(*core_, GetAllocatedSize(_, _, _)) .Times(1) .WillOnce(DoAll(SetArgPointee<1>(10 * segmentSize), Return(0))); @@ -182,7 +182,7 @@ TEST_F(NameSpaceToolTest, ListDir) { .Times(2) .WillRepeatedly(DoAll(SetArgPointee<1>(files), Return(0))); - EXPECT_CALL(*core_, GetAllocatedSize(_, _)) + EXPECT_CALL(*core_, GetAllocatedSize(_, _, _)) .Times(6) .WillRepeatedly(DoAll(SetArgPointee<1>(10 * segmentSize), Return(0))); @@ -202,7 +202,7 @@ TEST_F(NameSpaceToolTest, ListDir) { .Times(1) .WillOnce(DoAll(SetArgPointee<1>(files), Return(0))); - EXPECT_CALL(*core_, GetAllocatedSize(_, _)) + EXPECT_CALL(*core_, GetAllocatedSize(_, _, _)) .Times(3) .WillOnce(Return(-1)) .WillRepeatedly(DoAll(SetArgPointee<1>(10 * segmentSize), diff --git a/test/tools/status_tool_test.cpp b/test/tools/status_tool_test.cpp index 504cde40f1..b4c28ee6de 100644 --- a/test/tools/status_tool_test.cpp +++ b/test/tools/status_tool_test.cpp @@ -243,9 +243,9 @@ TEST_F(StatusToolTest, SpaceCmd) { Return(0))) .WillOnce(DoAll(SetArgPointee<1>(29292213829632), Return(0))); - EXPECT_CALL(*nameSpaceTool_, GetAllocatedSize(_, _)) + EXPECT_CALL(*nameSpaceTool_, GetAllocatedSize(_, _, _)) .Times(1) - .WillOnce(DoAll(SetArgPointee<1>(14646106914816), + .WillOnce(DoAll(SetArgPointee<2>(14646106914816), Return(0))); ASSERT_EQ(0, statusTool.RunCommand("space")); ASSERT_EQ(-1, statusTool.RunCommand("123")); @@ -307,7 +307,7 @@ TEST_F(StatusToolTest, SpaceCmd) { Return(0))) .WillOnce(DoAll(SetArgPointee<1>(29292213829632), Return(0))); - EXPECT_CALL(*nameSpaceTool_, GetAllocatedSize(_, _)) + EXPECT_CALL(*nameSpaceTool_, GetAllocatedSize(_, _, _)) .Times(1) .WillOnce(Return(-1)); ASSERT_EQ(-1, statusTool.RunCommand("space")); @@ -479,9 +479,9 @@ TEST_F(StatusToolTest, StatusCmdCommon) { Return(0))) .WillOnce(DoAll(SetArgPointee<1>(58584427659264), Return(0))); - EXPECT_CALL(*nameSpaceTool_, GetAllocatedSize(_, _)) + EXPECT_CALL(*nameSpaceTool_, GetAllocatedSize(_, _, _)) .Times(1) - .WillOnce(DoAll(SetArgPointee<1>(14646106914816), + .WillOnce(DoAll(SetArgPointee<2>(14646106914816), Return(0))); // 设置client status的输出