-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 修复ddc_blob references字段过大导致慢查询问题 #2181
- Loading branch information
Showing
8 changed files
with
137 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/backend/ddc/biz-ddc/src/main/kotlin/com/tencent/bkrepo/ddc/model/TDdcBlobRef.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.tencent.bkrepo.ddc.model | ||
|
||
import org.springframework.data.mongodb.core.index.CompoundIndex | ||
import org.springframework.data.mongodb.core.index.CompoundIndexes | ||
import org.springframework.data.mongodb.core.mapping.Document | ||
|
||
|
||
@Document("ddc_blob_ref") | ||
@CompoundIndexes( | ||
CompoundIndex( | ||
name = "projectId_repoName_blobId_ref_idx", | ||
def = "{'projectId': 1, 'repoName': 1, 'blobId': 1, 'ref': 1}", | ||
unique = true, | ||
background = true | ||
), | ||
CompoundIndex( | ||
name = "projectId_repoName_ref_blobId_idx", | ||
def = "{'projectId': 1, 'repoName': 1, 'ref': 1, 'blobId': 1}", | ||
unique = true, | ||
background = true | ||
), | ||
) | ||
data class TDdcBlobRef( | ||
var id: String? = null, | ||
var projectId: String, | ||
var repoName: String, | ||
/** | ||
* blob blake3 hash | ||
*/ | ||
var blobId: String, | ||
/** | ||
* 引用了该blob的ref或blob,ref的inline blob中直接或间接引用的所有blob都会关联到ref | ||
* ref类型引用 ref/{bucket}/{key} | ||
* blob类型引用 blob/{blobId} | ||
*/ | ||
var ref: String, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...ackend/ddc/biz-ddc/src/main/kotlin/com/tencent/bkrepo/ddc/repository/BlobRefRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.tencent.bkrepo.ddc.repository | ||
|
||
import com.tencent.bkrepo.common.mongo.dao.simple.SimpleMongoDao | ||
import com.tencent.bkrepo.ddc.model.TDdcBlobRef | ||
import org.springframework.dao.DuplicateKeyException | ||
import org.springframework.data.mongodb.core.query.Criteria | ||
import org.springframework.data.mongodb.core.query.Query | ||
import org.springframework.data.mongodb.core.query.isEqualTo | ||
import org.springframework.stereotype.Repository | ||
|
||
@Repository | ||
class BlobRefRepository : SimpleMongoDao<TDdcBlobRef>() { | ||
fun addRefToBlob(projectId: String, repoName: String, bucket: String, refKey: String, blobIds: Set<String>) { | ||
blobIds.forEach { | ||
try { | ||
insert( | ||
TDdcBlobRef( | ||
id = null, | ||
projectId = projectId, | ||
repoName = repoName, | ||
blobId = it, | ||
ref = buildRef(bucket, refKey) | ||
) | ||
) | ||
} catch (ignore: DuplicateKeyException) { | ||
} | ||
} | ||
} | ||
|
||
fun removeRefFromBlob(projectId: String, repoName: String, bucket: String, refKey: String): List<TDdcBlobRef> { | ||
val criteria = Criteria | ||
.where(TDdcBlobRef::projectId.name).isEqualTo(projectId) | ||
.and(TDdcBlobRef::repoName.name).isEqualTo(repoName) | ||
.and(TDdcBlobRef::ref.name).isEqualTo(buildRef(bucket, refKey)) | ||
return determineMongoTemplate().findAllAndRemove(Query(criteria), TDdcBlobRef::class.java) | ||
} | ||
|
||
private fun buildRef(bucket: String, key: String): String = "ref/$bucket/$key" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters