Skip to content

Commit 5a7c8bb

Browse files
authored
Cleanup network / transport related settings (#25489)
This commit makes the use of the global network settings explicit instead of implicit within NetworkService. It cleans up several places where we fall back to the global settings while we should have used tcp or http ones. In addition this change also removes unnecessary settings classes
1 parent 2975e7f commit 5a7c8bb

File tree

44 files changed

+231
-301
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+231
-301
lines changed

core/src/main/java/org/elasticsearch/bootstrap/Security.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.elasticsearch.env.Environment;
2828
import org.elasticsearch.http.HttpTransportSettings;
2929
import org.elasticsearch.plugins.PluginInfo;
30-
import org.elasticsearch.transport.TransportSettings;
30+
import org.elasticsearch.transport.TcpTransport;
3131

3232
import java.io.FilePermission;
3333
import java.io.IOException;
@@ -324,8 +324,8 @@ private static void addSocketPermissionForTransportProfiles(
324324
final Permissions policy,
325325
final Settings settings) {
326326
// transport is way over-engineered
327-
final Map<String, Settings> profiles = new HashMap<>(TransportSettings.TRANSPORT_PROFILES_SETTING.get(settings).getAsGroups());
328-
profiles.putIfAbsent(TransportSettings.DEFAULT_PROFILE, Settings.EMPTY);
327+
final Map<String, Settings> profiles = new HashMap<>(TcpTransport.TRANSPORT_PROFILES_SETTING.get(settings).getAsGroups());
328+
profiles.putIfAbsent(TcpTransport.DEFAULT_PROFILE, Settings.EMPTY);
329329

330330
// loop through all profiles and add permissions for each one, if it's valid; otherwise Netty transports are lenient and ignores it
331331
for (final Map.Entry<String, Settings> entry : profiles.entrySet()) {
@@ -335,7 +335,7 @@ private static void addSocketPermissionForTransportProfiles(
335335
// a profile is only valid if it's the default profile, or if it has an actual name and specifies a port
336336
// TODO: can this leniency be removed?
337337
final boolean valid =
338-
TransportSettings.DEFAULT_PROFILE.equals(name) ||
338+
TcpTransport.DEFAULT_PROFILE.equals(name) ||
339339
(name != null && name.length() > 0 && profileSettings.get("port") != null);
340340
if (valid) {
341341
final String transportRange = profileSettings.get("port");
@@ -355,7 +355,7 @@ private static void addSocketPermissionForTransportProfiles(
355355
* @param settings the {@link Settings} instance to read the transport settings from
356356
*/
357357
private static void addSocketPermissionForTransport(final Permissions policy, final Settings settings) {
358-
final String transportRange = TransportSettings.PORT.get(settings);
358+
final String transportRange = TcpTransport.PORT.get(settings);
359359
addSocketPermissionForPortRange(policy, transportRange);
360360
}
361361

core/src/main/java/org/elasticsearch/client/transport/TransportClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private static ClientTemplate buildTemplate(Settings providedSettings, Settings
127127
final List<Closeable> resourcesToClose = new ArrayList<>();
128128
final ThreadPool threadPool = new ThreadPool(settings);
129129
resourcesToClose.add(() -> ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS));
130-
final NetworkService networkService = new NetworkService(settings, Collections.emptyList());
130+
final NetworkService networkService = new NetworkService(Collections.emptyList());
131131
try {
132132
final List<Setting<?>> additionalSettings = new ArrayList<>(pluginsService.getPluginSettings());
133133
final List<String> additionalSettingsFilter = new ArrayList<>(pluginsService.getPluginSettingsFilter());

core/src/main/java/org/elasticsearch/common/network/NetworkService.java

Lines changed: 33 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -19,50 +19,46 @@
1919

2020
package org.elasticsearch.common.network;
2121

22-
import org.elasticsearch.common.Strings;
23-
import org.elasticsearch.common.component.AbstractComponent;
2422
import org.elasticsearch.common.settings.Setting;
2523
import org.elasticsearch.common.settings.Setting.Property;
26-
import org.elasticsearch.common.settings.Settings;
2724
import org.elasticsearch.common.unit.ByteSizeValue;
2825
import org.elasticsearch.common.unit.TimeValue;
2926

3027
import java.io.IOException;
3128
import java.net.InetAddress;
3229
import java.util.ArrayList;
3330
import java.util.Arrays;
31+
import java.util.Collections;
3432
import java.util.HashSet;
3533
import java.util.List;
34+
import java.util.Objects;
3635
import java.util.concurrent.TimeUnit;
3736
import java.util.function.Function;
3837

39-
public class NetworkService extends AbstractComponent {
38+
public final class NetworkService {
4039

4140
/** By default, we bind to loopback interfaces */
4241
public static final String DEFAULT_NETWORK_HOST = "_local_";
43-
4442
public static final Setting<List<String>> GLOBAL_NETWORK_HOST_SETTING =
45-
Setting.listSetting("network.host", Arrays.asList(DEFAULT_NETWORK_HOST), Function.identity(), Property.NodeScope);
43+
Setting.listSetting("network.host", Collections.emptyList(), Function.identity(), Property.NodeScope);
4644
public static final Setting<List<String>> GLOBAL_NETWORK_BINDHOST_SETTING =
4745
Setting.listSetting("network.bind_host", GLOBAL_NETWORK_HOST_SETTING, Function.identity(), Property.NodeScope);
4846
public static final Setting<List<String>> GLOBAL_NETWORK_PUBLISHHOST_SETTING =
4947
Setting.listSetting("network.publish_host", GLOBAL_NETWORK_HOST_SETTING, Function.identity(), Property.NodeScope);
5048
public static final Setting<Boolean> NETWORK_SERVER = Setting.boolSetting("network.server", true, Property.NodeScope);
5149

52-
public static final class TcpSettings {
53-
public static final Setting<Boolean> TCP_NO_DELAY =
54-
Setting.boolSetting("network.tcp.no_delay", true, Property.NodeScope);
55-
public static final Setting<Boolean> TCP_KEEP_ALIVE =
56-
Setting.boolSetting("network.tcp.keep_alive", true, Property.NodeScope);
57-
public static final Setting<Boolean> TCP_REUSE_ADDRESS =
58-
Setting.boolSetting("network.tcp.reuse_address", NetworkUtils.defaultReuseAddress(), Property.NodeScope);
59-
public static final Setting<ByteSizeValue> TCP_SEND_BUFFER_SIZE =
60-
Setting.byteSizeSetting("network.tcp.send_buffer_size", new ByteSizeValue(-1), Property.NodeScope);
61-
public static final Setting<ByteSizeValue> TCP_RECEIVE_BUFFER_SIZE =
62-
Setting.byteSizeSetting("network.tcp.receive_buffer_size", new ByteSizeValue(-1), Property.NodeScope);
63-
public static final Setting<TimeValue> TCP_CONNECT_TIMEOUT =
64-
Setting.timeSetting("network.tcp.connect_timeout", new TimeValue(30, TimeUnit.SECONDS), Property.NodeScope);
65-
}
50+
public static final Setting<Boolean> TCP_NO_DELAY =
51+
Setting.boolSetting("network.tcp.no_delay", true, Property.NodeScope);
52+
public static final Setting<Boolean> TCP_KEEP_ALIVE =
53+
Setting.boolSetting("network.tcp.keep_alive", true, Property.NodeScope);
54+
public static final Setting<Boolean> TCP_REUSE_ADDRESS =
55+
Setting.boolSetting("network.tcp.reuse_address", NetworkUtils.defaultReuseAddress(), Property.NodeScope);
56+
public static final Setting<ByteSizeValue> TCP_SEND_BUFFER_SIZE =
57+
Setting.byteSizeSetting("network.tcp.send_buffer_size", new ByteSizeValue(-1), Property.NodeScope);
58+
public static final Setting<ByteSizeValue> TCP_RECEIVE_BUFFER_SIZE =
59+
Setting.byteSizeSetting("network.tcp.receive_buffer_size", new ByteSizeValue(-1), Property.NodeScope);
60+
public static final Setting<TimeValue> TCP_CONNECT_TIMEOUT =
61+
Setting.timeSetting("network.tcp.connect_timeout", new TimeValue(30, TimeUnit.SECONDS), Property.NodeScope);
6662

6763
/**
6864
* A custom name resolver can support custom lookup keys (my_net_key:ipv4) and also change
@@ -82,39 +78,29 @@ public interface CustomNameResolver {
8278

8379
private final List<CustomNameResolver> customNameResolvers;
8480

85-
public NetworkService(Settings settings, List<CustomNameResolver> customNameResolvers) {
86-
super(settings);
87-
this.customNameResolvers = customNameResolvers;
81+
public NetworkService(List<CustomNameResolver> customNameResolvers) {
82+
this.customNameResolvers = Objects.requireNonNull(customNameResolvers, "customNameResolvers must be non null");
8883
}
8984

9085
/**
9186
* Resolves {@code bindHosts} to a list of internet addresses. The list will
9287
* not contain duplicate addresses.
9388
*
9489
* @param bindHosts list of hosts to bind to. this may contain special pseudo-hostnames
95-
* such as _local_ (see the documentation). if it is null, it will be populated
96-
* based on global default settings.
90+
* such as _local_ (see the documentation). if it is null, it will fall back to _local_
91+
*
9792
* @return unique set of internet addresses
9893
*/
9994
public InetAddress[] resolveBindHostAddresses(String bindHosts[]) throws IOException {
100-
// first check settings
10195
if (bindHosts == null || bindHosts.length == 0) {
102-
if (GLOBAL_NETWORK_BINDHOST_SETTING.exists(settings) || GLOBAL_NETWORK_HOST_SETTING.exists(settings)) {
103-
// if we have settings use them (we have a fallback to GLOBAL_NETWORK_HOST_SETTING inline
104-
bindHosts = GLOBAL_NETWORK_BINDHOST_SETTING.get(settings).toArray(Strings.EMPTY_ARRAY);
105-
} else {
106-
// next check any registered custom resolvers if any
107-
if (customNameResolvers != null) {
108-
for (CustomNameResolver customNameResolver : customNameResolvers) {
109-
InetAddress addresses[] = customNameResolver.resolveDefault();
110-
if (addresses != null) {
111-
return addresses;
112-
}
113-
}
96+
for (CustomNameResolver customNameResolver : customNameResolvers) {
97+
InetAddress addresses[] = customNameResolver.resolveDefault();
98+
if (addresses != null) {
99+
return addresses;
114100
}
115-
// we know it's not here. get the defaults
116-
bindHosts = GLOBAL_NETWORK_BINDHOST_SETTING.get(settings).toArray(Strings.EMPTY_ARRAY);
117101
}
102+
// we know it's not here. get the defaults
103+
bindHosts = new String[] {"_local_"};
118104
}
119105

120106
InetAddress addresses[] = resolveInetAddresses(bindHosts);
@@ -140,29 +126,20 @@ public InetAddress[] resolveBindHostAddresses(String bindHosts[]) throws IOExcep
140126
* If {@code publishHosts} resolves to more than one address, <b>then one is selected with magic</b>
141127
*
142128
* @param publishHosts list of hosts to publish as. this may contain special pseudo-hostnames
143-
* such as _local_ (see the documentation). if it is null, it will be populated
144-
* based on global default settings.
129+
* such as _local_ (see the documentation). if it is null, it will fall back to _local_
145130
* @return single internet address
146131
*/
147132
// TODO: needs to be InetAddress[]
148133
public InetAddress resolvePublishHostAddresses(String publishHosts[]) throws IOException {
149134
if (publishHosts == null || publishHosts.length == 0) {
150-
if (GLOBAL_NETWORK_PUBLISHHOST_SETTING.exists(settings) || GLOBAL_NETWORK_HOST_SETTING.exists(settings)) {
151-
// if we have settings use them (we have a fallback to GLOBAL_NETWORK_HOST_SETTING inline
152-
publishHosts = GLOBAL_NETWORK_PUBLISHHOST_SETTING.get(settings).toArray(Strings.EMPTY_ARRAY);
153-
} else {
154-
// next check any registered custom resolvers if any
155-
if (customNameResolvers != null) {
156-
for (CustomNameResolver customNameResolver : customNameResolvers) {
157-
InetAddress addresses[] = customNameResolver.resolveDefault();
158-
if (addresses != null) {
159-
return addresses[0];
160-
}
161-
}
135+
for (CustomNameResolver customNameResolver : customNameResolvers) {
136+
InetAddress addresses[] = customNameResolver.resolveDefault();
137+
if (addresses != null) {
138+
return addresses[0];
162139
}
163-
// we know it's not here. get the defaults
164-
publishHosts = GLOBAL_NETWORK_PUBLISHHOST_SETTING.get(settings).toArray(Strings.EMPTY_ARRAY);
165140
}
141+
// we know it's not here. get the defaults
142+
publishHosts = new String[] {DEFAULT_NETWORK_HOST};
166143
}
167144

168145
InetAddress addresses[] = resolveInetAddresses(publishHosts);

core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
import org.elasticsearch.transport.TcpTransport;
9292
import org.elasticsearch.transport.Transport;
9393
import org.elasticsearch.transport.TransportService;
94-
import org.elasticsearch.transport.TransportSettings;
9594
import org.elasticsearch.tribe.TribeService;
9695
import org.elasticsearch.watcher.ResourceWatcherService;
9796

@@ -270,12 +269,12 @@ public void apply(Settings value, Settings current, Settings previous) {
270269
HierarchyCircuitBreakerService.FIELDDATA_CIRCUIT_BREAKER_TYPE_SETTING,
271270
HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_TYPE_SETTING,
272271
Transport.TRANSPORT_TCP_COMPRESS,
273-
TransportSettings.TRANSPORT_PROFILES_SETTING,
274-
TransportSettings.HOST,
275-
TransportSettings.PUBLISH_HOST,
276-
TransportSettings.BIND_HOST,
277-
TransportSettings.PUBLISH_PORT,
278-
TransportSettings.PORT,
272+
TcpTransport.TRANSPORT_PROFILES_SETTING,
273+
TcpTransport.HOST,
274+
TcpTransport.PUBLISH_HOST,
275+
TcpTransport.BIND_HOST,
276+
TcpTransport.PUBLISH_PORT,
277+
TcpTransport.PORT,
279278
TcpTransport.CONNECTIONS_PER_NODE_RECOVERY,
280279
TcpTransport.CONNECTIONS_PER_NODE_BULK,
281280
TcpTransport.CONNECTIONS_PER_NODE_REG,
@@ -292,12 +291,12 @@ public void apply(Settings value, Settings current, Settings previous) {
292291
NetworkService.GLOBAL_NETWORK_HOST_SETTING,
293292
NetworkService.GLOBAL_NETWORK_BINDHOST_SETTING,
294293
NetworkService.GLOBAL_NETWORK_PUBLISHHOST_SETTING,
295-
NetworkService.TcpSettings.TCP_NO_DELAY,
296-
NetworkService.TcpSettings.TCP_KEEP_ALIVE,
297-
NetworkService.TcpSettings.TCP_REUSE_ADDRESS,
298-
NetworkService.TcpSettings.TCP_SEND_BUFFER_SIZE,
299-
NetworkService.TcpSettings.TCP_RECEIVE_BUFFER_SIZE,
300-
NetworkService.TcpSettings.TCP_CONNECT_TIMEOUT,
294+
NetworkService.TCP_NO_DELAY,
295+
NetworkService.TCP_KEEP_ALIVE,
296+
NetworkService.TCP_REUSE_ADDRESS,
297+
NetworkService.TCP_SEND_BUFFER_SIZE,
298+
NetworkService.TCP_RECEIVE_BUFFER_SIZE,
299+
NetworkService.TCP_CONNECT_TIMEOUT,
301300
IndexSettings.QUERY_STRING_ANALYZE_WILDCARD,
302301
IndexSettings.QUERY_STRING_ALLOW_LEADING_WILDCARD,
303302
ScriptService.SCRIPT_CACHE_SIZE_SETTING,

core/src/main/java/org/elasticsearch/node/Node.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import org.elasticsearch.cluster.routing.RoutingService;
5353
import org.elasticsearch.cluster.service.ClusterService;
5454
import org.elasticsearch.common.StopWatch;
55-
import org.elasticsearch.common.SuppressForbidden;
5655
import org.elasticsearch.common.component.Lifecycle;
5756
import org.elasticsearch.common.component.LifecycleComponent;
5857
import org.elasticsearch.common.inject.Binder;
@@ -61,7 +60,6 @@
6160
import org.elasticsearch.common.inject.Module;
6261
import org.elasticsearch.common.inject.ModulesBuilder;
6362
import org.elasticsearch.common.inject.util.Providers;
64-
import org.elasticsearch.common.io.PathUtils;
6563
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
6664
import org.elasticsearch.common.lease.Releasables;
6765
import org.elasticsearch.common.logging.DeprecationLogger;
@@ -151,9 +149,7 @@
151149
import java.util.Collection;
152150
import java.util.Collections;
153151
import java.util.List;
154-
import java.util.Locale;
155152
import java.util.Map;
156-
import java.util.Set;
157153
import java.util.concurrent.CountDownLatch;
158154
import java.util.concurrent.TimeUnit;
159155
import java.util.function.Consumer;
@@ -330,7 +326,7 @@ protected Node(final Environment environment, Collection<Class<? extends Plugin>
330326
final SettingsModule settingsModule = new SettingsModule(this.settings, additionalSettings, additionalSettingsFilter);
331327
scriptModule.registerClusterSettingsListeners(settingsModule.getClusterSettings());
332328
resourcesToClose.add(resourceWatcherService);
333-
final NetworkService networkService = new NetworkService(settings,
329+
final NetworkService networkService = new NetworkService(
334330
getCustomNameResolvers(pluginsService.filterPlugins(DiscoveryPlugin.class)));
335331
final ClusterService clusterService = new ClusterService(settings, settingsModule.getClusterSettings(), threadPool);
336332
clusterService.addListener(scriptModule.getScriptService());

0 commit comments

Comments
 (0)