From 47fa5d083a8d374dce967eee6f413683c4f68b3a 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 | 17 +++++++++++------ .../src/client/s3/disk_cache_manager_impl.cpp | 15 +-------------- .../client/test_disk_cache_manager_impl.cpp | 1 - 3 files changed, 12 insertions(+), 21 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..8b5c15f129 100644 --- a/curvefs/src/client/s3/client_s3_cache_manager.cpp +++ b/curvefs/src/client/s3/client_s3_cache_manager.cpp @@ -2225,6 +2225,12 @@ 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) { if (context->retCode == 0) { @@ -2243,6 +2249,10 @@ 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 +2264,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 +2301,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..54a2854728 100644 --- a/curvefs/test/client/test_disk_cache_manager_impl.cpp +++ b/curvefs/test/client/test_disk_cache_manager_impl.cpp @@ -160,7 +160,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);