Skip to content

Commit

Permalink
change the judge to enum
Browse files Browse the repository at this point in the history
Signed-off-by: tangruilin <[email protected]>
  • Loading branch information
Tangruilin committed Nov 16, 2022
1 parent 86f101f commit 131a9c3
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions curvefs/src/client/s3/client_s3_cache_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2197,6 +2197,11 @@ CURVEFS_ERROR DataCache::Flush(uint64_t inodeId, bool toS3) {
curve::common::CountDownEvent cond(1);
std::atomic<uint64_t> pendingReq(0);
FSStatusCode ret;
enum class cachePoily {
NCache,
RCache,
WRCache,
} cachePoily = cachePoily::NCache;

VLOG(9) << "DataCache::Flush : now:" << now << ",createTime:" << createTime_
<< ",flushIntervalSec:" << flushIntervalSec
Expand Down Expand Up @@ -2226,13 +2231,20 @@ CURVEFS_ERROR DataCache::Flush(uint64_t inodeId, bool toS3) {
<< ",Len:" << tmpLen << ",blockPos:" << blockPos
<< ",blockIndex:" << blockIndex;

bool useReadCacheOnly =
s3ClientAdaptor_->IsReadCache() &&
if ( s3ClientAdaptor_->IsReadCache() &&
!s3ClientAdaptor_->GetDiskCacheManager()->IsDiskCacheFull() &&
!toS3;
!toS3 ) {
cachePoily = cachePoily::RCache;
} else if ( s3ClientAdaptor_->IsReadWriteCache() &&
!s3ClientAdaptor_->GetDiskCacheManager()->IsDiskCacheFull() &&
!toS3 ) {
cachePoily = cachePoily::WRCache;
} else {
cachePoily = cachePoily::NCache;
}

PutObjectAsyncCallBack cb =
[&, useReadCacheOnly]
[&, cachePoily]
(const std::shared_ptr<PutObjectAsyncContext> &context) {
if (context->retCode == 0) {
if (s3ClientAdaptor_->s3Metric_.get() != nullptr) {
Expand All @@ -2250,7 +2262,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);
Expand All @@ -2262,10 +2274,6 @@ CURVEFS_ERROR DataCache::Flush(uint64_t inodeId, bool toS3) {
};

std::vector<std::shared_ptr<PutObjectAsyncContext>> uploadTasks;
bool useReadWriteCache =
s3ClientAdaptor_->IsReadWriteCache() &&
!s3ClientAdaptor_->GetDiskCacheManager()->IsDiskCacheFull() &&
!toS3;

while (tmpLen > 0) {
if (blockPos + tmpLen > blockSize) {
Expand Down Expand Up @@ -2301,7 +2309,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);
Expand Down

0 comments on commit 131a9c3

Please sign in to comment.