70
70
import org .elasticsearch .discovery .SeedHostsProvider ;
71
71
import org .elasticsearch .discovery .SeedHostsResolver ;
72
72
import org .elasticsearch .discovery .zen .PendingClusterStateStats ;
73
+ import org .elasticsearch .monitor .NodeHealthService ;
74
+ import org .elasticsearch .monitor .StatusInfo ;
73
75
import org .elasticsearch .threadpool .Scheduler ;
74
76
import org .elasticsearch .threadpool .ThreadPool .Names ;
75
77
import org .elasticsearch .transport .TransportResponse .Empty ;
94
96
import static org .elasticsearch .cluster .coordination .NoMasterBlockService .NO_MASTER_BLOCK_ID ;
95
97
import static org .elasticsearch .gateway .ClusterStateUpdaters .hideStateIfNotRecovered ;
96
98
import static org .elasticsearch .gateway .GatewayService .STATE_NOT_RECOVERED_BLOCK ;
99
+ import static org .elasticsearch .monitor .StatusInfo .Status .UNHEALTHY ;
97
100
98
101
public class Coordinator extends AbstractLifecycleComponent implements Discovery {
99
102
@@ -153,6 +156,7 @@ public class Coordinator extends AbstractLifecycleComponent implements Discovery
153
156
private Optional <Join > lastJoin ;
154
157
private JoinHelper .JoinAccumulator joinAccumulator ;
155
158
private Optional <CoordinatorPublication > currentPublication = Optional .empty ();
159
+ private final NodeHealthService nodeHealthService ;
156
160
157
161
/**
158
162
* @param nodeName The name of the node, used to name the {@link java.util.concurrent.ExecutorService} of the {@link SeedHostsResolver}.
@@ -162,7 +166,7 @@ public Coordinator(String nodeName, Settings settings, ClusterSettings clusterSe
162
166
NamedWriteableRegistry namedWriteableRegistry , AllocationService allocationService , MasterService masterService ,
163
167
Supplier <CoordinationState .PersistedState > persistedStateSupplier , SeedHostsProvider seedHostsProvider ,
164
168
ClusterApplier clusterApplier , Collection <BiConsumer <DiscoveryNode , ClusterState >> onJoinValidators , Random random ,
165
- RerouteService rerouteService , ElectionStrategy electionStrategy ) {
169
+ RerouteService rerouteService , ElectionStrategy electionStrategy , NodeHealthService nodeHealthService ) {
166
170
this .settings = settings ;
167
171
this .transportService = transportService ;
168
172
this .masterService = masterService ;
@@ -172,7 +176,7 @@ public Coordinator(String nodeName, Settings settings, ClusterSettings clusterSe
172
176
this .electionStrategy = electionStrategy ;
173
177
this .joinHelper = new JoinHelper (settings , allocationService , masterService , transportService ,
174
178
this ::getCurrentTerm , this ::getStateForMasterService , this ::handleJoinRequest , this ::joinLeaderInTerm , this .onJoinValidators ,
175
- rerouteService );
179
+ rerouteService , nodeHealthService );
176
180
this .persistedStateSupplier = persistedStateSupplier ;
177
181
this .noMasterBlockService = new NoMasterBlockService (settings , clusterSettings );
178
182
this .lastKnownLeader = Optional .empty ();
@@ -182,14 +186,16 @@ public Coordinator(String nodeName, Settings settings, ClusterSettings clusterSe
182
186
this .publishInfoTimeout = PUBLISH_INFO_TIMEOUT_SETTING .get (settings );
183
187
this .random = random ;
184
188
this .electionSchedulerFactory = new ElectionSchedulerFactory (settings , random , transportService .getThreadPool ());
185
- this .preVoteCollector = new PreVoteCollector (transportService , this ::startElection , this ::updateMaxTermSeen , electionStrategy );
189
+ this .preVoteCollector = new PreVoteCollector (transportService , this ::startElection , this ::updateMaxTermSeen , electionStrategy ,
190
+ nodeHealthService );
186
191
configuredHostsResolver = new SeedHostsResolver (nodeName , settings , transportService , seedHostsProvider );
187
192
this .peerFinder = new CoordinatorPeerFinder (settings , transportService ,
188
193
new HandshakingTransportAddressConnector (settings , transportService ), configuredHostsResolver );
189
194
this .publicationHandler = new PublicationTransportHandler (transportService , namedWriteableRegistry ,
190
195
this ::handlePublishRequest , this ::handleApplyCommit );
191
- this .leaderChecker = new LeaderChecker (settings , transportService , this ::onLeaderFailure );
192
- this .followersChecker = new FollowersChecker (settings , transportService , this ::onFollowerCheckRequest , this ::removeNode );
196
+ this .leaderChecker = new LeaderChecker (settings , transportService , this ::onLeaderFailure , nodeHealthService );
197
+ this .followersChecker = new FollowersChecker (settings , transportService , this ::onFollowerCheckRequest , this ::removeNode ,
198
+ nodeHealthService );
193
199
this .nodeRemovalExecutor = new NodeRemovalClusterStateTaskExecutor (allocationService , logger );
194
200
this .clusterApplier = clusterApplier ;
195
201
masterService .setClusterStateSupplier (this ::getStateForMasterService );
@@ -202,12 +208,13 @@ public Coordinator(String nodeName, Settings settings, ClusterSettings clusterSe
202
208
transportService ::getLocalNode );
203
209
this .clusterFormationFailureHelper = new ClusterFormationFailureHelper (settings , this ::getClusterFormationState ,
204
210
transportService .getThreadPool (), joinHelper ::logLastFailedJoinAttempt );
211
+ this .nodeHealthService = nodeHealthService ;
205
212
}
206
213
207
214
private ClusterFormationState getClusterFormationState () {
208
215
return new ClusterFormationState (settings , getStateForMasterService (), peerFinder .getLastResolvedAddresses (),
209
216
Stream .concat (Stream .of (getLocalNode ()), StreamSupport .stream (peerFinder .getFoundPeers ().spliterator (), false ))
210
- .collect (Collectors .toList ()), getCurrentTerm (), electionStrategy );
217
+ .collect (Collectors .toList ()), getCurrentTerm (), electionStrategy , nodeHealthService . getHealth () );
211
218
}
212
219
213
220
private void onLeaderFailure (Exception e ) {
@@ -1230,6 +1237,12 @@ public void run() {
1230
1237
return ;
1231
1238
}
1232
1239
1240
+ final StatusInfo statusInfo = nodeHealthService .getHealth ();
1241
+ if (statusInfo .getStatus () == UNHEALTHY ) {
1242
+ logger .debug ("skip prevoting as local node is unhealthy: [{}]" , statusInfo .getInfo ());
1243
+ return ;
1244
+ }
1245
+
1233
1246
if (prevotingRound != null ) {
1234
1247
prevotingRound .close ();
1235
1248
}
0 commit comments