Skip to content

Commit

Permalink
let autoFollowIndices() handle passing down the result to finilise() …
Browse files Browse the repository at this point in the history
…method,

this avoids handleClusterAlias() having to know about clusterAliasSlot parameter.
  • Loading branch information
martijnvg committed Sep 17, 2018
1 parent 59cde1a commit 90fb198
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<AutoFollowResult> resultHandler = result -> finalise(slot, result);
handleClusterAlias(clusterAlias, autoFollowPattern, followedIndices, leaderClusterState, resultHandler);
} else {
finalise(slot, new AutoFollowResult(clusterAlias, e));
}
Expand All @@ -267,16 +268,16 @@ void autoFollowIndices() {
}

private void handleClusterAlias(
int clusterAliasSlot,
String clusterAlias,
AutoFollowPattern autoFollowPattern,
List<String> followedIndexUUIDs,
ClusterState leaderClusterState
ClusterState leaderClusterState,
Consumer<AutoFollowResult> resultHandler
) {
final List<Index> 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<Tuple<Index, Exception>> results = new AtomicArray<>(leaderIndicesToFollow.size());
Expand Down Expand Up @@ -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()));
}
});
};
Expand All @@ -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);
Expand Down

0 comments on commit 90fb198

Please sign in to comment.