zentol commented on a change in pull request #13464:
URL: https://github.com/apache/flink/pull/13464#discussion_r494202178



##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/slots/ResourceCounter.java
##########
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.slots;
+
+import org.apache.flink.runtime.clusterframework.types.ResourceProfile;
+import org.apache.flink.util.Preconditions;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A counter for resources.
+ *
+ * <p>ResourceCounter contains a set of {@link ResourceProfile 
ResourceProfiles} and their
+ * associated counts. The counts are always positive (> 0).
+ */
+public class ResourceCounter {
+       public static final ResourceCounter EMPTY = new 
ResourceCounter(Collections.emptyMap());
+
+       private final Map<ResourceProfile, Integer> resources;
+
+       public ResourceCounter() {
+               this(new HashMap<>());
+       }
+
+       private ResourceCounter(Map<ResourceProfile, Integer> resources) {
+               this.resources = resources;
+       }
+
+       public void incrementCount(ResourceProfile profile, int increment) {
+               Preconditions.checkArgument(increment > 0);
+               resources.compute(profile, (ignored, currentCount) -> 
currentCount == null ? increment : currentCount + increment);
+       }
+
+       public void decrementCount(ResourceProfile profile, int decrement) {
+               Preconditions.checkArgument(decrement > 0);
+               resources.computeIfPresent(profile, (ignored, currentCount) -> 
currentCount == decrement ? null : guardAgainstNegativeCount(currentCount - 
decrement));

Review comment:
       true, will adjust it.




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


Reply via email to