Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip_enablesumindir #2310

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions curvefs/src/client/fuse_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ CURVEFS_ERROR FuseClient::FuseOpInit(void *userdata,

LOG(INFO) << "Mount " << fsName << " on " << mountpoint_.ShortDebugString()
<< " success!" << " enableSumInDir = " << enableSumInDir_;
if (enableSumInDir_) {
xattrManager_->RefreshAllXAttr();
}

fsMetric_ = std::make_shared<FSMetric>(fsName);

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

,

  1. It looks like the code is trying to initialize a fuse client and refresh all xattrs if the enableSumInDir_ flag is set.

  2. There are no bugs in the code, but one improvement could be adding a log statement to indicate when the xattrManager_->RefreshAllXAttr() is called.

  3. The code should also check if enableSumInDir_ is set before calling the xattrManager_->RefreshAllXAttr() method.

  4. Another improvement could be to add a try-catch block around the xattrManager_->RefreshAllXAttr() call to handle any exceptions that might be thrown.

Expand Down
8 changes: 4 additions & 4 deletions curvefs/src/client/fuse_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ class FuseClient {

virtual void FuseOpDestroy(void* userdata);

virtual CURVEFS_ERROR FuseOpWrite(fuse_req_t req, fuse_ino_t ino,
const char* buf, size_t size, off_t off,
struct fuse_file_info* fi,
size_t* wSize) = 0;
virtual CURVEFS_ERROR FuseOpWrite(fuse_req_t req, fuse_ino_t ino,
const char* buf, size_t size, off_t off,
struct fuse_file_info* fi,
size_t* wSize) = 0;

virtual CURVEFS_ERROR FuseOpRead(fuse_req_t req, fuse_ino_t ino,
size_t size, off_t off,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code review

  1. The code patch looks correct and valid, without any syntax errors.
  2. It is always good to add comments above the code snippets to provide more information about the changes being made.
  3. Since the code patch is changing the signature of a virtual method, it is important to check that all derived classes override this method with the new signature.
  4. The code patch should be tested for any regressions before applying it.

Expand Down
103 changes: 103 additions & 0 deletions curvefs/src/client/xattr_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,109 @@ CURVEFS_ERROR XattrManager::CalAllLayerSumInfo(InodeAttr *attr) {
return CURVEFS_ERROR::OK;
}

CURVEFS_ERROR XattrManager::RefreshAllXAttr() {
std::stack<uint64_t> iStack;
std::mutex stackMutex;
Atomic<uint32_t> inflightNum(0);
Atomic<bool> ret(true);
iStack.emplace(ROOTINODEID);
std::vector<Thread> threadpool;
for (auto i = listDentryThreads_; i > 0; i--) {
try {
threadpool.emplace_back(
Thread(&XattrManager::ConcurrentRefreshInodeXattr, this,
&iStack, &stackMutex, &inflightNum, &ret));
} catch (const std::exception &e) {
LOG(WARNING) << "RefreshInodeXattr create thread failed,"
<< " err: " << e.what();
}
}

if (threadpool.empty()) {
return CURVEFS_ERROR::INTERNAL;
}

for (auto &thread : threadpool) {
thread.join();
}

if (!ret.load()) {
return CURVEFS_ERROR::INTERNAL;
}

return CURVEFS_ERROR::OK;
}

void XattrManager::ConcurrentRefreshInodeXattr(
std::stack<uint64_t> *iStack, std::mutex *stackMutex, Atomic<uint32_t> *inflightNum, Atomic<bool> *ret) {
while (1) {
std::list<Dentry> dentryList;
std::set<uint64_t> inodeIds;
std::list<InodeAttr> attrs;
auto tret = ConcurrentListDentry(&dentryList, iStack, stackMutex, true,
inflightNum, ret);
if (!tret) {
return;
}
{
std::lock_guard<std::mutex> guard(*stackMutex);
for (const auto &it : dentryList) {
iStack->emplace(it.inodeid());
inodeIds.emplace(it.inodeid());
}
inflightNum->fetch_sub(1);
}
if (!inodeIds.empty()){
auto tret = inodeManager_->BatchGetInodeAttr(&inodeIds, &attrs);
if (tret == CURVEFS_ERROR::OK) {
for (auto &it : attrs) {
if (it.type() == FsFileType::TYPE_DIRECTORY) {
RefreshInodeXAttr(&it);
}
}
} else {
ret->store(false);
return;
}
}
}
}

CURVEFS_ERROR XattrManager::RefreshInodeXAttr(InodeAttr *attr) {
auto ret = CalAllLayerSumInfo(attr);
std::shared_ptr<InodeWrapper> InodeWrapper;
CURVEFS_ERROR ret = inodeManager_->GetInode(attr->inodeid(), InodeWrapper);
if (ret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "RefreshXAttr get root inode fail, ret = " << ret
<< ", inodeid = " << ROOTINODEID;
return ret;
}
::curve::common::UniqueLock lgGuard = InodeWrapper->GetUniqueLock();
auto inodeXAttr = InodeWrapper->GetInodeLocked()->xattr();
bool update = false;
for (const auto &it : *attr->mutable_xattr()) {
auto iter = inodeXAttr.find(it.first);
if (iter != inodeXAttr.end()) {
uint64_t dat = 0;
if (StringToUll(it.second, &dat)) {
if (!AddUllStringToFirst(&(iter->second), dat, true)) {
return CURVEFS_ERROR::INTERNAL;
}
} else {
LOG(ERROR) << "StringToUll failed, first = " << it.second;
return CURVEFS_ERROR::INTERNAL;
}
update = true;
}
}
if (update) {
InodeWrapper->MergeXAttrLocked(inodeXAttr);
inodeManager_->ShipToFlush(InodeWrapper);
}

return ret;
}

void XattrManager::ConcurrentGetInodeXattr(
std::stack<uint64_t> *iStack,
std::mutex *stackMutex,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with a brief overview of the code patch. This code patch is used to refresh all xAttributes of an inode. The main logic is that a thread pool is created and each thread is responsible for getting a list of dentries and inode attributes associated with them, and then refreshing the xAttributes of the inode.

Now let's start with a detailed code review:

  1. The thread pool should be created in the constructor, so that you don't have to create a thread every time you call RefreshAllXAttr.

  2. You need to guard the stackMutex before calling ConcurrentListDentry.

  3. You should check the return value of Atomic ret, otherwise it may cause error.

  4. You should check the return value of ConcurrentListDentry and BatchGetInodeAttr.

  5. You should check the return value of AddUllStringToFirst().

  6. We should use std::lock_guard to make sure the lock is released at the end of the scope.

  7. You should check the return value of ShipToFlush().

I hope this review helps you. If there are any questions, please don't hesitate to let me know.

Expand Down
10 changes: 10 additions & 0 deletions curvefs/src/client/xattr_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class XattrManager {
isStop_.store(true);
}

CURVEFS_ERROR RefreshAllXAttr();

CURVEFS_ERROR RefreshInodeXAttr(InodeAttr *attr);

CURVEFS_ERROR GetXattr(const char* name, std::string *value,
InodeAttr *attr, bool enableSumInDir);

Expand Down Expand Up @@ -103,6 +107,12 @@ class XattrManager {
Atomic<uint32_t> *inflightNum,
Atomic<bool> *ret);

void ConcurrentRefreshInodeXattr(
std::stack<uint64_t> *iStack,
std::mutex *stackMutex,
Atomic<uint32_t> *inflightNum,
Atomic<bool> *ret);

void ConcurrentGetInodeXattr(
std::stack<uint64_t> *iStack,
std::mutex *stackMutex,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code review:

  1. The new functions RefreshAllXAttr() and RefreshInodeXAttr() look promising, but the code patch could be improved by adding a few more comments to explain the purpose and functionality of these functions.

  2. Both ConcurrentRefreshInodeXattr() and ConcurrentGetInodeXattr() should have input validation. In other words, all the passed parameters should be properly tested to ensure that they are not NULL and that they contain valid data before being used in the functions.

  3. Both functions should also use exception handling to catch any possible errors or exceptions that may occur during their execution.

  4. Lastly, it may be helpful to add logging statements at appropriate places to help with debugging and troubleshooting if any issues arise in the future.

Expand Down