Skip to content

Commit

Permalink
fix: 优化一下细节问题 #2813
Browse files Browse the repository at this point in the history
  • Loading branch information
zzdjx committed Jan 13, 2025
1 parent ce19623 commit e4735c0
Showing 1 changed file with 21 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,27 @@ class UploadService(

fun completeSeparateBlockUpload(userId: String, uploadId: String, artifactInfo: GenericArtifactInfo) {

// 获取并按起始位置排序块信息列表
val blockInfoList = blockNodeService.listBlocksInUploadId(
artifactInfo.projectId,
artifactInfo.repoName,
artifactInfo.getArtifactFullPath(),
uploadId = uploadId
)

blockInfoList.ifEmpty {
logger.warn("No block information found for uploadId: $uploadId")
throw ErrorCodeException(GenericMessageCode.BLOCK_UPDATE_LIST_IS_NULL, artifactInfo)
}

// 计算所有块的总大小
val totalSize = blockInfoList.sumOf { it.size }

// 验证节点大小是否与块总大小一致
if (getLongHeader(HEADER_FILE_SIZE) != totalSize) {
throw ErrorCodeException(GenericMessageCode.NODE_DATA_ERROR, artifactInfo)
}

// 创建新的基础节点(Base Node)
try {
blockBaseNodeCreate(userId, artifactInfo, uploadId)
Expand All @@ -275,25 +296,6 @@ class UploadService(
artifactInfo.getArtifactFullPath()
)

// 获取节点信息(不再进行节点存在性检查)
val node = ArtifactContextHolder.getNodeDetail(artifactInfo)

// 获取并按起始位置排序块信息列表
val blockInfoList = blockNodeService.listBlocksInUploadId(
node!!.projectId,
node.repoName,
node.fullPath,
uploadId = uploadId
)

blockInfoList.ifEmpty {
logger.warn("No block information found for uploadId: $uploadId")
throw ErrorCodeException(GenericMessageCode.BLOCK_UPDATE_LIST_IS_NULL, artifactInfo)
}

// 计算所有块的总大小
val totalSize = blockInfoList.sumOf { it.size }

// 更新节点版本信息为null
blockNodeService.updateBlockUploadId(
artifactInfo.projectId,
Expand All @@ -302,11 +304,6 @@ class UploadService(
uploadId
)

// 验证节点大小是否与块总大小一致
if (node.size != totalSize) {
throw ErrorCodeException(GenericMessageCode.NODE_DATA_ERROR, artifactInfo)
}

// 上传完成,记录日志
logger.info(
"User [$userId] successfully completed block upload [uploadId: $uploadId], " +
Expand Down

0 comments on commit e4735c0

Please sign in to comment.