@@ -98,7 +98,7 @@ public class UnicastZenPing extends AbstractComponent implements ZenPing {
9898 public static final Setting <Integer > DISCOVERY_ZEN_PING_UNICAST_CONCURRENT_CONNECTS_SETTING =
9999 Setting .intSetting ("discovery.zen.ping.unicast.concurrent_connects" , 10 , 0 , Property .NodeScope );
100100 public static final Setting <TimeValue > DISCOVERY_ZEN_PING_UNICAST_HOSTS_RESOLVE_TIMEOUT =
101- Setting .positiveTimeSetting ("discovery.zen.ping.unicast.hosts.resolve_timeout" , TimeValue .timeValueSeconds (30 ), Property .NodeScope );
101+ Setting .positiveTimeSetting ("discovery.zen.ping.unicast.hosts.resolve_timeout" , TimeValue .timeValueSeconds (1 ), Property .NodeScope );
102102
103103 // these limits are per-address
104104 public static final int LIMIT_FOREIGN_PORTS_COUNT = 1 ;
@@ -131,7 +131,7 @@ public class UnicastZenPing extends AbstractComponent implements ZenPing {
131131
132132 private final UnicastHostsProvider hostsProvider ;
133133
134- private final ExecutorService unicastConnectExecutor ;
134+ private final ExecutorService unicastZenPingExecutorService ;
135135
136136 private final TimeValue resolveTimeout ;
137137
@@ -166,10 +166,14 @@ public UnicastZenPing(Settings settings, ThreadPool threadPool, TransportService
166166 transportService .registerRequestHandler (ACTION_NAME , UnicastPingRequest ::new , ThreadPool .Names .SAME ,
167167 new UnicastPingRequestHandler ());
168168
169- ThreadFactory threadFactory = EsExecutors .daemonThreadFactory (settings , "[unicast_connect]" );
170- unicastConnectExecutor = EsExecutors .newScaling ("unicast_connect" , 0 , concurrentConnects , 60 , TimeUnit .SECONDS ,
171- threadFactory , threadPool .getThreadContext ());
172-
169+ final ThreadFactory threadFactory = EsExecutors .daemonThreadFactory (settings , "[unicast_connect]" );
170+ unicastZenPingExecutorService = EsExecutors .newScaling (
171+ "unicast_connect" ,
172+ 0 , concurrentConnects ,
173+ 60 ,
174+ TimeUnit .SECONDS ,
175+ threadFactory ,
176+ threadPool .getThreadContext ());
173177 }
174178
175179 private static class ResolvedHostname {
@@ -209,9 +213,9 @@ public UnknownHostException failure() {
209213 /**
210214 * Resolves a list of hosts to a list of discovery nodes. Each host is resolved into a transport address (or a collection of addresses
211215 * if the number of ports is greater than one) and the transport addresses are used to created discovery nodes. Host lookups are done
212- * in parallel using the generic thread pool from the specified thread pool up to the specified resolve timeout.
216+ * in parallel using specified executor service up to the specified resolve timeout.
213217 *
214- * @param threadPool the thread pool used to parallelize hostname lookups
218+ * @param executorService the executor service used to parallelize hostname lookups
215219 * @param logger logger used for logging messages regarding hostname lookups
216220 * @param hosts the hosts to resolve
217221 * @param limitPortCounts the number of ports to resolve (should be 1 for non-local transport)
@@ -221,14 +225,14 @@ public UnknownHostException failure() {
221225 * @return a list of discovery nodes with resolved transport addresses
222226 */
223227 public static List <DiscoveryNode > resolveDiscoveryNodes (
224- final ThreadPool threadPool ,
228+ final ExecutorService executorService ,
225229 final Logger logger ,
226230 final List <String > hosts ,
227231 final int limitPortCounts ,
228232 final TransportService transportService ,
229233 final Supplier <String > idGenerator ,
230234 final TimeValue resolveTimeout ) throws InterruptedException {
231- Objects .requireNonNull (threadPool );
235+ Objects .requireNonNull (executorService );
232236 Objects .requireNonNull (logger );
233237 Objects .requireNonNull (hosts );
234238 Objects .requireNonNull (transportService );
@@ -241,7 +245,7 @@ public static List<DiscoveryNode> resolveDiscoveryNodes(
241245 final List <Callable <ResolvedHostname >> callables =
242246 hosts .stream ().map (hn -> lookup (hn , transportService , limitPortCounts )).collect (Collectors .toList ());
243247 final List <Future <ResolvedHostname >> futures =
244- threadPool . generic () .invokeAll (callables , resolveTimeout .nanos (), TimeUnit .NANOSECONDS );
248+ executorService .invokeAll (callables , resolveTimeout .nanos (), TimeUnit .NANOSECONDS );
245249 final List <DiscoveryNode > discoveryNodes = new ArrayList <>();
246250 // ExecutorService#invokeAll guarantees that the futures are returned in the iteration order of the tasks so we can associate the
247251 // hostname with the corresponding task by iterating together
@@ -300,7 +304,7 @@ private static Callable<ResolvedHostname> lookup(
300304
301305 @ Override
302306 public void close () {
303- ThreadPool .terminate (unicastConnectExecutor , 0 , TimeUnit .SECONDS );
307+ ThreadPool .terminate (unicastZenPingExecutorService , 0 , TimeUnit .SECONDS );
304308 Releasables .close (receivedResponses .values ());
305309 closed = true ;
306310 }
@@ -335,25 +339,38 @@ Collection<PingResponse> pingAndWait(TimeValue duration) {
335339
336340 @ Override
337341 public void ping (final PingListener listener , final TimeValue duration ) {
342+ final List <DiscoveryNode > resolvedDiscoveryNodes ;
343+ try {
344+ resolvedDiscoveryNodes = resolveDiscoveryNodes (
345+ unicastZenPingExecutorService ,
346+ logger ,
347+ configuredHosts ,
348+ limitPortCounts ,
349+ transportService ,
350+ () -> UNICAST_NODE_PREFIX + unicastNodeIdGenerator .incrementAndGet () + "#" ,
351+ resolveTimeout );
352+ } catch (InterruptedException e ) {
353+ throw new RuntimeException (e );
354+ }
338355 final SendPingsHandler sendPingsHandler = new SendPingsHandler (pingHandlerIdGenerator .incrementAndGet ());
339356 try {
340357 receivedResponses .put (sendPingsHandler .id (), sendPingsHandler );
341358 try {
342- sendPings (duration , null , sendPingsHandler );
359+ sendPings (duration , null , sendPingsHandler , resolvedDiscoveryNodes );
343360 } catch (RejectedExecutionException e ) {
344361 logger .debug ("Ping execution rejected" , e );
345- // The RejectedExecutionException can come from the fact unicastConnectExecutor is at its max down in sendPings
362+ // The RejectedExecutionException can come from the fact unicastZenPingExecutorService is at its max down in sendPings
346363 // But don't bail here, we can retry later on after the send ping has been scheduled.
347364 }
348365
349366 threadPool .schedule (TimeValue .timeValueMillis (duration .millis () / 2 ), ThreadPool .Names .GENERIC , new AbstractRunnable () {
350367 @ Override
351368 protected void doRun () {
352- sendPings (duration , null , sendPingsHandler );
369+ sendPings (duration , null , sendPingsHandler , resolvedDiscoveryNodes );
353370 threadPool .schedule (TimeValue .timeValueMillis (duration .millis () / 2 ), ThreadPool .Names .GENERIC , new AbstractRunnable () {
354371 @ Override
355372 protected void doRun () throws Exception {
356- sendPings (duration , TimeValue .timeValueMillis (duration .millis () / 2 ), sendPingsHandler );
373+ sendPings (duration , TimeValue .timeValueMillis (duration .millis () / 2 ), sendPingsHandler , resolvedDiscoveryNodes );
357374 sendPingsHandler .close ();
358375 listener .onPing (sendPingsHandler .pingCollection ().toList ());
359376 for (DiscoveryNode node : sendPingsHandler .nodeToDisconnect ) {
@@ -418,7 +435,11 @@ public void close() {
418435 }
419436
420437
421- void sendPings (final TimeValue timeout , @ Nullable TimeValue waitTime , final SendPingsHandler sendPingsHandler ) {
438+ void sendPings (
439+ final TimeValue timeout ,
440+ @ Nullable TimeValue waitTime ,
441+ final SendPingsHandler sendPingsHandler ,
442+ final List <DiscoveryNode > resolvedDiscoveryNodes ) {
422443 final UnicastPingRequest pingRequest = new UnicastPingRequest ();
423444 pingRequest .id = sendPingsHandler .id ();
424445 pingRequest .timeout = timeout ;
@@ -444,22 +465,8 @@ void sendPings(final TimeValue timeout, @Nullable TimeValue waitTime, final Send
444465 List <DiscoveryNode > sortedNodesToPing = ElectMasterService .sortByMasterLikelihood (nodesToPingSet );
445466
446467 // add the configured hosts first
447- final List <DiscoveryNode > nodesToPing = new ArrayList <>();
448- final List <DiscoveryNode > resolvedDiscoveryNodes ;
449- try {
450- resolvedDiscoveryNodes = resolveDiscoveryNodes (
451- threadPool ,
452- logger ,
453- configuredHosts ,
454- limitPortCounts ,
455- transportService ,
456- () -> UNICAST_NODE_PREFIX + unicastNodeIdGenerator .incrementAndGet () + "#" ,
457- resolveTimeout );
458- nodesToPing .addAll (resolvedDiscoveryNodes );
459- } catch (final InterruptedException e ) {
460- throw new RuntimeException (e );
461- }
462-
468+ final List <DiscoveryNode > nodesToPing = new ArrayList <>(resolvedDiscoveryNodes .size () + sortedNodesToPing .size ());
469+ nodesToPing .addAll (resolvedDiscoveryNodes );
463470 nodesToPing .addAll (sortedNodesToPing );
464471
465472 final CountDownLatch latch = new CountDownLatch (nodesToPing .size ());
@@ -497,7 +504,7 @@ void sendPings(final TimeValue timeout, @Nullable TimeValue waitTime, final Send
497504 }
498505 // fork the connection to another thread
499506 final DiscoveryNode finalNodeToSend = nodeToSend ;
500- unicastConnectExecutor .execute (new Runnable () {
507+ unicastZenPingExecutorService .execute (new Runnable () {
501508 @ Override
502509 public void run () {
503510 if (sendPingsHandler .isClosed ()) {
0 commit comments