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 18, 2022
1 parent 86f101f commit 2985361
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 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,13 @@ 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;
bool mayCache = !s3ClientAdaptor_->GetDiskCacheManager()
->IsDiskCacheFull() && !toS3;

VLOG(9) << "DataCache::Flush : now:" << now << ",createTime:" << createTime_
<< ",flushIntervalSec:" << flushIntervalSec
Expand Down Expand Up @@ -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<PutObjectAsyncContext> &context) {
if (context->retCode == 0) {
if (s3ClientAdaptor_->s3Metric_.get() != nullptr) {
Expand All @@ -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);
Expand All @@ -2262,10 +2272,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 +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);
Expand Down

0 comments on commit 2985361

Please sign in to comment.