Skip to content

Commit

Permalink
fix: opt pump cache, issue: TencentBlueKing#296
Browse files Browse the repository at this point in the history
  • Loading branch information
tbs60 committed Sep 11, 2024
1 parent cc405cf commit dbaeedb
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/backend/booster/bk_dist/common/sdk/toolchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (t *Toolchain) ToFileDesc() ([]FileDesc, error) {
// 将文件集合中涉及到目录的链接列出来,这种需要提前发送
getAllLinkDirs(&toolfiles)

blog.Infof("toolchain: get all files:%v", toolfiles)
blog.Infof("toolchain: get all files:%+v", toolfiles)

return toolfiles, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,12 @@ func (m *Mgr) ensureFilesWithPriority(
sandbox *dcSyscall.Sandbox,
fileDetails []*types.FilesDetails) ([]string, error) {

// 刷新优先级
freshPriority(fileDetails)
for _, v := range fileDetails {
blog.Debugf("remote: after fresh Priority, file:%+v", *v)
}

fileMap := make(map[dcSDK.FileDescPriority]*[]*types.FilesDetails)
posMap := make(map[dcSDK.FileDescPriority]*[]int)
var maxP dcSDK.FileDescPriority = 0
Expand Down
88 changes: 88 additions & 0 deletions src/backend/booster/bk_dist/controller/pkg/manager/remote/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/TencentBlueKing/bk-turbo/src/backend/booster/bk_dist/common/env"
dcProtocol "github.com/TencentBlueKing/bk-turbo/src/backend/booster/bk_dist/common/protocol"
"github.com/TencentBlueKing/bk-turbo/src/backend/booster/bk_dist/common/sdk"
dcSyscall "github.com/TencentBlueKing/bk-turbo/src/backend/booster/bk_dist/common/syscall"
"github.com/TencentBlueKing/bk-turbo/src/backend/booster/bk_dist/controller/pkg/types"
"github.com/TencentBlueKing/bk-turbo/src/backend/booster/common/blog"
Expand Down Expand Up @@ -145,3 +146,90 @@ func isCaredNetError(err error) bool {

return false
}

// calculateDependencies 计算依赖关系
func calculateDependencies(fileDetails []*types.FilesDetails) [][]int {
// 初始化依赖列表
dependencies := make([][]int, 0, len(fileDetails))
for range len(fileDetails) {
dependencies = append(dependencies, make([]int, 0, 0))
}

// 遍历字符串数组,计算依赖关系
for i, s1 := range fileDetails {
for j, s2 := range fileDetails {
if i != j && depend(s1, s2) {
dependencies[i] = append(dependencies[i], j)
}
}
}

return dependencies
}

// depend 检查 s1 是否依赖 s2
func depend(s1, s2 *types.FilesDetails) bool {
// 如果是s2是s1的子目录,则s1依赖s2
if len(s2.File.FilePath) < len(s1.File.FilePath) &&
strings.HasPrefix(s1.File.FilePath, s2.File.FilePath) {
return true
}

// 如果s1是链接,并且指向s2,则s1依赖s2
if s1.File.LinkTarget != "" && s1.File.LinkTarget == s2.File.FilePath {
return true
}

return false
}

func freshPriority(fileDetails []*types.FilesDetails) error {
for _, v := range fileDetails {
// 重置优先级为-1
v.File.Priority = -1
}

// 得到路径的依赖关系
dependencies := calculateDependencies(fileDetails)

// 计算权重
for {
allok := true
for i := range fileDetails {
if len(dependencies[i]) == 0 {
if fileDetails[i].File.Priority < 0 {
fileDetails[i].File.Priority = 0
}
} else {
maxPriority := -1
alldependok := true
for _, v := range dependencies[i] {
dependPriority := int(fileDetails[v].File.Priority)
if dependPriority >= 0 {
if dependPriority > maxPriority {
maxPriority = dependPriority
}
} else {
blog.Debugf("remote uitl: %s wait %s",
fileDetails[i].File.FilePath, fileDetails[v].File.FilePath)
alldependok = false
}
}
if alldependok {
dependencies[i] = nil
fileDetails[i].File.Priority = sdk.FileDescPriority(maxPriority + 1)
blog.Debugf("remote uitl: %s set Priority to %d",
fileDetails[i].File.FilePath, maxPriority+1)
} else {
allok = false
}
}
}

if allok {
break
}
}

return nil
}

0 comments on commit dbaeedb

Please sign in to comment.