wilfred-s commented on code in PR #668:
URL: https://github.com/apache/yunikorn-core/pull/668#discussion_r1379644106


##########
pkg/scheduler/ugm/manager.go:
##########
@@ -365,127 +381,159 @@ func (m *Manager) internalProcessConfig(cur 
configs.QueueConfig, queuePath strin
                                zap.String("queue path", queuePath),
                                zap.Uint64("max application", 
limit.MaxApplications),
                                zap.Any("max resources", limit.MaxResources))
-                       if err := m.processGroupConfig(group, limitConfig, 
queuePath, groupLimits); err != nil {
+                       if err := m.setGroupLimits(group, limitConfig, 
queuePath); err != nil {
                                return err
                        }
+                       if _, ok := newGroupLimits[queuePath]; !ok {
+                               newGroupLimits[queuePath] = 
make(map[string]*LimitConfig)
+                       }
+                       newGroupLimits[queuePath][group] = limitConfig
                        if group == common.Wildcard {
-                               m.groupWildCardLimitsConfig[queuePath] = 
limitConfig
+                               newGroupWildCardLimitsConfig[queuePath] = 
limitConfig
                        } else {
-                               m.configuredGroups[queuePath] = 
append(m.configuredGroups[queuePath], group)
+                               newConfiguredGroups[queuePath] = 
append(newConfiguredGroups[queuePath], group)
                        }
                }
        }
-       if err := m.clearEarlierSetLimits(userLimits, groupLimits, queuePath); 
err != nil {
-               return err
-       }
-
        if len(cur.Queues) > 0 {
                for _, child := range cur.Queues {
                        childQueuePath := queuePath + configs.DOT + child.Name
-                       if err := m.internalProcessConfig(child, 
childQueuePath); err != nil {
+                       if err := m.internalProcessConfig(child, 
childQueuePath, newUserLimits, newGroupLimits, newUserWildCardLimitsConfig, 
newGroupWildCardLimitsConfig, newConfiguredGroups); err != nil {
                                return err
                        }
                }
        }
        return nil
 }
 
