-
Notifications
You must be signed in to change notification settings - Fork 526
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
wip_enablesumindir #2310
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. code review
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
I hope this review helps you. If there are any questions, please don't hesitate to let me know. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
||
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the code review:
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
,
It looks like the code is trying to initialize a fuse client and refresh all xattrs if the enableSumInDir_ flag is set.
There are no bugs in the code, but one improvement could be adding a log statement to indicate when the xattrManager_->RefreshAllXAttr() is called.
The code should also check if enableSumInDir_ is set before calling the xattrManager_->RefreshAllXAttr() method.
Another improvement could be to add a try-catch block around the xattrManager_->RefreshAllXAttr() call to handle any exceptions that might be thrown.