Skip to content

Commit

Permalink
[feat] curvefs: merge two rpc into one when call makenode
Browse files Browse the repository at this point in the history
Signed-off-by: swj <[email protected]>
  • Loading branch information
201341 committed Sep 7, 2023
1 parent 6f5c85b commit 4cce35b
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 82 deletions.
1 change: 1 addition & 0 deletions curvefs/proto/metaserver.proto
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ message CreateDentryRequest {
required uint32 copysetId = 2;
required uint32 partitionId = 3;
required Dentry dentry = 4;
optional Time create = 5;
}

message CreateDentryResponse {
Expand Down
40 changes: 0 additions & 40 deletions curvefs/src/client/fuse_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ CURVEFS_ERROR FuseClient::MakeNode(
if (type == FsFileType::TYPE_FILE || type == FsFileType::TYPE_S3) {
dentry.set_flag(DentryFlag::TYPE_FILE_FLAG);
}

ret = dentryManager_->CreateDentry(dentry);
if (ret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "dentryManager_ CreateDentry fail, ret = " << ret
Expand All @@ -456,15 +455,6 @@ CURVEFS_ERROR FuseClient::MakeNode(
return ret;
}

ret = UpdateParentMCTimeAndNlink(parent, type, NlinkChange::kAddOne);
if (ret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "UpdateParentMCTimeAndNlink failed"
<< ", parent: " << parent
<< ", name: " << name
<< ", type: " << type;
return ret;
}

VLOG(6) << "dentryManager_ CreateDentry success"
<< ", parent = " << parent << ", name = " << name
<< ", mode = " << mode;
Expand Down Expand Up @@ -620,7 +610,6 @@ CURVEFS_ERROR FuseClient::CreateManageNode(fuse_req_t req,
if (type == FsFileType::TYPE_FILE || type == FsFileType::TYPE_S3) {
dentry.set_flag(DentryFlag::TYPE_FILE_FLAG);
}

ret = dentryManager_->CreateDentry(dentry);
if (ret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "dentryManager_ CreateDentry fail, ret = " << ret
Expand All @@ -636,15 +625,6 @@ CURVEFS_ERROR FuseClient::CreateManageNode(fuse_req_t req,
return ret;
}

ret = UpdateParentMCTimeAndNlink(parent, type, NlinkChange::kAddOne);
if (ret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "UpdateParentMCTimeAndNlink failed"
<< ", parent: " << parent
<< ", name: " << name
<< ", type: " << type;
return ret;
}

VLOG(6) << "dentryManager_ CreateDentry success"
<< ", parent = " << parent << ", name = " << name
<< ", mode = " << mode;
Expand Down Expand Up @@ -1231,17 +1211,6 @@ CURVEFS_ERROR FuseClient::FuseOpSymlink(fuse_req_t req,
return ret;
}

ret = UpdateParentMCTimeAndNlink(parent, FsFileType::TYPE_SYM_LINK,
NlinkChange::kAddOne);
if (ret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "UpdateParentMCTimeAndNlink failed"
<< ", link:" << link
<< ", parent: " << parent
<< ", name: " << name
<< ", type: " << FsFileType::TYPE_SYM_LINK;
return ret;
}

if (enableSumInDir_.load()) {
// update parent summary info
XAttr xattr;
Expand Down Expand Up @@ -1303,15 +1272,6 @@ CURVEFS_ERROR FuseClient::FuseOpLink(fuse_req_t req,
return ret;
}

ret = UpdateParentMCTimeAndNlink(newparent, type, NlinkChange::kAddOne);
if (ret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "UpdateParentMCTimeAndNlink failed"
<< ", parent: " << newparent
<< ", name: " << newname
<< ", type: " << type;
return ret;
}

if (enableSumInDir_.load()) {
// update parent summary info
XAttr xattr;
Expand Down
6 changes: 6 additions & 0 deletions curvefs/src/client/rpcclient/metaserver_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ 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);
curvefs::metaserver::MetaServerService_Stub stub(channel);
stub.CreateDentry(cntl, &request, &response, nullptr);

Expand Down
7 changes: 6 additions & 1 deletion curvefs/src/mds/metaserverclient/metaserver_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,12 @@ FSStatusCode MetaserverClient::CreateDentry(
d->set_txid(0);
d->set_type(FsFileType::TYPE_DIRECTORY);
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);
auto fp = &MetaServerService_Stub::CreateDentry;
LeaderCtx ctx;
ctx.addrs = addrs;
Expand Down
48 changes: 33 additions & 15 deletions curvefs/src/metaserver/inode_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,27 +471,34 @@ MetaStatusCode InodeManager::PaddingInodeS3ChunkInfo(int32_t fsId,
}

MetaStatusCode InodeManager::UpdateInodeWhenCreateOrRemoveSubNode(
uint32_t fsId, uint64_t inodeId, FsFileType type, bool isCreate) {
const Dentry &dentry,
uint64_t now,
uint32_t now_ns,
bool isCreate) {
uint64_t fsId = dentry.fsid();
uint64_t parentInodeId = dentry.parentinodeid();
FsFileType type = dentry.type();
MetaStatusCode ret = MetaStatusCode::OK;

VLOG(6) << "UpdateInodeWhenCreateOrRemoveSubNode, fsId = " << fsId
<< ", inodeId = " << inodeId
<< ", inodeId = " << parentInodeId
<< ", isCreate = " << isCreate;
NameLockGuard lg(inodeLock_, GetInodeLockName(fsId, inodeId));

Inode inode;
MetaStatusCode ret = inodeStorage_->Get(
Key4Inode(fsId, inodeId), &inode);
NameLockGuard lg(inodeLock_, GetInodeLockName(fsId, parentInodeId));
Inode parentInode;
ret = inodeStorage_->Get(
Key4Inode(fsId, parentInodeId), &parentInode);
if (ret != MetaStatusCode::OK) {
LOG(ERROR) << "GetInode fail, " << inode.ShortDebugString()
LOG(ERROR) << "GetInode fail, " << parentInode.ShortDebugString()
<< ", ret = " << MetaStatusCode_Name(ret);
return ret;
}

uint32_t oldNlink = inode.nlink();
uint32_t oldNlink = parentInode.nlink();
if (oldNlink == 0) {
LOG(ERROR)
<< "UpdateInodeWhenCreateOrRemoveSubNode already be deleted!"
<< " fsId: " << fsId
<< ", inodeId: " << inodeId
<< ", inodeId: " << parentInodeId
<< ", type: " << type
<< ", isCreate: " << isCreate;
// already be deleted
Expand All @@ -500,21 +507,32 @@ MetaStatusCode InodeManager::UpdateInodeWhenCreateOrRemoveSubNode(

if (FsFileType::TYPE_DIRECTORY == type) {
if (isCreate) {
inode.set_nlink(++oldNlink);
parentInode.set_nlink(++oldNlink);
} else {
inode.set_nlink(--oldNlink);
parentInode.set_nlink(--oldNlink);
}
}

ret = inodeStorage_->Update(inode);
// update mctime and changetime
if (now != 0) {
parentInode.set_mtime(now);
parentInode.set_ctime(now);
}

if (now_ns != 0) {
parentInode.set_mtime_ns(now_ns);
parentInode.set_ctime_ns(now_ns);
}

ret = inodeStorage_->Update(parentInode);
if (ret != MetaStatusCode::OK) {
LOG(ERROR) << "UpdateInode fail, " << inode.ShortDebugString()
LOG(ERROR) << "UpdateInode fail, " << parentInode.ShortDebugString()
<< ", ret = " << MetaStatusCode_Name(ret);
return ret;
}

VLOG(9) << "UpdateInodeWhenCreateOrRemoveSubNode success, "
<< inode.ShortDebugString();
<< parentInode.ShortDebugString();
return MetaStatusCode::OK;
}

Expand Down
7 changes: 5 additions & 2 deletions curvefs/src/metaserver/inode_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ class InodeManager {
S3ChunkInfoMap* m,
uint64_t limit = 0);

MetaStatusCode UpdateInodeWhenCreateOrRemoveSubNode(uint32_t fsId,
uint64_t inodeId, FsFileType type, bool isCreate);
MetaStatusCode UpdateInodeWhenCreateOrRemoveSubNode(
const Dentry &dentry,
uint64_t now,
uint32_t now_ns,
bool isCreate);

MetaStatusCode InsertInode(const Inode &inode);

Expand Down
13 changes: 11 additions & 2 deletions curvefs/src/metaserver/metastore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,17 @@ MetaStatusCode MetaStoreImpl::CreateDentry(const CreateDentryRequest *request,
ReadLockGuard readLockGuard(rwLock_);
std::shared_ptr<Partition> partition;
GET_PARTITION_OR_RETURN(partition);

MetaStatusCode status = partition->CreateDentry(request->dentry());
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);
MetaStatusCode status =
partition->CreateDentry(request->dentry(), tm);
response->set_statuscode(status);
return status;
}
Expand Down
9 changes: 4 additions & 5 deletions curvefs/src/metaserver/partition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ Partition::Partition(PartitionInfo partition,
} \
} while (0)

MetaStatusCode Partition::CreateDentry(const Dentry& dentry) {
MetaStatusCode Partition::CreateDentry(const Dentry& dentry,
const Time& tm) {
PRECHECK(dentry.fsid(), dentry.parentinodeid());

MetaStatusCode ret = dentryManager_->CreateDentry(dentry);
if (MetaStatusCode::OK == ret) {
if (dentry.has_type()) {
return inodeManager_->UpdateInodeWhenCreateOrRemoveSubNode(
dentry.fsid(), dentry.parentinodeid(),
dentry.type(), true);
dentry, tm.sec(), tm.nsec(), true);
} else {
LOG(ERROR) << "CreateDentry does not have type, "
<< dentry.ShortDebugString();
Expand Down Expand Up @@ -149,8 +149,7 @@ MetaStatusCode Partition::DeleteDentry(const Dentry& dentry) {
if (MetaStatusCode::OK == ret) {
if (dentry.has_type()) {
return inodeManager_->UpdateInodeWhenCreateOrRemoveSubNode(
dentry.fsid(), dentry.parentinodeid(),
dentry.type(), false);
dentry, 0, 0, false);
} else {
LOG(ERROR) << "DeleteDentry does not have type, "
<< dentry.ShortDebugString();
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 @@ -56,7 +56,8 @@ class Partition {
Partition() = default;

// dentry
MetaStatusCode CreateDentry(const Dentry& dentry);
MetaStatusCode CreateDentry(const Dentry& dentry,
const Time& tm);

MetaStatusCode LoadDentry(const DentryVec& vec, bool merge);

Expand Down
3 changes: 0 additions & 3 deletions curvefs/test/client/test_fuse_s3_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1558,9 +1558,6 @@ TEST_F(TestFuseS3Client, FuseOpCreate_EnableSummary) {
auto parentInodeWrapper = std::make_shared<InodeWrapper>(
parentInode, metaClient_);
EXPECT_CALL(*inodeManager_, GetInode(_, _))
.WillOnce(
DoAll(SetArgReferee<1>(parentInodeWrapper),
Return(CURVEFS_ERROR::OK)))
.WillOnce(
DoAll(SetArgReferee<1>(parentInodeWrapper),
Return(CURVEFS_ERROR::OK)));
Expand Down
10 changes: 8 additions & 2 deletions curvefs/test/metaserver/partition_clean_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,15 @@ TEST_F(PartitionCleanManagerTest, test1) {
dentry.set_inodeid(1100);
dentry.set_txid(0);
dentry.set_type(FsFileType::TYPE_DIRECTORY);

Time tm;
tm.set_sec(0);
tm.set_nsec(0);
ASSERT_EQ(partition->CreateRootInode(param), MetaStatusCode::OK);
ASSERT_EQ(partition->CreateDentry(dentry), MetaStatusCode::OK);
ASSERT_EQ(partition->CreateDentry(dentry), MetaStatusCode::OK);
ASSERT_EQ(partition->CreateDentry(dentry, tm),
MetaStatusCode::OK);
ASSERT_EQ(partition->CreateDentry(dentry, tm),
MetaStatusCode::OK);

Inode inode1;
param.type = FsFileType::TYPE_S3;
Expand Down
13 changes: 10 additions & 3 deletions curvefs/test/metaserver/partition_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,11 @@ TEST_F(PartitionTest, dentrynum) {
dentry.set_name("name");
dentry.set_txid(0);
dentry.set_type(FsFileType::TYPE_DIRECTORY);
ASSERT_EQ(partition1.CreateDentry(dentry), MetaStatusCode::OK);
Time tm;
tm.set_sec(0);
tm.set_nsec(0);
ASSERT_EQ(partition1.CreateDentry(dentry, tm),
MetaStatusCode::OK);
ASSERT_EQ(partition1.GetDentryNum(), 1);

ASSERT_EQ(partition1.DeleteDentry(dentry), MetaStatusCode::OK);
Expand All @@ -294,10 +298,13 @@ TEST_F(PartitionTest, PARTITION_ID_MISSMATCH_ERROR) {
dentry2.set_fsid(1);
dentry2.set_parentinodeid(200);

Time tm;
tm.set_sec(0);
tm.set_nsec(0);
// test CreateDentry
ASSERT_EQ(partition1.CreateDentry(dentry1),
ASSERT_EQ(partition1.CreateDentry(dentry1, tm),
MetaStatusCode::PARTITION_ID_MISSMATCH);
ASSERT_EQ(partition1.CreateDentry(dentry2),
ASSERT_EQ(partition1.CreateDentry(dentry2, tm),
MetaStatusCode::PARTITION_ID_MISSMATCH);

// test DeleteDentry
Expand Down
25 changes: 19 additions & 6 deletions curvefs/test/metaserver/recycle_cleaner_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ class RecycleCleanerTest : public testing::Test {
dentry.set_parentinodeid(ROOTINODEID);
dentry.set_type(FsFileType::TYPE_DIRECTORY);
dentry.set_txid(0);
ASSERT_EQ(partition_->CreateDentry(dentry), MetaStatusCode::OK);
Time tm;
tm.set_sec(0);
tm.set_nsec(0);
ASSERT_EQ(partition_->CreateDentry(dentry, tm),
MetaStatusCode::OK);
}

void TearDown() override {
Expand Down Expand Up @@ -173,7 +177,8 @@ TEST_F(RecycleCleanerTest, dir_time_out_test) {
EXPECT_CALL(*mdsclient_, GetFsInfo(2, _))
.WillOnce(DoAll(SetArgPointee<1>(fsInfo),
Return(FSStatusCode::UNKNOWN_ERROR)))
.WillOnce(DoAll(SetArgPointee<1>(fsInfo), Return(FSStatusCode::OK)));
.WillOnce(DoAll(SetArgPointee<1>(fsInfo),
Return(FSStatusCode::OK)));
ASSERT_FALSE(cleaner_->UpdateFsInfo());
ASSERT_TRUE(cleaner_->UpdateFsInfo());

Expand Down Expand Up @@ -354,8 +359,11 @@ TEST_F(RecycleCleanerTest, scan_recycle_test5) {
dentry2.set_inodeid(2001);
dentry2.set_txid(0);
dentry2.set_type(FsFileType::TYPE_DIRECTORY);
partition_->CreateDentry(dentry1);
partition_->CreateDentry(dentry2);
Time tm;
tm.set_sec(0);
tm.set_nsec(0);
partition_->CreateDentry(dentry1, tm);
partition_->CreateDentry(dentry2, tm);
LOG(INFO) << "create dentry1 " << dentry1.ShortDebugString();
LOG(INFO) << "create dentry2 " << dentry2.ShortDebugString();

Expand Down Expand Up @@ -384,8 +392,13 @@ TEST_F(RecycleCleanerTest, scan_recycle_test6) {
dentry2.set_inodeid(2001);
dentry2.set_txid(0);
dentry2.set_type(FsFileType::TYPE_DIRECTORY);
ASSERT_EQ(partition_->CreateDentry(dentry1), MetaStatusCode::OK);
ASSERT_EQ(partition_->CreateDentry(dentry2), MetaStatusCode::OK);
Time tm;
tm.set_sec(0);
tm.set_nsec(0);
ASSERT_EQ(partition_->CreateDentry(dentry1, tm),
MetaStatusCode::OK);
ASSERT_EQ(partition_->CreateDentry(dentry2, tm),
MetaStatusCode::OK);
LOG(INFO) << "create dentry1 " << dentry1.ShortDebugString();
LOG(INFO) << "create dentry2 " << dentry2.ShortDebugString();

Expand Down
Loading

0 comments on commit 4cce35b

Please sign in to comment.