Skip to content

Commit

Permalink
check for the use of _local_ cluster alias
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnvg committed Sep 23, 2018
1 parent 006f583 commit df20939
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ void autoFollowIndices() {
if (leaderClusterState != null) {
assert e == null;
final List<String> followedIndices = autoFollowMetadata.getFollowedLeaderIndexUUIDs().get(clusterAlias);
final List<Index> leaderIndicesToFollow =
getLeaderIndicesToFollow(autoFollowPattern, leaderClusterState, followerClusterState, followedIndices);
final List<Index> leaderIndicesToFollow = getLeaderIndicesToFollow(clusterAlias, autoFollowPattern,
leaderClusterState, followerClusterState, followedIndices);
if (leaderIndicesToFollow.isEmpty()) {
finalise(slot, new AutoFollowResult(clusterAlias));
} else {
Expand Down Expand Up @@ -331,17 +331,18 @@ private void finalise(int slot, AutoFollowResult result) {
}
}

static List<Index> getLeaderIndicesToFollow(AutoFollowPattern autoFollowPattern,
static List<Index> getLeaderIndicesToFollow(String clusterAlias,
AutoFollowPattern autoFollowPattern,
ClusterState leaderClusterState,
ClusterState followerClusterState,
List<String> followedIndexUUIDs) {
List<Index> leaderIndicesToFollow = new ArrayList<>();
for (IndexMetaData leaderIndexMetaData : leaderClusterState.getMetaData()) {
// We should not automatically follow a leader index that is also a follow index and
// that both leader and follow index are in the same cluster otherwise this can
// result into an index creation explosion.
// If an auto follow pattern has been set up for the local cluster then
// we should not automatically follow a leader index that is also a follow index because
// this can result into an index creation explosion.
if (leaderIndexMetaData.getCustomData(Ccr.CCR_CUSTOM_METADATA_KEY) != null &&
leaderClusterState.getClusterName().equals(followerClusterState.getClusterName())) {
clusterAlias.equals("_local_")) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ public void testGetLeaderIndicesToFollow() {
.metaData(imdBuilder)
.build();

List<Index> result = AutoFollower.getLeaderIndicesToFollow(autoFollowPattern, leaderState, followerState, Collections.emptyList());
List<Index> result = AutoFollower.getLeaderIndicesToFollow("remote", autoFollowPattern, leaderState, followerState,
Collections.emptyList());
result.sort(Comparator.comparing(Index::getName));
assertThat(result.size(), equalTo(5));
assertThat(result.get(0).getName(), equalTo("metrics-0"));
Expand All @@ -321,7 +322,7 @@ public void testGetLeaderIndicesToFollow() {
assertThat(result.get(4).getName(), equalTo("metrics-4"));

List<String> followedIndexUUIDs = Collections.singletonList(leaderState.metaData().index("metrics-2").getIndexUUID());
result = AutoFollower.getLeaderIndicesToFollow(autoFollowPattern, leaderState, followerState, followedIndexUUIDs);
result = AutoFollower.getLeaderIndicesToFollow("remote", autoFollowPattern, leaderState, followerState, followedIndexUUIDs);
result.sort(Comparator.comparing(Index::getName));
assertThat(result.size(), equalTo(4));
assertThat(result.get(0).getName(), equalTo("metrics-0"));
Expand All @@ -331,13 +332,6 @@ public void testGetLeaderIndicesToFollow() {
}

public void testGetLeaderIndicesToFollowDoNotSelectFollowIndicesInTheSameCluster() {
AutoFollowPattern autoFollowPattern =
new AutoFollowPattern(Collections.singletonList("metrics-*"), null, null, null, null, null, null, null, null, null);
ClusterState followerState = ClusterState.builder(new ClusterName("name"))
.metaData(MetaData.builder().putCustom(AutoFollowMetadata.TYPE,
new AutoFollowMetadata(Collections.singletonMap("remote", autoFollowPattern), Collections.emptyMap())))
.build();

MetaData.Builder imdBuilder = MetaData.builder();
imdBuilder.put(IndexMetaData.builder("metrics-0")
.settings(settings(Version.CURRENT))
Expand All @@ -349,11 +343,17 @@ public void testGetLeaderIndicesToFollowDoNotSelectFollowIndicesInTheSameCluster
.numberOfShards(1)
.numberOfReplicas(0));

ClusterState leaderState = ClusterState.builder(new ClusterName("name"))
AutoFollowPattern autoFollowPattern =
new AutoFollowPattern(Collections.singletonList("metrics-*"), null, null, null, null, null, null, null, null, null);
imdBuilder.putCustom(AutoFollowMetadata.TYPE,
new AutoFollowMetadata(Collections.singletonMap("remote", autoFollowPattern), Collections.emptyMap()));

ClusterState clusterState = ClusterState.builder(new ClusterName("name"))
.metaData(imdBuilder)
.build();

List<Index> result = AutoFollower.getLeaderIndicesToFollow(autoFollowPattern, leaderState, followerState, Collections.emptyList());
List<Index> result = AutoFollower.getLeaderIndicesToFollow("_local_", autoFollowPattern, clusterState,
clusterState, Collections.emptyList());
result.sort(Comparator.comparing(Index::getName));
assertThat(result.size(), equalTo(1));
assertThat(result.get(0).getName(), equalTo("metrics-0"));
Expand Down

0 comments on commit df20939

Please sign in to comment.