Skip to content

Commit

Permalink
Merge pull request #5920 from tming/master
Browse files Browse the repository at this point in the history
bug: bk-ubt-tool在错误处理时,和ue原始逻辑有差异
  • Loading branch information
tming authored Jan 5, 2022
2 parents e9fc127 + 8ab4804 commit 6c7073c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 24 deletions.
5 changes: 5 additions & 0 deletions src/backend/booster/bk_dist/booster/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const (
FlagLocalRecord = "local_record"
FlagWriteMemroMemroy = "write_memory"
FlagIdleKeepSecs = "idle_keep_secs"
FlagResourceTimeoutSecs = "resource_timeout_secs"

EnvBuildIDOld = "TURBO_PLAN_BUILD_ID"
EnvBuildID = "TBS_BUILD_ID"
Expand Down Expand Up @@ -316,6 +317,10 @@ var (
Name: "idle_keep_secs",
Usage: "max wait seconds before release idle resource",
},
commandCli.IntFlag{
Name: "resource_timeout_secs",
Usage: "max seconds while waiting for apply resource",
},
}
)

Expand Down
7 changes: 6 additions & 1 deletion src/backend/booster/bk_dist/booster/command/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ func newBooster(c *commandCli.Context) (*pkg.Booster, error) {
remaintime = c.Int(FlagControllerRemainTime)
}

waitResourceSeconds := 60
if c.IsSet(FlagResourceTimeoutSecs) {
waitResourceSeconds = c.Int(FlagResourceTimeoutSecs)
}

// generate a new booster.
cmdConfig := dcType.BoosterConfig{
Type: dcType.GetBoosterType(bt),
Expand Down Expand Up @@ -261,7 +266,7 @@ func newBooster(c *commandCli.Context) (*pkg.Booster, error) {
Timeout: 5 * time.Second,
HeartBeatTick: 5 * time.Second,
InspectTaskTick: 100 * time.Millisecond,
TaskPreparingTimeout: 60 * time.Second,
TaskPreparingTimeout: time.Duration(waitResourceSeconds) * time.Second,
PrintTaskInfoEveryTime: 5,
CommitSuicideCheckTick: 5 * time.Second,
},
Expand Down
9 changes: 5 additions & 4 deletions src/backend/booster/bk_dist/ubttool/command/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@ func setLogLevel(level string) {

func initialLogDir(dir string) {
blog.InitLogs(conf.LogConfig{
LogDir: dir,
LogMaxNum: 10,
LogMaxSize: 500,
AlsoToStdErr: false,
LogDir: dir,
LogMaxNum: 10,
LogMaxSize: 500,
AlsoToStdErr: false,
StdErrThreshold: "3", //fatalLog
})
}

Expand Down
1 change: 1 addition & 0 deletions src/backend/booster/bk_dist/ubttool/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Actionresult struct {
Succeed bool
Outputmsg string
Errormsg string
Exitcode int
}

func uniqueAndCheck(strlist []string, allindex map[string]bool) []string {
Expand Down
44 changes: 25 additions & 19 deletions src/backend/booster/bk_dist/ubttool/pkg/ubttool.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (h *UBTTool) executeActions() error {
select {
case r := <-h.actionchan:
blog.Infof("UBTTool: got action result:%+v", r)
h.onActionFinished(r.Index)
h.onActionFinished(r.Index, r.Exitcode)
if h.finished {
blog.Infof("UBTTool: all actions finished")
return nil
Expand Down Expand Up @@ -242,14 +242,15 @@ func (h *UBTTool) executeOneAction(action common.Action, actionchan chan common.
fullargs := []string{action.Cmd}
args, _ := shlex.Split(replaceWithNextExclude(action.Arg, '\\', "\\\\", []byte{'"'}))
fullargs = append(fullargs, args...)
_, err := h.executor.Run(fullargs, action.Workdir)
exitcode, err := h.executor.Run(fullargs, action.Workdir)

r := common.Actionresult{
Index: action.Index,
Finished: true,
Succeed: err == nil,
Outputmsg: "",
Errormsg: "",
Exitcode: exitcode,
}

actionchan <- r
Expand Down Expand Up @@ -279,8 +280,8 @@ func (h *UBTTool) getReadyActions() error {
}

// update all actions and ready actions
func (h *UBTTool) onActionFinished(index string) error {
blog.Infof("UBTTool: action %s finished", index)
func (h *UBTTool) onActionFinished(index string, exitcode int) error {
blog.Infof("UBTTool: action %s finished with exitcode %d", index, exitcode)

h.finishednumberlock.Lock()
h.finishednumber++
Expand Down Expand Up @@ -309,30 +310,35 @@ func (h *UBTTool) onActionFinished(index string) error {
}
}

// update all action array
// update status in allactions
for i, v := range h.allactions {
// update status
if v.Index == index {
h.allactions[i].Finished = true
continue
break
}
}

if v.Finished {
continue
}
// update depend in allactions if current action succeed
if exitcode == 0 {
for i, v := range h.allactions {
if v.Finished {
continue
}

// update depend
for i1, v1 := range v.Dep {
if v1 == index {
h.allactions[i].Dep = remove(h.allactions[i].Dep, i1)
break
// update depend
for i1, v1 := range v.Dep {
if v1 == index {
h.allactions[i].Dep = remove(h.allactions[i].Dep, i1)
break
}
}
}

// copy to ready if no depent
if !v.Running && !v.Finished && len(h.allactions[i].Dep) == 0 {
h.readyactions = append(h.readyactions, v)
h.allactions[i].Running = true
// copy to ready if no depent
if !v.Running && !v.Finished && len(h.allactions[i].Dep) == 0 {
h.readyactions = append(h.readyactions, v)
h.allactions[i].Running = true
}
}
}

Expand Down

0 comments on commit 6c7073c

Please sign in to comment.