Skip to content

Commit

Permalink
curvefs: batch get inode attr and xattr fater find in cache
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanHai committed Mar 10, 2022
1 parent 2f979b7 commit 3c14d0c
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 40 deletions.
12 changes: 9 additions & 3 deletions curvefs/src/client/fuse_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,12 @@ CURVEFS_ERROR FuseClient::FuseOpMkDir(fuse_req_t req, fuse_ino_t parent,

CURVEFS_ERROR FuseClient::FuseOpUnlink(fuse_req_t req, fuse_ino_t parent,
const char *name) {
if (enableSumInDir_) {
// don't support hardlink
LOG(ERROR) << "FuseOpUnlink doesn't support when enableSumInDir.";
return CURVEFS_ERROR::NOTSUPPORT;
}

LOG(INFO) << "FuseOpUnlink, parent: " << parent
<< ", name: " << name;
return RemoveNode(req, parent, name, false);
Expand Down Expand Up @@ -852,7 +858,7 @@ CURVEFS_ERROR FuseClient::CalOneLayerSumInfo(Inode *inode) {
for (const auto &it : dentryList) {
inodeIds.emplace(it.inodeid());
}
ret = inodeManager_->BatchGetInodeAttr(inodeIds, &attrs);
ret = inodeManager_->BatchGetInodeAttr(&inodeIds, &attrs);
if (ret == CURVEFS_ERROR::OK) {
uint64_t files = 0;
uint64_t subdirs = 0;
Expand Down Expand Up @@ -920,7 +926,7 @@ CURVEFS_ERROR FuseClient::CalAllLayerSumInfo(Inode *inode) {
}
// check size
if (inodeIds.size() >= attrsLimit || iStack.empty()) {
ret = inodeManager_->BatchGetInodeAttr(inodeIds, &attrs);
ret = inodeManager_->BatchGetInodeAttr(&inodeIds, &attrs);
if (ret == CURVEFS_ERROR::OK) {
for (const auto &it : attrs) {
if (it.type() == FsFileType::TYPE_DIRECTORY) {
Expand Down Expand Up @@ -1005,7 +1011,7 @@ CURVEFS_ERROR FuseClient::FastCalAllLayerSumInfo(Inode *inode) {
}
// check size
if (inodeIds.size() >= xattrsLimit || iStack.empty()) {
ret = inodeManager_->BatchGetXAttr(inodeIds, &xattrs);
ret = inodeManager_->BatchGetXAttr(&inodeIds, &xattrs);
if (ret == CURVEFS_ERROR::OK) {
for (const auto &it : xattrs) {
if (it.xattrinfos().count(XATTRFILES)) {
Expand Down
5 changes: 0 additions & 5 deletions curvefs/src/client/fuse_s3_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,6 @@ CURVEFS_ERROR FuseS3Client::FuseOpRelease(fuse_req_t req, fuse_ino_t ino,
inodeManager_->ClearInodeCache(ino);
}

if (enableSumInDir_) {
// update parent relationship
inodeManager_->ClearParent(ino);
}

return ret;
}

Expand Down
34 changes: 32 additions & 2 deletions curvefs/src/client/inode_cache_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,23 @@ CURVEFS_ERROR InodeCacheManagerImpl::GetInode(uint64_t inodeid,
}

CURVEFS_ERROR InodeCacheManagerImpl::BatchGetInodeAttr(
const std::set<uint64_t> &inodeIds,
std::set<uint64_t> *inodeIds,
std::list<InodeAttr> *attr) {
// get some inode in icache
for (auto iter = inodeIds->begin(); iter != inodeIds->end();) {
std::shared_ptr<InodeWrapper> inodeWrapper;
NameLockGuard lock(nameLock_, std::to_string(*iter));
bool ok = iCache_->Get(*iter, &inodeWrapper);
if (ok) {
InodeAttr tmpAttr;
inodeWrapper->GetInodeAttrLocked(&tmpAttr);
attr->emplace_back(tmpAttr);
iter = inodeIds->erase(iter);
} else {
++iter;
}
}

MetaStatusCode ret = metaClient_->BatchGetInodeAttr(fsId_, inodeIds, attr);
if (MetaStatusCode::OK != ret) {
LOG(ERROR) << "metaClient BatchGetInodeAttr failed, MetaStatusCode = "
Expand All @@ -78,8 +93,23 @@ CURVEFS_ERROR InodeCacheManagerImpl::BatchGetInodeAttr(
}

CURVEFS_ERROR InodeCacheManagerImpl::BatchGetXAttr(
const std::set<uint64_t> &inodeIds,
std::set<uint64_t> *inodeIds,
std::list<XAttr> *xattr) {
// get some inode in icache
for (auto iter = inodeIds->begin(); iter != inodeIds->end();) {
std::shared_ptr<InodeWrapper> inodeWrapper;
NameLockGuard lock(nameLock_, std::to_string(*iter));
bool ok = iCache_->Get(*iter, &inodeWrapper);
if (ok) {
XAttr tmpXattr;
inodeWrapper->GetXattrLocked(&tmpXattr);
xattr->emplace_back(tmpXattr);
iter = inodeIds->erase(iter);
} else {
++iter;
}
}

MetaStatusCode ret = metaClient_->BatchGetXAttr(fsId_, inodeIds, xattr);
if (MetaStatusCode::OK != ret) {
LOG(ERROR) << "metaClient BatchGetXAttr failed, MetaStatusCode = "
Expand Down
8 changes: 4 additions & 4 deletions curvefs/src/client/inode_cache_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ class InodeCacheManager {
std::shared_ptr<InodeWrapper> &out) = 0; // NOLINT

virtual CURVEFS_ERROR BatchGetInodeAttr(
const std::set<uint64_t> &inodeIds,
std::set<uint64_t> *inodeIds,
std::list<InodeAttr> *attrs) = 0;

virtual CURVEFS_ERROR BatchGetXAttr(const std::set<uint64_t> &inodeIds,
virtual CURVEFS_ERROR BatchGetXAttr(std::set<uint64_t> *inodeIds,
std::list<XAttr> *xattrs) = 0;

virtual CURVEFS_ERROR CreateInode(const InodeParam &param,
Expand Down Expand Up @@ -125,10 +125,10 @@ class InodeCacheManagerImpl : public InodeCacheManager {
CURVEFS_ERROR GetInode(uint64_t inodeid,
std::shared_ptr<InodeWrapper> &out) override; // NOLINT

CURVEFS_ERROR BatchGetInodeAttr(const std::set<uint64_t> &inodeIds,
CURVEFS_ERROR BatchGetInodeAttr(std::set<uint64_t> *inodeIds,
std::list<InodeAttr> *attrs) override;

CURVEFS_ERROR BatchGetXAttr(const std::set<uint64_t> &inodeIds,
CURVEFS_ERROR BatchGetXAttr(std::set<uint64_t> *inodeIds,
std::list<XAttr> *xattrs) override;

CURVEFS_ERROR CreateInode(const InodeParam &param,
Expand Down
37 changes: 37 additions & 0 deletions curvefs/src/client/inode_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,43 @@ class InodeWrapper : public std::enable_shared_from_this<InodeWrapper> {
return;
}

void GetInodeAttrLocked(InodeAttr *attr) {
curve::common::UniqueLock lg(mtx_);
attr->set_inodeid(inode_.inodeid());
attr->set_fsid(inode_.fsid());
attr->set_length(inode_.length());
attr->set_ctime(inode_.ctime());
attr->set_ctime_ns(inode_.ctime_ns());
attr->set_mtime(inode_.mtime());
attr->set_mtime_ns(inode_.mtime_ns());
attr->set_atime(inode_.atime());
attr->set_atime_ns(inode_.atime_ns());
attr->set_uid(inode_.uid());
attr->set_gid(inode_.gid());
attr->set_mode(inode_.mode());
attr->set_nlink(inode_.nlink());
attr->set_type(inode_.type());
if (inode_.has_symlink()) {
attr->set_symlink(inode_.symlink());
}
if (inode_.has_rdev()) {
attr->set_rdev(inode_.rdev());
}
if (inode_.has_dtime()) {
attr->set_dtime(inode_.dtime());
}
if (inode_.has_openmpcount()) {
attr->set_openmpcount(inode_.openmpcount());
}
}

void GetXattrLocked(XAttr *xattr) {
curve::common::UniqueLock lg(mtx_);
xattr->set_fsid(inode_.fsid());
xattr->set_inodeid(inode_.inodeid());
*(xattr->mutable_xattrinfos()) = inode_.xattr();
}

bool GetXattrUnLocked(const char *name, std::string *value) {
auto it = inode_.xattr().find(name);
if (it != inode_.xattr().end()) {
Expand Down
8 changes: 4 additions & 4 deletions curvefs/src/client/rpcclient/metaserver_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,9 @@ MetaStatusCode MetaServerClientImpl::GetInode(uint32_t fsId, uint64_t inodeid,
bool GroupInodeIdByPartition(
uint32_t fsId,
std::shared_ptr<MetaCache> metaCache,
const std::set<uint64_t> &inodeIds,
std::set<uint64_t> *inodeIds,
std::unordered_map<uint32_t, std::list<uint64_t>> *inodeGroups) {
for (const auto &it : inodeIds) {
for (const auto &it : *inodeIds) {
uint32_t pId = 0;
if (metaCache->GetPartitionIdByInodeId(fsId, it, &pId)) {
auto iter = inodeGroups->find(pId);
Expand All @@ -469,7 +469,7 @@ bool GroupInodeIdByPartition(
}

MetaStatusCode MetaServerClientImpl::BatchGetInodeAttr(uint32_t fsId,
const std::set<uint64_t> &inodeIds,
std::set<uint64_t> *inodeIds,
std::list<InodeAttr> *attr) {
uint32_t limit = opt_.batchLimit;
// group inodeid by partition
Expand Down Expand Up @@ -548,7 +548,7 @@ MetaStatusCode MetaServerClientImpl::BatchGetInodeAttr(uint32_t fsId,
}

MetaStatusCode MetaServerClientImpl::BatchGetXAttr(uint32_t fsId,
const std::set<uint64_t> &inodeIds,
std::set<uint64_t> *inodeIds,
std::list<XAttr> *xattr) {
uint32_t limit = opt_.batchLimit;
// group inodeid by partition
Expand Down
8 changes: 4 additions & 4 deletions curvefs/src/client/rpcclient/metaserver_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ class MetaServerClient {
Inode *out) = 0;

virtual MetaStatusCode BatchGetInodeAttr(uint32_t fsId,
const std::set<uint64_t> &inodeIds,
std::set<uint64_t> *inodeIds,
std::list<InodeAttr> *attr) = 0;

virtual MetaStatusCode BatchGetXAttr(uint32_t fsId,
const std::set<uint64_t> &inodeIds,
std::set<uint64_t> *inodeIds,
std::list<XAttr> *xattr) = 0;

virtual MetaStatusCode UpdateInode(const Inode &inode,
Expand Down Expand Up @@ -159,11 +159,11 @@ class MetaServerClientImpl : public MetaServerClient {
Inode *out) override;

MetaStatusCode BatchGetInodeAttr(uint32_t fsId,
const std::set<uint64_t> &inodeIds,
std::set<uint64_t> *inodeIds,
std::list<InodeAttr> *attr) override;

MetaStatusCode BatchGetXAttr(uint32_t fsId,
const std::set<uint64_t> &inodeIds,
std::set<uint64_t> *inodeIds,
std::list<XAttr> *xattr) override;

MetaStatusCode UpdateInode(const Inode &inode,
Expand Down
4 changes: 2 additions & 2 deletions curvefs/test/client/mock_inode_cache_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ class MockInodeCacheManager : public InodeCacheManager {
uint64_t inodeid, std::shared_ptr<InodeWrapper> &out)); // NOLINT

MOCK_METHOD2(BatchGetInodeAttr, CURVEFS_ERROR(
const std::set<uint64_t> &inodeIds, std::list<InodeAttr> *attrs));
std::set<uint64_t> *inodeIds, std::list<InodeAttr> *attrs));

MOCK_METHOD2(BatchGetXAttr, CURVEFS_ERROR(
const std::set<uint64_t> &inodeIds, std::list<XAttr> *xattrs));
std::set<uint64_t> *inodeIds, std::list<XAttr> *xattrs));

MOCK_METHOD2(CreateInode, CURVEFS_ERROR(const InodeParam &param,
std::shared_ptr<InodeWrapper> &out)); // NOLINT
Expand Down
4 changes: 2 additions & 2 deletions curvefs/test/client/mock_metaserver_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ class MockMetaServerClient : public MetaServerClient {
uint32_t fsId, uint64_t inodeid, Inode *out));

MOCK_METHOD3(BatchGetInodeAttr, MetaStatusCode(
uint32_t fsId, const std::set<uint64_t> &inodeIds,
uint32_t fsId, std::set<uint64_t> *inodeIds,
std::list<InodeAttr> *attr));

MOCK_METHOD3(BatchGetXAttr, MetaStatusCode(
uint32_t fsId, const std::set<uint64_t> &inodeIds,
uint32_t fsId, std::set<uint64_t> *inodeIds,
std::list<XAttr> *xattr));

MOCK_METHOD2(UpdateInode,
Expand Down
16 changes: 8 additions & 8 deletions curvefs/test/client/rpcclient/metaserver_client_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ TEST_F(MetaServerClientImplTest, test_BatchGetInodeAttr) {
SetArgPointee<3>(applyIndex), Return(true)));

MetaStatusCode status = metaserverCli_.BatchGetInodeAttr(
fsid, inodeIds, &attr);
fsid, &inodeIds, &attr);
ASSERT_EQ(MetaStatusCode::RPC_ERROR, status);

// test1: batchGetInodeAttr ok
Expand All @@ -1081,7 +1081,7 @@ TEST_F(MetaServerClientImplTest, test_BatchGetInodeAttr) {
BatchGetInodeAttrResponse>)));
EXPECT_CALL(*mockMetacache_.get(), UpdateApplyIndex(_, _));

status = metaserverCli_.BatchGetInodeAttr(fsid, inodeIds, &attr);
status = metaserverCli_.BatchGetInodeAttr(fsid, &inodeIds, &attr);
ASSERT_EQ(MetaStatusCode::OK, status);
ASSERT_EQ(attr.size(), 2);
ASSERT_THAT(attr.begin()->inodeid(), AnyOf(inodeId1, inodeId2));
Expand All @@ -1097,7 +1097,7 @@ TEST_F(MetaServerClientImplTest, test_BatchGetInodeAttr) {
DoAll(SetArgPointee<2>(response),
Invoke(SetRpcService<BatchGetInodeAttrRequest,
BatchGetInodeAttrResponse>)));
status = metaserverCli_.BatchGetInodeAttr(fsid, inodeIds, &attr);
status = metaserverCli_.BatchGetInodeAttr(fsid, &inodeIds, &attr);
ASSERT_EQ(MetaStatusCode::NOT_FOUND, status);

// test3: test response do not have applyindex
Expand All @@ -1113,7 +1113,7 @@ TEST_F(MetaServerClientImplTest, test_BatchGetInodeAttr) {
Invoke(SetRpcService<BatchGetInodeAttrRequest,
BatchGetInodeAttrResponse>)));

status = metaserverCli_.BatchGetInodeAttr(fsid, inodeIds, &attr);
status = metaserverCli_.BatchGetInodeAttr(fsid, &inodeIds, &attr);
ASSERT_EQ(MetaStatusCode::RPC_ERROR, status);
}

Expand Down Expand Up @@ -1161,7 +1161,7 @@ TEST_F(MetaServerClientImplTest, test_BatchGetXAttr) {
SetArgPointee<3>(applyIndex), Return(true)));

MetaStatusCode status = metaserverCli_.BatchGetXAttr(
fsid, inodeIds, &xattr);
fsid, &inodeIds, &xattr);
ASSERT_EQ(MetaStatusCode::RPC_ERROR, status);

// test1: batchGetXAttr ok
Expand All @@ -1183,7 +1183,7 @@ TEST_F(MetaServerClientImplTest, test_BatchGetXAttr) {
BatchGetXAttrResponse>)));
EXPECT_CALL(*mockMetacache_.get(), UpdateApplyIndex(_, _));

status = metaserverCli_.BatchGetXAttr(fsid, inodeIds, &xattr);
status = metaserverCli_.BatchGetXAttr(fsid, &inodeIds, &xattr);
ASSERT_EQ(MetaStatusCode::OK, status);
ASSERT_EQ(xattr.size(), 2);
ASSERT_THAT(xattr.begin()->inodeid(), AnyOf(inodeId1, inodeId2));
Expand All @@ -1199,7 +1199,7 @@ TEST_F(MetaServerClientImplTest, test_BatchGetXAttr) {
DoAll(SetArgPointee<2>(response),
Invoke(SetRpcService<BatchGetXAttrRequest,
BatchGetXAttrResponse>)));
status = metaserverCli_.BatchGetXAttr(fsid, inodeIds, &xattr);
status = metaserverCli_.BatchGetXAttr(fsid, &inodeIds, &xattr);
ASSERT_EQ(MetaStatusCode::NOT_FOUND, status);

// test3: test response do not have applyindex
Expand All @@ -1215,7 +1215,7 @@ TEST_F(MetaServerClientImplTest, test_BatchGetXAttr) {
Invoke(SetRpcService<BatchGetXAttrRequest,
BatchGetXAttrResponse>)));

status = metaserverCli_.BatchGetXAttr(fsid, inodeIds, &xattr);
status = metaserverCli_.BatchGetXAttr(fsid, &inodeIds, &xattr);
ASSERT_EQ(MetaStatusCode::RPC_ERROR, status);
}

Expand Down
12 changes: 6 additions & 6 deletions curvefs/test/client/test_inode_cache_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,16 @@ TEST_F(TestInodeCacheManager, BatchGetInodeAttr) {
attr.set_inodeid(inodeId2);
attrs.emplace_back(attr);

EXPECT_CALL(*metaClient_, BatchGetInodeAttr(fsId_, inodeIds, _))
EXPECT_CALL(*metaClient_, BatchGetInodeAttr(fsId_, &inodeIds, _))
.WillOnce(Return(MetaStatusCode::NOT_FOUND))
.WillOnce(DoAll(SetArgPointee<2>(attrs),
Return(MetaStatusCode::OK)));

std::list<InodeAttr> getAttrs;
CURVEFS_ERROR ret = iCacheManager_->BatchGetInodeAttr(inodeIds, &getAttrs);
CURVEFS_ERROR ret = iCacheManager_->BatchGetInodeAttr(&inodeIds, &getAttrs);
ASSERT_EQ(CURVEFS_ERROR::NOTEXIST, ret);

ret = iCacheManager_->BatchGetInodeAttr(inodeIds, &getAttrs);
ret = iCacheManager_->BatchGetInodeAttr(&inodeIds, &getAttrs);
ASSERT_EQ(CURVEFS_ERROR::OK, ret);
ASSERT_EQ(getAttrs.size(), 2);
ASSERT_THAT(getAttrs.begin()->inodeid(), AnyOf(inodeId1, inodeId2));
Expand Down Expand Up @@ -248,16 +248,16 @@ TEST_F(TestInodeCacheManager, BatchGetXAttr) {
xattr.mutable_xattrinfos()->find(XATTRFBYTES)->second = "200";
xattrs.emplace_back(xattr);

EXPECT_CALL(*metaClient_, BatchGetXAttr(fsId_, inodeIds, _))
EXPECT_CALL(*metaClient_, BatchGetXAttr(fsId_, &inodeIds, _))
.WillOnce(Return(MetaStatusCode::NOT_FOUND))
.WillOnce(DoAll(SetArgPointee<2>(xattrs),
Return(MetaStatusCode::OK)));

std::list<XAttr> getXAttrs;
CURVEFS_ERROR ret = iCacheManager_->BatchGetXAttr(inodeIds, &getXAttrs);
CURVEFS_ERROR ret = iCacheManager_->BatchGetXAttr(&inodeIds, &getXAttrs);
ASSERT_EQ(CURVEFS_ERROR::NOTEXIST, ret);

ret = iCacheManager_->BatchGetXAttr(inodeIds, &getXAttrs);
ret = iCacheManager_->BatchGetXAttr(&inodeIds, &getXAttrs);
ASSERT_EQ(CURVEFS_ERROR::OK, ret);
ASSERT_EQ(getXAttrs.size(), 2);
ASSERT_THAT(getXAttrs.begin()->inodeid(), AnyOf(inodeId1, inodeId2));
Expand Down

0 comments on commit 3c14d0c

Please sign in to comment.