Skip to content
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

add async in read from s3 #2080

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions curvefs/src/client/s3/client_s3_cache_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ int FileCacheManager::ReadFromS3(const std::vector<S3ReadRequest> &requests,
std::vector<S3ReadRequest>::const_iterator iter = requests.begin();
std::atomic<uint64_t> pendingReq(0);
curve::common::CountDownEvent cond(1);
bool async = false;
bool async = true;
// first is chunkIndex, second is vector chunkPos
std::map<uint64_t, std::vector<uint64_t>> dataCacheMap;
GetObjectAsyncCallBack cb =
Expand Down Expand Up @@ -532,14 +532,35 @@ int FileCacheManager::ReadFromS3(const std::vector<S3ReadRequest> &requests,
uint64_t start = butil::cpuwide_time_us();
if (async) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if async is enable, you can set(bool async = true;)

VLOG(9) << "async read s3";
auto context = std::make_shared<GetObjectAsyncContext>();
context->key = name;
context->buf = response.GetDataBuf() + readOffset;
context->offset = blockPos - objectOffset;
context->len = n;
context->cb = cb;
pendingReq.fetch_add(1, std::memory_order_relaxed);
s3ClientAdaptor_->GetS3Client()->DownloadAsync(context);
int ret = 0;
if (s3ClientAdaptor_->HasDiskCache() &&
s3ClientAdaptor_->GetDiskCacheManager()->IsCached(name)) {
VLOG(9) << "cached in disk: " << name;
ret = s3ClientAdaptor_->GetDiskCacheManager()->Read(
name, response.GetDataBuf() + readOffset,
blockPos - objectOffset, n);
if (s3ClientAdaptor_->s3Metric_.get() != nullptr) {
s3ClientAdaptor_->CollectMetrics(
&s3ClientAdaptor_->s3Metric_->adaptorReadDiskCache,
n, start);
}
} else {
auto context = std::make_shared<GetObjectAsyncContext>();
context->key = name;
context->buf = response.GetDataBuf() + readOffset;
context->offset = blockPos - objectOffset;
context->len = n;
context->cb = cb;
pendingReq.fetch_add(1, std::memory_order_relaxed);
s3ClientAdaptor_->GetS3Client()->DownloadAsync(context);
}
if (ret < 0) {
LOG(ERROR) << "get obj failed, name is: " << name
<< ", offset is: " << blockPos
<< ", objoffset is: " << objectOffset
<< ", len: " << n << ", ret is: " << ret;
return ret;
}
} else {
VLOG(9) << "sync read s3";
int ret = 0;
Expand Down