-func (m *Manager) processUserConfig(user string, limitConfig *LimitConfig, 
queuePath string, userLimits map[string]bool) error {
-       if err := m.setUserLimits(user, limitConfig, queuePath); err != nil {
-               return err
-       }
-       userLimits[user] = true
-       return nil
-}
+// clearEarlierSetLimits Clear already configured limits of users and groups 
for which limits have been configured before but not now
+func (m *Manager) clearEarlierSetLimits(newUserLimits 
map[string]map[string]*LimitConfig, newGroupLimits 
map[string]map[string]*LimitConfig) {
+       // Clear already configured limits of group for which limits have been 
configured before but not now
+       m.clearEarlierSetGroupLimits(newGroupLimits)
 
-func (m *Manager) processGroupConfig(group string, limitConfig *LimitConfig, 
queuePath string, groupLimits map[string]bool) error {
-       if err := m.setGroupLimits(group, limitConfig, queuePath); err != nil {
-               return err
-       }
-       groupLimits[group] = true
-       return nil
+       // Clear already configured limits of user for which limits have been 
configured before but not now
+       m.clearEarlierSetUserLimits(newUserLimits)
 }
 
-// clearEarlierSetLimits Clear already configured limits of users and groups 
for which limits have been configured before but not now
-func (m *Manager) clearEarlierSetLimits(userLimits map[string]bool, 
groupLimits map[string]bool, queuePath string) error {
-       // Clear already configured limits of group for which limits have been 
configured before but not now
-       for _, gt := range m.groupTrackers {
-               appUsersMap := m.clearEarlierSetGroupLimits(gt, queuePath, 
groupLimits)
-               if len(appUsersMap) > 0 {
-                       for app, user := range appUsersMap {
-                               ut := m.userTrackers[user]
-                               ut.setGroupForApp(app, nil)
+func (m *Manager) clearEarlierSetUserLimits(newUserLimits 
map[string]map[string]*LimitConfig) {

Review Comment:
   keep the comment



##########
pkg/scheduler/ugm/manager.go:
##########
@@ -318,13 +320,30 @@ func (m *Manager) UpdateConfig(config 
configs.QueueConfig, queuePath string) err
        m.userWildCardLimitsConfig = make(map[string]*LimitConfig)
        m.groupWildCardLimitsConfig = make(map[string]*LimitConfig)
        m.configuredGroups = make(map[string][]string)
-       return m.internalProcessConfig(config, queuePath)
+
+       // deep copy of the existing user and group limits
+       earlierUserLimits := make(map[string]map[string]bool)
+       earlierGroupLimits := make(map[string]map[string]bool)
+       for k, v := range m.userLimits {
+               if _, ok := earlierUserLimits[k]; !ok {
+                       earlierUserLimits[k] = make(map[string]bool)
+               }
+               earlierUserLimits[k] = v
+       }
+       for k, v := range m.groupLimits {
+               if _, ok := earlierGroupLimits[k]; !ok {
+                       earlierGroupLimits[k] = make(map[string]bool)
+               }
+               earlierGroupLimits[k] = v
+       }

Review Comment:
   No deep copy needed just an assign like this:
   ```
   earlierUserLimits := m.userLimits
   m.userLimits = make(map[string]map[string]bool)
   ```



##########
pkg/scheduler/ugm/manager.go:
##########
@@ -365,127 +381,159 @@ func (m *Manager) internalProcessConfig(cur 
configs.QueueConfig, queuePath strin
                                zap.String("queue path", queuePath),
                                zap.Uint64("max application", 
limit.MaxApplications),
                                zap.Any("max resources", limit.MaxResources))
-                       if err := m.processGroupConfig(group, limitConfig, 
queuePath, groupLimits); err != nil {
+                       if err := m.setGroupLimits(group, limitConfig, 
queuePath); err != nil {
                                return err
                        }
+                       if _, ok := newGroupLimits[queuePath]; !ok {
+                               newGroupLimits[queuePath] = 
make(map[string]*LimitConfig)
+                       }
+                       newGroupLimits[queuePath][group] = limitConfig
                        if group == common.Wildcard {
-                               m.groupWildCardLimitsConfig[queuePath] = 
limitConfig
+                               newGroupWildCardLimitsConfig[queuePath] = 
limitConfig
                        } else {
-                               m.configuredGroups[queuePath] = 
append(m.configuredGroups[queuePath], group)
+                               newConfiguredGroups[queuePath] = 
append(newConfiguredGroups[queuePath], group)
                        }
                }
        }
-       if err := m.clearEarlierSetLimits(userLimits, groupLimits, queuePath); 
err != nil {
-               return err
-       }
-
        if len(cur.Queues) > 0 {
                for _, child := range cur.Queues {
                        childQueuePath := queuePath + configs.DOT + child.Name
-                       if err := m.internalProcessConfig(child, 
childQueuePath); err != nil {
+                       if err := m.internalProcessConfig(child, 
childQueuePath, newUserLimits, newGroupLimits, newUserWildCardLimitsConfig, 
newGroupWildCardLimitsConfig, newConfiguredGroups); err != nil {
                                return err
                        }
                }
        }
        return nil
 }
 
-func (m *Manager) processUserConfig(user string, limitConfig *LimitConfig, 
queuePath string, userLimits map[string]bool) error {
-       if err := m.setUserLimits(user, limitConfig, queuePath); err != nil {
-               return err
-       }
-       userLimits[user] = true
-       return nil
-}
+// clearEarlierSetLimits Clear already configured limits of users and groups 
for which limits have been configured before but not now
+func (m *Manager) clearEarlierSetLimits(newUserLimits 
map[string]map[string]*LimitConfig, newGroupLimits 
map[string]map[string]*LimitConfig) {
+       // Clear already configured limits of group for which limits have been 
configured before but not now
+       m.clearEarlierSetGroupLimits(newGroupLimits)
 
-func (m *Manager) processGroupConfig(group string, limitConfig *LimitConfig, 
queuePath string, groupLimits map[string]bool) error {
-       if err := m.setGroupLimits(group, limitConfig, queuePath); err != nil {
-               return err
-       }
-       groupLimits[group] = true
-       return nil
+       // Clear already configured limits of user for which limits have been 
configured before but not now
+       m.clearEarlierSetUserLimits(newUserLimits)
 }
 
-// clearEarlierSetLimits Clear already configured limits of users and groups 
for which limits have been configured before but not now
-func (m *Manager) clearEarlierSetLimits(userLimits map[string]bool, 
groupLimits map[string]bool, queuePath string) error {
-       // Clear already configured limits of group for which limits have been 
configured before but not now
-       for _, gt := range m.groupTrackers {
-               appUsersMap := m.clearEarlierSetGroupLimits(gt, queuePath, 
groupLimits)
-               if len(appUsersMap) > 0 {
-                       for app, user := range appUsersMap {
-                               ut := m.userTrackers[user]
-                               ut.setGroupForApp(app, nil)
+func (m *Manager) clearEarlierSetUserLimits(newUserLimits 
map[string]map[string]*LimitConfig) {
+       if len(m.userLimits) == 0 {
+               return
+       }
+       m.RLock()
+       defer m.RUnlock()
+       // Need to clear user config only when
+       // 1. config set earlier but not now
+       // 2. user already tracked for the queue path
+       for queuePath, limitConfig := range m.userLimits {
+               // Is queue path exists?
+               if newUserLimit, ok := newUserLimits[queuePath]; !ok {
+                       for u := range limitConfig {
+                               if ut, utExists := m.userTrackers[u]; utExists {
+                                       m.clearEarlierSetUserLimit(ut, 
queuePath)
+                               }
+                       }
+               } else {
+                       // Queue path exists. Is user exists?
+                       for u := range limitConfig {
+                               if _, ulExists := newUserLimit[u]; !ulExists {
+                                       if ut, utExists := m.userTrackers[u]; 
utExists {
+                                               m.clearEarlierSetUserLimit(ut, 
queuePath)
+                                       }
+                               }
                        }
                }
        }
-
-       // Clear already configured limits of user for which limits have been 
configured before but not now
-       for _, ut := range m.userTrackers {
-               m.clearEarlierSetUserLimits(ut, queuePath, userLimits)
-       }
-       return nil
 }
 
-func (m *Manager) clearEarlierSetUserLimits(ut *UserTracker, queuePath string, 
userLimits map[string]bool) {
+func (m *Manager) clearEarlierSetUserLimit(ut *UserTracker, queuePath string) {

Review Comment:
   This really removes, while the previous function does the looping:
   the names look too much alike difficult to understand the difference between 
the two.



##########
pkg/scheduler/ugm/manager.go:
##########
@@ -365,127 +381,159 @@ func (m *Manager) internalProcessConfig(cur 
configs.QueueConfig, queuePath strin
                                zap.String("queue path", queuePath),
                                zap.Uint64("max application", 
limit.MaxApplications),
                                zap.Any("max resources", limit.MaxResources))
-                       if err := m.processGroupConfig(group, limitConfig, 
queuePath, groupLimits); err != nil {
+                       if err := m.setGroupLimits(group, limitConfig, 
queuePath); err != nil {
                                return err
                        }
+                       if _, ok := newGroupLimits[queuePath]; !ok {
+                               newGroupLimits[queuePath] = 
make(map[string]*LimitConfig)
+                       }
+                       newGroupLimits[queuePath][group] = limitConfig
                        if group == common.Wildcard {
-                               m.groupWildCardLimitsConfig[queuePath] = 
limitConfig
+                               newGroupWildCardLimitsConfig[queuePath] = 
limitConfig
                        } else {
-                               m.configuredGroups[queuePath] = 
append(m.configuredGroups[queuePath], group)
+                               newConfiguredGroups[queuePath] = 
append(newConfiguredGroups[queuePath], group)
                        }
                }
        }
-       if err := m.clearEarlierSetLimits(userLimits, groupLimits, queuePath); 
err != nil {
-               return err
-       }
-
        if len(cur.Queues) > 0 {
                for _, child := range cur.Queues {
                        childQueuePath := queuePath + configs.DOT + child.Name
-                       if err := m.internalProcessConfig(child, 
childQueuePath); err != nil {
+                       if err := m.internalProcessConfig(child, 
childQueuePath, newUserLimits, newGroupLimits, newUserWildCardLimitsConfig, 
newGroupWildCardLimitsConfig, newConfiguredGroups); err != nil {
                                return err
                        }
                }
        }
        return nil
 }
 
-func (m *Manager) processUserConfig(user string, limitConfig *LimitConfig, 
queuePath string, userLimits map[string]bool) error {
-       if err := m.setUserLimits(user, limitConfig, queuePath); err != nil {
-               return err
-       }
-       userLimits[user] = true
-       return nil
-}
+// clearEarlierSetLimits Clear already configured limits of users and groups 
for which limits have been configured before but not now
+func (m *Manager) clearEarlierSetLimits(newUserLimits 
map[string]map[string]*LimitConfig, newGroupLimits 
map[string]map[string]*LimitConfig) {
+       // Clear already configured limits of group for which limits have been 
configured before but not now
+       m.clearEarlierSetGroupLimits(newGroupLimits)
 
-func (m *Manager) processGroupConfig(group string, limitConfig *LimitConfig, 
queuePath string, groupLimits map[string]bool) error {
-       if err := m.setGroupLimits(group, limitConfig, queuePath); err != nil {
-               return err
-       }
-       groupLimits[group] = true
-       return nil
+       // Clear already configured limits of user for which limits have been 
configured before but not now
+       m.clearEarlierSetUserLimits(newUserLimits)
 }
 
-// clearEarlierSetLimits Clear already configured limits of users and groups 
for which limits have been configured before but not now
-func (m *Manager) clearEarlierSetLimits(userLimits map[string]bool, 
groupLimits map[string]bool, queuePath string) error {
-       // Clear already configured limits of group for which limits have been 
configured before but not now
-       for _, gt := range m.groupTrackers {
-               appUsersMap := m.clearEarlierSetGroupLimits(gt, queuePath, 
groupLimits)
-               if len(appUsersMap) > 0 {
-                       for app, user := range appUsersMap {
-                               ut := m.userTrackers[user]
-                               ut.setGroupForApp(app, nil)
+func (m *Manager) clearEarlierSetUserLimits(newUserLimits 
map[string]map[string]*LimitConfig) {
+       if len(m.userLimits) == 0 {
+               return
+       }
+       m.RLock()
+       defer m.RUnlock()
+       // Need to clear user config only when
+       // 1. config set earlier but not now
+       // 2. user already tracked for the queue path
+       for queuePath, limitConfig := range m.userLimits {
+               // Is queue path exists?
+               if newUserLimit, ok := newUserLimits[queuePath]; !ok {
+                       for u := range limitConfig {
+                               if ut, utExists := m.userTrackers[u]; utExists {
+                                       m.clearEarlierSetUserLimit(ut, 
queuePath)
+                               }
+                       }
+               } else {
+                       // Queue path exists. Is user exists?
+                       for u := range limitConfig {
+                               if _, ulExists := newUserLimit[u]; !ulExists {
+                                       if ut, utExists := m.userTrackers[u]; 
utExists {
+                                               m.clearEarlierSetUserLimit(ut, 
queuePath)
+                                       }
+                               }
                        }
                }
        }
-
-       // Clear already configured limits of user for which limits have been 
configured before but not now
-       for _, ut := range m.userTrackers {
-               m.clearEarlierSetUserLimits(ut, queuePath, userLimits)
-       }
-       return nil
 }
 
-func (m *Manager) clearEarlierSetUserLimits(ut *UserTracker, queuePath string, 
userLimits map[string]bool) {
+func (m *Manager) clearEarlierSetUserLimit(ut *UserTracker, queuePath string) {
        // Is this user already tracked for the queue path?
        if ut.IsQueuePathTrackedCompletely(queuePath) {
-               u := ut.userName
-               // Is there any limit config set for user in the current 
configuration? If not, then clear those old limit settings
-               if _, ok := userLimits[u]; !ok {
-                       log.Log(log.SchedUGM).Debug("Need to clear earlier set 
configs for user",
-                               zap.String("user", u),
-                               zap.String("queue path", queuePath))
-                       // Is there any running applications in end queue of 
this queue path? If not, then remove the linkage between end queue and its 
immediate parent
-                       if ut.IsUnlinkRequired(queuePath) {
-                               ut.UnlinkQT(queuePath)
-                       } else {
-                               ut.setLimits(queuePath, 
resources.NewResource(), 0)
-                               log.Log(log.SchedUGM).Debug("Cleared earlier 
set limit configs for user",
-                                       zap.String("user", u),
-                                       zap.String("queue path", queuePath))
+               log.Log(log.SchedUGM).Debug("Need to clear earlier set configs 
for user",
+                       zap.String("user", ut.userName),
+                       zap.String("queue path", queuePath))
+               ut.setLimits(queuePath, resources.NewResource(), 0)
+               // Is there any running applications in end queue of this queue 
path? If not, then remove the linkage between end queue and its immediate parent
+               if ut.IsUnlinkRequired(queuePath) {
+                       ut.UnlinkQT(queuePath)
+               }
+               log.Log(log.SchedUGM).Debug("Cleared earlier set limit configs 
for user",
+                       zap.String("user", ut.userName),
+                       zap.String("queue path", queuePath))
+               if ut.canBeRemoved() {
+                       delete(m.userTrackers, ut.userName)
+               }
+       }
+}
+
+func (m *Manager) clearEarlierSetGroupLimits(newGroupLimits 
map[string]map[string]*LimitConfig) {
+       if len(m.groupLimits) == 0 {
+               return
+       }
+       m.RLock()
+       defer m.RUnlock()

Review Comment:
   move before the check



##########
pkg/scheduler/ugm/manager.go:
##########
@@ -365,127 +381,159 @@ func (m *Manager) internalProcessConfig(cur 
configs.QueueConfig, queuePath strin
                                zap.String("queue path", queuePath),
                                zap.Uint64("max application", 
limit.MaxApplications),
                                zap.Any("max resources", limit.MaxResources))
-                       if err := m.processGroupConfig(group, limitConfig, 
queuePath, groupLimits); err != nil {
+                       if err := m.setGroupLimits(group, limitConfig, 
queuePath); err != nil {
                                return err
                        }
+                       if _, ok := newGroupLimits[queuePath]; !ok {
+                               newGroupLimits[queuePath] = 
make(map[string]*LimitConfig)
+                       }
+                       newGroupLimits[queuePath][group] = limitConfig
                        if group == common.Wildcard {
-                               m.groupWildCardLimitsConfig[queuePath] = 
limitConfig
+                               newGroupWildCardLimitsConfig[queuePath] = 
limitConfig
                        } else {
-                               m.configuredGroups[queuePath] = 
append(m.configuredGroups[queuePath], group)
+                               newConfiguredGroups[queuePath] = 
append(newConfiguredGroups[queuePath], group)
                        }
                }
        }
-       if err := m.clearEarlierSetLimits(userLimits, groupLimits, queuePath); 
err != nil {
-               return err
-       }
-
        if len(cur.Queues) > 0 {
                for _, child := range cur.Queues {
                        childQueuePath := queuePath + configs.DOT + child.Name
-                       if err := m.internalProcessConfig(child, 
childQueuePath); err != nil {
+                       if err := m.internalProcessConfig(child, 
childQueuePath, newUserLimits, newGroupLimits, newUserWildCardLimitsConfig, 
newGroupWildCardLimitsConfig, newConfiguredGroups); err != nil {
                                return err
                        }
                }
        }
        return nil
 }
 
-func (m *Manager) processUserConfig(user string, limitConfig *LimitConfig, 
queuePath string, userLimits map[string]bool) error {
-       if err := m.setUserLimits(user, limitConfig, queuePath); err != nil {
-               return err
-       }
-       userLimits[user] = true
-       return nil
-}
+// clearEarlierSetLimits Clear already configured limits of users and groups 
for which limits have been configured before but not now
+func (m *Manager) clearEarlierSetLimits(newUserLimits 
map[string]map[string]*LimitConfig, newGroupLimits 
map[string]map[string]*LimitConfig) {
+       // Clear already configured limits of group for which limits have been 
configured before but not now
+       m.clearEarlierSetGroupLimits(newGroupLimits)
 
-func (m *Manager) processGroupConfig(group string, limitConfig *LimitConfig, 
queuePath string, groupLimits map[string]bool) error {
-       if err := m.setGroupLimits(group, limitConfig, queuePath); err != nil {
-               return err
-       }
-       groupLimits[group] = true
-       return nil
+       // Clear already configured limits of user for which limits have been 
configured before but not now
+       m.clearEarlierSetUserLimits(newUserLimits)
 }
 
-// clearEarlierSetLimits Clear already configured limits of users and groups 
for which limits have been configured before but not now
-func (m *Manager) clearEarlierSetLimits(userLimits map[string]bool, 
groupLimits map[string]bool, queuePath string) error {
-       // Clear already configured limits of group for which limits have been 
configured before but not now
-       for _, gt := range m.groupTrackers {
-               appUsersMap := m.clearEarlierSetGroupLimits(gt, queuePath, 
groupLimits)
-               if len(appUsersMap) > 0 {
-                       for app, user := range appUsersMap {
-                               ut := m.userTrackers[user]
-                               ut.setGroupForApp(app, nil)
+func (m *Manager) clearEarlierSetUserLimits(newUserLimits 
map[string]map[string]*LimitConfig) {
+       if len(m.userLimits) == 0 {
+               return
+       }
+       m.RLock()
+       defer m.RUnlock()

Review Comment:
   needs to be before the check of the userlimits



##########
pkg/scheduler/ugm/manager.go:
##########
@@ -365,127 +381,159 @@ func (m *Manager) internalProcessConfig(cur 
configs.QueueConfig, queuePath strin
                                zap.String("queue path", queuePath),
                                zap.Uint64("max application", 
limit.MaxApplications),
                                zap.Any("max resources", limit.MaxResources))
-                       if err := m.processGroupConfig(group, limitConfig, 
queuePath, groupLimits); err != nil {
+                       if err := m.setGroupLimits(group, limitConfig, 
queuePath); err != nil {
                                return err
                        }
+                       if _, ok := newGroupLimits[queuePath]; !ok {
+                               newGroupLimits[queuePath] = 
make(map[string]*LimitConfig)
+                       }
+                       newGroupLimits[queuePath][group] = limitConfig
                        if group == common.Wildcard {
-                               m.groupWildCardLimitsConfig[queuePath] = 
limitConfig
+                               newGroupWildCardLimitsConfig[queuePath] = 
limitConfig
                        } else {
-                               m.configuredGroups[queuePath] = 
append(m.configuredGroups[queuePath], group)
+                               newConfiguredGroups[queuePath] = 
append(newConfiguredGroups[queuePath], group)
                        }
                }
        }
-       if err := m.clearEarlierSetLimits(userLimits, groupLimits, queuePath); 
err != nil {
-               return err
-       }
-
        if len(cur.Queues) > 0 {
                for _, child := range cur.Queues {
                        childQueuePath := queuePath + configs.DOT + child.Name
-                       if err := m.internalProcessConfig(child, 
childQueuePath); err != nil {
+                       if err := m.internalProcessConfig(child, 
childQueuePath, newUserLimits, newGroupLimits, newUserWildCardLimitsConfig, 
newGroupWildCardLimitsConfig, newConfiguredGroups); err != nil {
                                return err
                        }
                }
        }
        return nil
 }
 
-func (m *Manager) processUserConfig(user string, limitConfig *LimitConfig, 
queuePath string, userLimits map[string]bool) error {
-       if err := m.setUserLimits(user, limitConfig, queuePath); err != nil {
-               return err
-       }
-       userLimits[user] = true
-       return nil
-}
+// clearEarlierSetLimits Clear already configured limits of users and groups 
for which limits have been configured before but not now
+func (m *Manager) clearEarlierSetLimits(newUserLimits 
map[string]map[string]*LimitConfig, newGroupLimits 
map[string]map[string]*LimitConfig) {
+       // Clear already configured limits of group for which limits have been 
configured before but not now
+       m.clearEarlierSetGroupLimits(newGroupLimits)
 
-func (m *Manager) processGroupConfig(group string, limitConfig *LimitConfig, 
queuePath string, groupLimits map[string]bool) error {
-       if err := m.setGroupLimits(group, limitConfig, queuePath); err != nil {
-               return err
-       }
-       groupLimits[group] = true
-       return nil
+       // Clear already configured limits of user for which limits have been 
configured before but not now
+       m.clearEarlierSetUserLimits(newUserLimits)
 }
 
-// clearEarlierSetLimits Clear already configured limits of users and groups 
for which limits have been configured before but not now
-func (m *Manager) clearEarlierSetLimits(userLimits map[string]bool, 
groupLimits map[string]bool, queuePath string) error {
-       // Clear already configured limits of group for which limits have been 
configured before but not now
-       for _, gt := range m.groupTrackers {
-               appUsersMap := m.clearEarlierSetGroupLimits(gt, queuePath, 
groupLimits)
-               if len(appUsersMap) > 0 {
-                       for app, user := range appUsersMap {
-                               ut := m.userTrackers[user]
-                               ut.setGroupForApp(app, nil)
+func (m *Manager) clearEarlierSetUserLimits(newUserLimits 
map[string]map[string]*LimitConfig) {
+       if len(m.userLimits) == 0 {
+               return
+       }
+       m.RLock()
+       defer m.RUnlock()
+       // Need to clear user config only when
+       // 1. config set earlier but not now
+       // 2. user already tracked for the queue path
+       for queuePath, limitConfig := range m.userLimits {
+               // Is queue path exists?
+               if newUserLimit, ok := newUserLimits[queuePath]; !ok {
+                       for u := range limitConfig {
+                               if ut, utExists := m.userTrackers[u]; utExists {
+                                       m.clearEarlierSetUserLimit(ut, 
queuePath)
+                               }
+                       }
+               } else {
+                       // Queue path exists. Is user exists?
+                       for u := range limitConfig {
+                               if _, ulExists := newUserLimit[u]; !ulExists {
+                                       if ut, utExists := m.userTrackers[u]; 
utExists {
+                                               m.clearEarlierSetUserLimit(ut, 
queuePath)
+                                       }
+                               }
                        }
                }
        }
-
-       // Clear already configured limits of user for which limits have been 
configured before but not now
-       for _, ut := range m.userTrackers {
-               m.clearEarlierSetUserLimits(ut, queuePath, userLimits)
-       }
-       return nil
 }
 
-func (m *Manager) clearEarlierSetUserLimits(ut *UserTracker, queuePath string, 
userLimits map[string]bool) {
+func (m *Manager) clearEarlierSetUserLimit(ut *UserTracker, queuePath string) {
        // Is this user already tracked for the queue path?
        if ut.IsQueuePathTrackedCompletely(queuePath) {
-               u := ut.userName
-               // Is there any limit config set for user in the current 
configuration? If not, then clear those old limit settings
-               if _, ok := userLimits[u]; !ok {
-                       log.Log(log.SchedUGM).Debug("Need to clear earlier set 
configs for user",
-                               zap.String("user", u),
-                               zap.String("queue path", queuePath))
-                       // Is there any running applications in end queue of 
this queue path? If not, then remove the linkage between end queue and its 
immediate parent
-                       if ut.IsUnlinkRequired(queuePath) {
-                               ut.UnlinkQT(queuePath)
-                       } else {
-                               ut.setLimits(queuePath, 
resources.NewResource(), 0)
-                               log.Log(log.SchedUGM).Debug("Cleared earlier 
set limit configs for user",
-                                       zap.String("user", u),
-                                       zap.String("queue path", queuePath))
+               log.Log(log.SchedUGM).Debug("Need to clear earlier set configs 
for user",
+                       zap.String("user", ut.userName),
+                       zap.String("queue path", queuePath))
+               ut.setLimits(queuePath, resources.NewResource(), 0)
+               // Is there any running applications in end queue of this queue 
path? If not, then remove the linkage between end queue and its immediate parent
+               if ut.IsUnlinkRequired(queuePath) {
+                       ut.UnlinkQT(queuePath)
+               }
+               log.Log(log.SchedUGM).Debug("Cleared earlier set limit configs 
for user",
+                       zap.String("user", ut.userName),
+                       zap.String("queue path", queuePath))
+               if ut.canBeRemoved() {
+                       delete(m.userTrackers, ut.userName)
+               }
+       }
+}
+
+func (m *Manager) clearEarlierSetGroupLimits(newGroupLimits 
map[string]map[string]*LimitConfig) {

Review Comment:
   Similar comment as for the user: comments for the functions to explain what 
they do and the names look too much alike 



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