From a0aafd46c57cb5e6d7cc7a49b48bed29fdf8d0ce Mon Sep 17 00:00:00 2001 From: swj <1186093704@qq.com> Date: Thu, 7 Sep 2023 14:10:45 +0800 Subject: [PATCH] [feat]: curvefs: merge two rpc into one when delete dentry Signed-off-by: swj <1186093704@qq.com> --- curvefs/proto/metaserver.proto | 1 + curvefs/src/client/fuse_client.cpp | 38 ------------------- curvefs/src/client/fuse_client.h | 3 -- .../client/rpcclient/metaserver_client.cpp | 7 +++- curvefs/src/metaserver/inode_manager.cpp | 7 ++-- curvefs/src/metaserver/inode_manager.h | 8 ++-- curvefs/src/metaserver/metastore.cpp | 12 +++++- curvefs/src/metaserver/partition.cpp | 6 +-- curvefs/src/metaserver/partition.h | 6 +-- curvefs/test/client/test_fuse_s3_client.cpp | 13 +------ .../test/client/test_fuse_volume_client.cpp | 8 ---- curvefs/test/metaserver/partition_test.cpp | 6 +-- 12 files changed, 34 insertions(+), 81 deletions(-) diff --git a/curvefs/proto/metaserver.proto b/curvefs/proto/metaserver.proto index 266b6d8407..671492b2f7 100644 --- a/curvefs/proto/metaserver.proto +++ b/curvefs/proto/metaserver.proto @@ -131,6 +131,7 @@ message DeleteDentryRequest { required uint64 parentInodeId = 6; required string name = 7; optional FsFileType type = 8; + optional Time time = 9; } message DeleteDentryResponse { diff --git a/curvefs/src/client/fuse_client.cpp b/curvefs/src/client/fuse_client.cpp index 8b66a20d41..6b0d837a6d 100644 --- a/curvefs/src/client/fuse_client.cpp +++ b/curvefs/src/client/fuse_client.cpp @@ -349,35 +349,6 @@ CURVEFS_ERROR FuseClient::FuseOpOpen(fuse_req_t req, return HandleOpenFlags(req, ino, fi, fileOut); } -CURVEFS_ERROR FuseClient::UpdateParentMCTimeAndNlink( - fuse_ino_t parent, FsFileType type, NlinkChange nlink) { - - std::shared_ptr parentInodeWrapper; - auto ret = inodeManager_->GetInode(parent, parentInodeWrapper); - if (ret != CURVEFS_ERROR::OK) { - LOG(ERROR) << "inodeManager get inode fail, ret = " << ret - << ", inodeid = " << parent; - return ret; - } - - { - curve::common::UniqueLock lk = parentInodeWrapper->GetUniqueLock(); - parentInodeWrapper->UpdateTimestampLocked(kModifyTime | kChangeTime); - - if (FsFileType::TYPE_DIRECTORY == type) { - parentInodeWrapper->UpdateNlinkLocked(nlink); - } - - if (option_.fileSystemOption.deferSyncOption.deferDirMtime) { - inodeManager_->ShipToFlush(parentInodeWrapper); - } else { - return parentInodeWrapper->SyncAttr(); - } - } - - return CURVEFS_ERROR::OK; -} - CURVEFS_ERROR FuseClient::MakeNode( fuse_req_t req, fuse_ino_t parent, @@ -515,15 +486,6 @@ CURVEFS_ERROR FuseClient::DeleteNode(uint64_t ino, fuse_ino_t parent, return ret; } - ret = UpdateParentMCTimeAndNlink(parent, type, NlinkChange::kSubOne); - if (ret != CURVEFS_ERROR::OK) { - LOG(ERROR) << "UpdateParentMCTimeAndNlink failed" - << ", parent: " << parent - << ", name: " << name - << ", type: " << type; - return ret; - } - std::shared_ptr inodeWrapper; ret = inodeManager_->GetInode(ino, inodeWrapper); if (ret != CURVEFS_ERROR::OK) { diff --git a/curvefs/src/client/fuse_client.h b/curvefs/src/client/fuse_client.h index 3988b77866..a5e16a5c56 100644 --- a/curvefs/src/client/fuse_client.h +++ b/curvefs/src/client/fuse_client.h @@ -393,9 +393,6 @@ class FuseClient { private: virtual void FlushData() = 0; - CURVEFS_ERROR UpdateParentMCTimeAndNlink( - fuse_ino_t parent, FsFileType type, NlinkChange nlink); - std::string GenerateNewRecycleName(fuse_ino_t ino, fuse_ino_t parent, const char* name) { std::string newName(name); diff --git a/curvefs/src/client/rpcclient/metaserver_client.cpp b/curvefs/src/client/rpcclient/metaserver_client.cpp index febde15dc2..76a715569e 100644 --- a/curvefs/src/client/rpcclient/metaserver_client.cpp +++ b/curvefs/src/client/rpcclient/metaserver_client.cpp @@ -321,7 +321,12 @@ MetaStatusCode MetaServerClientImpl::DeleteDentry(uint32_t fsId, request.set_name(name); request.set_txid(txId); request.set_type(type); - + struct timespec now; + clock_gettime(CLOCK_REALTIME, &now); + Time* tm = new Time(); + tm->set_sec(now.tv_sec); + tm->set_nsec(now.tv_nsec); + request.set_allocated_time(tm); curvefs::metaserver::MetaServerService_Stub stub(channel); stub.DeleteDentry(cntl, &request, &response, nullptr); diff --git a/curvefs/src/metaserver/inode_manager.cpp b/curvefs/src/metaserver/inode_manager.cpp index f0e1146445..afc71d1d43 100644 --- a/curvefs/src/metaserver/inode_manager.cpp +++ b/curvefs/src/metaserver/inode_manager.cpp @@ -471,12 +471,11 @@ MetaStatusCode InodeManager::PaddingInodeS3ChunkInfo(int32_t fsId, } MetaStatusCode InodeManager::UpdateInodeWhenCreateOrRemoveSubNode( - const Dentry &dentry, - uint64_t now, - uint32_t now_ns, - bool isCreate) { + const Dentry& dentry, const Time& tm, bool isCreate) { uint64_t fsId = dentry.fsid(); uint64_t parentInodeId = dentry.parentinodeid(); + uint64_t now = tm.sec(); + uint64_t now_ns = tm.nsec(); FsFileType type = dentry.type(); MetaStatusCode ret = MetaStatusCode::OK; diff --git a/curvefs/src/metaserver/inode_manager.h b/curvefs/src/metaserver/inode_manager.h index e1abbb1627..a89d6e9c1d 100644 --- a/curvefs/src/metaserver/inode_manager.h +++ b/curvefs/src/metaserver/inode_manager.h @@ -103,11 +103,9 @@ class InodeManager { S3ChunkInfoMap* m, uint64_t limit = 0); - MetaStatusCode UpdateInodeWhenCreateOrRemoveSubNode( - const Dentry &dentry, - uint64_t now, - uint32_t now_ns, - bool isCreate); + MetaStatusCode UpdateInodeWhenCreateOrRemoveSubNode(const Dentry& dentry, + const Time& tm, + bool isCreate); MetaStatusCode InsertInode(const Inode &inode); diff --git a/curvefs/src/metaserver/metastore.cpp b/curvefs/src/metaserver/metastore.cpp index 2ba443f60e..b5f83790ae 100644 --- a/curvefs/src/metaserver/metastore.cpp +++ b/curvefs/src/metaserver/metastore.cpp @@ -415,8 +415,16 @@ MetaStatusCode MetaStoreImpl::DeleteDentry(const DeleteDentryRequest *request, dentry.set_name(name); dentry.set_txid(txId); dentry.set_type(request->type()); - - auto rc = partition->DeleteDentry(dentry); + uint64_t now = 0; + uint32_t now_ns = 0; + if (request->has_time()) { + now = request->time().sec(); + now_ns = request->time().nsec(); + } + Time tm; + tm.set_sec(now); + tm.set_nsec(now_ns); + auto rc = partition->DeleteDentry(dentry, tm); response->set_statuscode(rc); return rc; } diff --git a/curvefs/src/metaserver/partition.cpp b/curvefs/src/metaserver/partition.cpp index 7b7e745a6c..c16d45219c 100644 --- a/curvefs/src/metaserver/partition.cpp +++ b/curvefs/src/metaserver/partition.cpp @@ -116,7 +116,7 @@ MetaStatusCode Partition::CreateDentry(const Dentry& dentry, if (MetaStatusCode::OK == ret) { if (dentry.has_type()) { return inodeManager_->UpdateInodeWhenCreateOrRemoveSubNode( - dentry, tm.sec(), tm.nsec(), true); + dentry, tm, true); } else { LOG(ERROR) << "CreateDentry does not have type, " << dentry.ShortDebugString(); @@ -142,14 +142,14 @@ MetaStatusCode Partition::LoadDentry(const DentryVec& vec, bool merge) { return rc; } -MetaStatusCode Partition::DeleteDentry(const Dentry& dentry) { +MetaStatusCode Partition::DeleteDentry(const Dentry& dentry, const Time& tm) { PRECHECK(dentry.fsid(), dentry.parentinodeid()); MetaStatusCode ret = dentryManager_->DeleteDentry(dentry); if (MetaStatusCode::OK == ret) { if (dentry.has_type()) { return inodeManager_->UpdateInodeWhenCreateOrRemoveSubNode( - dentry, 0, 0, false); + dentry, tm, false); } else { LOG(ERROR) << "DeleteDentry does not have type, " << dentry.ShortDebugString(); diff --git a/curvefs/src/metaserver/partition.h b/curvefs/src/metaserver/partition.h index e24c0abd40..15e423a5fc 100644 --- a/curvefs/src/metaserver/partition.h +++ b/curvefs/src/metaserver/partition.h @@ -56,12 +56,12 @@ class Partition { Partition() = default; // dentry - MetaStatusCode CreateDentry(const Dentry& dentry, - const Time& tm); + MetaStatusCode CreateDentry(const Dentry& dentry, const Time& tm); MetaStatusCode LoadDentry(const DentryVec& vec, bool merge); - MetaStatusCode DeleteDentry(const Dentry& dentry); + MetaStatusCode DeleteDentry(const Dentry& dentry, + const Time& tm); MetaStatusCode GetDentry(Dentry* dentry); diff --git a/curvefs/test/client/test_fuse_s3_client.cpp b/curvefs/test/client/test_fuse_s3_client.cpp index 2eb3e03e0a..2b04937d77 100644 --- a/curvefs/test/client/test_fuse_s3_client.cpp +++ b/curvefs/test/client/test_fuse_s3_client.cpp @@ -1732,26 +1732,17 @@ TEST_F(TestFuseS3Client, FuseOpUnlink_EnableSummary) { parentInode, metaClient_); EXPECT_CALL(*inodeManager_, GetInode(_, _)) - .WillOnce( - DoAll(SetArgReferee<1>(parentInodeWrapper), - Return(CURVEFS_ERROR::OK))) .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(*metaClient_, GetInodeAttr(_, _, _)) .WillOnce(DoAll(SetArgPointee<2>(attr), Return(MetaStatusCode::OK))); EXPECT_CALL(*metaClient_, UpdateInodeAttr(_, _, _)) .WillRepeatedly(Return(MetaStatusCode::OK)); - EXPECT_CALL(*inodeManager_, ShipToFlush(_)) - .Times(1); - CURVEFS_ERROR ret = client_->FuseOpUnlink(req, parent, name.c_str()); ASSERT_EQ(CURVEFS_ERROR::OK, ret); - Inode inode2 = inodeWrapper->GetInode(); - ASSERT_EQ(nlink - 1, inode2.nlink()); auto p = parentInodeWrapper->GetInode(); ASSERT_EQ(3, p.nlink()); diff --git a/curvefs/test/client/test_fuse_volume_client.cpp b/curvefs/test/client/test_fuse_volume_client.cpp index b31b6193f8..1b984c6b81 100644 --- a/curvefs/test/client/test_fuse_volume_client.cpp +++ b/curvefs/test/client/test_fuse_volume_client.cpp @@ -569,8 +569,6 @@ TEST_F(TestFuseVolumeClient, FuseOpUnlink) { std::make_shared(parentInode, metaClient_); EXPECT_CALL(*inodeManager_, GetInode(_, _)) - .WillOnce(DoAll(SetArgReferee<1>(parentInodeWrapper), - Return(CURVEFS_ERROR::OK))) .WillOnce( DoAll(SetArgReferee<1>(inodeWrapper), Return(CURVEFS_ERROR::OK))); EXPECT_CALL(*metaClient_, GetInodeAttr(_, _, _)) @@ -630,8 +628,6 @@ TEST_F(TestFuseVolumeClient, FuseOpRmDir) { std::make_shared(parentInode, metaClient_); EXPECT_CALL(*inodeManager_, GetInode(_, _)) - .WillOnce(DoAll(SetArgReferee<1>(parentInodeWrapper), - Return(CURVEFS_ERROR::OK))) .WillOnce( DoAll(SetArgReferee<1>(inodeWrapper), Return(CURVEFS_ERROR::OK))); EXPECT_CALL(*metaClient_, GetInodeAttr(_, _, _)) @@ -695,11 +691,7 @@ TEST_F(TestFuseVolumeClient, FuseOpUnlinkFailed) { std::make_shared(parentInode, metaClient_); EXPECT_CALL(*inodeManager_, GetInode(_, _)) - .WillOnce(DoAll(SetArgReferee<1>(parentInodeWrapper), - Return(CURVEFS_ERROR::OK))) .WillOnce(Return(CURVEFS_ERROR::INTERNAL)) - .WillOnce(DoAll(SetArgReferee<1>(parentInodeWrapper), - Return(CURVEFS_ERROR::OK))) .WillOnce( DoAll(SetArgReferee<1>(inodeWrapper), Return(CURVEFS_ERROR::OK))); EXPECT_CALL(*metaClient_, GetInodeAttr(_, _, _)) diff --git a/curvefs/test/metaserver/partition_test.cpp b/curvefs/test/metaserver/partition_test.cpp index 7c405e335c..3bd9d8d4ef 100644 --- a/curvefs/test/metaserver/partition_test.cpp +++ b/curvefs/test/metaserver/partition_test.cpp @@ -275,7 +275,7 @@ TEST_F(PartitionTest, dentrynum) { MetaStatusCode::OK); ASSERT_EQ(partition1.GetDentryNum(), 1); - ASSERT_EQ(partition1.DeleteDentry(dentry), MetaStatusCode::OK); + ASSERT_EQ(partition1.DeleteDentry(dentry, tm), MetaStatusCode::OK); ASSERT_EQ(partition1.GetDentryNum(), 0); } @@ -308,9 +308,9 @@ TEST_F(PartitionTest, PARTITION_ID_MISSMATCH_ERROR) { MetaStatusCode::PARTITION_ID_MISSMATCH); // test DeleteDentry - ASSERT_EQ(partition1.DeleteDentry(dentry1), + ASSERT_EQ(partition1.DeleteDentry(dentry1, tm), MetaStatusCode::PARTITION_ID_MISSMATCH); - ASSERT_EQ(partition1.DeleteDentry(dentry2), + ASSERT_EQ(partition1.DeleteDentry(dentry2, tm), MetaStatusCode::PARTITION_ID_MISSMATCH); // test GetDentry