From f7ebf6c67bc4a6fc753878c214a6220a12d0a6bc Mon Sep 17 00:00:00 2001 From: kunlongli <16629885+cnlkl@users.noreply.github.com> Date: Mon, 20 May 2024 14:30:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=B0=83=E6=95=B4=E7=94=9F=E6=88=90?= =?UTF-8?q?=E9=A2=84=E5=8A=A0=E8=BD=BD=E7=AD=96=E7=95=A5=E6=97=B6node?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E8=B6=85=E8=BF=87=E9=99=90=E5=88=B6=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E6=97=A5=E5=BF=97=E7=BA=A7=E5=88=AB=EF=BC=8C=E5=8F=96?= =?UTF-8?q?=E6=B6=88lastModifiedDate=E5=94=AF=E4=B8=80=E7=B4=A2=E5=BC=95?= =?UTF-8?q?=E9=99=90=E5=88=B6=20#2153?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 调整生成预加载策略时node数量超过限制错误日志级别 #2153 * feat: 调整生成预加载策略时node数量超过限制错误日志级别 #2153 * feat: 移除制品访问记录lastModifiedDate索引唯一限制 #2153 --- .../common/artifact/cache/model/TArtifactAccessRecord.kt | 2 +- .../cache/service/impl/ArtifactPreloadPlanServiceImpl.kt | 9 ++++++--- .../service/impl/ArtifactPreloadPlanServiceImplTest.kt | 5 +++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/backend/common/common-artifact/artifact-cache/src/main/kotlin/com/tencent/bkrepo/common/artifact/cache/model/TArtifactAccessRecord.kt b/src/backend/common/common-artifact/artifact-cache/src/main/kotlin/com/tencent/bkrepo/common/artifact/cache/model/TArtifactAccessRecord.kt index 08027be0a4..9b6325d5cc 100644 --- a/src/backend/common/common-artifact/artifact-cache/src/main/kotlin/com/tencent/bkrepo/common/artifact/cache/model/TArtifactAccessRecord.kt +++ b/src/backend/common/common-artifact/artifact-cache/src/main/kotlin/com/tencent/bkrepo/common/artifact/cache/model/TArtifactAccessRecord.kt @@ -43,7 +43,7 @@ import java.time.LocalDateTime unique = true, background = true ), - CompoundIndex(name = "lastModifiedDate_idx", def = "{'lastModifiedDate': 1}", unique = true, background = true) + CompoundIndex(name = "lastModifiedDate_idx", def = "{'lastModifiedDate': 1}", background = true) ) data class TArtifactAccessRecord( val id: String? = null, diff --git a/src/backend/common/common-artifact/artifact-cache/src/main/kotlin/com/tencent/bkrepo/common/artifact/cache/service/impl/ArtifactPreloadPlanServiceImpl.kt b/src/backend/common/common-artifact/artifact-cache/src/main/kotlin/com/tencent/bkrepo/common/artifact/cache/service/impl/ArtifactPreloadPlanServiceImpl.kt index 5677e8ae86..1bdaae8e01 100644 --- a/src/backend/common/common-artifact/artifact-cache/src/main/kotlin/com/tencent/bkrepo/common/artifact/cache/service/impl/ArtifactPreloadPlanServiceImpl.kt +++ b/src/backend/common/common-artifact/artifact-cache/src/main/kotlin/com/tencent/bkrepo/common/artifact/cache/service/impl/ArtifactPreloadPlanServiceImpl.kt @@ -81,7 +81,8 @@ class ArtifactPreloadPlanServiceImpl( val nodes = res.data?.records ?: return if (nodes.size >= MAX_PAGE_SIZE) { // 限制查询出来的最大node数量,避免预加载计划创建时间过久 - throw RuntimeException("exceed max page size[$MAX_PAGE_SIZE]") + logger.warn("nodes of sha256[$sha256] exceed max page size[$MAX_PAGE_SIZE]") + return } // node属于同一项目仓库的概率较大,缓存避免频繁查询策略 val strategyCache = HashMap>() @@ -145,8 +146,10 @@ class ArtifactPreloadPlanServiceImpl( val pathNotMatch = !strategy.fullPathRegex.toRegex().matches(node.fullPath) val createTimeNotMatch = Duration.between(createdDateTime, now).seconds > strategy.recentSeconds if (sizeNotMatch || pathNotMatch || createTimeNotMatch) { - logger.info("${node.projectId}/${node.repoName}${node.fullPath} not match preload strategy, " + - "node size[${node.size}], node createdDateTime[$createdDateTime]") + logger.info( + "${node.projectId}/${node.repoName}${node.fullPath} not match preload strategy, " + + "node size[${node.size}], node createdDateTime[$createdDateTime]" + ) return null } diff --git a/src/backend/common/common-artifact/artifact-cache/src/test/kotlin/com/tencent/bkrepo/common/artifact/cache/service/impl/ArtifactPreloadPlanServiceImplTest.kt b/src/backend/common/common-artifact/artifact-cache/src/test/kotlin/com/tencent/bkrepo/common/artifact/cache/service/impl/ArtifactPreloadPlanServiceImplTest.kt index 3937d41072..fc57912c67 100644 --- a/src/backend/common/common-artifact/artifact-cache/src/test/kotlin/com/tencent/bkrepo/common/artifact/cache/service/impl/ArtifactPreloadPlanServiceImplTest.kt +++ b/src/backend/common/common-artifact/artifact-cache/src/test/kotlin/com/tencent/bkrepo/common/artifact/cache/service/impl/ArtifactPreloadPlanServiceImplTest.kt @@ -53,7 +53,6 @@ import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertThrows import org.mockito.ArgumentMatchers.anyString import org.mockito.kotlin.any import org.mockito.kotlin.whenever @@ -165,7 +164,9 @@ class ArtifactPreloadPlanServiceImplTest @Autowired constructor( Pages.ofResponse(Pages.ofRequest(0, 2000), nodes.size.toLong(), nodes) ) ) - assertThrows { preloadPlanService.generatePlan(null, UT_SHA256) } + preloadPlanService.generatePlan(null, UT_SHA256) + val plans = preloadPlanService.plans(UT_PROJECT_ID, UT_REPO_NAME, Pages.ofRequest(0, 10)).records + assertEquals(0, plans.size) } @Test