Skip to content

Commit d5e2ed9

Browse files
committed
[CCR] Fail with a better error if leader index is red (elastic#35298)
as part of fetching history uuids from leader index.
1 parent b438921 commit d5e2ed9

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

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

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

+33
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.action.support.ActiveShardCount;
2428
import org.elasticsearch.cluster.ClusterState;
@@ -553,6 +557,35 @@ public void testUnknownClusterAlias() throws Exception {
553557
assertThat(e.getMessage(), equalTo("unknown cluster alias [another_cluster]"));
554558
}
555559

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

0 commit comments

Comments
 (0)