This is an automated email from the ASF dual-hosted git repository.

pbacsko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 63a91f69 [YUNIKORN-2632] Data race in IncAllocatedResource (#870)
63a91f69 is described below

commit 63a91f6994d3c0880df20a5a011939e52ae41dd2
Author: Peter Bacsko <pbac...@cloudera.com>
AuthorDate: Fri May 17 17:40:46 2024 +0200

    [YUNIKORN-2632] Data race in IncAllocatedResource (#870)
    
    Closes: #870
    
    Signed-off-by: Peter Bacsko <pbac...@cloudera.com>
---
 pkg/scheduler/objects/queue.go | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/pkg/scheduler/objects/queue.go b/pkg/scheduler/objects/queue.go
index 83623ca7..4d0e416d 100644
--- a/pkg/scheduler/objects/queue.go
+++ b/pkg/scheduler/objects/queue.go
@@ -989,12 +989,10 @@ func (sq *Queue) isRoot() bool {
 // Guard against going over max resources if set
 func (sq *Queue) IncAllocatedResource(alloc *resources.Resource, nodeReported 
bool) error {
        // check this queue: failure stops checks if the allocation is not part 
of a node addition
-       newAllocated := resources.Add(sq.allocatedResource, alloc)
-       if !nodeReported {
-               if !sq.resourceFitsMaxRes(newAllocated) {
-                       return fmt.Errorf("allocation (%v) puts queue '%s' over 
maximum allocation (%v), current usage (%v)",
-                               alloc, sq.QueuePath, sq.maxResource, 
sq.allocatedResource)
-               }
+       fit, newAllocated := sq.allocatedResFits(alloc)
+       if !nodeReported && !fit {
+               return fmt.Errorf("allocation (%v) puts queue '%s' over maximum 
allocation (%v), current usage (%v)",
+                       alloc, sq.QueuePath, sq.maxResource, 
sq.allocatedResource)
        }
        // check the parent: need to pass before updating
        if sq.parent != nil {
@@ -1020,11 +1018,12 @@ func (sq *Queue) IncAllocatedResource(alloc 
*resources.Resource, nodeReported bo
        return nil
 }
 
-// small helper method to access sq.maxResource and avoid Clone() call
-func (sq *Queue) resourceFitsMaxRes(res *resources.Resource) bool {
+// small helper method to access sq.maxResource+sq.allocatedResource and avoid 
Clone() call
+func (sq *Queue) allocatedResFits(res *resources.Resource) (bool, 
*resources.Resource) {
        sq.RLock()
        defer sq.RUnlock()
-       return sq.maxResource.FitInMaxUndef(res)
+       newAllocated := resources.Add(sq.allocatedResource, res)
+       return sq.maxResource.FitInMaxUndef(newAllocated), newAllocated
 }
 
 // DecAllocatedResource decrement the allocated resources for this queue 
(recursively)


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@yunikorn.apache.org
For additional commands, e-mail: issues-h...@yunikorn.apache.org

Reply via email to