|
22 | 22 | import org.apache.logging.log4j.Logger;
|
23 | 23 | import org.apache.logging.log4j.message.ParameterizedMessage;
|
24 | 24 | import org.elasticsearch.Assertions;
|
25 |
| -import org.elasticsearch.action.ActionListener; |
26 | 25 | import org.elasticsearch.action.support.PlainActionFuture;
|
27 | 26 | import org.elasticsearch.cluster.AckedClusterStateTaskListener;
|
28 | 27 | import org.elasticsearch.cluster.ClusterChangedEvent;
|
@@ -249,50 +248,43 @@ protected boolean blockingAllowed() {
|
249 | 248 | };
|
250 | 249 | clusterStatePublisher.publish(clusterChangedEvent, fut, taskOutputs.createAckListener(threadPool, clusterChangedEvent.state()));
|
251 | 250 |
|
252 |
| - final ActionListener<Void> publishListener = getPublishListener(clusterChangedEvent, taskOutputs, startTimeNS); |
253 | 251 | // indefinitely wait for publication to complete
|
254 | 252 | try {
|
255 | 253 | FutureUtils.get(fut);
|
256 |
| - publishListener.onResponse(null); |
| 254 | + onPublicationSuccess(clusterChangedEvent, taskOutputs, startTimeNS); |
257 | 255 | } catch (Exception e) {
|
258 |
| - publishListener.onFailure(e); |
| 256 | + onPublicationFailed(clusterChangedEvent, taskOutputs, startTimeNS, e); |
259 | 257 | }
|
260 | 258 | }
|
261 | 259 |
|
262 |
| - protected ActionListener<Void> getPublishListener(ClusterChangedEvent clusterChangedEvent, TaskOutputs taskOutputs, long startTimeNS) { |
263 |
| - return new ActionListener<Void>() { |
| 260 | + protected void onPublicationSuccess(ClusterChangedEvent clusterChangedEvent, TaskOutputs taskOutputs, long startTimeNS) { |
| 261 | + taskOutputs.processedDifferentClusterState(clusterChangedEvent.previousState(), clusterChangedEvent.state()); |
264 | 262 |
|
265 |
| - @Override |
266 |
| - public void onResponse(Void ignore) { |
267 |
| - taskOutputs.processedDifferentClusterState(clusterChangedEvent.previousState(), clusterChangedEvent.state()); |
268 |
| - |
269 |
| - try { |
270 |
| - taskOutputs.clusterStatePublished(clusterChangedEvent); |
271 |
| - } catch (Exception e) { |
272 |
| - logger.error(() -> new ParameterizedMessage( |
273 |
| - "exception thrown while notifying executor of new cluster state publication [{}]", |
274 |
| - clusterChangedEvent.source()), e); |
275 |
| - } |
276 |
| - TimeValue executionTime = TimeValue.timeValueMillis(Math.max(0, TimeValue.nsecToMSec(currentTimeInNanos() - startTimeNS))); |
277 |
| - logger.debug("processing [{}]: took [{}] done publishing updated cluster state (version: {}, uuid: {})", |
278 |
| - clusterChangedEvent.source(), |
279 |
| - executionTime, clusterChangedEvent.state().version(), |
280 |
| - clusterChangedEvent.state().stateUUID()); |
281 |
| - warnAboutSlowTaskIfNeeded(executionTime, clusterChangedEvent.source()); |
282 |
| - } |
283 |
| - |
284 |
| - @Override |
285 |
| - public void onFailure(Exception exception) { |
286 |
| - if (exception instanceof FailedToCommitClusterStateException) { |
287 |
| - final long version = clusterChangedEvent.state().version(); |
288 |
| - logger.warn(() -> new ParameterizedMessage( |
289 |
| - "failing [{}]: failed to commit cluster state version [{}]", clusterChangedEvent.source(), version), exception); |
290 |
| - taskOutputs.publishingFailed((FailedToCommitClusterStateException) exception); |
291 |
| - } else { |
292 |
| - handleException(clusterChangedEvent.source(), startTimeNS, clusterChangedEvent.state(), exception); |
293 |
| - } |
294 |
| - } |
295 |
| - }; |
| 263 | + try { |
| 264 | + taskOutputs.clusterStatePublished(clusterChangedEvent); |
| 265 | + } catch (Exception e) { |
| 266 | + logger.error(() -> new ParameterizedMessage( |
| 267 | + "exception thrown while notifying executor of new cluster state publication [{}]", |
| 268 | + clusterChangedEvent.source()), e); |
| 269 | + } |
| 270 | + TimeValue executionTime = TimeValue.timeValueMillis(Math.max(0, TimeValue.nsecToMSec(currentTimeInNanos() - startTimeNS))); |
| 271 | + logger.debug("processing [{}]: took [{}] done publishing updated cluster state (version: {}, uuid: {})", |
| 272 | + clusterChangedEvent.source(), |
| 273 | + executionTime, clusterChangedEvent.state().version(), |
| 274 | + clusterChangedEvent.state().stateUUID()); |
| 275 | + warnAboutSlowTaskIfNeeded(executionTime, clusterChangedEvent.source()); |
| 276 | + } |
| 277 | + |
| 278 | + protected void onPublicationFailed(ClusterChangedEvent clusterChangedEvent, TaskOutputs taskOutputs, long startTimeNS, |
| 279 | + Exception exception) { |
| 280 | + if (exception instanceof FailedToCommitClusterStateException) { |
| 281 | + final long version = clusterChangedEvent.state().version(); |
| 282 | + logger.warn(() -> new ParameterizedMessage( |
| 283 | + "failing [{}]: failed to commit cluster state version [{}]", clusterChangedEvent.source(), version), exception); |
| 284 | + taskOutputs.publishingFailed((FailedToCommitClusterStateException) exception); |
| 285 | + } else { |
| 286 | + handleException(clusterChangedEvent.source(), startTimeNS, clusterChangedEvent.state(), exception); |
| 287 | + } |
296 | 288 | }
|
297 | 289 |
|
298 | 290 | private void handleException(String summary, long startTimeNS, ClusterState newClusterState, Exception e) {
|
|
0 commit comments