diff --git a/curvefs/conf/tools.conf b/curvefs/conf/tools.conf index ea5a76883e..ca3d0e750a 100644 --- a/curvefs/conf/tools.conf +++ b/curvefs/conf/tools.conf @@ -26,5 +26,5 @@ s3.endpoint=endpoint s3.bucket_name=bucket s3.blocksize=4194304 s3.chunksize=67108864 -# statistic info in xattr +# statistic info in xattr, hardlink will not be supported when enable enableSumInDir=false diff --git a/curvefs/src/client/curve_fuse_op.cpp b/curvefs/src/client/curve_fuse_op.cpp index f99dbdc339..c1cc55e8d8 100644 --- a/curvefs/src/client/curve_fuse_op.cpp +++ b/curvefs/src/client/curve_fuse_op.cpp @@ -209,7 +209,7 @@ void FuseReplyErrByErrCode(fuse_req_t req, CURVEFS_ERROR errcode) { fuse_reply_err(req, ENOTEMPTY); break; case CURVEFS_ERROR::NOTSUPPORT: - fuse_reply_err(req, ENOSYS); + fuse_reply_err(req, EOPNOTSUPP); break; case CURVEFS_ERROR::NAMETOOLONG: fuse_reply_err(req, ENAMETOOLONG); diff --git a/curvefs/src/client/fuse_client.cpp b/curvefs/src/client/fuse_client.cpp index b465c7cd92..339cd64b0c 100644 --- a/curvefs/src/client/fuse_client.cpp +++ b/curvefs/src/client/fuse_client.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include "curvefs/proto/mds.pb.h" #include "curvefs/src/client/fuse_common.h" @@ -308,9 +309,9 @@ CURVEFS_ERROR FuseClient::FuseOpOpen(fuse_req_t req, fuse_ino_t ino, XAttr xattr; xattr.mutable_xattrinfos()->insert({XATTRFBYTES, std::to_string(length)}); - std::list parentIds; - if (inodeManager_->GetParent(inode->inodeid(), &parentIds)) { - ret = UpdateParentInodeXattr(parentIds, xattr, false); + uint64_t parentId; + if (inodeManager_->GetParent(inode->inodeid(), &parentId)) { + ret = UpdateParentInodeXattr(parentId, xattr, false); } else { LOG(ERROR) << "inodeManager getParent failed, inodeId = " << inode; @@ -417,8 +418,7 @@ CURVEFS_ERROR FuseClient::MakeNode(fuse_req_t req, fuse_ino_t parent, } xattr.mutable_xattrinfos()->insert({XATTRFBYTES, std::to_string(inodeWrapper->GetLength())}); - ret = UpdateParentInodeXattr( - std::list({parent}), xattr, true); + ret = UpdateParentInodeXattr(parent, xattr, true); } GetDentryParamFromInode(inodeWrapper, e); @@ -516,7 +516,7 @@ CURVEFS_ERROR FuseClient::RemoveNode(fuse_req_t req, fuse_ino_t parent, if (enableSumInDir_) { // remove parent relationshaip - inodeManager_->RemoveParent(ino, parent); + inodeManager_->ClearParent(ino); // update parent summary info XAttr xattr; @@ -528,8 +528,7 @@ CURVEFS_ERROR FuseClient::RemoveNode(fuse_req_t req, fuse_ino_t parent, } xattr.mutable_xattrinfos()->insert({XATTRFBYTES, std::to_string(inodeWrapper->GetLength())}); - ret = UpdateParentInodeXattr( - std::list({parent}), xattr, false); + ret = UpdateParentInodeXattr(parent, xattr, false); } inodeManager_->ClearInodeCache(ino); @@ -669,17 +668,15 @@ CURVEFS_ERROR FuseClient::FuseOpRename(fuse_req_t req, fuse_ino_t parent, xattr.mutable_xattrinfos()->insert({XATTRFBYTES, std::to_string(inodeWrapper->GetLength())}); - if (inodeManager_->UpdateParent(ino, parent, newparent)) { + if (inodeManager_->UpdateParent(ino, newparent)) { // TODO(wanghai): deal with failure - rc = UpdateParentInodeXattr( - std::list({parent}), xattr, false); + rc = UpdateParentInodeXattr(parent, xattr, false); if (rc != CURVEFS_ERROR::OK) { LOG(ERROR) << "UpdateParentInodeXattr failed, parentId = " << parent; return rc; } - rc = UpdateParentInodeXattr( - std::list({newparent}), xattr, true); + rc = UpdateParentInodeXattr(newparent, xattr, true); if (rc != CURVEFS_ERROR::OK) { LOG(ERROR) << "UpdateParentInodeXattr failed, parentId = " << newparent; @@ -782,10 +779,10 @@ CURVEFS_ERROR FuseClient::FuseOpSetAttr(fuse_req_t req, fuse_ino_t ino, XAttr xattr; xattr.mutable_xattrinfos()->insert({XATTRFBYTES, std::to_string(std::abs(changeSize))}); - std::list parentIds; - if (inodeManager_->GetParent(ino, &parentIds)) { + uint64_t parentId; + if (inodeManager_->GetParent(ino, &parentId)) { bool direction = changeSize > 0; - ret = UpdateParentInodeXattr(parentIds, xattr, direction); + ret = UpdateParentInodeXattr(parentId, xattr, direction); } else { LOG(ERROR) << "inodeManager getParent failed, inodeId = " << inode; @@ -893,7 +890,8 @@ CURVEFS_ERROR FuseClient::CalOneLayerSumInfo(Inode *inode) { CURVEFS_ERROR FuseClient::CalAllLayerSumInfo(Inode *inode) { std::stack iStack; - // use set can deal with hard link + // record hard link, + std::unordered_map hardLinkMap; std::set inodeIds; std::list attrs; auto ino = inode->inodeid(); @@ -935,6 +933,15 @@ CURVEFS_ERROR FuseClient::CalAllLayerSumInfo(Inode *inode) { } rentries++; rfbytes += it.length(); + // record hardlink + if (it.type() != FsFileType::TYPE_DIRECTORY && + it.nlink() > 1) { + if (hardLinkMap.count(it.inodeid())) { + hardLinkMap[it.inodeid()] += it.length(); + } else { + hardLinkMap.emplace(it.inodeid(), 0); + } + } } inodeIds.clear(); attrs.clear(); @@ -944,6 +951,11 @@ CURVEFS_ERROR FuseClient::CalAllLayerSumInfo(Inode *inode) { } } + // deal with hardlink + for (const auto &it : hardLinkMap) { + rfbytes -= it.second; + } + inode->mutable_xattr()->insert({XATTRRFILES, std::to_string(rfiles)}); inode->mutable_xattr()->insert({XATTRRSUBDIRS, @@ -1180,8 +1192,7 @@ CURVEFS_ERROR FuseClient::FuseOpSymlink(fuse_req_t req, const char *link, xattr.mutable_xattrinfos()->insert({XATTRFILES, "1"}); xattr.mutable_xattrinfos()->insert({XATTRFBYTES, std::to_string(inodeWrapper->GetLength())}); - ret = UpdateParentInodeXattr( - std::list({parent}), xattr, true); + ret = UpdateParentInodeXattr(parent, xattr, true); } GetDentryParamFromInode(inodeWrapper, e); @@ -1194,6 +1205,12 @@ CURVEFS_ERROR FuseClient::FuseOpLink(fuse_req_t req, fuse_ino_t ino, LOG(INFO) << "FuseOpLink, ino: " << ino << ", newparent: " << newparent << ", newname: " << newname; + if (enableSumInDir_) { + // don't support hardlink + LOG(ERROR) << "FuseOpLink doesn't support when enableSumInDir."; + return CURVEFS_ERROR::NOTSUPPORT; + } + if (strlen(newname) > option_.maxNameLength) { return CURVEFS_ERROR::NAMETOOLONG; } @@ -1244,19 +1261,6 @@ CURVEFS_ERROR FuseClient::FuseOpLink(fuse_req_t req, fuse_ino_t ino, return ret; } - if (enableSumInDir_) { - // recore parent inodeId - inodeManager_->AddParent(inodeWrapper->GetInodeId(), newparent); - // update parent summary info - XAttr xattr; - xattr.mutable_xattrinfos()->insert({XATTRENTRIES, "1"}); - xattr.mutable_xattrinfos()->insert({XATTRFILES, "1"}); - xattr.mutable_xattrinfos()->insert({XATTRFBYTES, - std::to_string(inodeWrapper->GetLength())}); - ret = UpdateParentInodeXattr( - std::list({newparent}), xattr, true); - } - GetDentryParamFromInode(inodeWrapper, e); return ret; } @@ -1297,10 +1301,6 @@ CURVEFS_ERROR FuseClient::FuseOpRelease(fuse_req_t req, fuse_ino_t ino, return ret; } - if (enableSumInDir_) { - // update parent relationship - inodeManager_->ClearParent(ino); - } return ret; } @@ -1313,41 +1313,31 @@ void FuseClient::FlushAll() { FlushInodeAll(); } -CURVEFS_ERROR FuseClient::UpdateParentInodeXattr( - const std::list &parentIds, +CURVEFS_ERROR FuseClient::UpdateParentInodeXattr(uint64_t parentId, const XAttr &xattr, bool direction) { - for (const auto &parentId : parentIds) { - VLOG(1) << "UpdateParentInodeXattr inodeId = " << parentId - << ", \nxattr = " << xattr.DebugString(); - std::shared_ptr pInodeWrapper; - CURVEFS_ERROR ret = inodeManager_->GetInode(parentId, pInodeWrapper); - if (ret != CURVEFS_ERROR::OK) { - LOG(ERROR) << "UpdateParentInodeXattr get parent inode fail, ret = " - << ret << ", inodeid = " << parentId; - return ret; - } - // if dirty, flush attr first - if (pInodeWrapper->Dirty()) { - ret = pInodeWrapper->SyncAttr(); - if (ret != CURVEFS_ERROR::OK) { - LOG(ERROR) << "sync parent inode attr failed when" - << " UpdateParentInodeXattr, inodeId = " << parentId; - return ret; - } - } - ::curve::common::UniqueLock lgGuard = pInodeWrapper->GetUniqueLock(); - auto inode = pInodeWrapper->GetMutableInodeUnlocked(); - for (const auto &it : xattr.xattrinfos()) { - auto iter = inode->mutable_xattr()->find(it.first); - if (iter != inode->mutable_xattr()->end()) { - if (!AddUllStringToFirst(&(iter->second), it.second, - direction)) { - return CURVEFS_ERROR::INTERNAL; - } + VLOG(1) << "UpdateParentInodeXattr inodeId = " << parentId + << ", direction = " << direction + << ", \nxattr = " << xattr.DebugString(); + std::shared_ptr pInodeWrapper; + CURVEFS_ERROR ret = inodeManager_->GetInode(parentId, pInodeWrapper); + if (ret != CURVEFS_ERROR::OK) { + LOG(ERROR) << "UpdateParentInodeXattr get parent inode fail, ret = " + << ret << ", inodeid = " << parentId; + return ret; + } + + ::curve::common::UniqueLock lgGuard = pInodeWrapper->GetUniqueLock(); + auto inode = pInodeWrapper->GetMutableInodeUnlocked(); + for (const auto &it : xattr.xattrinfos()) { + auto iter = inode->mutable_xattr()->find(it.first); + if (iter != inode->mutable_xattr()->end()) { + if (!AddUllStringToFirst(&(iter->second), it.second, + direction)) { + return CURVEFS_ERROR::INTERNAL; } } - pInodeWrapper->FlushXattrAsync(); } + pInodeWrapper->FlushXattrAsync(); return CURVEFS_ERROR::OK; } diff --git a/curvefs/src/client/fuse_client.h b/curvefs/src/client/fuse_client.h index ccac1243cc..abeb24cbd2 100644 --- a/curvefs/src/client/fuse_client.h +++ b/curvefs/src/client/fuse_client.h @@ -240,7 +240,7 @@ class FuseClient { return 0; } - CURVEFS_ERROR UpdateParentInodeXattr(const std::list &parentIds, + CURVEFS_ERROR UpdateParentInodeXattr(uint64_t parentId, const XAttr &xattr, bool direction); private: diff --git a/curvefs/src/client/fuse_s3_client.cpp b/curvefs/src/client/fuse_s3_client.cpp index 4840ca4a83..68a39ee21d 100644 --- a/curvefs/src/client/fuse_s3_client.cpp +++ b/curvefs/src/client/fuse_s3_client.cpp @@ -129,9 +129,9 @@ CURVEFS_ERROR FuseS3Client::FuseOpWrite(fuse_req_t req, fuse_ino_t ino, XAttr xattr; xattr.mutable_xattrinfos()->insert({XATTRFBYTES, std::to_string(*wSize)}); - std::list parentIds; - if (inodeManager_->GetParent(ino, &parentIds)) { - ret = UpdateParentInodeXattr(parentIds, xattr, true); + uint64_t parentId; + if (inodeManager_->GetParent(ino, &parentId)) { + ret = UpdateParentInodeXattr(parentId, xattr, true); } else { LOG(ERROR) << "inodeManager getParent failed, inodeId = " << ino; return CURVEFS_ERROR::INTERNAL; diff --git a/curvefs/src/client/inode_cache_manager.cpp b/curvefs/src/client/inode_cache_manager.cpp index f73ad5a9d0..b1a4f5ba5a 100644 --- a/curvefs/src/client/inode_cache_manager.cpp +++ b/curvefs/src/client/inode_cache_manager.cpp @@ -183,47 +183,36 @@ void InodeCacheManagerImpl::FlushInodeOnce() { void InodeCacheManagerImpl::AddParent(uint64_t inodeId, uint64_t parentId) { curve::common::LockGuard lg2(parentIdMapMutex_); if (parentIdMap_.count(inodeId)) { - parentIdMap_[inodeId].emplace_back(parentId); - } else { - parentIdMap_.emplace(inodeId, std::list({parentId})); - } -} - -void InodeCacheManagerImpl::RemoveParent(uint64_t inodeId, uint64_t parentId) { - curve::common::LockGuard lg2(parentIdMapMutex_); - if (parentIdMap_.count(inodeId)) { - auto iter = std::find(parentIdMap_[inodeId].begin(), - parentIdMap_[inodeId].end(), parentId); - if (iter != parentIdMap_[inodeId].end()) { - parentIdMap_[inodeId].erase(iter); - } + LOG(WARNING) << "AddParent but exist, inodeId = " << inodeId + << ", parentId = " << parentIdMap_[inodeId] + << ", need2AddParentId = " << parentId; } + parentIdMap_[inodeId] = parentId; } void InodeCacheManagerImpl::ClearParent(uint64_t inodeId) { curve::common::LockGuard lg2(parentIdMapMutex_); parentIdMap_.erase(inodeId); + VLOG(1) << "ClearParent inodeId = " << inodeId + << ", after clear the parentmap size = " + << parentIdMap_.size(); } -bool InodeCacheManagerImpl::UpdateParent(uint64_t inodeId, uint64_t oldParentId, +bool InodeCacheManagerImpl::UpdateParent(uint64_t inodeId, uint64_t newParentId) { curve::common::LockGuard lg2(parentIdMapMutex_); if (parentIdMap_.count(inodeId)) { - auto iter = std::find(parentIdMap_[inodeId].begin(), - parentIdMap_[inodeId].end(), oldParentId); - if (iter != parentIdMap_[inodeId].end()) { - *iter = newParentId; - return true; - } + parentIdMap_[inodeId] = newParentId; + return true; } return false; } bool InodeCacheManagerImpl::GetParent(uint64_t inodeId, - std::list *parentIds) { + uint64_t *parentId) { curve::common::LockGuard lg2(parentIdMapMutex_); if (parentIdMap_.count(inodeId)) { - *parentIds = parentIdMap_[inodeId]; + *parentId = parentIdMap_[inodeId]; return true; } return false; diff --git a/curvefs/src/client/inode_cache_manager.h b/curvefs/src/client/inode_cache_manager.h index 194d6d101d..814cfc97b1 100644 --- a/curvefs/src/client/inode_cache_manager.h +++ b/curvefs/src/client/inode_cache_manager.h @@ -89,15 +89,11 @@ class InodeCacheManager { virtual void AddParent(uint64_t inodeId, uint64_t parentId) = 0; - virtual void RemoveParent(uint64_t inodeId, uint64_t parentId) = 0; - virtual void ClearParent(uint64_t inodeId) = 0; - virtual bool GetParent(uint64_t inodeId, - std::list *parentIds) = 0; + virtual bool GetParent(uint64_t inodeId, uint64_t *parentId) = 0; - virtual bool UpdateParent(uint64_t inodeId, uint64_t oldParentId, - uint64_t newParentId) = 0; + virtual bool UpdateParent(uint64_t inodeId, uint64_t newParentId) = 0; protected: uint32_t fsId_; @@ -151,14 +147,11 @@ class InodeCacheManagerImpl : public InodeCacheManager { void AddParent(uint64_t inodeId, uint64_t parentId) override; - void RemoveParent(uint64_t inodeId, uint64_t parentId) override; - void ClearParent(uint64_t inodeId) override; - bool GetParent(uint64_t inodeId, std::list *parentIds) override; + bool GetParent(uint64_t inodeId, uint64_t *parentId) override; - bool UpdateParent(uint64_t inodeId, uint64_t oldParentId, - uint64_t newParentId) override; + bool UpdateParent(uint64_t inodeId, uint64_t newParentId) override; private: std::shared_ptr metaClient_; @@ -168,8 +161,8 @@ class InodeCacheManagerImpl : public InodeCacheManager { std::map> dirtyMap_; curve::common::Mutex dirtyMapMutex_; - // inodeid to parent inodeid, may have more parent at hard link - std::map> parentIdMap_; + // inodeid to parent inodeid + std::map parentIdMap_; curve::common::Mutex parentIdMapMutex_; curve::common::GenericNameLock nameLock_; diff --git a/curvefs/src/client/inode_wrapper.cpp b/curvefs/src/client/inode_wrapper.cpp index bb60e406e5..31e59eddc1 100644 --- a/curvefs/src/client/inode_wrapper.cpp +++ b/curvefs/src/client/inode_wrapper.cpp @@ -180,12 +180,9 @@ void InodeWrapper::FlushAttrAsync() { } void InodeWrapper::FlushXattrAsync() { - if (dirty_) { - LockSyncingXattr(); - auto *done = new UpdateXattrAsyncDone(shared_from_this()); - metaClient_->UpdateXattrAsync(inode_, done); - dirty_ = false; - } + LockSyncingXattr(); + auto *done = new UpdateXattrAsyncDone(shared_from_this()); + metaClient_->UpdateXattrAsync(inode_, done); } void InodeWrapper::FlushS3ChunkInfoAsync() { diff --git a/curvefs/test/client/mock_inode_cache_manager.h b/curvefs/test/client/mock_inode_cache_manager.h index 8771135a63..00981cfcea 100644 --- a/curvefs/test/client/mock_inode_cache_manager.h +++ b/curvefs/test/client/mock_inode_cache_manager.h @@ -67,16 +67,13 @@ class MockInodeCacheManager : public InodeCacheManager { MOCK_METHOD2(AddParent, void(uint64_t inodeId, uint64_t parentId)); - MOCK_METHOD2(RemoveParent, void(uint64_t inodeId, - uint64_t parentId)); - MOCK_METHOD1(ClearParent, void(uint64_t inodeId)); MOCK_METHOD2(GetParent, bool(uint64_t inodeId, - std::list *parentId)); + uint64_t *parentId)); - MOCK_METHOD3(UpdateParent, bool(uint64_t inodeId, - uint64_t oldParentId, uint64_t newParentId)); + MOCK_METHOD2(UpdateParent, bool(uint64_t inodeId, + uint64_t newParentId)); }; } // namespace client diff --git a/curvefs/test/client/test_fuse_client.cpp b/curvefs/test/client/test_fuse_client.cpp index b901fdf7bc..fc2acf5f76 100644 --- a/curvefs/test/client/test_fuse_client.cpp +++ b/curvefs/test/client/test_fuse_client.cpp @@ -2577,8 +2577,7 @@ TEST_F(TestFuseS3Client, FuseOpWrite_EnableSummary) { parentInode.mutable_xattr()->insert({XATTRENTRIES, "1"}); parentInode.mutable_xattr()->insert({XATTRFBYTES, "0"}); - std::list parentIds; - parentIds.emplace_back(1); + uint64_t parentId = 1; auto parentInodeWrapper = std::make_shared( parentInode, metaClient_); @@ -2592,7 +2591,7 @@ TEST_F(TestFuseS3Client, FuseOpWrite_EnableSummary) { EXPECT_CALL(*s3ClientAdaptor_, Write(_, _, _, _)) .WillOnce(Return(size)); EXPECT_CALL(*inodeManager_, GetParent(_, _)) - .WillOnce(DoAll(SetArgPointee<1>(parentIds), Return(true))); + .WillOnce(DoAll(SetArgPointee<1>(parentId), Return(true))); EXPECT_CALL(*metaClient_, UpdateXattrAsync(_, _)) .WillOnce(Invoke([](const Inode &inode, MetaServerClientDone *done){ @@ -2621,61 +2620,9 @@ TEST_F(TestFuseS3Client, FuseOpLink_EnableSummary) { fuse_ino_t newparent = 2; const char* newname = "xxxx"; - uint32_t nlink = 100; - - Inode inode; - inode.set_inodeid(ino); - inode.set_length(0); - inode.set_nlink(nlink); - auto inodeWrapper = std::make_shared(inode, metaClient_); - - Inode parentInode; - parentInode.set_fsid(fsId); - parentInode.set_inodeid(newparent); - parentInode.set_type(FsFileType::TYPE_DIRECTORY); - parentInode.set_nlink(2); - parentInode.mutable_xattr()->insert({XATTRFILES, "1"}); - parentInode.mutable_xattr()->insert({XATTRSUBDIRS, "1"}); - parentInode.mutable_xattr()->insert({XATTRENTRIES, "2"}); - parentInode.mutable_xattr()->insert({XATTRFBYTES, "100"}); - auto parentInodeWrapper = std::make_shared( - parentInode, metaClient_); - - EXPECT_CALL(*inodeManager_, GetInode(_, _)) - .WillOnce( - DoAll(SetArgReferee<1>(inodeWrapper), Return(CURVEFS_ERROR::OK))) - .WillOnce( - DoAll(SetArgReferee<1>(parentInodeWrapper), - Return(CURVEFS_ERROR::OK))) - .WillOnce( - DoAll(SetArgReferee<1>(parentInodeWrapper), - Return(CURVEFS_ERROR::OK))); - - EXPECT_CALL(*dentryManager_, CreateDentry(_)) - .WillOnce(Return(CURVEFS_ERROR::OK)); - - EXPECT_CALL(*metaClient_, UpdateInode(_, _)) - .WillRepeatedly(Return(MetaStatusCode::OK)); - EXPECT_CALL(*inodeManager_, AddParent(_, _)) - .Times(1); - EXPECT_CALL(*metaClient_, UpdateXattrAsync(_, _)) - .WillOnce(Invoke([](const Inode &inode, - MetaServerClientDone *done){ - done->SetMetaStatusCode(MetaStatusCode::OK); - done->Run(); - })); - fuse_entry_param e; CURVEFS_ERROR ret = client_->FuseOpLink(req, ino, newparent, newname, &e); - ASSERT_EQ(CURVEFS_ERROR::OK, ret); - Inode inode2 = inodeWrapper->GetInodeUnlocked(); - ASSERT_EQ(nlink + 1, inode2.nlink()); - - auto p = parentInodeWrapper->GetInodeLocked(); - ASSERT_EQ(p.xattr().find(XATTRFILES)->second, "2"); - ASSERT_EQ(p.xattr().find(XATTRSUBDIRS)->second, "1"); - ASSERT_EQ(p.xattr().find(XATTRENTRIES)->second, "3"); - ASSERT_EQ(p.xattr().find(XATTRFBYTES)->second, "100"); + ASSERT_EQ(CURVEFS_ERROR::NOTSUPPORT, ret); } TEST_F(TestFuseS3Client, FuseOpUnlink_EnableSummary) { @@ -2733,7 +2680,7 @@ TEST_F(TestFuseS3Client, FuseOpUnlink_EnableSummary) { EXPECT_CALL(*metaClient_, UpdateInode(_, _)) .WillRepeatedly(Return(MetaStatusCode::OK)); - EXPECT_CALL(*inodeManager_, RemoveParent(_, _)) + EXPECT_CALL(*inodeManager_, ClearParent(_)) .Times(1); EXPECT_CALL(*metaClient_, UpdateXattrAsync(_, _)) .WillOnce(Invoke([](const Inode &inode, @@ -2786,8 +2733,7 @@ TEST_F(TestFuseS3Client, FuseOpOpen_Trunc_EnableSummary) { auto parentInodeWrapper = std::make_shared( parentInode, metaClient_); - std::list parentIds; - parentIds.emplace_back(1); + uint64_t parentId = 1; EXPECT_CALL(*inodeManager_, GetInode(ino, _)) .WillOnce( @@ -2800,7 +2746,7 @@ TEST_F(TestFuseS3Client, FuseOpOpen_Trunc_EnableSummary) { EXPECT_CALL(*metaClient_, UpdateInode(_, _)) .WillRepeatedly(Return(MetaStatusCode::OK)); EXPECT_CALL(*inodeManager_, GetParent(_, _)) - .WillOnce(DoAll(SetArgPointee<1>(parentIds), Return(true))); + .WillOnce(DoAll(SetArgPointee<1>(parentId), Return(true))); EXPECT_CALL(*metaClient_, UpdateXattrAsync(_, _)) .WillOnce(Invoke([](const Inode &inode, MetaServerClientDone *done){ diff --git a/curvefs/test/client/test_inode_cache_manager.cpp b/curvefs/test/client/test_inode_cache_manager.cpp index bf6383b32e..cd4b335e61 100644 --- a/curvefs/test/client/test_inode_cache_manager.cpp +++ b/curvefs/test/client/test_inode_cache_manager.cpp @@ -298,36 +298,23 @@ TEST_F(TestInodeCacheManager, ParentMap) { uint64_t p2 = 200; uint64_t p3 = 300; - std::list parents; - ASSERT_FALSE(iCacheManager_->GetParent(inodeId1, &parents)); + uint64_t parent; + ASSERT_FALSE(iCacheManager_->GetParent(inodeId1, &parent)); iCacheManager_->AddParent(inodeId1, p1); - ASSERT_TRUE(iCacheManager_->GetParent(inodeId1, &parents)); - ASSERT_EQ(parents.size(), 1); - ASSERT_EQ(*(parents.begin()), p1); + ASSERT_TRUE(iCacheManager_->GetParent(inodeId1, &parent)); + ASSERT_EQ(parent, p1); - parents.clear(); iCacheManager_->AddParent(inodeId1, p2); - ASSERT_TRUE(iCacheManager_->GetParent(inodeId1, &parents)); - ASSERT_EQ(parents.size(), 2); - ASSERT_EQ(*(parents.begin()), p1); - ASSERT_EQ(*(++parents.begin()), p2); - - parents.clear(); - ASSERT_TRUE(iCacheManager_->UpdateParent(inodeId1, p1, p3)); - ASSERT_TRUE(iCacheManager_->GetParent(inodeId1, &parents)); - ASSERT_EQ(parents.size(), 2); - ASSERT_EQ(*(parents.begin()), p3); - - parents.clear(); - iCacheManager_->RemoveParent(inodeId1, p3); - ASSERT_TRUE(iCacheManager_->GetParent(inodeId1, &parents)); - ASSERT_EQ(parents.size(), 1); - ASSERT_EQ(*(parents.begin()), p2); - - parents.clear(); + ASSERT_TRUE(iCacheManager_->GetParent(inodeId1, &parent)); + ASSERT_EQ(parent, p2); + + ASSERT_TRUE(iCacheManager_->UpdateParent(inodeId1, p3)); + ASSERT_TRUE(iCacheManager_->GetParent(inodeId1, &parent)); + ASSERT_EQ(parent, p3); + iCacheManager_->ClearParent(inodeId1); - ASSERT_FALSE(iCacheManager_->GetParent(inodeId1, &parents)); + ASSERT_FALSE(iCacheManager_->GetParent(inodeId1, &parent)); } } // namespace client diff --git a/curvefs/test/mds/mds_test.cpp b/curvefs/test/mds/mds_test.cpp index 81195a8100..8e5de6c913 100644 --- a/curvefs/test/mds/mds_test.cpp +++ b/curvefs/test/mds/mds_test.cpp @@ -91,7 +91,7 @@ class MdsTest : public ::testing::Test { EtcdConf conf{const_cast(kEtcdAddr), strlen(kEtcdAddr), 1000}; uint64_t now = curve::common::TimeUtility::GetTimeofDaySec(); bool initSucc = false; - while (curve::common::TimeUtility::GetTimeofDaySec() - now <= 5) { + while (curve::common::TimeUtility::GetTimeofDaySec() - now <= 50) { if (0 == client->Init(conf, 0, 3)) { initSucc = true; break;