Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CCR] Clean followed leader index UUIDs in auto follow metadata #36408

Merged

Conversation

martijnvg
Copy link
Member

The auto follow coordinator keeps track of the UUIDs of indices that it has followed. The index UUID strings need to be cleaned up in the case that these indices are removed in the remote cluster.

Relates to #33007

The auto follow coordinator keeps track of the UUIDs of indices that it has followed. The index UUID strings need to be cleaned up in the case that these indices are removed in the remote cluster.

Relates to elastic#33007
@martijnvg martijnvg added >enhancement v7.0.0 :Distributed/CCR Issues around the Cross Cluster State Replication features v6.6.0 labels Dec 9, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed

Copy link
Member

@jasontedor jasontedor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I left a few comments. They are pretty minor.

}
i++;
}
getLeaderClusterState(remoteCluster, (remoteClusterState, remoteError) -> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this should be renamed to getRemoteClusterState now.

for (String autoFollowPatternName : patterns) {
results.add(new AutoFollowResult(autoFollowPatternName, e));
for (int i = 0; i < patterns.size(); i++) {
String autoFollowPatternName = patterns.get(i);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe an assertion that remoteError is not null?

@@ -460,6 +467,56 @@ static String getFollowerIndexName(AutoFollowPattern autoFollowPattern, String l
};
}

void cleanFollowedLeaderIndices(final ClusterState remoteClusterState,
final List<String> patterns) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These parameters should fit on online.

@@ -460,6 +467,56 @@ static String getFollowerIndexName(AutoFollowPattern autoFollowPattern, String l
};
}

void cleanFollowedLeaderIndices(final ClusterState remoteClusterState,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continuing with the theme, let us leave "leader" out of this method name and instead prefer "remote".

});
}

static Function<ClusterState, ClusterState> cleanFollowedLeaderIndices(final MetaData remoteMetadata,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leader -> Remote.

}

static Function<ClusterState, ClusterState> cleanFollowedLeaderIndices(final MetaData remoteMetadata,
final List<String> autoFollowPatternNames) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

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 b3e437bc381..8fe89b3ae35 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
@@ -476,8 +476,8 @@ public class AutoFollowCoordinator implements ClusterStateListener {
             });
         }
 
-        static Function<ClusterState, ClusterState> cleanFollowedLeaderIndices(final MetaData remoteMetadata,
-                                                                               final List<String> autoFollowPatternNames) {
+        static Function<ClusterState, ClusterState> cleanFollowedLeaderIndices(
+                final MetaData remoteMetadata, final List<String> autoFollowPatternNames) {
             return currentState -> {
                 AutoFollowMetadata currentAutoFollowMetadata = currentState.metaData().custom(AutoFollowMetadata.TYPE);
                 Map<String, List<String>> newFollowedIndexUUIDS = new HashMap<>(currentAutoFollowMetadata.getFollowedLeaderIndexUUIDs());

final List<String> autoFollowPatternNames) {
return currentState -> {
AutoFollowMetadata currentAutoFollowMetadata = currentState.metaData().custom(AutoFollowMetadata.TYPE);
Map<String, List<String>> newFollowedIndexUUIDS = new HashMap<>(currentAutoFollowMetadata.getFollowedLeaderIndexUUIDs());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs a rename. I got confused by it a few times later on in the code. Perhaps autoFollowPatternNameToFollowedIndexUUIDs?

continue;
}

List<String> followedLeaderIndices = new ArrayList<>(newFollowedIndexUUIDS.get(autoFollowPatternName));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

followedLeaderIndices -> followedIndexUUIDs?

@martijnvg
Copy link
Member Author

@jasontedor I've updated the PR.

I noticed that new test (AutoFollowIT#testCleanFollowedLeaderIndexUUIDs) was randomly failing. It turned out that because AutoFollowMetadata did not properly implement equals / hashcode and this is problematic, because AutoFollowMetadata extends AbstractNamedDiffable. In the test AutoFollowMetadata was introspected from an arbitrary node, but sometimes the followedLeaderIndexUUIDs did not contain the expected values. Changes to the headers and followedLeaderIndexUUIDs fields were never detected and therefor other nodes never got a cluster state with updates to these fields. The AutoFollowMetadataTests should have detected this problem.

Copy link
Member

@jasontedor jasontedor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The production code LGTM. Sorry for one more naming nit though. No need for another round!

if (leaderIndicesToFollow.isEmpty()) {
finalise(slot, new AutoFollowResult(autoFollowPatternName));
} else {
List<Tuple<String, AutoFollowPattern>> patternsForTheSameLeaderCluster = autoFollowMetadata.getPatterns()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LeaderCluster -> RemoteCluster?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have done find and replace case insensitive... it is more difficult to get rid of leaderCluster and variants than I thought it would be.

@martijnvg martijnvg merged commit 4a825e2 into elastic:master Dec 12, 2018
martijnvg added a commit that referenced this pull request Dec 12, 2018
The auto follow coordinator keeps track of the UUIDs of indices that it has followed. The index UUID strings need to be cleaned up in the case that these indices are removed in the remote cluster.

Relates to #33007
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed/CCR Issues around the Cross Cluster State Replication features >enhancement v6.6.0 v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants