forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-14189][runtime] Extend TaskExecutor to support dynamic slot al…
…location
- Loading branch information
1 parent
da071ce
commit 516aee3
Showing
18 changed files
with
600 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
.../src/main/java/org/apache/flink/runtime/clusterframework/types/ResourceBudgetManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* 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:https://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.clusterframework.types; | ||
|
||
import org.apache.flink.util.Preconditions; | ||
|
||
/** | ||
* Budget manager for {@link ResourceProfile}. | ||
* | ||
* <p>For a given total resource budget, this class handles reserving and releasing resources | ||
* from the budget, and rejects reservations if they cannot be satisfied by the remaining budget. | ||
* | ||
* <p>Both the total budget and the reservations are in the form of {@link ResourceProfile}. | ||
*/ | ||
public class ResourceBudgetManager { | ||
|
||
private final ResourceProfile totalBudget; | ||
|
||
private ResourceProfile availableBudget; | ||
|
||
public ResourceBudgetManager(final ResourceProfile totalBudget) { | ||
checkResourceProfileNotNullOrUnknown(totalBudget); | ||
this.totalBudget = totalBudget; | ||
this.availableBudget = totalBudget; | ||
} | ||
|
||
public ResourceProfile getTotalBudget() { | ||
return totalBudget; | ||
} | ||
|
||
public ResourceProfile getAvailableBudget() { | ||
return availableBudget; | ||
} | ||
|
||
public boolean reserve(final ResourceProfile reservation) { | ||
checkResourceProfileNotNullOrUnknown(reservation); | ||
if (!availableBudget.isMatching(reservation)) { | ||
return false; | ||
} | ||
|
||
availableBudget = availableBudget.subtract(reservation); | ||
return true; | ||
} | ||
|
||
public boolean release(final ResourceProfile reservation) { | ||
checkResourceProfileNotNullOrUnknown(reservation); | ||
ResourceProfile newAvailableBudget = availableBudget.merge(reservation); | ||
if (!totalBudget.isMatching(newAvailableBudget)) { | ||
return false; | ||
} | ||
|
||
availableBudget = newAvailableBudget; | ||
return true; | ||
} | ||
|
||
private static void checkResourceProfileNotNullOrUnknown(final ResourceProfile resourceProfile) { | ||
Preconditions.checkNotNull(resourceProfile); | ||
Preconditions.checkArgument(!resourceProfile.equals(ResourceProfile.UNKNOWN)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.