Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: tangruilin <[email protected]>
  • Loading branch information
Tangruilin committed Nov 15, 2022
1 parent fdd2804 commit 9def2b5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
18 changes: 12 additions & 6 deletions curvefs/src/client/s3/client_s3_cache_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<PutObjectAsyncContext> &context) {
if (context->retCode == 0) {
Expand All @@ -2243,6 +2249,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;
Expand All @@ -2254,10 +2265,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;
Expand Down Expand Up @@ -2294,8 +2302,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);
}
Expand Down
15 changes: 1 addition & 14 deletions curvefs/src/client/s3/disk_cache_manager_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,9 @@ void DiskCacheManagerImpl::Enqueue(
int DiskCacheManagerImpl::WriteReadDirectClosure(
std::shared_ptr<PutObjectAsyncContext> 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;
}
Expand Down
1 change: 0 additions & 1 deletion curvefs/test/client/test_disk_cache_manager_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9def2b5

Please sign in to comment.