-
Notifications
You must be signed in to change notification settings - Fork 361
feat(connectors): use TCP client for Flink sink #3657
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
Open
Standing-Man
wants to merge
3
commits into
apache:master
Choose a base branch
from
Standing-Man:flink-transport
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| .project | ||
| .settings/ | ||
| .gradle/ | ||
| .kotlin/ | ||
| build/ | ||
| out/ | ||
|
|
||
|
|
||
This file contains hidden or 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
92 changes: 92 additions & 0 deletions
92
...nk/iggy-connector-library/src/main/java/org/apache/iggy/connector/config/TcpEndpoint.java
This file contains hidden or 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,92 @@ | ||
| /* | ||
| * 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.iggy.connector.config; | ||
|
|
||
| import java.net.URI; | ||
| import java.net.URISyntaxException; | ||
|
|
||
| /** | ||
| * Host and port of an Iggy TCP endpoint. | ||
| * | ||
| * @param host server host | ||
| * @param port server TCP port | ||
| */ | ||
| public record TcpEndpoint(String host, int port) { | ||
|
|
||
| public static final int DEFAULT_PORT = 8090; | ||
|
|
||
| /** | ||
| * Parses an Iggy TCP server address. | ||
| * | ||
| * @param serverAddress address in host, host:port, or tcp://host:port form | ||
| * @return parsed TCP endpoint | ||
| */ | ||
| public static TcpEndpoint parse(String serverAddress) { | ||
| if (serverAddress == null || serverAddress.isBlank()) { | ||
| throw new IllegalArgumentException("TCP server address cannot be null or blank"); | ||
| } | ||
|
|
||
| URI uri = parseUri(serverAddress); | ||
| validateScheme(uri); | ||
| String host = extractHost(uri, serverAddress); | ||
| validateComponents(uri, serverAddress); | ||
|
|
||
| int port = uri.getPort() >= 0 ? uri.getPort() : DEFAULT_PORT; | ||
| validatePort(port, serverAddress); | ||
| return new TcpEndpoint(host, port); | ||
| } | ||
|
|
||
| private static URI parseUri(String serverAddress) { | ||
| try { | ||
| return serverAddress.contains("://") ? new URI(serverAddress) : new URI("tcp://" + serverAddress); | ||
| } catch (URISyntaxException e) { | ||
| throw new IllegalArgumentException("Invalid TCP server address: " + serverAddress, e); | ||
| } | ||
| } | ||
|
|
||
| private static void validateScheme(URI uri) { | ||
| if (!"tcp".equalsIgnoreCase(uri.getScheme())) { | ||
| throw new IllegalArgumentException("Unsupported TCP server address scheme: " + uri.getScheme()); | ||
| } | ||
| } | ||
|
|
||
| private static String extractHost(URI uri, String serverAddress) { | ||
| String host = uri.getHost(); | ||
| if (host == null || host.isBlank()) { | ||
| throw new IllegalArgumentException("Cannot extract host from TCP server address: " + serverAddress); | ||
| } | ||
| return host; | ||
| } | ||
|
|
||
| private static void validateComponents(URI uri, String serverAddress) { | ||
| if (uri.getUserInfo() != null | ||
| || !uri.getPath().isEmpty() | ||
| || uri.getQuery() != null | ||
| || uri.getFragment() != null) { | ||
| throw new IllegalArgumentException("Invalid TCP server address: " + serverAddress); | ||
| } | ||
| } | ||
|
|
||
| private static void validatePort(int port, String serverAddress) { | ||
| if (port == 0 || port > 65535) { | ||
| throw new IllegalArgumentException("Invalid TCP port in server address: " + serverAddress); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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.
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.
flush()wraps send failures inConnectorException, which extendsRuntimeException, so thiscatch (IOException e)never fires for the most common failure mode. The exception then propagates beforetcpClient.close()runs, leaking the Netty channels and event-loop threads in the TaskManager JVM. This defeats the scenario this block was written for. Widening the catch keeps the intended semantics: