From 147109eb9b2fe327b783563d9c1ff909b1287a93 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 | 25 ++++++------ .../src/client/rpcclient/metaserver_client.h | 2 + curvefs/src/metaserver/inode_manager.cpp | 5 ++- curvefs/src/metaserver/inode_manager.h | 7 +--- curvefs/src/metaserver/metastore.cpp | 22 ++++++----- curvefs/src/metaserver/partition.cpp | 11 +++--- curvefs/src/metaserver/partition.h | 11 +++--- curvefs/test/client/test_fuse_s3_client.cpp | 10 +---- .../test/client/test_fuse_volume_client.cpp | 8 ---- curvefs/test/metaserver/partition_test.cpp | 15 ++++---- 13 files changed, 55 insertions(+), 103 deletions(-) diff --git a/curvefs/proto/metaserver.proto b/curvefs/proto/metaserver.proto index f0ab8167a2..7bc0759841 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 create = 9; } message DeleteDentryResponse { diff --git a/curvefs/src/client/fuse_client.cpp b/curvefs/src/client/fuse_client.cpp index e3159fcc81..a5305b62b3 100644 --- a/curvefs/src/client/fuse_client.cpp +++ b/curvefs/src/client/fuse_client.cpp @@ -363,35 +363,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, @@ -530,15 +501,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 13adc3c591..cad4af68c7 100644 --- a/curvefs/src/client/fuse_client.h +++ b/curvefs/src/client/fuse_client.h @@ -415,9 +415,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..afaf3669d7 100644 --- a/curvefs/src/client/rpcclient/metaserver_client.cpp +++ b/curvefs/src/client/rpcclient/metaserver_client.cpp @@ -107,6 +107,15 @@ class MetaServerClientRpcDoneBase : public google::protobuf::Closure { MetaServerClientMetric *metric_; }; +Time* MetaServerClientImpl::CreateTime() { + struct timespec now; + clock_gettime(CLOCK_REALTIME, &now); + Time* tm = new Time(); + tm->set_sec(now.tv_sec); + tm->set_nsec(now.tv_nsec); + return tm; +} + MetaStatusCode MetaServerClientImpl::GetTxId(uint32_t fsId, uint64_t inodeId, uint32_t *partitionId, uint64_t *txId) { @@ -255,12 +264,7 @@ MetaStatusCode MetaServerClientImpl::CreateDentry(const Dentry &dentry) { d->set_txid(txId); d->set_type(dentry.type()); request.set_allocated_dentry(d); - 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_create(tm); + request.set_allocated_create(CreateTime()); curvefs::metaserver::MetaServerService_Stub stub(channel); stub.CreateDentry(cntl, &request, &response, nullptr); @@ -321,7 +325,7 @@ MetaStatusCode MetaServerClientImpl::DeleteDentry(uint32_t fsId, request.set_name(name); request.set_txid(txId); request.set_type(type); - + request.set_allocated_create(CreateTime()); curvefs::metaserver::MetaServerService_Stub stub(channel); stub.DeleteDentry(cntl, &request, &response, nullptr); @@ -1147,12 +1151,7 @@ MetaStatusCode MetaServerClientImpl::CreateInode(const InodeParam ¶m, request.set_rdev(param.rdev); request.set_symlink(param.symlink); request.set_parent(param.parent); - 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_create(tm); + request.set_allocated_create(CreateTime()); curvefs::metaserver::MetaServerService_Stub stub(channel); stub.CreateInode(cntl, &request, &response, nullptr); diff --git a/curvefs/src/client/rpcclient/metaserver_client.h b/curvefs/src/client/rpcclient/metaserver_client.h index cd2a233da3..292e45d7ae 100644 --- a/curvefs/src/client/rpcclient/metaserver_client.h +++ b/curvefs/src/client/rpcclient/metaserver_client.h @@ -298,6 +298,8 @@ class MetaServerClientImpl : public MetaServerClient { bool HandleS3MetaStreamBuffer(butil::IOBuf* buffer, S3ChunkInfoMap* out); + Time* CreateTime(); + private: ExcutorOpt opt_; ExcutorOpt optInternal_; diff --git a/curvefs/src/metaserver/inode_manager.cpp b/curvefs/src/metaserver/inode_manager.cpp index 91fb83a784..9fc94643a4 100644 --- a/curvefs/src/metaserver/inode_manager.cpp +++ b/curvefs/src/metaserver/inode_manager.cpp @@ -541,10 +541,11 @@ MetaStatusCode InodeManager::PaddingInodeS3ChunkInfo(int32_t fsId, } MetaStatusCode InodeManager::UpdateInodeWhenCreateOrRemoveSubNode( - const Dentry& dentry, uint64_t now, uint32_t now_ns, bool isCreate, - int64_t logIndex) { + const Dentry& dentry, const Time& tm, bool isCreate, int64_t logIndex) { uint64_t fsId = dentry.fsid(); uint64_t parentInodeId = dentry.parentinodeid(); + uint64_t now = tm.sec(); + uint32_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 bd28f65790..29b9b13251 100644 --- a/curvefs/src/metaserver/inode_manager.h +++ b/curvefs/src/metaserver/inode_manager.h @@ -105,11 +105,8 @@ class InodeManager { S3ChunkInfoMap* m, uint64_t limit = 0); - MetaStatusCode UpdateInodeWhenCreateOrRemoveSubNode(const Dentry& dentry, - uint64_t now, - uint32_t now_ns, - bool isCreate, - int64_t logIndex); + MetaStatusCode UpdateInodeWhenCreateOrRemoveSubNode( + const Dentry& dentry, const Time& tm, bool isCreate, int64_t logIndex); MetaStatusCode InsertInode(const Inode& inode, int64_t logIndex); diff --git a/curvefs/src/metaserver/metastore.cpp b/curvefs/src/metaserver/metastore.cpp index 875f71cffc..a2fd20323c 100644 --- a/curvefs/src/metaserver/metastore.cpp +++ b/curvefs/src/metaserver/metastore.cpp @@ -358,6 +358,15 @@ std::shared_ptr MetaStoreImpl::GetStreamServer() { return status; \ } +#define GET_TIME_FROM_REQUEST(TIME) \ + uint64_t now = 0; \ + uint32_t now_ns = 0; \ + if (request->has_create()) { \ + now = request->create().sec(); \ + now_ns = request->create().nsec(); \ + } \ + TIME.set_sec(now); \ + TIME.set_nsec(now_ns); // dentry MetaStatusCode MetaStoreImpl::CreateDentry(const CreateDentryRequest* request, @@ -366,15 +375,8 @@ MetaStatusCode MetaStoreImpl::CreateDentry(const CreateDentryRequest* request, ReadLockGuard readLockGuard(rwLock_); std::shared_ptr partition; GET_PARTITION_OR_RETURN(partition); - uint64_t now = 0; - uint32_t now_ns = 0; - if (request->has_create()) { - now = request->create().sec(); - now_ns = request->create().nsec(); - } Time tm; - tm.set_sec(now); - tm.set_nsec(now_ns); + GET_TIME_FROM_REQUEST(tm); MetaStatusCode status = partition->CreateDentry(request->dentry(), tm, logIndex); response->set_statuscode(status); @@ -428,7 +430,9 @@ MetaStatusCode MetaStoreImpl::DeleteDentry(const DeleteDentryRequest* request, dentry.set_txid(txId); dentry.set_type(request->type()); - auto rc = partition->DeleteDentry(dentry, logIndex); + Time tm; + GET_TIME_FROM_REQUEST(tm); + auto rc = partition->DeleteDentry(dentry, tm, logIndex); response->set_statuscode(rc); return rc; } diff --git a/curvefs/src/metaserver/partition.cpp b/curvefs/src/metaserver/partition.cpp index 3c3e7d7b99..0ee48f50f5 100644 --- a/curvefs/src/metaserver/partition.cpp +++ b/curvefs/src/metaserver/partition.cpp @@ -117,7 +117,7 @@ MetaStatusCode Partition::CreateDentry(const Dentry& dentry, const Time& tm, if (MetaStatusCode::OK == ret) { if (dentry.has_type()) { return inodeManager_->UpdateInodeWhenCreateOrRemoveSubNode( - dentry, tm.sec(), tm.nsec(), true, logIndex); + dentry, tm, true, logIndex); } else { LOG(ERROR) << "CreateDentry does not have type, " << dentry.ShortDebugString(); @@ -128,7 +128,7 @@ MetaStatusCode Partition::CreateDentry(const Dentry& dentry, const Time& tm, // NOTE: we enter here means that // this log maybe is "half apply" ret = inodeManager_->UpdateInodeWhenCreateOrRemoveSubNode( - dentry, tm.sec(), tm.nsec(), true, logIndex); + dentry, tm, true, logIndex); if (ret == MetaStatusCode::IDEMPOTENCE_OK) { ret = MetaStatusCode::OK; } @@ -155,14 +155,15 @@ MetaStatusCode Partition::LoadDentry(const DentryVec& vec, bool merge, return rc; } -MetaStatusCode Partition::DeleteDentry(const Dentry& dentry, int64_t logIndex) { +MetaStatusCode Partition::DeleteDentry( + const Dentry& dentry, const Time& tm, int64_t logIndex) { PRECHECK(dentry.fsid(), dentry.parentinodeid()); MetaStatusCode ret = dentryManager_->DeleteDentry(dentry, logIndex); if (MetaStatusCode::OK == ret) { if (dentry.has_type()) { return inodeManager_->UpdateInodeWhenCreateOrRemoveSubNode( - dentry, 0, 0, false, logIndex); + dentry, tm, false, logIndex); } else { LOG(ERROR) << "DeleteDentry does not have type, " << dentry.ShortDebugString(); @@ -173,7 +174,7 @@ MetaStatusCode Partition::DeleteDentry(const Dentry& dentry, int64_t logIndex) { // NOTE: we enter here means that // this log maybe is "half apply" ret = inodeManager_->UpdateInodeWhenCreateOrRemoveSubNode( - dentry, 0, 0, false, logIndex); + dentry, tm, false, logIndex); } if (ret == MetaStatusCode::IDEMPOTENCE_OK) { ret = MetaStatusCode::OK; diff --git a/curvefs/src/metaserver/partition.h b/curvefs/src/metaserver/partition.h index c78738cb85..cd6d2e4dd7 100644 --- a/curvefs/src/metaserver/partition.h +++ b/curvefs/src/metaserver/partition.h @@ -58,13 +58,14 @@ class Partition { Partition() = default; // dentry - MetaStatusCode CreateDentry(const Dentry& dentry, const Time& tm, - int64_t logIndex); + MetaStatusCode CreateDentry( + const Dentry& dentry, const Time& tm, int64_t logIndex); - MetaStatusCode LoadDentry(const DentryVec& vec, bool merge, - int64_t logIndex); + MetaStatusCode LoadDentry( + const DentryVec& vec, bool merge, int64_t logIndex); - MetaStatusCode DeleteDentry(const Dentry& dentry, int64_t logIndex); + MetaStatusCode DeleteDentry( + const Dentry& dentry, const Time& tm, int64_t logIndex); 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 0d98351b30..1e3cd28843 100644 --- a/curvefs/test/client/test_fuse_s3_client.cpp +++ b/curvefs/test/client/test_fuse_s3_client.cpp @@ -3939,23 +3939,17 @@ TEST_F(TestFuseS3Client, FuseOpUnlink_EnableSummary) { 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))) - .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 ce0a49c915..755cd74265 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 9d29461e39..a68087714f 100644 --- a/curvefs/test/metaserver/partition_test.cpp +++ b/curvefs/test/metaserver/partition_test.cpp @@ -292,11 +292,12 @@ TEST_F(PartitionTest, dentrynum) { Time tm; tm.set_sec(0); tm.set_nsec(0); - ASSERT_EQ(partition1.CreateDentry(dentry, tm, logIndex_++), - MetaStatusCode::OK); + ASSERT_EQ( + partition1.CreateDentry(dentry, tm, logIndex_++), MetaStatusCode::OK); ASSERT_EQ(partition1.GetDentryNum(), 1); - ASSERT_EQ(partition1.DeleteDentry(dentry, logIndex_++), MetaStatusCode::OK); + ASSERT_EQ( + partition1.DeleteDentry(dentry, tm, logIndex_++), MetaStatusCode::OK); ASSERT_EQ(partition1.GetDentryNum(), 0); } @@ -331,10 +332,10 @@ TEST_F(PartitionTest, PARTITION_ID_MISSMATCH_ERROR) { MetaStatusCode::PARTITION_ID_MISSMATCH); // test DeleteDentry - ASSERT_EQ(partition1.DeleteDentry(dentry1, logIndex_++), - MetaStatusCode::PARTITION_ID_MISSMATCH); - ASSERT_EQ(partition1.DeleteDentry(dentry2, logIndex_++), - MetaStatusCode::PARTITION_ID_MISSMATCH); + ASSERT_EQ(partition1.DeleteDentry(dentry1, tm, logIndex_++), + MetaStatusCode::PARTITION_ID_MISSMATCH); + ASSERT_EQ(partition1.DeleteDentry(dentry2, tm, logIndex_++), + MetaStatusCode::PARTITION_ID_MISSMATCH); // test GetDentry ASSERT_EQ(partition1.GetDentry(&dentry1),