Skip to content

Commit

Permalink
[feat]: curvefs: merge two rpc into one rpc when 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 15, 2023
1 parent b12c86b commit 2ca6b85
Show file tree
Hide file tree
Showing 22 changed files with 211 additions and 290 deletions.
4 changes: 4 additions & 0 deletions curvefs/proto/metaserver.proto
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ message CreateDentryRequest {
required uint32 copysetId = 2;
required uint32 partitionId = 3;
required Dentry dentry = 4;
required bool enableSumInDir = 5;
required uint64 length = 6;
required uint64 time = 7;
required uint32 time_ns = 8;
}

message CreateDentryResponse {
Expand Down
10 changes: 8 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,16 @@ 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,
bool enableSumInDir,
uint64_t length,
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,
enableSumInDir,
length,
now);
if (ret != MetaStatusCode::OK) {
LOG(ERROR) << "metaClient_ CreateDentry failed, MetaStatusCode = "
<< ret
Expand Down
12 changes: 10 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,11 @@ 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,
bool enableSumInDir,
uint64_t length,
const struct timespec &now) = 0;

virtual CURVEFS_ERROR DeleteDentry(uint64_t parent,
const std::string &name,
Expand All @@ -86,7 +90,11 @@ 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,
bool enableSumInDir,
uint64_t length,
const struct timespec &now) override;

CURVEFS_ERROR DeleteDentry(uint64_t parent,
const std::string &name,
Expand Down
140 changes: 26 additions & 114 deletions curvefs/src/client/fuse_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,12 @@ 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,
enableSumInDir_.load(),
inodeWrapper->GetLength(),
now);
if (ret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "dentryManager_ CreateDentry fail, ret = " << ret
<< ", parent = " << parent << ", name = " << name
Expand All @@ -456,37 +460,10 @@ 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;

if (enableSumInDir_.load()) {
// update parent summary info
XAttr xattr;
xattr.mutable_xattrinfos()->insert({XATTRENTRIES, "1"});
if (type == FsFileType::TYPE_DIRECTORY) {
xattr.mutable_xattrinfos()->insert({XATTRSUBDIRS, "1"});
} else {
xattr.mutable_xattrinfos()->insert({XATTRFILES, "1"});
}
xattr.mutable_xattrinfos()->insert({XATTRFBYTES,
std::to_string(inodeWrapper->GetLength())});
auto tret = xattrManager_->UpdateParentInodeXattr(parent, xattr, true);
if (tret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "UpdateParentInodeXattr failed,"
<< " inodeId = " << parent
<< ", xattr = " << xattr.DebugString();
}
}
<< ", mode = " << mode << " , length:"<< inodeWrapper->GetLength()
<< " , sumIndir:" << enableSumInDir_.load();

return ret;
}
Expand Down Expand Up @@ -620,8 +597,12 @@ 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,
enableSumInDir_.load(),
inodeWrapper->GetLength(),
now);
if (ret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "dentryManager_ CreateDentry fail, ret = " << ret
<< ", parent = " << parent << ", name = " << name
Expand All @@ -636,38 +617,10 @@ 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;

if (enableSumInDir_.load()) {
// update parent summary info
XAttr xattr;
xattr.mutable_xattrinfos()->insert({XATTRENTRIES, "1"});
if (type == FsFileType::TYPE_DIRECTORY) {
xattr.mutable_xattrinfos()->insert({XATTRSUBDIRS, "1"});
} else {
xattr.mutable_xattrinfos()->insert({XATTRFILES, "1"});
}
xattr.mutable_xattrinfos()->insert({XATTRFBYTES,
std::to_string(inodeWrapper->GetLength())});
auto tret = xattrManager_->UpdateParentInodeXattr(parent, xattr, true);
if (tret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "UpdateParentInodeXattr failed,"
<< " inodeId = " << parent
<< ", xattr = " << xattr.DebugString();
}
}

inodeWrapper->GetInodeAttrLocked(&entryOut->attr);
return ret;
}
Expand Down Expand Up @@ -1216,7 +1169,12 @@ 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,
enableSumInDir_.load(),
inodeWrapper->GetLength(),
now);
if (ret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "dentryManager_ CreateDentry fail, ret = " << ret
<< ", parent = " << parent << ", name = " << name
Expand All @@ -1231,32 +1189,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;
xattr.mutable_xattrinfos()->insert({XATTRENTRIES, "1"});
xattr.mutable_xattrinfos()->insert({XATTRFILES, "1"});
xattr.mutable_xattrinfos()->insert({XATTRFBYTES,
std::to_string(inodeWrapper->GetLength())});
auto tret = xattrManager_->UpdateParentInodeXattr(parent, xattr, true);
if (tret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "UpdateParentInodeXattr failed,"
<< " inodeId = " << parent
<< ", xattr = " << xattr.DebugString();
}
}

inodeWrapper->GetInodeAttr(&entryOut->attr);
return ret;
}
Expand Down Expand Up @@ -1290,7 +1222,12 @@ 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,
enableSumInDir_.load(),
inodeWrapper->GetLength(),
now);
if (ret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "dentryManager_ CreateDentry fail, ret = " << ret
<< ", parent = " << newparent << ", name = " << newname;
Expand All @@ -1303,31 +1240,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;
xattr.mutable_xattrinfos()->insert({XATTRENTRIES, "1"});
xattr.mutable_xattrinfos()->insert({XATTRFILES, "1"});
xattr.mutable_xattrinfos()->insert({XATTRFBYTES,
std::to_string(inodeWrapper->GetLength())});
auto tret = xattrManager_->UpdateParentInodeXattr(
newparent, xattr, true);
if (tret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "UpdateParentInodeXattr failed,"
<< " inodeId = " << newparent
<< ", xattr = " << xattr.DebugString();
}
}

inodeWrapper->GetInodeAttr(&entryOut->attr);
return ret;
}
Expand Down
9 changes: 8 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,10 @@ 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,
bool enableSumInDir,
uint64_t length,
const struct timespec &now) {
auto task = RPCTask {
(void)taskExecutorDone;
metric_.createDentry.qps.count << 1;
Expand All @@ -255,6 +258,10 @@ MetaStatusCode MetaServerClientImpl::CreateDentry(const Dentry &dentry) {
d->set_txid(txId);
d->set_type(dentry.type());
request.set_allocated_dentry(d);
request.set_enablesumindir(enableSumInDir);
request.set_length(length);
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
10 changes: 8 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,10 @@ class MetaServerClient {
bool onlyDir,
std::list<Dentry> *dentryList) = 0;

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

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

MetaStatusCode CreateDentry(const Dentry &dentry) override;
MetaStatusCode CreateDentry(const Dentry &dentry,
bool enableSumInDir,
uint64_t length,
const struct timespec &now) override;

MetaStatusCode DeleteDentry(uint32_t fsId, uint64_t inodeid,
const std::string &name,
Expand Down
4 changes: 4 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,10 @@ FSStatusCode MetaserverClient::CreateDentry(
d->set_txid(0);
d->set_type(FsFileType::TYPE_DIRECTORY);
request.set_allocated_dentry(d);
request.set_enablesumindir(false);
request.set_length(0);
request.set_time(0);
request.set_time_ns(0);

auto fp = &MetaServerService_Stub::CreateDentry;
LeaderCtx ctx;
Expand Down
Loading

0 comments on commit 2ca6b85

Please sign in to comment.