Search in sources :

Example 11 with ShardOperationFailedException

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.ShardOperationFailedException in project elasticsearch by elastic.

the class SearchPhaseExecutionException method guessRootCauses.

@Override
public ElasticsearchException[] guessRootCauses() {
    ShardOperationFailedException[] failures = ExceptionsHelper.groupBy(shardFailures);
    List<ElasticsearchException> rootCauses = new ArrayList<>(failures.length);
    for (ShardOperationFailedException failure : failures) {
        ElasticsearchException[] guessRootCauses = ElasticsearchException.guessRootCauses(failure.getCause());
        rootCauses.addAll(Arrays.asList(guessRootCauses));
    }
    return rootCauses.toArray(new ElasticsearchException[0]);
}
Also used : ArrayList(java.util.ArrayList) ShardOperationFailedException(org.elasticsearch.action.ShardOperationFailedException) ElasticsearchException(org.elasticsearch.ElasticsearchException)

Example 12 with ShardOperationFailedException

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.ShardOperationFailedException in project elasticsearch by elastic.

the class TransportBroadcastReplicationAction method finishAndNotifyListener.

private void finishAndNotifyListener(ActionListener listener, CopyOnWriteArrayList<ShardResponse> shardsResponses) {
    logger.trace("{}: got all shard responses", actionName);
    int successfulShards = 0;
    int failedShards = 0;
    int totalNumCopies = 0;
    List<ShardOperationFailedException> shardFailures = null;
    for (int i = 0; i < shardsResponses.size(); i++) {
        ReplicationResponse shardResponse = shardsResponses.get(i);
        if (shardResponse == null) {
        // non active shard, ignore
        } else {
            failedShards += shardResponse.getShardInfo().getFailed();
            successfulShards += shardResponse.getShardInfo().getSuccessful();
            totalNumCopies += shardResponse.getShardInfo().getTotal();
            if (shardFailures == null) {
                shardFailures = new ArrayList<>();
            }
            for (ReplicationResponse.ShardInfo.Failure failure : shardResponse.getShardInfo().getFailures()) {
                shardFailures.add(new DefaultShardOperationFailedException(new BroadcastShardOperationFailedException(failure.fullShardId(), failure.getCause())));
            }
        }
    }
    listener.onResponse(newResponse(successfulShards, failedShards, totalNumCopies, shardFailures));
}
Also used : BroadcastShardOperationFailedException(org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException) BroadcastShardOperationFailedException(org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException) ShardOperationFailedException(org.elasticsearch.action.ShardOperationFailedException) DefaultShardOperationFailedException(org.elasticsearch.action.support.DefaultShardOperationFailedException) DefaultShardOperationFailedException(org.elasticsearch.action.support.DefaultShardOperationFailedException)

Example 13 with ShardOperationFailedException

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.ShardOperationFailedException in project elasticsearch by elastic.

the class ExceptionsHelper method groupBy.

/**
     * Deduplicate the failures by exception message and index.
     */
public static ShardOperationFailedException[] groupBy(ShardOperationFailedException[] failures) {
    List<ShardOperationFailedException> uniqueFailures = new ArrayList<>();
    Set<GroupBy> reasons = new HashSet<>();
    for (ShardOperationFailedException failure : failures) {
        GroupBy reason = new GroupBy(failure.getCause());
        if (reasons.contains(reason) == false) {
            reasons.add(reason);
            uniqueFailures.add(failure);
        }
    }
    return uniqueFailures.toArray(new ShardOperationFailedException[0]);
}
Also used : ArrayList(java.util.ArrayList) ShardOperationFailedException(org.elasticsearch.action.ShardOperationFailedException) HashSet(java.util.HashSet)

Example 14 with ShardOperationFailedException

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.ShardOperationFailedException in project elasticsearch by elastic.

the class RestActions method buildBroadcastShardsHeader.

public static void buildBroadcastShardsHeader(XContentBuilder builder, Params params, int total, int successful, int failed, ShardOperationFailedException[] shardFailures) throws IOException {
    builder.startObject("_shards");
    builder.field("total", total);
    builder.field("successful", successful);
    builder.field("failed", failed);
    if (shardFailures != null && shardFailures.length > 0) {
        builder.startArray("failures");
        // we group by default
        final boolean group = params.paramAsBoolean("group_shard_failures", true);
        for (ShardOperationFailedException shardFailure : group ? ExceptionsHelper.groupBy(shardFailures) : shardFailures) {
            builder.startObject();
            shardFailure.toXContent(builder, params);
            builder.endObject();
        }
        builder.endArray();
    }
    builder.endObject();
}
Also used : ShardOperationFailedException(org.elasticsearch.action.ShardOperationFailedException)

Example 15 with ShardOperationFailedException

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.ShardOperationFailedException in project elasticsearch by elastic.

the class GetActionIT method testGetFieldsComplexField.

