craigcondit commented on code in PR #429:
URL: https://github.com/apache/yunikorn-core/pull/429#discussion_r1026683207
##########
pkg/scheduler/objects/queue.go:
##########
@@ -1292,3 +1304,67 @@ func (sq *Queue) String() string {
return fmt.Sprintf("{QueuePath: %s, State: %s, StateTime: %x,
MaxResource: %s}",
sq.QueuePath, sq.stateMachine.Current(), sq.stateTime,
sq.maxResource)
}
+
+func (sq *Queue) incRunningApps() {
+ if sq == nil {
+ return
+ }
+ if sq.parent != nil {
+ sq.parent.incRunningApps()
+ }
+ sq.internalIncRunningApps()
+}
+
+func (sq *Queue) internalIncRunningApps() {
+ sq.Lock()
+ defer sq.Unlock()
+ sq.runningApps++
+}
+
+func (sq *Queue) decRunningApps() {
+ if sq == nil {
+ return
+ }
+ if sq.parent != nil {
+ sq.parent.decRunningApps()
+ }
+ sq.internalDecRunningApps()
+}
+
+func (sq *Queue) internalDecRunningApps() {
+ sq.Lock()
+ defer sq.Unlock()
+ sq.runningApps--
+}
+
+func (sq *Queue) canRun() bool {
+ if sq == nil {
+ return false
+ }
+ ok := true
+ if sq.parent != nil {
+ ok = sq.parent.canRun()
+ }
+ return sq.internalCanRun(ok)
+}
+
+func (sq *Queue) internalCanRun(ok bool) bool {
+ sq.RLock()
+ defer sq.RUnlock()
+ if sq.maxRunningApps == 0 {
+ return true && ok
+ }
+ return ok && sq.runningApps < sq.maxRunningApps
+}
Review Comment:
Wilfred is correct, this can be merged together. It can even be simplified
further:
```
func (sq *Queue) canRun() bool {
if sq == nil {
return false
}
// check the parent(s)
if sq.parent != nil && !sq.parent.canRun() {
return false
}
// check this queue only if all parents allowed it
sq.RLock()
defer sq.RUnlock()
if sq.maxRunningApps == 0 {
return true
}
return sq.runningApps < sq.maxRunningApps
}
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]