diff --git a/curvefs/src/client/s3/client_s3_cache_manager.cpp b/curvefs/src/client/s3/client_s3_cache_manager.cpp index 36a883a012..3d082037d0 100644 --- a/curvefs/src/client/s3/client_s3_cache_manager.cpp +++ b/curvefs/src/client/s3/client_s3_cache_manager.cpp @@ -2197,6 +2197,13 @@ CURVEFS_ERROR DataCache::Flush(uint64_t inodeId, bool toS3) { curve::common::CountDownEvent cond(1); std::atomic pendingReq(0); FSStatusCode ret; + enum class cachePoily { + NCache, + RCache, + WRCache, + } cachePoily = cachePoily::NCache; + bool mayCache = !s3ClientAdaptor_->GetDiskCacheManager() + ->IsDiskCacheFull() && !toS3; VLOG(9) << "DataCache::Flush : now:" << now << ",createTime:" << createTime_ << ",flushIntervalSec:" << flushIntervalSec @@ -2226,13 +2233,16 @@ CURVEFS_ERROR DataCache::Flush(uint64_t inodeId, bool toS3) { << ",Len:" << tmpLen << ",blockPos:" << blockPos << ",blockIndex:" << blockIndex; - bool useReadCacheOnly = - s3ClientAdaptor_->IsReadCache() && - !s3ClientAdaptor_->GetDiskCacheManager()->IsDiskCacheFull() && - !toS3; + if ( s3ClientAdaptor_->IsReadCache() && mayCache ) { + cachePoily = cachePoily::RCache; + } else if ( s3ClientAdaptor_->IsReadWriteCache() && mayCache ) { + cachePoily = cachePoily::WRCache; + } else { + cachePoily = cachePoily::NCache; + } PutObjectAsyncCallBack cb = - [&, useReadCacheOnly] + [&, cachePoily] (const std::shared_ptr &context) { if (context->retCode == 0) { if (s3ClientAdaptor_->s3Metric_.get() != nullptr) { @@ -2250,7 +2260,7 @@ CURVEFS_ERROR DataCache::Flush(uint64_t inodeId, bool toS3) { } VLOG(9) << "PutObjectAsyncCallBack: " << context->key << " pendingReq is: " << pendingReq; - if (useReadCacheOnly) { + if (cachePoily::RCache == cachePoily) { VLOG(9) << "Write to read cache, name: " << context->key; s3ClientAdaptor_->GetDiskCacheManager() ->Enqueue(context, true); @@ -2262,10 +2272,6 @@ CURVEFS_ERROR DataCache::Flush(uint64_t inodeId, bool toS3) { }; std::vector> uploadTasks; - bool useReadWriteCache = - s3ClientAdaptor_->IsReadWriteCache() && - !s3ClientAdaptor_->GetDiskCacheManager()->IsDiskCacheFull() && - !toS3; while (tmpLen > 0) { if (blockPos + tmpLen > blockSize) { @@ -2301,7 +2307,7 @@ CURVEFS_ERROR DataCache::Flush(uint64_t inodeId, bool toS3) { ++iter) { VLOG(9) << "upload start: " << (*iter)->key << " len : " << (*iter)->bufferSize; - if (useReadWriteCache) { + if (cachePoily::WRCache == cachePoily) { s3ClientAdaptor_->GetDiskCacheManager()->Enqueue(*iter); } else { s3ClientAdaptor_->GetS3Client()->UploadAsync(*iter);