Skip to content

Commit

Permalink
tidy code
Browse files Browse the repository at this point in the history
  • Loading branch information
wshwsh12 committed Aug 16, 2022
1 parent e0d7d76 commit 1e5af99
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions util/memory/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,15 @@ func (t *Tracker) Consume(bs int64) {
}
}

if bs > 0 && rootExceedForSoftLimit != nil {
tryAction(&rootExceedForSoftLimit.actionMuForSoftLimit, rootExceedForSoftLimit)
}
if bs > 0 && rootExceed != nil {
tryAction(&rootExceed.actionMuForHardLimit, rootExceed)
}
}

func tryAction(mu *actionMu, tracker *Tracker) {
actionOne := func(nowAction ActionOnExceed, tracker *Tracker) ActionOnExceed {
for nowAction != nil && nowAction.IsFinished() {
nowAction = nowAction.GetFallback()
Expand All @@ -380,23 +389,9 @@ func (t *Tracker) Consume(bs int64) {
}
return firstAction
}

tryAction := func(mu *actionMu, tracker *Tracker, actionAllAction bool) {
mu.Lock()
defer mu.Unlock()
if actionAllAction {
mu.actionOnExceed = actionAll(mu.actionOnExceed, tracker)
} else {
mu.actionOnExceed = actionOne(mu.actionOnExceed, tracker)
}
}

if bs > 0 && rootExceedForSoftLimit != nil {
tryAction(&rootExceedForSoftLimit.actionMuForSoftLimit, rootExceedForSoftLimit, true)
}
if bs > 0 && rootExceed != nil {
tryAction(&rootExceed.actionMuForHardLimit, rootExceed, false)
}
mu.Lock()
defer mu.Unlock()
mu.actionOnExceed = actionAll(mu.actionOnExceed, tracker)
}

// BufferedConsume is used to buffer memory usage and do late consume
Expand Down

0 comments on commit 1e5af99

Please sign in to comment.