Skip to content

Commit

Permalink
[CCR] Fail with a better error if leader index is red (elastic#35298)
Browse files Browse the repository at this point in the history
as part of fetching history uuids from leader index.
  • Loading branch information
martijnvg committed Nov 7, 2018
1 parent 9a319ec commit e685cfe
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ public void fetchLeaderHistoryUUIDs(
String leaderIndex = leaderIndexMetaData.getIndex().getName();
CheckedConsumer<IndicesStatsResponse, Exception> indicesStatsHandler = indicesStatsResponse -> {
IndexStats indexStats = indicesStatsResponse.getIndices().get(leaderIndex);
if (indexStats == null) {
onFailure.accept(new IllegalArgumentException("no index stats available for the leader index"));
return;
}

String[] historyUUIDs = new String[leaderIndexMetaData.getNumberOfShards()];
for (IndexShardStats indexShardStats : indexStats) {
for (ShardStats shardStats : indexShardStats) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
import org.elasticsearch.action.admin.indices.close.CloseIndexRequest;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest;
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest;
import org.elasticsearch.action.admin.indices.stats.ShardStats;
Expand All @@ -19,6 +22,7 @@
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetaData;
Expand Down Expand Up @@ -552,6 +556,35 @@ public void testUnknownClusterAlias() throws Exception {
assertThat(e.getMessage(), equalTo("unknown cluster alias [another_cluster]"));
}

public void testLeaderIndexRed() throws Exception {
try {
ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest();
updateSettingsRequest.transientSettings(Settings.builder().put("cluster.routing.allocation.enable", "none"));
assertAcked(leaderClient().admin().cluster().updateSettings(updateSettingsRequest).actionGet());
assertAcked(leaderClient().admin().indices().prepareCreate("index1")
.setWaitForActiveShards(ActiveShardCount.NONE)
.setSettings(Settings.builder()
.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true)
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.build()));

final PutFollowAction.Request followRequest = putFollow("index1", "index2");
Exception e = expectThrows(IllegalArgumentException.class,
() -> followerClient().execute(PutFollowAction.INSTANCE, followRequest).actionGet());
assertThat(e.getMessage(), equalTo("no index stats available for the leader index"));

IndicesExistsResponse existsResponse = followerClient().admin().indices().exists(new IndicesExistsRequest("index2"))
.actionGet();
assertThat(existsResponse.isExists(), is(false));
} finally {
// Always unset allocation enable setting to avoid other assertions from failing too when this test fails:
ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest();
updateSettingsRequest.transientSettings(Settings.builder().put("cluster.routing.allocation.enable", (String) null));
assertAcked(leaderClient().admin().cluster().updateSettings(updateSettingsRequest).actionGet());
}
}

private CheckedRunnable<Exception> assertTask(final int numberOfPrimaryShards, final Map<ShardId, Long> numDocsPerShard) {
return () -> {
final ClusterState clusterState = followerClient().admin().cluster().prepareState().get().getState();
Expand Down

0 comments on commit e685cfe

Please sign in to comment.