From dce170e58afa70f53faf5b7663a29622dd3c3b09 Mon Sep 17 00:00:00 2001 From: tangruilin Date: Tue, 15 Nov 2022 12:30:23 +0800 Subject: [PATCH] fix Signed-off-by: tangruilin --- .../src/client/s3/client_s3_cache_manager.cpp | 21 ++++++++++++------- .../src/client/s3/disk_cache_manager_impl.cpp | 15 +------------ .../client/test_disk_cache_manager_impl.cpp | 3 ++- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/curvefs/src/client/s3/client_s3_cache_manager.cpp b/curvefs/src/client/s3/client_s3_cache_manager.cpp index c3ca1b4966..36a883a012 100644 --- a/curvefs/src/client/s3/client_s3_cache_manager.cpp +++ b/curvefs/src/client/s3/client_s3_cache_manager.cpp @@ -2225,8 +2225,15 @@ CURVEFS_ERROR DataCache::Flush(uint64_t inodeId, bool toS3) { << ", inodeId:" << inodeId << ",Len:" << tmpLen << ",blockPos:" << blockPos << ",blockIndex:" << blockIndex; + + bool useReadCacheOnly = + s3ClientAdaptor_->IsReadCache() && + !s3ClientAdaptor_->GetDiskCacheManager()->IsDiskCacheFull() && + !toS3; + PutObjectAsyncCallBack cb = - [&](const std::shared_ptr &context) { + [&, useReadCacheOnly] + (const std::shared_ptr &context) { if (context->retCode == 0) { if (s3ClientAdaptor_->s3Metric_.get() != nullptr) { s3ClientAdaptor_->CollectMetrics( @@ -2243,6 +2250,11 @@ CURVEFS_ERROR DataCache::Flush(uint64_t inodeId, bool toS3) { } VLOG(9) << "PutObjectAsyncCallBack: " << context->key << " pendingReq is: " << pendingReq; + if (useReadCacheOnly) { + VLOG(9) << "Write to read cache, name: " << context->key; + s3ClientAdaptor_->GetDiskCacheManager() + ->Enqueue(context, true); + } return; } LOG(WARNING) << "Put object failed, key: " << context->key; @@ -2254,10 +2266,7 @@ CURVEFS_ERROR DataCache::Flush(uint64_t inodeId, bool toS3) { s3ClientAdaptor_->IsReadWriteCache() && !s3ClientAdaptor_->GetDiskCacheManager()->IsDiskCacheFull() && !toS3; - bool useReadCacheOnly = - s3ClientAdaptor_->IsReadCache() && - !s3ClientAdaptor_->GetDiskCacheManager()->IsDiskCacheFull() && - !toS3; + while (tmpLen > 0) { if (blockPos + tmpLen > blockSize) { n = blockSize - blockPos; @@ -2294,8 +2303,6 @@ CURVEFS_ERROR DataCache::Flush(uint64_t inodeId, bool toS3) { << " len : " << (*iter)->bufferSize; if (useReadWriteCache) { s3ClientAdaptor_->GetDiskCacheManager()->Enqueue(*iter); - } else if (useReadCacheOnly) { - s3ClientAdaptor_->GetDiskCacheManager()->Enqueue(*iter, true); } else { s3ClientAdaptor_->GetS3Client()->UploadAsync(*iter); } diff --git a/curvefs/src/client/s3/disk_cache_manager_impl.cpp b/curvefs/src/client/s3/disk_cache_manager_impl.cpp index 5414aceaf4..d1bc3ec82d 100644 --- a/curvefs/src/client/s3/disk_cache_manager_impl.cpp +++ b/curvefs/src/client/s3/disk_cache_manager_impl.cpp @@ -75,22 +75,9 @@ void DiskCacheManagerImpl::Enqueue( int DiskCacheManagerImpl::WriteReadDirectClosure( std::shared_ptr context) { VLOG(9) << "WriteReadClosure start, name: " << context->key; - // Upload to s3 - int s3Ret = client_->Upload(context->key, - context->buffer, context->bufferSize); - if (s3Ret < 0) { - LOG(ERROR) << "Upload to s3 error"; - context->retCode = s3Ret; - context->cb(context); - return s3Ret; - } - - // Write to read cache + // Write to read cache, we don't care if the cache wirte success int ret = WriteReadDirect(context->key, context->buffer, context->bufferSize); - context->retCode = ret; - context->cb(context); - return ret; VLOG(9) << "WriteReadClosure end, name: " << context->key; return ret; } diff --git a/curvefs/test/client/test_disk_cache_manager_impl.cpp b/curvefs/test/client/test_disk_cache_manager_impl.cpp index 602e89fe61..2c16c14cca 100644 --- a/curvefs/test/client/test_disk_cache_manager_impl.cpp +++ b/curvefs/test/client/test_disk_cache_manager_impl.cpp @@ -23,6 +23,7 @@ #include #include +#include "curvefs/src/client/common/common.h" #include "curvefs/test/client/mock_disk_cache_write.h" #include "curvefs/test/client/mock_disk_cache_read.h" #include "curvefs/test/client/mock_disk_cache_manager.h" @@ -152,6 +153,7 @@ TEST_F(TestDiskCacheManagerImpl, WriteReadClosure) { S3ClientAdaptorOption s3AdaptorOption; s3AdaptorOption.diskCacheOpt.threads = 5; + s3AdaptorOption.diskCacheOpt.diskCacheType = DiskCacheType::OnlyRead; EXPECT_CALL(*diskCacheManager_, Init(_, _)).WillOnce(Return(0)); diskCacheManagerImpl_->Init(s3AdaptorOption); std::string fileName = "test"; @@ -160,7 +162,6 @@ TEST_F(TestDiskCacheManagerImpl, WriteReadClosure) { // If the mode is read cache, will call WriteReadDirect EXPECT_CALL(*diskCacheManager_, IsDiskUsedInited()).WillOnce(Return(true)); EXPECT_CALL(*diskCacheManager_, IsDiskCacheFull()).WillOnce(Return(false)); - EXPECT_CALL(*client_, Upload(_, _, _)).WillOnce(Return(0)); EXPECT_CALL(*diskCacheManager_, WriteReadDirect(_, _, _)) .WillOnce(Return(context->bufferSize)); diskCacheManagerImpl_->Enqueue(context, true);