-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Cleanup network / transport related settings #25489
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,50 +19,45 @@ | |
|
|
||
| package org.elasticsearch.common.network; | ||
|
|
||
| import org.elasticsearch.common.Strings; | ||
| import org.elasticsearch.common.component.AbstractComponent; | ||
| import org.elasticsearch.common.settings.Setting; | ||
| import org.elasticsearch.common.settings.Setting.Property; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.common.unit.ByteSizeValue; | ||
| import org.elasticsearch.common.unit.TimeValue; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.InetAddress; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.function.Function; | ||
|
|
||
| public class NetworkService extends AbstractComponent { | ||
| public final class NetworkService { | ||
|
|
||
| /** By default, we bind to loopback interfaces */ | ||
| public static final String DEFAULT_NETWORK_HOST = "_local_"; | ||
|
|
||
| public static final Setting<List<String>> GLOBAL_NETWORK_HOST_SETTING = | ||
| Setting.listSetting("network.host", Arrays.asList(DEFAULT_NETWORK_HOST), Function.identity(), Property.NodeScope); | ||
| Setting.listSetting("network.host", Collections.emptyList(), Function.identity(), Property.NodeScope); | ||
| public static final Setting<List<String>> GLOBAL_NETWORK_BINDHOST_SETTING = | ||
| Setting.listSetting("network.bind_host", GLOBAL_NETWORK_HOST_SETTING, Function.identity(), Property.NodeScope); | ||
| public static final Setting<List<String>> GLOBAL_NETWORK_PUBLISHHOST_SETTING = | ||
| Setting.listSetting("network.publish_host", GLOBAL_NETWORK_HOST_SETTING, Function.identity(), Property.NodeScope); | ||
| public static final Setting<Boolean> NETWORK_SERVER = Setting.boolSetting("network.server", true, Property.NodeScope); | ||
|
|
||
| public static final class TcpSettings { | ||
| public static final Setting<Boolean> TCP_NO_DELAY = | ||
| Setting.boolSetting("network.tcp.no_delay", true, Property.NodeScope); | ||
| public static final Setting<Boolean> TCP_KEEP_ALIVE = | ||
| Setting.boolSetting("network.tcp.keep_alive", true, Property.NodeScope); | ||
| public static final Setting<Boolean> TCP_REUSE_ADDRESS = | ||
| Setting.boolSetting("network.tcp.reuse_address", NetworkUtils.defaultReuseAddress(), Property.NodeScope); | ||
| public static final Setting<ByteSizeValue> TCP_SEND_BUFFER_SIZE = | ||
| Setting.byteSizeSetting("network.tcp.send_buffer_size", new ByteSizeValue(-1), Property.NodeScope); | ||
| public static final Setting<ByteSizeValue> TCP_RECEIVE_BUFFER_SIZE = | ||
| Setting.byteSizeSetting("network.tcp.receive_buffer_size", new ByteSizeValue(-1), Property.NodeScope); | ||
| public static final Setting<TimeValue> TCP_CONNECT_TIMEOUT = | ||
| Setting.timeSetting("network.tcp.connect_timeout", new TimeValue(30, TimeUnit.SECONDS), Property.NodeScope); | ||
| } | ||
| public static final Setting<Boolean> TCP_NO_DELAY = | ||
| Setting.boolSetting("network.tcp.no_delay", true, Property.NodeScope); | ||
| public static final Setting<Boolean> TCP_KEEP_ALIVE = | ||
| Setting.boolSetting("network.tcp.keep_alive", true, Property.NodeScope); | ||
| public static final Setting<Boolean> TCP_REUSE_ADDRESS = | ||
| Setting.boolSetting("network.tcp.reuse_address", NetworkUtils.defaultReuseAddress(), Property.NodeScope); | ||
| public static final Setting<ByteSizeValue> TCP_SEND_BUFFER_SIZE = | ||
| Setting.byteSizeSetting("network.tcp.send_buffer_size", new ByteSizeValue(-1), Property.NodeScope); | ||
| public static final Setting<ByteSizeValue> TCP_RECEIVE_BUFFER_SIZE = | ||
| Setting.byteSizeSetting("network.tcp.receive_buffer_size", new ByteSizeValue(-1), Property.NodeScope); | ||
| public static final Setting<TimeValue> TCP_CONNECT_TIMEOUT = | ||
| Setting.timeSetting("network.tcp.connect_timeout", new TimeValue(30, TimeUnit.SECONDS), Property.NodeScope); | ||
|
|
||
| /** | ||
| * A custom name resolver can support custom lookup keys (my_net_key:ipv4) and also change | ||
|
|
@@ -82,8 +77,7 @@ public interface CustomNameResolver { | |
|
|
||
| private final List<CustomNameResolver> customNameResolvers; | ||
|
|
||
| public NetworkService(Settings settings, List<CustomNameResolver> customNameResolvers) { | ||
| super(settings); | ||
| public NetworkService(List<CustomNameResolver> customNameResolvers) { | ||
| this.customNameResolvers = customNameResolvers; | ||
| } | ||
|
|
||
|
|
@@ -92,29 +86,23 @@ public NetworkService(Settings settings, List<CustomNameResolver> customNameReso | |
| * not contain duplicate addresses. | ||
| * | ||
| * @param bindHosts list of hosts to bind to. this may contain special pseudo-hostnames | ||
| * such as _local_ (see the documentation). if it is null, it will be populated | ||
| * based on global default settings. | ||
| * such as _local_ (see the documentation). if it is null, it will fall back to _local_ | ||
| * | ||
| * @return unique set of internet addresses | ||
| */ | ||
| public InetAddress[] resolveBindHostAddresses(String bindHosts[]) throws IOException { | ||
| // first check settings | ||
| if (bindHosts == null || bindHosts.length == 0) { | ||
| if (GLOBAL_NETWORK_BINDHOST_SETTING.exists(settings) || GLOBAL_NETWORK_HOST_SETTING.exists(settings)) { | ||
| // if we have settings use them (we have a fallback to GLOBAL_NETWORK_HOST_SETTING inline | ||
| bindHosts = GLOBAL_NETWORK_BINDHOST_SETTING.get(settings).toArray(Strings.EMPTY_ARRAY); | ||
| } else { | ||
| // next check any registered custom resolvers if any | ||
| if (customNameResolvers != null) { | ||
| for (CustomNameResolver customNameResolver : customNameResolvers) { | ||
| InetAddress addresses[] = customNameResolver.resolveDefault(); | ||
| if (addresses != null) { | ||
| return addresses; | ||
| } | ||
| // next check any registered custom resolvers if any | ||
| if (customNameResolvers != null) { | ||
|
||
| for (CustomNameResolver customNameResolver : customNameResolvers) { | ||
| InetAddress addresses[] = customNameResolver.resolveDefault(); | ||
| if (addresses != null) { | ||
| return addresses; | ||
| } | ||
| } | ||
| // we know it's not here. get the defaults | ||
| bindHosts = GLOBAL_NETWORK_BINDHOST_SETTING.get(settings).toArray(Strings.EMPTY_ARRAY); | ||
| } | ||
| // we know it's not here. get the defaults | ||
| bindHosts = new String[] {"_local_"}; | ||
| } | ||
|
|
||
| InetAddress addresses[] = resolveInetAddresses(bindHosts); | ||
|
|
@@ -140,29 +128,23 @@ public InetAddress[] resolveBindHostAddresses(String bindHosts[]) throws IOExcep | |
| * If {@code publishHosts} resolves to more than one address, <b>then one is selected with magic</b> | ||
| * | ||
| * @param publishHosts list of hosts to publish as. this may contain special pseudo-hostnames | ||
| * such as _local_ (see the documentation). if it is null, it will be populated | ||
| * based on global default settings. | ||
| * such as _local_ (see the documentation). if it is null, it will fall back to _local_ | ||
| * @return single internet address | ||
| */ | ||
| // TODO: needs to be InetAddress[] | ||
| public InetAddress resolvePublishHostAddresses(String publishHosts[]) throws IOException { | ||
| if (publishHosts == null || publishHosts.length == 0) { | ||
| if (GLOBAL_NETWORK_PUBLISHHOST_SETTING.exists(settings) || GLOBAL_NETWORK_HOST_SETTING.exists(settings)) { | ||
| // if we have settings use them (we have a fallback to GLOBAL_NETWORK_HOST_SETTING inline | ||
| publishHosts = GLOBAL_NETWORK_PUBLISHHOST_SETTING.get(settings).toArray(Strings.EMPTY_ARRAY); | ||
| } else { | ||
| // next check any registered custom resolvers if any | ||
| if (customNameResolvers != null) { | ||
| for (CustomNameResolver customNameResolver : customNameResolvers) { | ||
| InetAddress addresses[] = customNameResolver.resolveDefault(); | ||
| if (addresses != null) { | ||
| return addresses[0]; | ||
| } | ||
| // next check any registered custom resolvers if any | ||
| if (customNameResolvers != null) { | ||
| for (CustomNameResolver customNameResolver : customNameResolvers) { | ||
| InetAddress addresses[] = customNameResolver.resolveDefault(); | ||
| if (addresses != null) { | ||
| return addresses[0]; | ||
| } | ||
| } | ||
| // we know it's not here. get the defaults | ||
| publishHosts = GLOBAL_NETWORK_PUBLISHHOST_SETTING.get(settings).toArray(Strings.EMPTY_ARRAY); | ||
| } | ||
| // we know it's not here. get the defaults | ||
| publishHosts = new String[] {DEFAULT_NETWORK_HOST}; | ||
| } | ||
|
|
||
| InetAddress addresses[] = resolveInetAddresses(publishHosts); | ||
|
|
||
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.
nit: I think remove "next", since this is no longer a second step in the method