From ddd740162e0c0066f5ab458e2310f56e5390cb69 Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Wed, 17 Jul 2019 17:32:47 +0200 Subject: [PATCH] Do not use CancellableThreads for Zen1 (#44430) Zen 1 stops pinging threads in ZenDiscovery by calling Thread.interrupt(). This is incompatible with the CancellableThreads that only allow threads to be interrupted through cancellation. The use of CancellableThreads was introduced in #42844 and added to UnicastZenPing as part of the backport, as both Zen1 and Zen2 share the same SeedHostsResolver implementation. This commit effectively undoes the change in the backport while still allowing to share same implementation. Closes #44425 --- .../discovery/zen/UnicastZenPing.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/discovery/zen/UnicastZenPing.java b/server/src/main/java/org/elasticsearch/discovery/zen/UnicastZenPing.java index 040ebe19fc9..bbbc3697acd 100644 --- a/server/src/main/java/org/elasticsearch/discovery/zen/UnicastZenPing.java +++ b/server/src/main/java/org/elasticsearch/discovery/zen/UnicastZenPing.java @@ -101,8 +101,6 @@ public class UnicastZenPing implements ZenPing { private final AtomicInteger pingingRoundIdGenerator = new AtomicInteger(); - private final CancellableThreads cancellableThreads = new CancellableThreads(); - private final Map activePingingRounds = newConcurrentMap(); // a list of temporal responses a node will return for a request (holds responses from other nodes) @@ -149,13 +147,21 @@ public class UnicastZenPing implements ZenPing { } private SeedHostsProvider.HostsResolver createHostsResolver() { - return hosts -> SeedHostsResolver.resolveHostsLists(cancellableThreads, unicastZenPingExecutorService, logger, hosts, - transportService, resolveTimeout); + return hosts -> SeedHostsResolver.resolveHostsLists( + new CancellableThreads() { + public void execute(Interruptible interruptible) { + try { + interruptible.run(); + } catch (InterruptedException e) { + throw new CancellableThreads.ExecutionCancelledException("interrupted by " + e); + } + } + }, + unicastZenPingExecutorService, logger, hosts, transportService, resolveTimeout); } @Override public void close() { - cancellableThreads.cancel("stopping UnicastZenPing"); ThreadPool.terminate(unicastZenPingExecutorService, 10, TimeUnit.SECONDS); Releasables.close(activePingingRounds.values()); closed = true;