From b80e0e99d1f83f10afc0cbce0f85e724d92dd9b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Fern=C3=A1ndez=20Casta=C3=B1o?= Date: Mon, 28 Jun 2021 17:49:36 +0200 Subject: [PATCH] Review comments --- .../main/java/org/elasticsearch/xpack/ccr/Ccr.java | 1 + .../xpack/ccr/action/AutoFollowCoordinatorTests.java | 1 - .../xpack/core/ccr/CcrAutoFollowInfoFetcher.java | 11 ++++++----- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/Ccr.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/Ccr.java index cdbb40b2819f7..c69c54e69b37a 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/Ccr.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/Ccr.java @@ -132,6 +132,7 @@ public class Ccr extends Plugin implements ActionPlugin, PersistentTaskPlugin, EnginePlugin, RepositoryPlugin, ClusterPlugin { public static final String CCR_THREAD_POOL_NAME = "ccr"; + // Constants have been moved into CcrConstants public static final String REQUESTED_OPS_MISSING_METADATA_KEY = "es.requested_operations_missing"; diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinatorTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinatorTests.java index 5685b66516021..fa8b26cb0749c 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinatorTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinatorTests.java @@ -2156,7 +2156,6 @@ void cleanFollowedRemoteIndices(ClusterState remoteClusterState, List pa } public void testDeprecationWarningsAreEmittedWhenASystemIndexIsAutoFollowed() throws Exception { - // Set up a mock log appender to watch for the log message we expect final Client client = mock(Client.class); when(client.getRemoteClusterClient(anyString())).thenReturn(client); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/CcrAutoFollowInfoFetcher.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/CcrAutoFollowInfoFetcher.java index 6b0f78f0b6166..1d30b821babdc 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/CcrAutoFollowInfoFetcher.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/CcrAutoFollowInfoFetcher.java @@ -15,6 +15,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.metadata.IndexMetadata; +import org.elasticsearch.index.Index; import org.elasticsearch.persistent.PersistentTasksCustomMetadata; import org.elasticsearch.xpack.core.ccr.action.ShardFollowTask; @@ -56,12 +57,12 @@ public static void getAutoFollowedSystemIndices(Client client, ClusterState stat final String leaderIndexName = ccrMetadata.get(CcrConstants.CCR_CUSTOM_METADATA_LEADER_INDEX_NAME_KEY); final String remoteCluster = ccrMetadata.get(CcrConstants.CCR_CUSTOM_METADATA_REMOTE_CLUSTER_NAME_KEY); - final String followerIndexName = indexMetadata.getIndex().getName(); - if (followedLeaderIndexUUIDs.contains(leaderIndexUUID) && isCurrentlyFollowed(persistentTasks, followerIndexName)) { + final Index followerIndex = indexMetadata.getIndex(); + if (followedLeaderIndexUUIDs.contains(leaderIndexUUID) && isCurrentlyFollowed(persistentTasks, followerIndex)) { List autoFollowedIndices = remoteClusterAutoFollowedIndices.computeIfAbsent(remoteCluster, unused -> new ArrayList<>()); - autoFollowedIndices.add(new AutoFollowedIndex(leaderIndexName, followerIndexName)); + autoFollowedIndices.add(new AutoFollowedIndex(leaderIndexName, followerIndex.getName())); } } @@ -118,10 +119,10 @@ public void onFailure(Exception e) { } } - private static boolean isCurrentlyFollowed(PersistentTasksCustomMetadata persistentTasks, String indexName) { + private static boolean isCurrentlyFollowed(PersistentTasksCustomMetadata persistentTasks, Index index) { return persistentTasks != null && persistentTasks.findTasks(ShardFollowTask.NAME, task -> true).stream() .map(task -> (ShardFollowTask) task.getParams()) - .anyMatch(shardFollowTask -> indexName.equals(shardFollowTask.getFollowShardId().getIndexName())); + .anyMatch(shardFollowTask -> index.equals(shardFollowTask.getFollowShardId().getIndex())); } private static boolean areShardFollowTasksRunning(PersistentTasksCustomMetadata persistentTasks) {