lixmgl commented on code in PR #429:
URL: https://github.com/apache/yunikorn-core/pull/429#discussion_r962361186


##########
pkg/scheduler/objects/queue.go:
##########
@@ -1292,3 +1306,83 @@ 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) incAllocatingAcceptedAppsIfCanRun(sa *Application) bool {
+       if sq == nil {
+               return false
+       }
+       ok := true
+       if sq.parent != nil {
+               ok = sq.parent.incAllocatingAcceptedAppsIfCanRun(sa)
+       }
+       return sq.InternalIncAllocatingAcceptedAppsIfCanRun(ok, sa)
+}
+
+func (sq *Queue) InternalIncAllocatingAcceptedAppsIfCanRun(ok bool, sa 
*Application) bool {
+       sq.Lock()
+       defer sq.Unlock()
+       if sq.maxRunningApps == 0 {
+               return true && ok

Review Comment:
   updated



##########
pkg/scheduler/objects/application_state.go:
##########
@@ -143,6 +143,10 @@ func NewAppState() *fsm.FSM {
                        },
                        fmt.Sprintf("enter_%s", Starting.String()): func(event 
*fsm.Event) {
                                app := event.Args[0].(*Application) 
//nolint:errcheck
+                               app.queue.incRunningApps()
+                               app.queue.decAllocatingAcceptedApps(app)
+                               
metrics.GetQueueMetrics(app.queuePath).IncQueueApplicationsRunning()

Review Comment:
   good catch, removed the one in enter_Starting, kept the one in enter_Running



##########
pkg/scheduler/objects/queue.go:
##########
@@ -1292,3 +1306,83 @@ 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) incAllocatingAcceptedAppsIfCanRun(sa *Application) bool {
+       if sq == nil {
+               return false
+       }
+       ok := true
+       if sq.parent != nil {
+               ok = sq.parent.incAllocatingAcceptedAppsIfCanRun(sa)
+       }
+       return sq.InternalIncAllocatingAcceptedAppsIfCanRun(ok, sa)
+}
+
+func (sq *Queue) InternalIncAllocatingAcceptedAppsIfCanRun(ok bool, sa 
*Application) bool {
+       sq.Lock()
+       defer sq.Unlock()
+       if sq.maxRunningApps == 0 {
+               return true && ok
+       }
+       result := ok && (sq.runningApps+uint64(len(sq.allocatingAcceptedApps)) 
< sq.maxRunningApps)
+       if result {
+               _, contains := sq.allocatingAcceptedApps[sa.ApplicationID]

Review Comment:
   updated, using ok instead of contains



##########
pkg/scheduler/objects/utilities_test.go:
##########
@@ -49,11 +49,20 @@ func createManagedQueue(parentSQ *Queue, name string, 
parent bool, maxRes map[st
 
 // create managed queue with props set
 func createManagedQueueWithProps(parentSQ *Queue, name string, parent bool, 
maxRes, props map[string]string) (*Queue, error) {
+       return createManagedQueuePropsMaxApps(parentSQ, name, parent, maxRes, 
props, uint64(0))

Review Comment:
   same



##########
pkg/scheduler/objects/utilities_test.go:
##########
@@ -49,11 +49,20 @@ func createManagedQueue(parentSQ *Queue, name string, 
parent bool, maxRes map[st
 
 // create managed queue with props set
 func createManagedQueueWithProps(parentSQ *Queue, name string, parent bool, 
maxRes, props map[string]string) (*Queue, error) {
+       return createManagedQueuePropsMaxApps(parentSQ, name, parent, maxRes, 
props, uint64(0))

Review Comment:
   updated to int64



##########
pkg/scheduler/objects/application_state.go:
##########
@@ -143,6 +143,10 @@ func NewAppState() *fsm.FSM {
                        },
                        fmt.Sprintf("enter_%s", Starting.String()): func(event 
*fsm.Event) {
                                app := event.Args[0].(*Application) 
//nolint:errcheck
+                               app.queue.incRunningApps()
+                               app.queue.decAllocatingAcceptedApps(app)
+                               
metrics.GetQueueMetrics(app.queuePath).IncQueueApplicationsRunning()
+                               
metrics.GetSchedulerMetrics().IncTotalApplicationsRunning()

Review Comment:
   same



##########
pkg/scheduler/objects/queue.go:
##########
@@ -1292,3 +1306,83 @@ 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) incAllocatingAcceptedAppsIfCanRun(sa *Application) bool {
+       if sq == nil {
+               return false
+       }
+       ok := true
+       if sq.parent != nil {
+               ok = sq.parent.incAllocatingAcceptedAppsIfCanRun(sa)
+       }
+       return sq.InternalIncAllocatingAcceptedAppsIfCanRun(ok, sa)
+}
+
+func (sq *Queue) InternalIncAllocatingAcceptedAppsIfCanRun(ok bool, sa 
*Application) bool {

Review Comment:
   updated, using success instead of ok



##########
pkg/scheduler/objects/utilities_test.go:
##########
@@ -49,11 +49,20 @@ func createManagedQueue(parentSQ *Queue, name string, 
parent bool, maxRes map[st
 
 // create managed queue with props set
 func createManagedQueueWithProps(parentSQ *Queue, name string, parent bool, 
maxRes, props map[string]string) (*Queue, error) {
+       return createManagedQueuePropsMaxApps(parentSQ, name, parent, maxRes, 
props, uint64(0))

Review Comment:
   same



-- 
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]

Reply via email to