Skip to content

Commit e685cfe

Browse files
authored
[CCR] Fail with a better error if leader index is red (#35298)
as part of fetching history uuids from leader index.
1 parent 9a319ec commit e685cfe

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/CcrLicenseChecker.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@ public void fetchLeaderHistoryUUIDs(
244244
String leaderIndex = leaderIndexMetaData.getIndex().getName();
245245
CheckedConsumer<IndicesStatsResponse, Exception> indicesStatsHandler = indicesStatsResponse -> {
246246
IndexStats indexStats = indicesStatsResponse.getIndices().get(leaderIndex);
247+
if (indexStats == null) {
248+
onFailure.accept(new IllegalArgumentException("no index stats available for the leader index"));
249+
return;
250+
}
251+
247252
String[] historyUUIDs = new String[leaderIndexMetaData.getNumberOfShards()];
248253
for (IndexShardStats indexShardStats : indexStats) {
249254
for (ShardStats shardStats : indexShardStats) {

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
import org.elasticsearch.ElasticsearchException;
1010
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
1111
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
12+
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
1213
import org.elasticsearch.action.admin.indices.close.CloseIndexRequest;
1314
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
15+
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest;
16+
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
1417
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
1518
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest;
1619
import org.elasticsearch.action.admin.indices.stats.ShardStats;
@@ -19,6 +22,7 @@
1922
import org.elasticsearch.action.bulk.BulkResponse;
2023
import org.elasticsearch.action.get.GetResponse;
2124
import org.elasticsearch.action.index.IndexRequest;
25+
import org.elasticsearch.action.support.ActiveShardCount;
2226
import org.elasticsearch.action.support.WriteRequest;
2327
import org.elasticsearch.cluster.ClusterState;
2428
import org.elasticsearch.cluster.metadata.IndexMetaData;
@@ -552,6 +556,35 @@ public void testUnknownClusterAlias() throws Exception {
552556
assertThat(e.getMessage(), equalTo("unknown cluster alias [another_cluster]"));
553557
}
554558

559+
public void testLeaderIndexRed() throws Exception {
560+
try {
561+
ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest();
562+
updateSettingsRequest.transientSettings(Settings.builder().put("cluster.routing.allocation.enable", "none"));
563+
assertAcked(leaderClient().admin().cluster().updateSettings(updateSettingsRequest).actionGet());
564+
assertAcked(leaderClient().admin().indices().prepareCreate("index1")
565+
.setWaitForActiveShards(ActiveShardCount.NONE)
566+
.setSettings(Settings.builder()
567+
.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true)
568+
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
569+
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
570+
.build()));
571+
572+
final PutFollowAction.Request followRequest = putFollow("index1", "index2");
573+
Exception e = expectThrows(IllegalArgumentException.class,
574+
() -> followerClient().execute(PutFollowAction.INSTANCE, followRequest).actionGet());
575+
assertThat(e.getMessage(), equalTo("no index stats available for the leader index"));
576+
577+
IndicesExistsResponse existsResponse = followerClient().admin().indices().exists(new IndicesExistsRequest("index2"))
578+
.actionGet();
579+
assertThat(existsResponse.isExists(), is(false));
580+
} finally {
581+
// Always unset allocation enable setting to avoid other assertions from failing too when this test fails:
582+
ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest();
583+
updateSettingsRequest.transientSettings(Settings.builder().put("cluster.routing.allocation.enable", (String) null));
584+
assertAcked(leaderClient().admin().cluster().updateSettings(updateSettingsRequest).actionGet());
585+
}
586+
}
587+
555588
private CheckedRunnable<Exception> assertTask(final int numberOfPrimaryShards, final Map<ShardId, Long> numDocsPerShard) {
556589
return () -> {
557590
final ClusterState clusterState = followerClient().admin().cluster().prepareState().get().getState();

0 commit comments

Comments
 (0)