diff --git a/curvefs/src/client/inode_cache_manager.cpp b/curvefs/src/client/inode_cache_manager.cpp index 441ac0f4a3..2d9c7ecdee 100644 --- a/curvefs/src/client/inode_cache_manager.cpp +++ b/curvefs/src/client/inode_cache_manager.cpp @@ -109,6 +109,10 @@ InodeCacheManagerImpl::GetInode(uint64_t inodeId, bool ok = iCache_->Get(inodeId, &out); if (ok) { curve::common::UniqueLock lgGuard = out->GetUniqueLock(); + if (out->GetType() == FsFileType::TYPE_FILE) { + return CURVEFS_ERROR::OK; + } + REFRESH_DATA_REMOTE(out, out->NeedRefreshData()); return CURVEFS_ERROR::OK; } @@ -122,7 +126,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); @@ -483,11 +490,14 @@ InodeCacheManagerImpl::RefreshData(std::shared_ptr &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; diff --git a/curvefs/src/client/inode_wrapper.h b/curvefs/src/client/inode_wrapper.h index 49aa50364b..c7bfbfe436 100644 --- a/curvefs/src/client/inode_wrapper.h +++ b/curvefs/src/client/inode_wrapper.h @@ -164,6 +164,12 @@ class InodeWrapper : public std::enable_shared_from_this { 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; diff --git a/curvefs/test/client/test_inode_cache_manager.cpp b/curvefs/test/client/test_inode_cache_manager.cpp index 11785fb3c7..718026d898 100644 --- a/curvefs/test/client/test_inode_cache_manager.cpp +++ b/curvefs/test/client/test_inode_cache_manager.cpp @@ -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)));