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 Oct 10, 2023
1 parent 505cc7a commit 75e591e
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 70 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 @@ -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);
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
5 changes: 3 additions & 2 deletions curvefs/src/metaserver/inode_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,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;

Expand Down
3 changes: 1 addition & 2 deletions curvefs/src/metaserver/inode_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ class InodeManager {
uint64_t limit = 0);

MetaStatusCode UpdateInodeWhenCreateOrRemoveSubNode(const Dentry& dentry,
uint64_t now,
uint32_t now_ns,
const Time& tm,
bool isCreate,
int64_t logIndex);

Expand Down
11 changes: 10 additions & 1 deletion curvefs/src/metaserver/metastore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,16 @@ MetaStatusCode MetaStoreImpl::DeleteDentry(const DeleteDentryRequest* request,
dentry.set_txid(txId);
dentry.set_type(request->type());

auto rc = partition->DeleteDentry(dentry, logIndex);
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, logIndex);
response->set_statuscode(rc);
return rc;
}
Expand Down
11 changes: 6 additions & 5 deletions curvefs/src/metaserver/partition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}
Expand All @@ -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();
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion curvefs/src/metaserver/partition.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class Partition {
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);

Expand Down
6 changes: 0 additions & 6 deletions curvefs/test/client/test_fuse_s3_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3939,8 +3939,6 @@ TEST_F(TestFuseS3Client, FuseOpUnlink_EnableSummary) {
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)))
.WillOnce(DoAll(SetArgReferee<1>(parentInodeWrapper),
Expand All @@ -3950,12 +3948,8 @@ TEST_F(TestFuseS3Client, FuseOpUnlink_EnableSummary) {
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
7 changes: 4 additions & 3 deletions curvefs/test/metaserver/partition_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ TEST_F(PartitionTest, dentrynum) {
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);
}

Expand Down Expand Up @@ -331,9 +332,9 @@ TEST_F(PartitionTest, PARTITION_ID_MISSMATCH_ERROR) {
MetaStatusCode::PARTITION_ID_MISSMATCH);

// test DeleteDentry
ASSERT_EQ(partition1.DeleteDentry(dentry1, logIndex_++),
ASSERT_EQ(partition1.DeleteDentry(dentry1, tm, logIndex_++),
MetaStatusCode::PARTITION_ID_MISSMATCH);
ASSERT_EQ(partition1.DeleteDentry(dentry2, logIndex_++),
ASSERT_EQ(partition1.DeleteDentry(dentry2, tm, logIndex_++),
MetaStatusCode::PARTITION_ID_MISSMATCH);

// test GetDentry
Expand Down

0 comments on commit 75e591e

Please sign in to comment.