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 <1186093704@qq.com>
  • Loading branch information
201341 committed Aug 31, 2023
1 parent 6f5c85b commit 80f2d22
Show file tree
Hide file tree
Showing 22 changed files with 144 additions and 109 deletions.
2 changes: 2 additions & 0 deletions curvefs/proto/metaserver.proto
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ message CreateDentryRequest {
required uint32 copysetId = 2;
required uint32 partitionId = 3;
required Dentry dentry = 4;
optional uint64 time = 5;
optional uint32 time_ns = 6;
}

message CreateDentryResponse {
Expand Down
6 changes: 4 additions & 2 deletions curvefs/src/client/dentry_cache_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ CURVEFS_ERROR DentryCacheManagerImpl::GetDentry(uint64_t parent,
return CURVEFS_ERROR::OK;
}

CURVEFS_ERROR DentryCacheManagerImpl::CreateDentry(const Dentry &dentry) {
CURVEFS_ERROR DentryCacheManagerImpl::CreateDentry(const Dentry &dentry,
const struct timespec &now) {
std::string key = GetDentryCacheKey(dentry.parentinodeid(), dentry.name());
NameLockGuard lock(nameLock_, key);
MetaStatusCode ret = metaClient_->CreateDentry(dentry);
MetaStatusCode ret = metaClient_->CreateDentry(dentry,
now);
if (ret != MetaStatusCode::OK) {
LOG(ERROR) << "metaClient_ CreateDentry failed, MetaStatusCode = "
<< ret
Expand Down
8 changes: 6 additions & 2 deletions curvefs/src/client/dentry_cache_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ class DentryCacheManager {
virtual CURVEFS_ERROR GetDentry(uint64_t parent,
const std::string &name, Dentry *out) = 0;

virtual CURVEFS_ERROR CreateDentry(const Dentry &dentry) = 0;
virtual CURVEFS_ERROR CreateDentry(
const Dentry &dentry,
const struct timespec &now) = 0;

virtual CURVEFS_ERROR DeleteDentry(uint64_t parent,
const std::string &name,
Expand All @@ -86,7 +88,9 @@ class DentryCacheManagerImpl : public DentryCacheManager {
CURVEFS_ERROR GetDentry(uint64_t parent,
const std::string &name, Dentry *out) override;

CURVEFS_ERROR CreateDentry(const Dentry &dentry) override;
CURVEFS_ERROR CreateDentry(
const Dentry &dentry,
const struct timespec &now) override;

CURVEFS_ERROR DeleteDentry(uint64_t parent,
const std::string &name,
Expand Down
60 changes: 16 additions & 44 deletions curvefs/src/client/fuse_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,10 @@ CURVEFS_ERROR FuseClient::MakeNode(
if (type == FsFileType::TYPE_FILE || type == FsFileType::TYPE_S3) {
dentry.set_flag(DentryFlag::TYPE_FILE_FLAG);
}

ret = dentryManager_->CreateDentry(dentry);
struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
ret = dentryManager_->CreateDentry(dentry,
now);
if (ret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "dentryManager_ CreateDentry fail, ret = " << ret
<< ", parent = " << parent << ", name = " << name
Expand All @@ -456,15 +458,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,8 +613,10 @@ 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);
struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
ret = dentryManager_->CreateDentry(dentry,
now);
if (ret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "dentryManager_ CreateDentry fail, ret = " << ret
<< ", parent = " << parent << ", name = " << name
Expand All @@ -636,15 +631,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 @@ -1216,7 +1202,10 @@ CURVEFS_ERROR FuseClient::FuseOpSymlink(fuse_req_t req,
dentry.set_parentinodeid(parent);
dentry.set_name(name);
dentry.set_type(inodeWrapper->GetType());
ret = dentryManager_->CreateDentry(dentry);
struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
ret = dentryManager_->CreateDentry(dentry,
now);
if (ret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "dentryManager_ CreateDentry fail, ret = " << ret
<< ", parent = " << parent << ", name = " << name
Expand All @@ -1231,17 +1220,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 @@ -1290,7 +1268,10 @@ CURVEFS_ERROR FuseClient::FuseOpLink(fuse_req_t req,
dentry.set_parentinodeid(newparent);
dentry.set_name(newname);
dentry.set_type(inodeWrapper->GetType());
ret = dentryManager_->CreateDentry(dentry);
struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
ret = dentryManager_->CreateDentry(dentry,
now);
if (ret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "dentryManager_ CreateDentry fail, ret = " << ret
<< ", parent = " << newparent << ", name = " << newname;
Expand All @@ -1303,15 +1284,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
5 changes: 4 additions & 1 deletion curvefs/src/client/rpcclient/metaserver_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ MetaStatusCode MetaServerClientImpl::ListDentry(uint32_t fsId, uint64_t inodeid,
return ConvertToMetaStatusCode(excutor.DoRPCTask());
}

MetaStatusCode MetaServerClientImpl::CreateDentry(const Dentry &dentry) {
MetaStatusCode MetaServerClientImpl::CreateDentry(const Dentry &dentry,
const struct timespec &now) {
auto task = RPCTask {
(void)taskExecutorDone;
metric_.createDentry.qps.count << 1;
Expand All @@ -255,6 +256,8 @@ MetaStatusCode MetaServerClientImpl::CreateDentry(const Dentry &dentry) {
d->set_txid(txId);
d->set_type(dentry.type());
request.set_allocated_dentry(d);
request.set_time(now.tv_sec);
request.set_time_ns(now.tv_nsec);
curvefs::metaserver::MetaServerService_Stub stub(channel);
stub.CreateDentry(cntl, &request, &response, nullptr);

Expand Down
6 changes: 4 additions & 2 deletions curvefs/src/client/rpcclient/metaserver_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ class MetaServerClient {
bool onlyDir,
std::list<Dentry> *dentryList) = 0;

virtual MetaStatusCode CreateDentry(const Dentry &dentry) = 0;
virtual MetaStatusCode CreateDentry(const Dentry &dentry,
const struct timespec &now) = 0;

virtual MetaStatusCode DeleteDentry(uint32_t fsId, uint64_t inodeid,
const std::string &name,
Expand Down Expand Up @@ -200,7 +201,8 @@ class MetaServerClientImpl : public MetaServerClient {
bool onlyDir,
std::list<Dentry> *dentryList) override;

MetaStatusCode CreateDentry(const Dentry &dentry) override;
MetaStatusCode CreateDentry(const Dentry &dentry,
const struct timespec &now) override;

MetaStatusCode DeleteDentry(uint32_t fsId, uint64_t inodeid,
const std::string &name,
Expand Down
2 changes: 2 additions & 0 deletions curvefs/src/mds/metaserverclient/metaserver_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ FSStatusCode MetaserverClient::CreateDentry(
d->set_txid(0);
d->set_type(FsFileType::TYPE_DIRECTORY);
request.set_allocated_dentry(d);
request.set_time(0);
request.set_time_ns(0);

auto fp = &MetaServerService_Stub::CreateDentry;
LeaderCtx ctx;
Expand Down
47 changes: 32 additions & 15 deletions curvefs/src/metaserver/inode_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,50 +471,67 @@ MetaStatusCode InodeManager::PaddingInodeS3ChunkInfo(int32_t fsId,
}

MetaStatusCode InodeManager::UpdateInodeWhenCreateOrRemoveSubNode(
uint32_t fsId, uint64_t inodeId, FsFileType type, bool isCreate) {
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;
Inode parentInode;
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);
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
return MetaStatusCode::OK;
}

NameLockGuard lg(inodeLock_, GetInodeLockName(fsId, parentInodeId));
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(
Dentry dentry,
uint64_t now,
uint32_t now_ns,
bool isCreate);

MetaStatusCode InsertInode(const Inode &inode);

Expand Down
5 changes: 4 additions & 1 deletion curvefs/src/metaserver/metastore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,10 @@ MetaStatusCode MetaStoreImpl::CreateDentry(const CreateDentryRequest *request,
std::shared_ptr<Partition> partition;
GET_PARTITION_OR_RETURN(partition);

MetaStatusCode status = partition->CreateDentry(request->dentry());
MetaStatusCode status =
partition->CreateDentry(request->dentry(),
request->time(),
request->time_ns());
response->set_statuscode(status);
return status;
}
Expand Down
10 changes: 5 additions & 5 deletions curvefs/src/metaserver/partition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,16 @@ Partition::Partition(PartitionInfo partition,
} \
} while (0)

MetaStatusCode Partition::CreateDentry(const Dentry& dentry) {
MetaStatusCode Partition::CreateDentry(const Dentry& dentry,
uint64_t now,
uint32_t now_ns) {
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, now, now_ns, true);
} else {
LOG(ERROR) << "CreateDentry does not have type, "
<< dentry.ShortDebugString();
Expand Down Expand Up @@ -149,8 +150,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
4 changes: 3 additions & 1 deletion curvefs/src/metaserver/partition.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ class Partition {
Partition() = default;

// dentry
MetaStatusCode CreateDentry(const Dentry& dentry);
MetaStatusCode CreateDentry(const Dentry& dentry,
uint64_t now,
uint32_t now_ns);

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

Expand Down
3 changes: 2 additions & 1 deletion curvefs/test/client/mock_dentry_cache_mamager.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class MockDentryCacheManager : public DentryCacheManager {
MOCK_METHOD3(GetDentry, CURVEFS_ERROR(uint64_t parent,
const std::string &name, Dentry *out));

MOCK_METHOD1(CreateDentry, CURVEFS_ERROR(const Dentry &dentry));
MOCK_METHOD2(CreateDentry, CURVEFS_ERROR(const Dentry &dentry,
const struct timespec &now));

MOCK_METHOD3(DeleteDentry, CURVEFS_ERROR(uint64_t parent,
const std::string &name,
Expand Down
3 changes: 2 additions & 1 deletion curvefs/test/client/mock_metaserver_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class MockMetaServerClient : public MetaServerClient {
const std::string &last, uint32_t count, bool onlyDir,
std::list<Dentry> *dentryList));

MOCK_METHOD1(CreateDentry, MetaStatusCode(const Dentry &dentry));
MOCK_METHOD2(CreateDentry, MetaStatusCode(const Dentry &dentry,
const struct timespec &now));

MOCK_METHOD4(DeleteDentry, MetaStatusCode(
uint32_t fsId, uint64_t inodeid, const std::string &name,
Expand Down
Loading

0 comments on commit 80f2d22

Please sign in to comment.