Skip to content

Commit

Permalink
perf:蓝盾引擎模块对应的数据库支持分库 TencentBlueKing#5267
Browse files Browse the repository at this point in the history
  • Loading branch information
carlyin0801 committed Nov 4, 2021
1 parent 0fad037 commit 84424cf
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 365 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

package com.tencent.devops.misc.cron.process

import com.tencent.devops.common.api.util.JsonUtil
import com.tencent.devops.common.redis.RedisLock
import com.tencent.devops.common.redis.RedisOperation
import com.tencent.devops.misc.config.MiscBuildDataClearConfig
Expand Down Expand Up @@ -308,12 +307,6 @@ class PipelineBuildHistoryDataClearJob @Autowired constructor(
maxBuildNum = maxBuildNum.toInt()
)
}
// 同步构建时间晚于maxStartTime的记录的项目信息
syncBuildProjectData(
pipelineId = pipelineId,
projectId = projectId,
maxStartTime = projectDataClearConfig.maxStartTime
)
}

private fun cleanDeletePipelineData(pipelineId: String, projectId: String) {
Expand Down Expand Up @@ -358,73 +351,6 @@ class PipelineBuildHistoryDataClearJob @Autowired constructor(
qualityDataClearService.clearBuildData(buildId)
artifactoryDataClearService.clearBuildData(buildId)
processDataClearService.clearOtherBuildData(projectId, pipelineId, buildId)
} else {
// 分库路由需要同步T_PIPELINE_BUILD_DETAIL的项目信息(同步完后再删除该逻辑)
val buildDetail = processMiscService.getPipelineBuildDetailList(listOf(buildId))?.get(0)
if (buildDetail != null) {
processMiscService.updatePipelineBuildDetailProject(
buildId = buildId,
projectId = projectId,
model = JsonUtil.toJson(buildDetail.modelInfo, false)
)
}
}
}
totalHandleNum += DEFAULT_PAGE_SIZE
}
}

