Skip to content

Commit 6018699

Browse files
committed
[feat]: curvefs: merge two rpc into one rpc when makenode
Signed-off-by: swj <1186093704@qq.com>
1 parent 05993a9 commit 6018699

22 files changed

+213
-179
lines changed

curvefs/proto/metaserver.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ message CreateDentryRequest {
114114
required uint32 copysetId = 2;
115115
required uint32 partitionId = 3;
116116
required Dentry dentry = 4;
117+
required bool enableSumInDir = 5;
118+
required uint64 length = 6;
119+
required uint64 time = 7;
120+
required uint32 time_ns = 8;
117121
}
118122

119123
message CreateDentryResponse {

curvefs/src/client/dentry_cache_manager.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,16 @@ CURVEFS_ERROR DentryCacheManagerImpl::GetDentry(uint64_t parent,
6363
return CURVEFS_ERROR::OK;
6464
}
6565

66-
CURVEFS_ERROR DentryCacheManagerImpl::CreateDentry(const Dentry &dentry) {
66+
CURVEFS_ERROR DentryCacheManagerImpl::CreateDentry(const Dentry &dentry,
67+
bool enableSumInDir,
68+
uint64_t length,
69+
const struct timespec &now) {
6770
std::string key = GetDentryCacheKey(dentry.parentinodeid(), dentry.name());
6871
NameLockGuard lock(nameLock_, key);
69-
MetaStatusCode ret = metaClient_->CreateDentry(dentry);
72+
MetaStatusCode ret = metaClient_->CreateDentry(dentry,
73+
enableSumInDir,
74+
length,
75+
now);
7076
if (ret != MetaStatusCode::OK) {
7177
LOG(ERROR) << "metaClient_ CreateDentry failed, MetaStatusCode = "
7278
<< ret

curvefs/src/client/dentry_cache_manager.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ class DentryCacheManager {
6060
virtual CURVEFS_ERROR GetDentry(uint64_t parent,
6161
const std::string &name, Dentry *out) = 0;
6262

63-
virtual CURVEFS_ERROR CreateDentry(const Dentry &dentry) = 0;
63+
virtual CURVEFS_ERROR CreateDentry(
64+
const Dentry &dentry,
65+
bool enableSumInDir,
66+
uint64_t length,
67+
const struct timespec &now) = 0;
6468

6569
virtual CURVEFS_ERROR DeleteDentry(uint64_t parent,
6670
const std::string &name,
@@ -86,7 +90,11 @@ class DentryCacheManagerImpl : public DentryCacheManager {
8690
CURVEFS_ERROR GetDentry(uint64_t parent,
8791
const std::string &name, Dentry *out) override;
8892

89-
CURVEFS_ERROR CreateDentry(const Dentry &dentry) override;
93+
CURVEFS_ERROR CreateDentry(
94+
const Dentry &dentry,
95+
bool enableSumInDir,
96+
uint64_t length,
97+
const struct timespec &now) override;
9098

9199
CURVEFS_ERROR DeleteDentry(uint64_t parent,
92100
const std::string &name,

curvefs/src/client/fuse_client.cpp

Lines changed: 26 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,12 @@ CURVEFS_ERROR FuseClient::MakeNode(
440440
if (type == FsFileType::TYPE_FILE || type == FsFileType::TYPE_S3) {
441441
dentry.set_flag(DentryFlag::TYPE_FILE_FLAG);
442442
}
443-
444-
ret = dentryManager_->CreateDentry(dentry);
443+
struct timespec now;
444+
clock_gettime(CLOCK_REALTIME, &now);
445+
ret = dentryManager_->CreateDentry(dentry,
446+
enableSumInDir_.load(),
447+
inodeWrapper->GetLength(),
448+
now);
445449
if (ret != CURVEFS_ERROR::OK) {
446450
LOG(ERROR) << "dentryManager_ CreateDentry fail, ret = " << ret
447451
<< ", parent = " << parent << ", name = " << name
@@ -456,37 +460,10 @@ CURVEFS_ERROR FuseClient::MakeNode(
456460
return ret;
457461
}
458462

459-
ret = UpdateParentMCTimeAndNlink(parent, type, NlinkChange::kAddOne);
460-
if (ret != CURVEFS_ERROR::OK) {
461-
LOG(ERROR) << "UpdateParentMCTimeAndNlink failed"
462-
<< ", parent: " << parent
463-
<< ", name: " << name
464-
<< ", type: " << type;
465-
return ret;
466-
}
467-
468463
VLOG(6) << "dentryManager_ CreateDentry success"
469464
<< ", parent = " << parent << ", name = " << name
470-
<< ", mode = " << mode;
471-
472-
if (enableSumInDir_.load()) {
473-
// update parent summary info
474-
XAttr xattr;
475-
xattr.mutable_xattrinfos()->insert({XATTRENTRIES, "1"});
476-
if (type == FsFileType::TYPE_DIRECTORY) {
477-
xattr.mutable_xattrinfos()->insert({XATTRSUBDIRS, "1"});
478-
} else {
479-
xattr.mutable_xattrinfos()->insert({XATTRFILES, "1"});
480-
}
481-
xattr.mutable_xattrinfos()->insert({XATTRFBYTES,
482-
std::to_string(inodeWrapper->GetLength())});
483-
auto tret = xattrManager_->UpdateParentInodeXattr(parent, xattr, true);
484-
if (tret != CURVEFS_ERROR::OK) {
485-
LOG(ERROR) << "UpdateParentInodeXattr failed,"
486-
<< " inodeId = " << parent
487-
<< ", xattr = " << xattr.DebugString();
488-
}
489-
}
465+
<< ", mode = " << mode << " , length:"<< inodeWrapper->GetLength()
466+
<< " , sumIndir:" << enableSumInDir_.load();
490467

491468
return ret;
492469
}
@@ -620,8 +597,12 @@ CURVEFS_ERROR FuseClient::CreateManageNode(fuse_req_t req,
620597
if (type == FsFileType::TYPE_FILE || type == FsFileType::TYPE_S3) {
621598
dentry.set_flag(DentryFlag::TYPE_FILE_FLAG);
622599
}
623-
624-
ret = dentryManager_->CreateDentry(dentry);
600+
struct timespec now;
601+
clock_gettime(CLOCK_REALTIME, &now);
602+
ret = dentryManager_->CreateDentry(dentry,
603+
enableSumInDir_.load(),
604+
inodeWrapper->GetLength(),
605+
now);
625606
if (ret != CURVEFS_ERROR::OK) {
626607
LOG(ERROR) << "dentryManager_ CreateDentry fail, ret = " << ret
627608
<< ", parent = " << parent << ", name = " << name
@@ -636,38 +617,10 @@ CURVEFS_ERROR FuseClient::CreateManageNode(fuse_req_t req,
636617
return ret;
637618
}
638619

639-
ret = UpdateParentMCTimeAndNlink(parent, type, NlinkChange::kAddOne);
640-
if (ret != CURVEFS_ERROR::OK) {
641-
LOG(ERROR) << "UpdateParentMCTimeAndNlink failed"
642-
<< ", parent: " << parent
643-
<< ", name: " << name
644-
<< ", type: " << type;
645-
return ret;
646-
}
647-
648620
VLOG(6) << "dentryManager_ CreateDentry success"
649621
<< ", parent = " << parent << ", name = " << name
650622
<< ", mode = " << mode;
651623

652-
if (enableSumInDir_.load()) {
653-
// update parent summary info
654-
XAttr xattr;
655-
xattr.mutable_xattrinfos()->insert({XATTRENTRIES, "1"});
656-
if (type == FsFileType::TYPE_DIRECTORY) {
657-
xattr.mutable_xattrinfos()->insert({XATTRSUBDIRS, "1"});
658-
} else {
659-
xattr.mutable_xattrinfos()->insert({XATTRFILES, "1"});
660-
}
661-
xattr.mutable_xattrinfos()->insert({XATTRFBYTES,
662-
std::to_string(inodeWrapper->GetLength())});
663-
auto tret = xattrManager_->UpdateParentInodeXattr(parent, xattr, true);
664-
if (tret != CURVEFS_ERROR::OK) {
665-
LOG(ERROR) << "UpdateParentInodeXattr failed,"
666-
<< " inodeId = " << parent
667-
<< ", xattr = " << xattr.DebugString();
668-
}
669-
}
670-
671624
inodeWrapper->GetInodeAttrLocked(&entryOut->attr);
672625
return ret;
673626
}
@@ -1216,7 +1169,12 @@ CURVEFS_ERROR FuseClient::FuseOpSymlink(fuse_req_t req,
12161169
dentry.set_parentinodeid(parent);
12171170
dentry.set_name(name);
12181171
dentry.set_type(inodeWrapper->GetType());
1219-
ret = dentryManager_->CreateDentry(dentry);
1172+
struct timespec now;
1173+
clock_gettime(CLOCK_REALTIME, &now);
1174+
ret = dentryManager_->CreateDentry(dentry,
1175+
enableSumInDir_.load(),
1176+
inodeWrapper->GetLength(),
1177+
now);
12201178
if (ret != CURVEFS_ERROR::OK) {
12211179
LOG(ERROR) << "dentryManager_ CreateDentry fail, ret = " << ret
12221180
<< ", parent = " << parent << ", name = " << name
@@ -1231,32 +1189,6 @@ CURVEFS_ERROR FuseClient::FuseOpSymlink(fuse_req_t req,
12311189
return ret;
12321190
}
12331191

1234-
ret = UpdateParentMCTimeAndNlink(parent, FsFileType::TYPE_SYM_LINK,
1235-
NlinkChange::kAddOne);
1236-
if (ret != CURVEFS_ERROR::OK) {
1237-
LOG(ERROR) << "UpdateParentMCTimeAndNlink failed"
1238-
<< ", link:" << link
1239-
<< ", parent: " << parent
1240-
<< ", name: " << name
1241-
<< ", type: " << FsFileType::TYPE_SYM_LINK;
1242-
return ret;
1243-
}
1244-
1245-
if (enableSumInDir_.load()) {
1246-
// update parent summary info
1247-
XAttr xattr;
1248-
xattr.mutable_xattrinfos()->insert({XATTRENTRIES, "1"});
1249-
xattr.mutable_xattrinfos()->insert({XATTRFILES, "1"});
1250-
xattr.mutable_xattrinfos()->insert({XATTRFBYTES,
1251-
std::to_string(inodeWrapper->GetLength())});
1252-
auto tret = xattrManager_->UpdateParentInodeXattr(parent, xattr, true);
1253-
if (tret != CURVEFS_ERROR::OK) {
1254-
LOG(ERROR) << "UpdateParentInodeXattr failed,"
1255-
<< " inodeId = " << parent
1256-
<< ", xattr = " << xattr.DebugString();
1257-
}
1258-
}
1259-
12601192
inodeWrapper->GetInodeAttr(&entryOut->attr);
12611193
return ret;
12621194
}
@@ -1290,7 +1222,12 @@ CURVEFS_ERROR FuseClient::FuseOpLink(fuse_req_t req,
12901222
dentry.set_parentinodeid(newparent);
12911223
dentry.set_name(newname);
12921224
dentry.set_type(inodeWrapper->GetType());
1293-
ret = dentryManager_->CreateDentry(dentry);
1225+
struct timespec now;
1226+
clock_gettime(CLOCK_REALTIME, &now);
1227+
ret = dentryManager_->CreateDentry(dentry,
1228+
enableSumInDir_.load(),
1229+
inodeWrapper->GetLength(),
1230+
now);
12941231
if (ret != CURVEFS_ERROR::OK) {
12951232
LOG(ERROR) << "dentryManager_ CreateDentry fail, ret = " << ret
12961233
<< ", parent = " << newparent << ", name = " << newname;
@@ -1303,31 +1240,6 @@ CURVEFS_ERROR FuseClient::FuseOpLink(fuse_req_t req,
13031240
return ret;
13041241
}
13051242

1306-
ret = UpdateParentMCTimeAndNlink(newparent, type, NlinkChange::kAddOne);
1307-
if (ret != CURVEFS_ERROR::OK) {
1308-
LOG(ERROR) << "UpdateParentMCTimeAndNlink failed"
1309-
<< ", parent: " << newparent
1310-
<< ", name: " << newname
1311-
<< ", type: " << type;
1312-
return ret;
1313-
}
1314-
1315-
if (enableSumInDir_.load()) {
1316-
// update parent summary info
1317-
XAttr xattr;
1318-
xattr.mutable_xattrinfos()->insert({XATTRENTRIES, "1"});
1319-
xattr.mutable_xattrinfos()->insert({XATTRFILES, "1"});
1320-
xattr.mutable_xattrinfos()->insert({XATTRFBYTES,
1321-
std::to_string(inodeWrapper->GetLength())});
1322-
auto tret = xattrManager_->UpdateParentInodeXattr(
1323-
newparent, xattr, true);
1324-
if (tret != CURVEFS_ERROR::OK) {
1325-
LOG(ERROR) << "UpdateParentInodeXattr failed,"
1326-
<< " inodeId = " << newparent
1327-
<< ", xattr = " << xattr.DebugString();
1328-
}
1329-
}
1330-
13311243
inodeWrapper->GetInodeAttr(&entryOut->attr);
13321244
return ret;
13331245
}

curvefs/src/client/rpcclient/metaserver_client.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,10 @@ MetaStatusCode MetaServerClientImpl::ListDentry(uint32_t fsId, uint64_t inodeid,
237237
return ConvertToMetaStatusCode(excutor.DoRPCTask());
238238
}
239239

240-
MetaStatusCode MetaServerClientImpl::CreateDentry(const Dentry &dentry) {
240+
MetaStatusCode MetaServerClientImpl::CreateDentry(const Dentry &dentry,
241+
bool enableSumInDir,
242+
uint64_t length,
243+
const struct timespec &now) {
241244
auto task = RPCTask {
242245
(void)taskExecutorDone;
243246
metric_.createDentry.qps.count << 1;
@@ -255,6 +258,10 @@ MetaStatusCode MetaServerClientImpl::CreateDentry(const Dentry &dentry) {
255258
d->set_txid(txId);
256259
d->set_type(dentry.type());
257260
request.set_allocated_dentry(d);
261+
request.set_enablesumindir(enableSumInDir);
262+
request.set_length(length);
263+
request.set_time(now.tv_sec);
264+
request.set_time_ns(now.tv_nsec);
258265
curvefs::metaserver::MetaServerService_Stub stub(channel);
259266
stub.CreateDentry(cntl, &request, &response, nullptr);
260267

curvefs/src/client/rpcclient/metaserver_client.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ class MetaServerClient {
9292
bool onlyDir,
9393
std::list<Dentry> *dentryList) = 0;
9494

95-
virtual MetaStatusCode CreateDentry(const Dentry &dentry) = 0;
95+
virtual MetaStatusCode CreateDentry(const Dentry &dentry,
96+
bool enableSumInDir,
97+
uint64_t length,
98+
const struct timespec &now) = 0;
9699

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

203-
MetaStatusCode CreateDentry(const Dentry &dentry) override;
206+
MetaStatusCode CreateDentry(const Dentry &dentry,
207+
bool enableSumInDir,
208+
uint64_t length,
209+
const struct timespec &now) override;
204210

205211
MetaStatusCode DeleteDentry(uint32_t fsId, uint64_t inodeid,
206212
const std::string &name,

curvefs/src/mds/metaserverclient/metaserver_client.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ FSStatusCode MetaserverClient::CreateDentry(
274274
d->set_txid(0);
275275
d->set_type(FsFileType::TYPE_DIRECTORY);
276276
request.set_allocated_dentry(d);
277+
request.set_enablesumindir(false);
278+
request.set_length(0);
279+
request.set_time(0);
280+
request.set_time_ns(0);
277281

278282
auto fp = &MetaServerService_Stub::CreateDentry;
279283
LeaderCtx ctx;

0 commit comments

Comments
 (0)