-
Notifications
You must be signed in to change notification settings - Fork 526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
curvefs/client: local cache policy optimization #2064
Conversation
EXPECT_CALL(*diskCacheManager_, IsDiskUsedInited()).WillOnce(Return(true)); | ||
EXPECT_CALL(*diskCacheManager_, IsDiskCacheFull()).WillOnce(Return(false)); | ||
EXPECT_CALL(*diskCacheManager_, WriteReadDirect(_, _, _)) | ||
.WillOnce(Return(context->bufferSize)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should have EXPECT_CALL(*diskCacheRead_, WriteDiskFile(_, _, _)).WillOnce(Return(context->bufferSize));
here, but the test will fail with it(It seems not enter the func which will be done ).
if (!useDiskCache) { | ||
s3ClientAdaptor_->GetS3Client()->UploadAsync(*iter); | ||
} else { | ||
if (useDiskCache) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we add useReadCache, maybe we need a new name of useDiskCache?
@@ -56,13 +56,37 @@ int DiskCacheManagerImpl::Init(const S3ClientAdaptorOption option) { | |||
} | |||
|
|||
void DiskCacheManagerImpl::Enqueue( | |||
std::shared_ptr<PutObjectAsyncContext> context) { | |||
std::shared_ptr<PutObjectAsyncContext> context, bool isReadWrite) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isReadWrite may cause confusion? isReadCacheOnly may be better?
int DiskCacheManagerImpl::WriteReadDirectClosure( | ||
std::shared_ptr<PutObjectAsyncContext> context) { | ||
VLOG(9) << "WriteReadClosure start, name: " << context->key; | ||
int ret = WriteReadDirect(context->key, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The write may have to be put after the s3 upload is successful, otherwise if the write is successful but the client exits before the upload is successful, the data will be inconsistent
e1ae703
to
fdd2804
Compare
std::shared_ptr<PutObjectAsyncContext> context) { | ||
VLOG(9) << "WriteReadClosure start, name: " << context->key; | ||
// Upload to s3 | ||
int s3Ret = client_->Upload(context->key, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
synchronous upload may affects performance, maybe we can put the enqueue(WriteReadDirect) to PutObjectAsyncCallBack which is defined in DataCache::Flush?
and i think we don't need to care if the cache read disk is successfully written
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah,I will do this
47fa5d0
to
9def2b5
Compare
context->startTime = butil::cpuwide_time_us(); | ||
|
||
S3ClientAdaptorOption s3AdaptorOption; | ||
s3AdaptorOption.diskCacheOpt.threads = 5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unit test is failed because code modification not covered, I guess it should be set here(s3AdaptorOption.diskCacheOpt.diskCache.diskCacheType=1)
c6e55af
to
dce170e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good job, LGTM
dce170e
to
86f101f
Compare
@ilixiaocui done |
return; | ||
} | ||
LOG(WARNING) << "Put object failed, key: " << context->key; | ||
s3ClientAdaptor_->GetS3Client()->UploadAsync(context); | ||
}; | ||
|
||
std::vector<std::shared_ptr<PutObjectAsyncContext>> uploadTasks; | ||
bool useDiskCache = | ||
bool useReadWriteCache = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useReadCacheOnly
和 useReadWriteCache
Is it possible to add an enum, like this:
enum CachePolicy {
NCache,
RCache,
WRCache,
}
To express caching strategy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A good idea.
So how about now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A good idea.
So how about now?
IMO, the best way is bit operation, that is, 0 means NCache, 1 means RCache, 2 means WCache, and 3 means WRcache. Bitwise AND to calculate whether to open the corresponding operation.
enum CachePolicy {
NCache = 0,
RCache = 1<<0,
WCache = 1<<1,
WRCache=RCache|WCache,
};
Whether to enable read cache:
if (cachePoily & CachePolicy::RCache) {
....
}
But this will lose the readability of the code.
just an opinion
cachePoily & CachePolicy::RCache
is not a good expression for enum class
, and it will really lose the readability as you say. I think readability can be more important in function Flush
.
Also, thanks for your suggestion, it's really a beautiful expression, I learn a lot
If this looks ok, I will rebase and commit again |
7c89082
to
131a9c3
Compare
recheck |
@@ -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() && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool mayCache = s3ClientAdaptor_->HasDiskCache() &&
!s3ClientAdaptor_->GetDiskCacheManager()->IsDiskCacheFull() && !toS3 ;
if ( mayCache) {
cachePoily = IsReadWriteCache()? cachePoily::WRCache:cachePoily::RCache;
} else {
cachePoily = cachePoily::NCache;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool mayCache = s3ClientAdaptor_->HasDiskCache() && !s3ClientAdaptor_->GetDiskCacheManager()->IsDiskCacheFull() && !toS3 ; if ( mayCache) { cachePoily = IsReadWriteCache()? cachePoily::WRCache:cachePoily::RCache; } else { cachePoily = cachePoily::NCache; }
I modify the code as this, and not the ut will fail, which is odd
@@ -2243,17 +2262,19 @@ CURVEFS_ERROR DataCache::Flush(uint64_t inodeId, bool toS3) { | |||
} | |||
VLOG(9) << "PutObjectAsyncCallBack: " << context->key | |||
<< " pendingReq is: " << pendingReq; | |||
if (cachePoily::RCache == cachePoily) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cachePoily::RCache == cachePoily || cachePoily::WRCache == cachePoily ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only ReadCache,WRCache will do s3ClientAdaptor_->GetDiskCacheManager()->Enqueue(*iter);
,in which it will wirte to WCache before uploading then doing upload async.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only ReadCache,WRCache will do
s3ClientAdaptor_->GetDiskCacheManager()->Enqueue(*iter);
,in which it will wirte to WCache before uploading then doing upload async.
ok
return; | ||
} | ||
LOG(WARNING) << "Put object failed, key: " << context->key; | ||
s3ClientAdaptor_->GetS3Client()->UploadAsync(context); | ||
}; | ||
|
||
std::vector<std::shared_ptr<PutObjectAsyncContext>> uploadTasks; | ||
bool useDiskCache = | ||
bool useReadWriteCache = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A good idea.
So how about now?
IMO, the best way is bit operation, that is, 0 means NCache, 1 means RCache, 2 means WCache, and 3 means WRcache. Bitwise AND to calculate whether to open the corresponding operation.
enum CachePolicy {
NCache = 0,
RCache = 1<<0,
WCache = 1<<1,
WRCache=RCache|WCache,
};
Whether to enable read cache:
if (cachePoily & CachePolicy::RCache) {
....
}
But this will lose the readability of the code.
just an opinion
cachePoily & CachePolicy::RCache
is not a good expression for enum class
, and it will really lose the readability as you say. I think readability can be more important in function Flush
.
Also, thanks for your suggestion, it's really a beautiful expression, I learn a lot
recheck |
I have no further questions and have reviewed +1 |
131a9c3
to
2985361
Compare
recheck |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
unittest has failed @Tangruilin |
796eac3
to
e198f65
Compare
recheck |
It seems there are some problem, I'll slove it these days, I have try three time and it failed for two different reasons |
recheck |
e198f65
to
8ac6bd5
Compare
recheck |
1 similar comment
recheck |
c311b33
to
8ac6bd5
Compare
recheck |
9ad3e07
to
dc59822
Compare
Signed-off-by: tangruilin <[email protected]>
dc59822
to
05e0102
Compare
recheck |
What problem does this PR solve?
Issue Number: #2025
Issue Number: #1280
Problem Summary:
What is changed and how it works?
What's Changed:
add
use ReadCache
and some Related function.How it Works:
Add
useReadCache
to decide if use read cache. If do, write to the read cache and update to s3 async.Side effects(Breaking backward compatibility? Performance regression?):
Check List