Skip to content

Commit 15a2bf6

Browse files
committed
Lazy resolve unicast hosts
Today we eagerly resolve unicast hosts. This means that if DNS changes, we will never find the host at the new address. Moreover, a single host failng to resolve causes startup to abort. This commit introduces lazy resolution of unicast hosts. If a DNS entry changes, there is an opportunity for the host to be discovered. Note that under the Java security manager, there is a default positive cache of infinity for resolved hosts; this means that if a user does want to operate in an environment where DNS can change, they must adjust networkaddress.cache.ttl in their security policy. And if a host fails to resolve, we warn log the hostname but continue pinging other configured hosts. When doing DNS resolutions for unicast hostnames, we wait until the DNS lookups timeout. This appears to be forty-five seconds on modern JVMs, and it is not configurable. If we do these serially, the cluster can be blocked during ping for a lengthy period of time. This commit introduces doing the DNS lookups in parallel, and adds a user-configurable timeout for these lookups. Relates #21630
1 parent 236f6e8 commit 15a2bf6

File tree

15 files changed

+668
-140
lines changed

15 files changed

+668
-140
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@
5555
import org.elasticsearch.discovery.DiscoveryModule;
5656
import org.elasticsearch.discovery.DiscoverySettings;
5757
import org.elasticsearch.discovery.zen.ElectMasterService;
58-
import org.elasticsearch.discovery.zen.ZenDiscovery;
5958
import org.elasticsearch.discovery.zen.FaultDetection;
6059
import org.elasticsearch.discovery.zen.UnicastZenPing;
60+
import org.elasticsearch.discovery.zen.ZenDiscovery;
6161
import org.elasticsearch.env.Environment;
6262
import org.elasticsearch.env.NodeEnvironment;
6363
import org.elasticsearch.gateway.GatewayService;
@@ -344,6 +344,7 @@ public void apply(Settings value, Settings current, Settings previous) {
344344
ZenDiscovery.MASTER_ELECTION_IGNORE_NON_MASTER_PINGS_SETTING,
345345
UnicastZenPing.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING,
346346
UnicastZenPing.DISCOVERY_ZEN_PING_UNICAST_CONCURRENT_CONNECTS_SETTING,
347+
UnicastZenPing.DISCOVERY_ZEN_PING_UNICAST_HOSTS_RESOLVE_TIMEOUT,
347348
SearchService.DEFAULT_KEEPALIVE_SETTING,
348349
SearchService.KEEPALIVE_INTERVAL_SETTING,
349350
SearchService.LOW_LEVEL_CANCELLATION_SETTING,

core/src/main/java/org/elasticsearch/discovery/zen/UnicastZenPing.java

Lines changed: 130 additions & 42 deletions
Large diffs are not rendered by default.

core/src/main/java/org/elasticsearch/transport/TcpTransport.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import com.carrotsearch.hppc.IntHashSet;
2222
import com.carrotsearch.hppc.IntSet;
23-
2423
import org.apache.logging.log4j.message.ParameterizedMessage;
2524
import org.apache.logging.log4j.util.Supplier;
2625
import org.apache.lucene.util.IOUtils;
@@ -716,7 +715,7 @@ public static int resolvePublishPort(String profileName, Settings settings, Sett
716715
}
717716

718717
@Override
719-
public TransportAddress[] addressesFromString(String address, int perAddressLimit) throws Exception {
718+
public TransportAddress[] addressesFromString(String address, int perAddressLimit) throws UnknownHostException {
720719
return parse(address, settings.get("transport.profiles.default.port", TransportSettings.PORT.get(settings)), perAddressLimit);
721720
}
722721

core/src/main/java/org/elasticsearch/transport/Transport.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.elasticsearch.common.transport.TransportAddress;
3030

3131
import java.io.IOException;
32+
import java.net.UnknownHostException;
3233
import java.util.List;
3334
import java.util.Map;
3435

@@ -56,7 +57,7 @@ public interface Transport extends LifecycleComponent {
5657
/**
5758
* Returns an address from its string representation.
5859
*/
59-
TransportAddress[] addressesFromString(String address, int perAddressLimit) throws Exception;
60+
TransportAddress[] addressesFromString(String address, int perAddressLimit) throws UnknownHostException;
6061

6162
/**
6263
* Is the address type supported.

core/src/main/java/org/elasticsearch/transport/TransportService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.elasticsearch.threadpool.ThreadPool;
5353

5454
import java.io.IOException;
55+
import java.net.UnknownHostException;
5556
import java.util.Arrays;
5657
import java.util.Collections;
5758
import java.util.LinkedHashMap;
@@ -622,7 +623,7 @@ private long newRequestId() {
622623
return requestIds.getAndIncrement();
623624
}
624625

625-
public TransportAddress[] addressesFromString(String address, int perAddressLimit) throws Exception {
626+
public TransportAddress[] addressesFromString(String address, int perAddressLimit) throws UnknownHostException {
626627
return transport.addressesFromString(address, perAddressLimit);
627628
}
628629

core/src/test/java/org/elasticsearch/client/transport/FailAndRetryMockTransport.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.elasticsearch.transport.TransportServiceAdapter;
3838

3939
import java.io.IOException;
40+
import java.net.UnknownHostException;
4041
import java.util.Collections;
4142
import java.util.Map;
4243
import java.util.Random;
@@ -133,7 +134,7 @@ public BoundTransportAddress boundAddress() {
133134
}
134135

135136
@Override
136-
public TransportAddress[] addressesFromString(String address, int perAddressLimit) throws Exception {
137+
public TransportAddress[] addressesFromString(String address, int perAddressLimit) throws UnknownHostException {
137138
throw new UnsupportedOperationException();
138139
}
139140

core/src/test/java/org/elasticsearch/cluster/NodeConnectionsServiceTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.junit.Before;
4444

4545
import java.io.IOException;
46+
import java.net.UnknownHostException;
4647
import java.util.ArrayList;
4748
import java.util.Arrays;
4849
import java.util.Collections;
@@ -189,7 +190,7 @@ public Map<String, BoundTransportAddress> profileBoundAddresses() {
189190
}
190191

191192
@Override
192-
public TransportAddress[] addressesFromString(String address, int perAddressLimit) throws Exception {
193+
public TransportAddress[] addressesFromString(String address, int perAddressLimit) throws UnknownHostException {
193194
return new TransportAddress[0];
194195
}
195196

0 commit comments

Comments
 (0)