Skip to content

Commit

Permalink
curvefs/client: Read process memory copy 2 times problem modification
Browse files Browse the repository at this point in the history
Signed-off-by: baijiaruo <[email protected]>
  • Loading branch information
baijiaruo1 committed Jul 27, 2022
1 parent 70d025d commit fa1e288
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
19 changes: 4 additions & 15 deletions curvefs/src/client/s3/client_s3_cache_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ int FileCacheManager::Read(uint64_t inodeId, uint64_t offset, uint64_t length,
<< ",inodeId:" << tmp_req.inodeId;
}

ret = ReadFromS3(totalS3Requests, &responses, fileLen);
ret = ReadFromS3(totalS3Requests, &responses, dataBuf, fileLen);
if (ret < 0) {
retry++;
responses.clear();
Expand Down Expand Up @@ -438,21 +438,14 @@ int FileCacheManager::Read(uint64_t inodeId, uint64_t offset, uint64_t length,
break;
}
}
auto repIter = responses.begin();
for (; repIter != responses.end(); repIter++) {
VLOG(6) << "readOffset:" << repIter->GetReadOffset()
<< ",bufLen:" << repIter->GetBufLen();
memcpy(dataBuf + repIter->GetReadOffset(),
repIter->GetDataBuf(), repIter->GetBufLen());
}
}

return readOffset;
}

int FileCacheManager::ReadFromS3(const std::vector<S3ReadRequest> &requests,
std::vector<S3ReadResponse> *responses,
uint64_t fileLen) {
char* dataBuf, uint64_t fileLen) {
uint64_t chunkSize = s3ClientAdaptor_->GetChunkSize();
uint64_t blockSize = s3ClientAdaptor_->GetBlockSize();
std::vector<S3ReadRequest>::const_iterator iter = requests.begin();
Expand Down Expand Up @@ -487,10 +480,7 @@ int FileCacheManager::ReadFromS3(const std::vector<S3ReadRequest> &requests,

std::vector<uint64_t> &dataCacheVec = dataCacheMap[chunkIndex];
dataCacheVec.push_back(chunkPos);
S3ReadResponse response(len);
if (!response.GetDataBuf()) {
return -1;
}
S3ReadResponse response(dataBuf + iter->readOffset, len);
VLOG(6) << "HandleReadRequest blockPos:" << blockPos << ",len:" << len
<< ",blockIndex:" << blockIndex
<< ",objectOffset:" << objectOffset << ",chunkid"
Expand Down Expand Up @@ -589,8 +579,7 @@ int FileCacheManager::ReadFromS3(const std::vector<S3ReadRequest> &requests,
blockPos = (blockPos + n) % blockSize;
objectOffset = 0;
}
response.SetReadOffset(iter->readOffset);
VLOG(6) << "response readOffset:" << response.GetReadOffset()
VLOG(6) << "readOffset:" << iter->readOffset
<< ",response len:" << response.GetBufLen()
<< ",bufLen:" << readOffset;
responses->emplace_back(std::move(response));
Expand Down
15 changes: 5 additions & 10 deletions curvefs/src/client/s3/client_s3_cache_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,20 +192,15 @@ class DataCache : public std::enable_shared_from_this<DataCache> {

class S3ReadResponse {
public:
explicit S3ReadResponse(uint64_t length)
: data_(new char[length]), len_(length) {}
explicit S3ReadResponse(char *data, uint64_t length)
: data_(data), len_(length) {}

char *GetDataBuf() { return data_.get(); }

void SetReadOffset(uint64_t readOffset) { readOffset_ = readOffset; }

uint64_t GetReadOffset() { return readOffset_; }
char *GetDataBuf() { return data_; }

uint64_t GetBufLen() { return len_; }

private:
uint64_t readOffset_;
std::unique_ptr<char[]> data_;
char *data_;
uint64_t len_;
};

Expand Down Expand Up @@ -314,7 +309,7 @@ class FileCacheManager {
uint64_t fsId, uint64_t inodeId);
int ReadFromS3(const std::vector<S3ReadRequest> &requests,
std::vector<S3ReadResponse> *responses,
uint64_t fileLen);
char* dataBuf, uint64_t fileLen);
void PrefetchS3Objs(
const std::vector<std::pair<std::string, uint64_t>> &prefetchObjs);
void HandleReadRequest(const ReadRequest &request,
Expand Down

0 comments on commit fa1e288

Please sign in to comment.