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

curve-fuse: fix missing update extent cache #1279

Merged
merged 1 commit into from
Apr 20, 2022
Merged
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
2 changes: 2 additions & 0 deletions curvefs/src/client/inode_cache_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ CURVEFS_ERROR InodeCacheManagerImpl::GetInode(uint64_t inodeid,
std::shared_ptr<InodeWrapper> eliminatedOne;
bool eliminated = iCache_->Put(inodeid, out, &eliminatedOne);
if (eliminated) {
VLOG(3) << "GetInode eliminate one inode, ino: "
<< eliminatedOne->GetInodeId();
eliminatedOne->FlushAsync();
}
return CURVEFS_ERROR::OK;
Expand Down
51 changes: 43 additions & 8 deletions curvefs/src/client/inode_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

#include "curvefs/src/client/inode_wrapper.h"
#include <sstream>

#include "curvefs/src/client/rpcclient/metaserver_client.h"

Expand Down Expand Up @@ -144,9 +145,7 @@ CURVEFS_ERROR InodeWrapper::SyncFullInode() {
return CURVEFS_ERROR::OK;
}

auto tmp = extentCache_.ToInodePb();
inode_.mutable_volumeextentmap()->swap(tmp);
VLOG(9) << "Update inode: " << inode_.ShortDebugString();
AddVolumeExtentMapToInode();
auto ret = metaClient_->UpdateInode(inode_);
if (ret != MetaStatusCode::OK) {
LOG(ERROR) << "update inode failed, error: " << MetaStatusCode_Name(ret)
Expand All @@ -161,6 +160,7 @@ CURVEFS_ERROR InodeWrapper::SyncFullInode() {
CURVEFS_ERROR InodeWrapper::SyncAttr() {
curve::common::UniqueLock lock = GetSyncingInodeUniqueLock();
if (dirty_) {
AddVolumeExtentMapToInode();
MetaStatusCode ret = metaClient_->UpdateInode(inode_);

if (ret != MetaStatusCode::OK) {
Expand All @@ -170,6 +170,7 @@ CURVEFS_ERROR InodeWrapper::SyncAttr() {
<< ", inodeid: " << inode_.inodeid();
return MetaStatusCodeToCurvefsErrCode(ret);
}

dirty_ = false;
}
return CURVEFS_ERROR::OK;
Expand Down Expand Up @@ -258,6 +259,7 @@ CURVEFS_ERROR InodeWrapper::LinkLocked(uint64_t parent) {
if (inode_.type() != FsFileType::TYPE_DIRECTORY && parent != 0) {
inode_.add_parent(parent);
}
AddVolumeExtentMapToInode();
MetaStatusCode ret = metaClient_->UpdateInode(inode_);
if (ret != MetaStatusCode::OK) {
inode_.set_nlink(old);
Expand Down Expand Up @@ -329,10 +331,7 @@ CURVEFS_ERROR InodeWrapper::UnLinkLocked(uint64_t parent) {
// 2. write "hello, world"
// 3. unlink this file
// 4. pread from 0 to 13, expected "hello, world"
auto extents = extentCache_.ToInodePb();
if (!extents.empty()) {
inode_.mutable_volumeextentmap()->swap(extents);
}
AddVolumeExtentMapToInode();
MetaStatusCode ret = metaClient_->UpdateInode(inode_);
VLOG(6) << "UnLinkInode, inodeid = " << inode_.inodeid()
<< ", nlink = " << inode_.nlink();
Expand Down Expand Up @@ -401,6 +400,7 @@ CURVEFS_ERROR InodeWrapper::Release() {

CURVEFS_ERROR
InodeWrapper::UpdateInodeStatus(InodeOpenStatusChange statusChange) {
AddVolumeExtentMapToInode();
MetaStatusCode ret = metaClient_->UpdateInode(inode_, statusChange);
if (ret != MetaStatusCode::OK) {
LOG(ERROR) << "metaClient_ UpdateInode failed, MetaStatusCode = " << ret
Expand All @@ -424,6 +424,7 @@ CURVEFS_ERROR InodeWrapper::UpdateParentLocked(
}
inode_.add_parent(newParent);

AddVolumeExtentMapToInode();
MetaStatusCode ret = metaClient_->UpdateInode(inode_);
if (ret != MetaStatusCode::OK) {
LOG(ERROR) << "metaClient_ UpdateInode failed, MetaStatusCode = " << ret
Expand All @@ -435,14 +436,48 @@ CURVEFS_ERROR InodeWrapper::UpdateParentLocked(
return CURVEFS_ERROR::OK;
}

static std::ostream &operator<<(
std::ostream &os,
const google::protobuf::Map<uint64_t, curvefs::metaserver::VolumeExtentList>
&exts) {
if (exts.empty()) {
os << "[empty]";
return os;
}

for (const auto &range : exts) {
for (const auto &ext : range.second.volumeextents()) {
os << ext.ShortDebugString();
}
}

return os;
}

void InodeWrapper::BuildExtentCache() {
if (inode_.type() != FsFileType::TYPE_VOLUME) {
return;
}

VLOG(9) << "Build extent for inode: " << inode_.ShortDebugString();
VLOG(9) << "Build extent for inode: " << inode_.ShortDebugString()
<< ", extents: " << inode_.volumeextentmap().size();
extentCache_.Build(inode_.volumeextentmap());
}

void InodeWrapper::AddVolumeExtentMapToInode() {
if (inode_.type() != FsFileType::TYPE_VOLUME) {
return;
}

auto tmp = extentCache_.ToInodePb();
if (tmp.empty()) {
return;
}

VLOG(9) << "Volume extent map, ino: " << inode_.inodeid()
<< ", extents: " << tmp;
inode_.mutable_volumeextentmap()->swap(tmp);
}

} // namespace client
} // namespace curvefs
3 changes: 3 additions & 0 deletions curvefs/src/client/inode_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,9 @@ class InodeWrapper : public std::enable_shared_from_this<InodeWrapper> {

void BuildExtentCache();

// TODO(wuhanqing): separate `volumeextentmap` from `Inode`
void AddVolumeExtentMapToInode();

private:
Inode inode_;
uint32_t openCount_;
Expand Down
3 changes: 0 additions & 3 deletions curvefs/src/client/rpcclient/metacache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ bool MetaCache::GetTxId(uint32_t fsId, uint64_t inodeId, uint32_t *partitionId,
bool MetaCache::GetTarget(uint32_t fsID, uint64_t inodeID,
CopysetTarget *target, uint64_t *applyIndex,
bool refresh) {
VLOG(3) << "Get target, fsid: " << fsID << ", inode id " << inodeID
<< ", target: " << *target;

// list infos from mds
if (!ListPartitions(fsID)) {
LOG(ERROR) << "get target for {fsid:" << fsID
Expand Down
62 changes: 62 additions & 0 deletions curvefs/test/client/test_inodeWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,68 @@ TEST_F(TestInodeWrapper, testSyncFailed) {
ASSERT_EQ(CURVEFS_ERROR::NOTEXIST, ret2);
}

static void AddOneExtent(InodeWrapper* wrap) {
auto extentcache = wrap->GetMutableExtentCache();
PExtent pext;
extentcache->Merge(0, pext);
}

MATCHER(HasVolumeExtentMap, "") {
return !arg.volumeextentmap().empty();
}

TEST_F(TestInodeWrapper, TestAllUpdateInodeMustHasVolumeExtentMap) {
inodeWrapper_->SetType(FsFileType::TYPE_VOLUME);

// Sync
{
AddOneExtent(inodeWrapper_.get());
EXPECT_CALL(*metaClient_, UpdateInode(HasVolumeExtentMap(), _))
.Times(1);
inodeWrapper_->Sync();
}

// Open and Release
{
AddOneExtent(inodeWrapper_.get());
EXPECT_CALL(*metaClient_, UpdateInode(HasVolumeExtentMap(), _))
.Times(2);
inodeWrapper_->Open();
inodeWrapper_->Release();
}

// UpdateParent
{
AddOneExtent(inodeWrapper_.get());
EXPECT_CALL(*metaClient_, UpdateInode(HasVolumeExtentMap(), _))
.Times(1);
inodeWrapper_->UpdateParentLocked(1, 2);
}

// SyncAttr
{
AddOneExtent(inodeWrapper_.get());
EXPECT_CALL(*metaClient_, UpdateInode(HasVolumeExtentMap(), _))
.Times(1);
inodeWrapper_->SyncAttr();
}

// Link
{
AddOneExtent(inodeWrapper_.get());
EXPECT_CALL(*metaClient_, UpdateInode(HasVolumeExtentMap(), _))
.Times(1);
inodeWrapper_->LinkLocked(2);
}

// UnLink
{
AddOneExtent(inodeWrapper_.get());
EXPECT_CALL(*metaClient_, UpdateInode(HasVolumeExtentMap(), _))
.Times(1);
inodeWrapper_->UnLinkLocked(2);
}
}

} // namespace client
} // namespace curvefs