private fun syncBuildProjectData(
pipelineId: String,
projectId: String,
maxStartTime: LocalDateTime? = null
) {
// 同步项目信息
val pipelineResourceList = processMiscService.getPipelineResourceList(pipelineId)
pipelineResourceList?.forEach { pipelineResource ->
processMiscService.updatePipelineResourceProject(
pipelineId = pipelineId,
version = pipelineResource.version,
projectId = projectId,
model = JsonUtil.toJson(pipelineResource.modelInfo, false)
)
}
val pipelineResourceVersionList = processMiscService.getPipelineResourceVersionList(pipelineId)
pipelineResourceVersionList?.forEach { pipelineResourceVersion ->
processMiscService.updatePipelineResourceVersionProject(
pipelineId = pipelineId,
version = pipelineResourceVersion.version,
projectId = projectId,
model = JsonUtil.toJson(pipelineResourceVersion.modelInfo, false)
)
}
processMiscService.updateTemplatePipelineProject(pipelineId, projectId)
val totalBuildCount = processMiscService.getTotalBuildCount(
projectId = projectId,
pipelineId = pipelineId,
maxStartTime = maxStartTime,
geTimeFlag = true
)
var totalHandleNum = 0
while (totalHandleNum < totalBuildCount) {
val pipelineHistoryBuildIdList = processMiscService.getHistoryBuildIdList(
projectId = projectId,
pipelineId = pipelineId,
totalHandleNum = totalHandleNum,
handlePageSize = DEFAULT_PAGE_SIZE,
isCompletelyDelete = false,
maxStartTime = maxStartTime,
geTimeFlag = true
)
if (!pipelineHistoryBuildIdList.isNullOrEmpty()) {
// 分库路由需要同步T_PIPELINE_BUILD_DETAIL的项目信息(同步完后再删除该逻辑)
val buildDetailList = processMiscService.getPipelineBuildDetailList(pipelineHistoryBuildIdList)
buildDetailList?.forEach { buildDetail ->
processMiscService.updatePipelineBuildDetailProject(
buildId = buildDetail.buildId,
projectId = projectId,
model = JsonUtil.toJson(buildDetail.modelInfo, false)
)
}
}
totalHandleNum += DEFAULT_PAGE_SIZE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,11 @@

package com.tencent.devops.misc.dao.process

import com.tencent.devops.model.process.tables.TPipelineBuildDetail
import com.tencent.devops.model.process.tables.TPipelineBuildHisDataClear
import com.tencent.devops.model.process.tables.TPipelineBuildHistory
import com.tencent.devops.model.process.tables.TPipelineDataClear
import com.tencent.devops.model.process.tables.TPipelineInfo
import com.tencent.devops.model.process.tables.TPipelineResource
import com.tencent.devops.model.process.tables.TPipelineResourceVersion
import com.tencent.devops.model.process.tables.TTemplatePipeline
import com.tencent.devops.model.process.tables.records.TPipelineBuildDetailRecord
import com.tencent.devops.model.process.tables.records.TPipelineInfoRecord
import com.tencent.devops.model.process.tables.records.TPipelineResourceRecord
import com.tencent.devops.model.process.tables.records.TPipelineResourceVersionRecord
import org.jooq.Condition
import org.jooq.DSLContext
import org.jooq.Record
Expand Down Expand Up @@ -244,100 +237,4 @@ class ProcessDao {
.fetch()
}
}

fun getPipelineBuildDetailList(
dslContext: DSLContext,
buildIdList: List<String>
): Result<TPipelineBuildDetailRecord>? {
with(TPipelineBuildDetail.T_PIPELINE_BUILD_DETAIL) {
return dslContext.selectFrom(this)
.where(BUILD_ID.`in`(buildIdList))
.fetch()
}
}

fun updatePipelineBuildDetailProject(
dslContext: DSLContext,
buildId: String,
projectId: String,
model: String? = null
) {
with(TPipelineBuildDetail.T_PIPELINE_BUILD_DETAIL) {
val baseStep = dslContext.update(this)
if (!model.isNullOrBlank()) {
baseStep.set(MODEL, model)
}
baseStep.set(PROJECT_ID, projectId).where(BUILD_ID.eq(buildId)).execute()
}
}

fun getPipelineResourceList(
dslContext: DSLContext,
pipelineId: String
): Result<TPipelineResourceRecord>? {
with(TPipelineResource.T_PIPELINE_RESOURCE) {
return dslContext.selectFrom(this)
.where(PIPELINE_ID.eq(pipelineId))
.fetch()
}
}

fun updatePipelineResourceProject(
dslContext: DSLContext,
pipelineId: String,
version: Int,
projectId: String,
model: String? = null
) {
with(TPipelineResource.T_PIPELINE_RESOURCE) {
val baseStep = dslContext.update(this)
if (!model.isNullOrBlank()) {
baseStep.set(MODEL, model)
}
baseStep.set(PROJECT_ID, projectId)
.where(PIPELINE_ID.eq(pipelineId).and(VERSION.eq(version)))
.execute()
}
}

fun getPipelineResourceVersionList(
dslContext: DSLContext,
pipelineId: String
): Result<TPipelineResourceVersionRecord>? {
with(TPipelineResourceVersion.T_PIPELINE_RESOURCE_VERSION) {
return dslContext.selectFrom(this)
.where(PIPELINE_ID.eq(pipelineId))
.fetch()
}
}

fun updatePipelineResourceVersionProject(
dslContext: DSLContext,
pipelineId: String,
version: Int,
projectId: String,
model: String? = null
) {
with(TPipelineResourceVersion.T_PIPELINE_RESOURCE_VERSION) {
val baseStep = dslContext.update(this)
if (!model.isNullOrBlank()) {
baseStep.set(MODEL, model)
}
baseStep.set(PROJECT_ID, projectId)
.where(PIPELINE_ID.eq(pipelineId).and(VERSION.eq(version)))
.execute()
}
}

fun updateTemplatePipelineProject(
dslContext: DSLContext,
pipelineId: String,
projectId: String
) {
with(TTemplatePipeline.T_TEMPLATE_PIPELINE) {
dslContext.update(this).set(PROJECT_ID, projectId)
.where(PIPELINE_ID.eq(pipelineId))
.execute()
}
}
}
Loading

0 comments on commit 84424cf

Please sign in to comment.