-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kube: Better Port Abstraction. #4829
Merged
Merged
Changes from 12 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a656d24
Kube pod name contains image-name for better operations.
davinchia 52ead75
Better logging to figure out what pod is not releasing the ports.
davinchia 0d2a125
Fix pod name error. Add better debug logs.
davinchia 4377d68
Better process naming.
davinchia c56337e
Format.
davinchia b967b9d
Explicitly pin ec2 runner version to 2.2.1.
davinchia caa58e9
Initial abstraction.
davinchia 29d42d9
Merge remote-tracking branch 'origin' into davinchia/better-port-abst…
davinchia dc7c7df
Remove merge errors.
davinchia a30f54c
Add warnings. Add better comments.
davinchia 4b25008
Add assertions to test ports are released.
davinchia 3e9fce0
Add more ports.
davinchia f013e39
Update airbyte-workers/src/main/java/io/airbyte/workers/process/KubeP…
davinchia 98aa0ef
Merge remote-tracking branch 'origin' into davinchia/better-port-abst…
davinchia 39f8486
Format. Edit comment.
davinchia b7d9cbb
Update num submitter thread if there are insufficient ports.
davinchia 1705c7a
Merge branch 'davinchia/better-port-abstraction' of github.com:airbyt…
davinchia b8b94d1
Fix name.
davinchia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
81 changes: 81 additions & 0 deletions
81
airbyte-workers/src/main/java/io/airbyte/workers/process/KubePortManagerSingleton.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,81 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2020 Airbyte | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package io.airbyte.workers.process; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import io.airbyte.config.EnvConfigs; | ||
import java.util.Set; | ||
import java.util.concurrent.BlockingQueue; | ||
import java.util.concurrent.LinkedBlockingDeque; | ||
import java.util.concurrent.TimeUnit; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Convenience wrapper around a thread-safe BlockingQueue. Keeps track of available ports for Kube | ||
* Pod Processes. | ||
* | ||
* Although this data structure can do without the wrapper class, this class allows easier testing | ||
* via the {@link #getNumAvailablePorts()} function. | ||
* | ||
* The singleton pattern clarifies that only one copy of this class is intended to exists per | ||
* scheduler deployment. | ||
*/ | ||
public class KubePortManagerSingleton { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(KubePortManagerSingleton.class); | ||
private static final int MAX_PORTS_PER_WORKERS = 4; // A sync has two workers. Each worker requires 2 ports. | ||
davinchia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private static BlockingQueue<Integer> workerPorts = new LinkedBlockingDeque<>(new EnvConfigs().getTemporalWorkerPorts()); | ||
|
||
public static Integer take() throws InterruptedException { | ||
return workerPorts.poll(10, TimeUnit.MINUTES); | ||
} | ||
|
||
public static boolean offer(Integer port) { | ||
if (!workerPorts.contains(port)) { | ||
workerPorts.add(port); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public static int getNumAvailablePorts() { | ||
return workerPorts.size(); | ||
} | ||
|
||
public static void warnIfInsufficientPorts(int potentialConcurrentWorkers) { | ||
var maxUsedPorts = potentialConcurrentWorkers * MAX_PORTS_PER_WORKERS; | ||
if (maxUsedPorts > workerPorts.size()) { | ||
LOGGER.warn("{} workers can use up to {} ports at once. Only {} ports allocated. This might result in stuck jobs.", | ||
potentialConcurrentWorkers, maxUsedPorts, workerPorts.size()); | ||
} | ||
} | ||
|
||
@VisibleForTesting | ||
protected static void setWorkerPorts(Set<Integer> ports) { | ||
workerPorts = new LinkedBlockingDeque<>(ports); | ||
} | ||
|
||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would error previously