From c5ca38b112bd706c4684e80bb2c13273150714f5 Mon Sep 17 00:00:00 2001 From: kunlongli Date: Fri, 6 Dec 2024 11:39:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0blob=E5=BC=95=E7=94=A8=E6=95=B0=20#2825?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bkrepo/ddc/repository/BlobRefRepository.kt | 15 ++++++++++++++- .../com/tencent/bkrepo/ddc/service/BlobService.kt | 6 ++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/backend/ddc/biz-ddc/src/main/kotlin/com/tencent/bkrepo/ddc/repository/BlobRefRepository.kt b/src/backend/ddc/biz-ddc/src/main/kotlin/com/tencent/bkrepo/ddc/repository/BlobRefRepository.kt index 2b4e6808b0..9a21311458 100644 --- a/src/backend/ddc/biz-ddc/src/main/kotlin/com/tencent/bkrepo/ddc/repository/BlobRefRepository.kt +++ b/src/backend/ddc/biz-ddc/src/main/kotlin/com/tencent/bkrepo/ddc/repository/BlobRefRepository.kt @@ -11,7 +11,18 @@ import org.springframework.stereotype.Repository @Repository class BlobRefRepository : SimpleMongoDao() { - fun addRefToBlob(projectId: String, repoName: String, bucket: String, refKey: String, blobIds: Set) { + + /** + * 添加blob与ref关系,返回插入成功的blobId列表 + */ + fun addRefToBlob( + projectId: String, + repoName: String, + bucket: String, + refKey: String, + blobIds: Set + ): Set { + val addedBlobIds = HashSet() if (blobIds.size > DEFAULT_BLOB_SIZE_LIMIT) { val ref = "$projectId/$repoName/${buildRef(bucket, refKey)}" logger.error("blobs of ref[$ref] exceed size limit, size[${blobIds.size}]]") @@ -27,9 +38,11 @@ class BlobRefRepository : SimpleMongoDao() { ref = buildRef(bucket, refKey) ) ) + addedBlobIds.add(it) } catch (ignore: DuplicateKeyException) { } } + return addedBlobIds } fun removeRefFromBlob(projectId: String, repoName: String, bucket: String, refKey: String): List { diff --git a/src/backend/ddc/biz-ddc/src/main/kotlin/com/tencent/bkrepo/ddc/service/BlobService.kt b/src/backend/ddc/biz-ddc/src/main/kotlin/com/tencent/bkrepo/ddc/service/BlobService.kt index 111465478b..5ff2de0a0c 100644 --- a/src/backend/ddc/biz-ddc/src/main/kotlin/com/tencent/bkrepo/ddc/service/BlobService.kt +++ b/src/backend/ddc/biz-ddc/src/main/kotlin/com/tencent/bkrepo/ddc/service/BlobService.kt @@ -109,8 +109,10 @@ class BlobService( } fun addRefToBlobs(ref: Reference, blobIds: Set) { - blobRefRepository.addRefToBlob(ref.projectId, ref.repoName, ref.bucket, ref.key.toString(), blobIds) - blobRepository.incRefCount(ref.projectId, ref.repoName, blobIds) + with(ref) { + val addedBlobIds = blobRefRepository.addRefToBlob(projectId, repoName, bucket, key.toString(), blobIds) + blobRepository.incRefCount(projectId, repoName, addedBlobIds) + } } fun removeRefFromBlobs(projectId: String, repoName: String, bucket: String, key: String) {