pbacsko commented on code in PR #935:
URL: https://github.com/apache/yunikorn-core/pull/935#discussion_r1716485342


##########
pkg/common/resources/resources.go:
##########
@@ -469,6 +469,64 @@ func (r *Resource) fitIn(smaller *Resource, skipUndef 
bool) bool {
        return true
 }
 
+// getShareFairForDenominator attempts to computes the denominator for a 
queue's fair share ratio.
+// Here Resources can be either guaranteed Resources or fairmax Resources.
+// If the quanity is explicitly 0 or negative, we will check usage.  If usage 
>= 0, the share will be set to 1.0.  Otherwise, it will be set 0.0.
+func getShareFairForDenominator(resourceType string, allocated Quantity, 
denominatorResources *Resource) (float64, bool) {
+       if denominatorResources == nil {
+               return 0.0, false
+       }
+
+       denominator, ok := denominatorResources.Resources[resourceType]
+
+       switch {
+       case ok && denominator <= 0:
+               if allocated <= 0 {
+                       // explicit 0 or negative value with NO usage
+                       return 0.0, true
+               } else {
+                       // explicit 0 or negative value with usage
+                       return 1.0, true
+               }
+       case denominator > 0:
+               return (float64(allocated) / float64(denominator)), true
+       default:
+               // no denominator. ie. no guarantee or fairmax for resourceType
+               return 0.0, false
+       }
+}
+
+// getFairShare produces a ratio which represents it's current 'fair' share 
usage.
+// Iterate over all of the allocated resource types.  For each, compute the 
ratio, ultimately returning the max ratio encountered.
+// The numerator will be the allocated usage.
+// If guarantees are present, they will be used for the denominator, otherwise 
we will fallback to the 'maxfair' capacity of the cluster.
+func getFairShare(allocated, guaranteed, fair *Resource) float64 {
+       if allocated == nil || len(allocated.Resources) == 0 {
+               return 0.0
+       }
+
+       var maxShare float64
+       for k, v := range allocated.Resources {
+               var nextShare float64
+
+               // if usage <= 0, resource has no share
+               if allocated.Resources[k] < 0 {
+                       continue
+               }
+
+               nextShare, found := getShareFairForDenominator(k, v, guaranteed)
+               if !found {
+                       nextShare, found = getShareFairForDenominator(k, v, 
fair)
+               }
+               if found {
+                       if nextShare > maxShare {
+                               maxShare = nextShare
+                       }

Review Comment:
   Nit: this can be written as
   
   ```
   if found && nextShare > maxShare {
     maxShare = nextShare
   }
   ```



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