Skip to content

Commit

Permalink
fix: stream接口上传小文件,文件内容错误 TencentBlueKing#2835
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoxuwan committed Dec 9, 2024
1 parent f22d686 commit 45e4f65
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ class RouteConfiguration(
}

"/stream".nest{
filter(artifactFileCleanupFilterFunction::filter)
PUT(DEFAULT_MAPPING_URI, fileOperationsHandler::stream)
addMetrics(serverMetrics.uploadingCount)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class ArtifactFileCleanupFilterFunction : CoHandlerFilterFunction {
try {
return next(request)
} finally {
logger.info("start clean up")
cleanup(request)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import com.tencent.bkrepo.repository.pojo.node.service.NodeCreateRequest
import com.tencent.bkrepo.repository.pojo.node.service.NodeSetLengthRequest
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.onCompletion
import org.slf4j.LoggerFactory
import org.springframework.core.io.buffer.DataBuffer
import org.springframework.core.io.buffer.DataBufferUtils
import org.springframework.web.reactive.function.server.bodyToFlow
Expand Down Expand Up @@ -98,6 +99,7 @@ class FileOperationService(
var reactiveArtifactFile = CoArtifactFileFactory.buildArtifactFile()
val offset = AtomicLong(0)
streamRequest.request.bodyToFlow<DataBuffer>().onCompletion {
logger.info("size: ${reactiveArtifactFile.getSize()}")
if (reactiveArtifactFile.getSize() > 0) {
storeBlockNode(reactiveArtifactFile, offset, user, streamRequest, true)
reactiveArtifactFile.close()
Expand Down Expand Up @@ -138,6 +140,9 @@ class FileOperationService(
size = reactiveArtifactFile.getSize()
)
storageManager.storeBlock(reactiveArtifactFile, blockNode)
if (!reactiveArtifactFile.isInMemory()) {
reactiveArtifactFile.getFile()?.deleteOnExit()
}
offset.addAndGet(blockSize)
true
} else {
Expand Down Expand Up @@ -209,4 +214,8 @@ class FileOperationService(
nodeMetadata = listOf(fsAttr)
)
}

companion object {
private val logger = LoggerFactory.getLogger(FileOperationService::class.java)
}
}

0 comments on commit 45e4f65

Please sign in to comment.