Skip to content

Commit

Permalink
fix chunk request hash problem
Browse files Browse the repository at this point in the history
  • Loading branch information
xu-chaojie committed Nov 29, 2023
1 parent b436c94 commit f346c2b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/chunkserver/copyset_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ uint64_t CopysetNode::GetHashCode(const ChunkRequest* request) {
version = request->version();
}
if (version == curve::common::kBaseFileVersion) {
hashcode = std::hash<uint64_t>{} (request->fileid());
hashcode = std::hash<uint64_t>{} (request->chunkid());
} else {
// judge if has originfileId
if (request->has_originfileid()) {
Expand All @@ -298,7 +298,7 @@ uint64_t CopysetNode::GetHashCode(const ChunkRequest* request) {
break;

default:
hashcode = std::hash<uint64_t>{} (request->fileid());
hashcode = std::hash<uint64_t>{} (request->chunkid());
break;
}
// has no originfileId it is the origin file just use the fileid
Expand All @@ -314,7 +314,7 @@ uint64_t CopysetNode::GetHashCode(const ChunkRequest* request) {
break;

default:
hashcode = std::hash<uint64_t>{} (request->fileid());
hashcode = std::hash<uint64_t>{} (request->chunkid());
break;
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/chunkserver/op_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,15 @@ void DeleteChunkRequest::OnApply(uint64_t index,
void DeleteChunkRequest::OnApplyFromLog(std::shared_ptr<CSDataStore> datastore,
const ChunkRequest &request,
const butil::IOBuf &data) {
uint64_t originfiledid = request.originfileid();
uint64_t filedid = request.fileid();
VLOG(9) << "DeleteChunkRequest::OnApplyFromLog: "
<< " logic pool id: " << request.logicpoolid()
<< " copyset id: " << request.copysetid()
<< " chunkid: " << request.chunkid()
<< " originfileid: " << originfiledid
<< " fileid: " << filedid
<< " version: " << request.version();
// NOTE: 处理过程中优先使用参数传入的datastore/request
auto ret = datastore->DeleteChunk(request.chunkid(),
request.sn(),
Expand Down Expand Up @@ -650,6 +659,15 @@ void WriteChunkRequest::OnApply(uint64_t index,
void WriteChunkRequest::OnApplyFromLog(std::shared_ptr<CSDataStore> datastore,
const ChunkRequest &request,
const butil::IOBuf &data) {
uint64_t originfiledid = request.originfileid();
uint64_t filedid = request.fileid();
VLOG(9) << "WriteChunkRequest::OnApplyFromLog: "
<< " logic pool id: " << request.logicpoolid()
<< " copyset id: " << request.copysetid()
<< " chunkid: " << request.chunkid()
<< " originfileid: " << originfiledid
<< " fileid: " << filedid
<< " version: " << request.version();
// NOTE: 处理过程中优先使用参数传入的datastore/request
uint32_t cost;
std::string cloneSourceLocation;
Expand Down
4 changes: 2 additions & 2 deletions src/client/request_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ struct CURVE_CACHELINE_ALIGNMENT RequestContext {

FileType filetype_;
std::vector<CloneInfo> cloneChain_;
uint64_t originFileId_;
uint64_t chunkIndex_;
uint64_t originFileId_ = 0;
uint64_t chunkIndex_ = 0;

uint32_t version_;

Expand Down
5 changes: 4 additions & 1 deletion src/client/request_sender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,11 @@ int RequestSender::WriteChunk(RequestContext *ctx,
request.set_chunkindex(ctx->chunkIndex_);
request.set_version(ctx->version_);

if (ctx->filetype_ == FileType::INODE_CLONE_PAGEFILE) {
if (ctx->originFileId_ != 0) {
request.set_originfileid(ctx->originFileId_);
}

if (ctx->filetype_ == FileType::INODE_CLONE_PAGEFILE) {
for (int i = 0; i < ctx->cloneChain_.size(); i++) {
auto cinfo = request.add_clones();
cinfo->set_fileid(ctx->cloneChain_[i].fileId);
Expand Down
14 changes: 8 additions & 6 deletions src/client/splitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,10 @@ bool Splitor::AssignInternal(IOTracker* iotracker, MetaCache* metaCache,
ctx->sourceInfo_ =
CalcRequestSourceInfo(iotracker, metaCache, chunkidx);
}
if (fileInfo->filetype == FileType::INODE_CLONE_PAGEFILE) {
ret = AssignCloneFileInfo(
iotracker, &templist, mdsclient,
fileInfo, chunkidx, chunkIdInfo);
}

ret = AssignCloneFileInfo(
iotracker, &templist, mdsclient,
fileInfo, chunkidx, chunkIdInfo);

targetlist->insert(targetlist->end(), templist.begin(),
templist.end());
Expand Down Expand Up @@ -454,8 +453,11 @@ int Splitor::AssignCloneFileInfo(IOTracker* iotracker,
ChunkIndex chunkidx,
const ChunkIDInfo &chunkIdInfo) {
for (auto& ctx : *targetlist) {
// always take originFileId
ctx->originFileId_ = chunkIdInfo.originFileId_;
ctx->cloneChain_ = fileInfo->cloneChain;
if (fileInfo->filetype == FileType::INODE_CLONE_PAGEFILE) {
ctx->cloneChain_ = fileInfo->cloneChain;
}
}
return 0;
}
Expand Down

0 comments on commit f346c2b

Please sign in to comment.