From 90fb198b20468bba0f1dbcfd5b8827c48b14fba0 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 17 Sep 2018 09:55:16 +0200 Subject: [PATCH] let autoFollowIndices() handle passing down the result to finilise() method, this avoids handleClusterAlias() having to know about clusterAliasSlot parameter. --- .../xpack/ccr/action/AutoFollowCoordinator.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java index 27ff7b20b0045..853b30b96da6a 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java @@ -257,7 +257,8 @@ void autoFollowIndices() { getLeaderClusterState(autoFollowPattern.getHeaders(), clusterAlias, (leaderClusterState, e) -> { if (leaderClusterState != null) { assert e == null; - handleClusterAlias(slot, clusterAlias, autoFollowPattern, followedIndices, leaderClusterState); + Consumer resultHandler = result -> finalise(slot, result); + handleClusterAlias(clusterAlias, autoFollowPattern, followedIndices, leaderClusterState, resultHandler); } else { finalise(slot, new AutoFollowResult(clusterAlias, e)); } @@ -267,16 +268,16 @@ void autoFollowIndices() { } private void handleClusterAlias( - int clusterAliasSlot, String clusterAlias, AutoFollowPattern autoFollowPattern, List followedIndexUUIDs, - ClusterState leaderClusterState + ClusterState leaderClusterState, + Consumer resultHandler ) { final List leaderIndicesToFollow = getLeaderIndicesToFollow(autoFollowPattern, leaderClusterState, followerClusterState, followedIndexUUIDs); if (leaderIndicesToFollow.isEmpty()) { - finalise(clusterAliasSlot, new AutoFollowResult(clusterAlias)); + resultHandler.accept(new AutoFollowResult(clusterAlias)); } else { final CountDown leaderIndicesCountDown = new CountDown(leaderIndicesToFollow.size()); final AtomicArray> results = new AtomicArray<>(leaderIndicesToFollow.size()); @@ -313,7 +314,7 @@ private void handleClusterAlias( LOGGER.debug("Successfully marked leader index [{}] as auto followed", leaderIndexName); } if (leaderIndicesCountDown.countDown()) { - finalise(clusterAliasSlot, new AutoFollowResult(clusterAlias, results.asList())); + resultHandler.accept(new AutoFollowResult(clusterAlias, results.asList())); } }); }; @@ -323,7 +324,7 @@ private void handleClusterAlias( LOGGER.warn("Failed to auto follow leader index [" + leaderIndexName + "]", followError); results.set(slot, new Tuple<>(indexToFollow, followError)); if (leaderIndicesCountDown.countDown()) { - finalise(clusterAliasSlot, new AutoFollowResult(clusterAlias, results.asList())); + resultHandler.accept(new AutoFollowResult(clusterAlias, results.asList())); } }; createAndFollow(autoFollowPattern.getHeaders(), followRequest, successHandler, failureHandler);