xintongsong commented on a change in pull request #8841: 
[FLINK-12765][coordinator] Bookkeeping of available resources of allocated 
slots in SlotPool
URL: https://github.com/apache/flink/pull/8841#discussion_r297465713
 
 

 ##########
 File path: 
flink-core/src/main/java/org/apache/flink/api/common/resources/Resource.java
 ##########
 @@ -73,12 +73,35 @@ public Resource merge(Resource other) {
 
                        case AGGREGATE_TYPE_SUM:
                        default:
-                               aggregatedValue = this.value + other.value;
+                               aggregatedValue = value + other.value;
                }
 
                return create(aggregatedValue, resourceAggregateType);
        }
 
+       public Resource subtract(Resource other) {
+               Preconditions.checkArgument(getClass() == other.getClass(), 
"Subtract with different resource resourceAggregateType");
+               Preconditions.checkArgument(this.name.equals(other.name), 
"Subtract with different resource name");
+               Preconditions.checkArgument(this.resourceAggregateType == 
other.resourceAggregateType, "Subtract with different aggregate 
resourceAggregateType");
+               Preconditions.checkArgument(this.value >= other.value, "Try to 
subtract a larger resource from this one. ");
+
+               final double subtractedValue;
+               switch (resourceAggregateType) {
+                       case AGGREGATE_TYPE_MAX:
+                               // From the perspective of resource matching, 
if aggregation type is max,
+                               // subtracting a value less than the current 
value should not decrease the
+                               // ability of the original resource.
+                               subtractedValue = value;
+                               break;
 
 Review comment:
   I think we need a TODO or warning here for cases that the subtrahend equals 
to the minuend.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to