public void testGetFieldsComplexField() throws Exception {
    assertAcked(prepareCreate("my-index").setSettings(Settings.builder().put("index.refresh_interval", -1)).addMapping("my-type2", jsonBuilder().startObject().startObject("my-type2").startObject("properties").startObject("field1").field("type", "object").startObject("properties").startObject("field2").field("type", "object").startObject("properties").startObject("field3").field("type", "object").startObject("properties").startObject("field4").field("type", "text").field("store", true).endObject().endObject().endObject().endObject().endObject().endObject().endObject().endObject().endObject().endObject()));
    BytesReference source = jsonBuilder().startObject().startArray("field1").startObject().startObject("field2").startArray("field3").startObject().field("field4", "value1").endObject().endArray().endObject().endObject().startObject().startObject("field2").startArray("field3").startObject().field("field4", "value2").endObject().endArray().endObject().endObject().endArray().endObject().bytes();
    logger.info("indexing documents");
    client().prepareIndex("my-index", "my-type1", "1").setSource(source, XContentType.JSON).get();
    client().prepareIndex("my-index", "my-type2", "1").setSource(source, XContentType.JSON).get();
    logger.info("checking real time retrieval");
    String field = "field1.field2.field3.field4";
    GetResponse getResponse = client().prepareGet("my-index", "my-type1", "1").setStoredFields(field).get();
    assertThat(getResponse.isExists(), equalTo(true));
    assertThat(getResponse.getField(field).isMetadataField(), equalTo(false));
    assertThat(getResponse.getField(field).getValues().size(), equalTo(2));
    assertThat(getResponse.getField(field).getValues().get(0).toString(), equalTo("value1"));
    assertThat(getResponse.getField(field).getValues().get(1).toString(), equalTo("value2"));
    getResponse = client().prepareGet("my-index", "my-type2", "1").setStoredFields(field).get();
    assertThat(getResponse.isExists(), equalTo(true));
    assertThat(getResponse.getField(field).isMetadataField(), equalTo(false));
    assertThat(getResponse.getField(field).getValues().size(), equalTo(2));
    assertThat(getResponse.getField(field).getValues().get(0).toString(), equalTo("value1"));
    assertThat(getResponse.getField(field).getValues().get(1).toString(), equalTo("value2"));
    logger.info("waiting for recoveries to complete");
    // Flush fails if shard has ongoing recoveries, make sure the cluster is settled down
    ensureGreen();
    logger.info("flushing");
    FlushResponse flushResponse = client().admin().indices().prepareFlush("my-index").setForce(true).get();
    if (flushResponse.getSuccessfulShards() == 0) {
        StringBuilder sb = new StringBuilder("failed to flush at least one shard. total shards [").append(flushResponse.getTotalShards()).append("], failed shards: [").append(flushResponse.getFailedShards()).append("]");
        for (ShardOperationFailedException failure : flushResponse.getShardFailures()) {
            sb.append("\nShard failure: ").append(failure);
        }
        fail(sb.toString());
    }
    logger.info("checking post-flush retrieval");
    getResponse = client().prepareGet("my-index", "my-type1", "1").setStoredFields(field).get();
    assertThat(getResponse.isExists(), equalTo(true));
    assertThat(getResponse.getField(field).isMetadataField(), equalTo(false));
    assertThat(getResponse.getField(field).getValues().size(), equalTo(2));
    assertThat(getResponse.getField(field).getValues().get(0).toString(), equalTo("value1"));
    assertThat(getResponse.getField(field).getValues().get(1).toString(), equalTo("value2"));
    getResponse = client().prepareGet("my-index", "my-type2", "1").setStoredFields(field).get();
    assertThat(getResponse.isExists(), equalTo(true));
    assertThat(getResponse.getField(field).isMetadataField(), equalTo(false));
    assertThat(getResponse.getField(field).getValues().size(), equalTo(2));
    assertThat(getResponse.getField(field).getValues().get(0).toString(), equalTo("value1"));
    assertThat(getResponse.getField(field).getValues().get(1).toString(), equalTo("value2"));
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) FlushResponse(org.elasticsearch.action.admin.indices.flush.FlushResponse) ShardOperationFailedException(org.elasticsearch.action.ShardOperationFailedException) GetResponse(org.elasticsearch.action.get.GetResponse) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse)

Aggregations

ShardOperationFailedException (org.elasticsearch.action.ShardOperationFailedException)17 ArrayList (java.util.ArrayList)9 List (java.util.List)5 DefaultShardOperationFailedException (org.elasticsearch.action.support.DefaultShardOperationFailedException)4 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 FlushResponse (org.elasticsearch.action.admin.indices.flush.FlushResponse)2 StoreStatus.readStoreStatus (org.elasticsearch.action.admin.indices.shards.IndicesShardStoresResponse.StoreStatus.readStoreStatus)2 BroadcastShardOperationFailedException (org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException)2 ImmutableOpenIntMap (org.elasticsearch.common.collect.ImmutableOpenIntMap)2 Maps (com.google.common.collect.Maps)1 Named (com.google.inject.name.Named)1 CrateUnitTest (io.crate.test.integration.CrateUnitTest)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1