Skip to content

Commit

Permalink
curve-fuse: skip refresh volume extent when inode has no data
Browse files Browse the repository at this point in the history
Signed-off-by: Hanqing Wu <[email protected]>
  • Loading branch information
wu-hanqing committed Aug 4, 2022
1 parent 25081fc commit d7478af
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
16 changes: 11 additions & 5 deletions curvefs/src/client/inode_cache_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ InodeCacheManagerImpl::GetInode(uint64_t inodeId,
option_.refreshDataIntervalSec);

// refresh data
REFRESH_DATA_REMOTE(out, streaming);
{
curve::common::UniqueLock lgGuard = out->GetUniqueLock();
REFRESH_DATA_REMOTE(out, streaming);
}

// put to cache
PUT_INODE_CACHE(inodeId, out);
Expand Down Expand Up @@ -483,11 +486,14 @@ InodeCacheManagerImpl::RefreshData(std::shared_ptr<InodeWrapper> &inode,
}
break;

case FsFileType::TYPE_FILE:
rc = inode->RefreshVolumeExtent();
LOG_IF(ERROR, rc != CURVEFS_ERROR::OK)
<< "RefreshVolumeExtent failed, error: " << rc;
case FsFileType::TYPE_FILE: {
if (inode->GetLengthLocked() > 0) {
rc = inode->RefreshVolumeExtent();
LOG_IF(ERROR, rc != CURVEFS_ERROR::OK)
<< "RefreshVolumeExtent failed, error: " << rc;
}
break;
}

default:
rc = CURVEFS_ERROR::OK;
Expand Down
6 changes: 6 additions & 0 deletions curvefs/src/client/inode_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ class InodeWrapper : public std::enable_shared_from_this<InodeWrapper> {
return inode_.length();
}

// Get inode's length.
// REQUIRES: |mtx_| is held
uint64_t GetLengthLocked() const {
return inode_.length();
}

void SetUid(uint32_t uid) {
inode_.set_uid(uid);
dirty_ = true;
Expand Down
1 change: 1 addition & 0 deletions curvefs/test/client/test_inode_cache_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ TEST_F(TestInodeCacheManager, RefreshInode) {
inodefile.set_inodeid(inodefileid);
inodefile.set_fsid(fsId_);
inodefile.set_type(FsFileType::TYPE_FILE);
inodefile.set_length(1);
EXPECT_CALL(*metaClient_, GetInode(fsId_, inodefileid, _, _))
.WillOnce(DoAll(SetArgPointee<2>(inodefile), SetArgPointee<3>(false),
Return(MetaStatusCode::OK)));
Expand Down

0 comments on commit d7478af

Please sign in to comment.