use of 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]);
}
use of 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));
}
use of 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]);
}
use of 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();
}
use of 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"));
}
Aggregations