Skip to content

Commit

Permalink
[feat]: curvefs: merge two rpc into one when delete dentry
Browse files Browse the repository at this point in the history
Signed-off-by: swj <1186093704@qq.com>
  • Loading branch information
201341 committed Sep 12, 2023
1 parent 14d4b07 commit a0aafd4
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 81 deletions.
1 change: 1 addition & 0 deletions curvefs/proto/metaserver.proto
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ message DeleteDentryRequest {
required uint64 parentInodeId = 6;
required string name = 7;
optional FsFileType type = 8;
optional Time time = 9;
}

message DeleteDentryResponse {
Expand Down
38 changes: 0 additions & 38 deletions curvefs/src/client/fuse_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<InodeWrapper> 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,
Expand Down Expand Up @@ -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> inodeWrapper;
ret = inodeManager_->GetInode(ino, inodeWrapper);
if (ret != CURVEFS_ERROR::OK) {
Expand Down
3 changes: 0 additions & 3 deletions curvefs/src/client/fuse_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion curvefs/src/client/rpcclient/metaserver_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
7 changes: 3 additions & 4 deletions curvefs/src/metaserver/inode_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 3 additions & 5 deletions curvefs/src/metaserver/inode_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
12 changes: 10 additions & 2 deletions curvefs/src/metaserver/metastore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions curvefs/src/metaserver/partition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions curvefs/src/metaserver/partition.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
13 changes: 2 additions & 11 deletions curvefs/test/client/test_fuse_s3_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
8 changes: 0 additions & 8 deletions curvefs/test/client/test_fuse_volume_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,6 @@ TEST_F(TestFuseVolumeClient, FuseOpUnlink) {
std::make_shared<InodeWrapper>(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(_, _, _))
Expand Down Expand Up @@ -630,8 +628,6 @@ TEST_F(TestFuseVolumeClient, FuseOpRmDir) {
std::make_shared<InodeWrapper>(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(_, _, _))
Expand Down Expand Up @@ -695,11 +691,7 @@ TEST_F(TestFuseVolumeClient, FuseOpUnlinkFailed) {
std::make_shared<InodeWrapper>(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(_, _, _))
Expand Down
6 changes: 3 additions & 3 deletions curvefs/test/metaserver/partition_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a0aafd4

Please sign in to comment.