Search in sources :

Example 1 with FailedNodeException

use of org.elasticsearch.action.FailedNodeException in project elasticsearch by elastic.

the class TransportNodesActionTests method testNewResponse.

public void testNewResponse() {
    TestTransportNodesAction action = getTestTransportNodesAction();
    TestNodesRequest request = new TestNodesRequest();
    List<TestNodeResponse> expectedNodeResponses = mockList(TestNodeResponse::new, randomIntBetween(0, 2));
    expectedNodeResponses.add(new TestNodeResponse());
    List<BaseNodeResponse> nodeResponses = new ArrayList<>(expectedNodeResponses);
    // This should be ignored:
    nodeResponses.add(new OtherNodeResponse());
    List<FailedNodeException> failures = mockList(() -> new FailedNodeException(randomAsciiOfLength(8), randomAsciiOfLength(8), new IllegalStateException(randomAsciiOfLength(8))), randomIntBetween(0, 2));
    List<Object> allResponses = new ArrayList<>(expectedNodeResponses);
    allResponses.addAll(failures);
    Collections.shuffle(allResponses, random());
    AtomicReferenceArray<?> atomicArray = new AtomicReferenceArray<>(allResponses.toArray());
    TestNodesResponse response = action.newResponse(request, atomicArray);
    assertSame(request, response.request);
    // note: I shuffled the overall list, so it's not possible to guarantee that it's in the right order
    assertTrue(expectedNodeResponses.containsAll(response.getNodes()));
    assertTrue(failures.containsAll(response.failures()));
}
Also used : ArrayList(java.util.ArrayList) AtomicReferenceArray(java.util.concurrent.atomic.AtomicReferenceArray) FailedNodeException(org.elasticsearch.action.FailedNodeException)

Example 2 with FailedNodeException

use of org.elasticsearch.action.FailedNodeException in project elasticsearch by elastic.

the class ListTasksResponse method toXContentCommon.

private void toXContentCommon(XContentBuilder builder, Params params) throws IOException {
    if (getTaskFailures() != null && getTaskFailures().size() > 0) {
        builder.startArray("task_failures");
        for (TaskOperationFailure ex : getTaskFailures()) {
            builder.startObject();
            builder.value(ex);
            builder.endObject();
        }
        builder.endArray();
    }
    if (getNodeFailures() != null && getNodeFailures().size() > 0) {
        builder.startArray("node_failures");
        for (FailedNodeException ex : getNodeFailures()) {
            builder.startObject();
            ex.toXContent(builder, params);
            builder.endObject();
        }
        builder.endArray();
    }
}
Also used : TaskOperationFailure(org.elasticsearch.action.TaskOperationFailure) FailedNodeException(org.elasticsearch.action.FailedNodeException)

Example 3 with FailedNodeException

use of org.elasticsearch.action.FailedNodeException in project elasticsearch by elastic.

the class Gateway method performStateRecovery.

public void performStateRecovery(final GatewayStateRecoveredListener listener) throws GatewayException {
    String[] nodesIds = clusterService.state().nodes().getMasterNodes().keys().toArray(String.class);
    logger.trace("performing state recovery from {}", Arrays.toString(nodesIds));
    TransportNodesListGatewayMetaState.NodesGatewayMetaState nodesState = listGatewayMetaState.list(nodesIds, null).actionGet();
    int requiredAllocation = Math.max(1, minimumMasterNodesProvider.get());
    if (nodesState.hasFailures()) {
        for (FailedNodeException failedNodeException : nodesState.failures()) {
            logger.warn("failed to fetch state from node", failedNodeException);
        }
    }
    ObjectFloatHashMap<Index> indices = new ObjectFloatHashMap<>();
    MetaData electedGlobalState = null;
    int found = 0;
    for (TransportNodesListGatewayMetaState.NodeGatewayMetaState nodeState : nodesState.getNodes()) {
        if (nodeState.metaData() == null) {
            continue;
        }
        found++;
        if (electedGlobalState == null) {
            electedGlobalState = nodeState.metaData();
        } else if (nodeState.metaData().version() > electedGlobalState.version()) {
            electedGlobalState = nodeState.metaData();
        }
        for (ObjectCursor<IndexMetaData> cursor : nodeState.metaData().indices().values()) {
            indices.addTo(cursor.value.getIndex(), 1);
        }
    }
    if (found < requiredAllocation) {
        listener.onFailure("found [" + found + "] metadata states, required [" + requiredAllocation + "]");
        return;
    }
    // update the global state, and clean the indices, we elect them in the next phase
    MetaData.Builder metaDataBuilder = MetaData.builder(electedGlobalState).removeAllIndices();
    assert !indices.containsKey(null);
    final Object[] keys = indices.keys;
    for (int i = 0; i < keys.length; i++) {
        if (keys[i] != null) {
            Index index = (Index) keys[i];
            IndexMetaData electedIndexMetaData = null;
            int indexMetaDataCount = 0;
            for (TransportNodesListGatewayMetaState.NodeGatewayMetaState nodeState : nodesState.getNodes()) {
                if (nodeState.metaData() == null) {
                    continue;
                }
                IndexMetaData indexMetaData = nodeState.metaData().index(index);
                if (indexMetaData == null) {
                    continue;
                }
                if (electedIndexMetaData == null) {
                    electedIndexMetaData = indexMetaData;
                } else if (indexMetaData.getVersion() > electedIndexMetaData.getVersion()) {
                    electedIndexMetaData = indexMetaData;
                }
                indexMetaDataCount++;
            }
            if (electedIndexMetaData != null) {
                if (indexMetaDataCount < requiredAllocation) {
                    logger.debug("[{}] found [{}], required [{}], not adding", index, indexMetaDataCount, requiredAllocation);
                }
                // TODO if this logging statement is correct then we are missing an else here
                try {
                    if (electedIndexMetaData.getState() == IndexMetaData.State.OPEN) {
                        // verify that we can actually create this index - if not we recover it as closed with lots of warn logs
                        indicesService.verifyIndexMetadata(electedIndexMetaData, electedIndexMetaData);
                    }
                } catch (Exception e) {
                    final Index electedIndex = electedIndexMetaData.getIndex();
                    logger.warn((org.apache.logging.log4j.util.Supplier<?>) () -> new ParameterizedMessage("recovering index {} failed - recovering as closed", electedIndex), e);
                    electedIndexMetaData = IndexMetaData.builder(electedIndexMetaData).state(IndexMetaData.State.CLOSE).build();
                }
                metaDataBuilder.put(electedIndexMetaData, false);
            }
        }
    }
    final ClusterSettings clusterSettings = clusterService.getClusterSettings();
    metaDataBuilder.persistentSettings(clusterSettings.archiveUnknownOrInvalidSettings(metaDataBuilder.persistentSettings(), e -> logUnknownSetting("persistent", e), (e, ex) -> logInvalidSetting("persistent", e, ex)));
    metaDataBuilder.transientSettings(clusterSettings.archiveUnknownOrInvalidSettings(metaDataBuilder.transientSettings(), e -> logUnknownSetting("transient", e), (e, ex) -> logInvalidSetting("transient", e, ex)));
    ClusterState.Builder builder = ClusterState.builder(clusterService.getClusterName());
    builder.metaData(metaDataBuilder);
    listener.onSuccess(builder.build());
}
Also used : MetaData(org.elasticsearch.cluster.metadata.MetaData) Arrays(java.util.Arrays) FailedNodeException(org.elasticsearch.action.FailedNodeException) AbstractComponent(org.elasticsearch.common.component.AbstractComponent) Discovery(org.elasticsearch.discovery.Discovery) ClusterService(org.elasticsearch.cluster.service.ClusterService) Index(org.elasticsearch.index.Index) ObjectCursor(com.carrotsearch.hppc.cursors.ObjectCursor) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) ClusterChangedEvent(org.elasticsearch.cluster.ClusterChangedEvent) Supplier(java.util.function.Supplier) ClusterState(org.elasticsearch.cluster.ClusterState) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) Settings(org.elasticsearch.common.settings.Settings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Map(java.util.Map) IndicesService(org.elasticsearch.indices.IndicesService) ObjectFloatHashMap(com.carrotsearch.hppc.ObjectFloatHashMap) ClusterStateApplier(org.elasticsearch.cluster.ClusterStateApplier) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) Index(org.elasticsearch.index.Index) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) FailedNodeException(org.elasticsearch.action.FailedNodeException) Supplier(java.util.function.Supplier) ClusterState(org.elasticsearch.cluster.ClusterState) FailedNodeException(org.elasticsearch.action.FailedNodeException) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) ObjectFloatHashMap(com.carrotsearch.hppc.ObjectFloatHashMap)

Example 4 with FailedNodeException

use of org.elasticsearch.action.FailedNodeException in project elasticsearch by elastic.

the class ExceptionSerializationTests method testFailedNodeException.

public void testFailedNodeException() throws IOException {
    FailedNodeException ex = serialize(new FailedNodeException("the node", "the message", null));
    assertEquals("the node", ex.nodeId());
    assertEquals("the message", ex.getMessage());
}
Also used : FailedNodeException(org.elasticsearch.action.FailedNodeException)

Example 5 with FailedNodeException

use of org.elasticsearch.action.FailedNodeException in project elasticsearch by elastic.

the class TransportRethrottleActionTests method testRethrottleNodeFailure.

public void testRethrottleNodeFailure() {
    FailedNodeException e = new FailedNodeException("test", "test", new Exception());
    rethrottleTestCase(slices, listener -> listener.onResponse(new ListTasksResponse(emptyList(), emptyList(), singletonList(e))), expectException(theInstance(e)));
}
Also used : FailedNodeException(org.elasticsearch.action.FailedNodeException) ListTasksResponse(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse) FailedNodeException(org.elasticsearch.action.FailedNodeException)

Aggregations

FailedNodeException (org.elasticsearch.action.FailedNodeException)14 ArrayList (java.util.ArrayList)4 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)3 TaskOperationFailure (org.elasticsearch.action.TaskOperationFailure)3 ObjectFloatHashMap (com.carrotsearch.hppc.ObjectFloatHashMap)2 ObjectCursor (com.carrotsearch.hppc.cursors.ObjectCursor)2 Arrays (java.util.Arrays)2 ElasticsearchTimeoutException (org.elasticsearch.ElasticsearchTimeoutException)2 DefaultShardOperationFailedException (org.elasticsearch.action.support.DefaultShardOperationFailedException)2 BroadcastShardOperationFailedException (org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException)2 ClusterState (org.elasticsearch.cluster.ClusterState)2 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)2 ClusterService (org.elasticsearch.cluster.service.ClusterService)2 EsRejectedExecutionException (org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)2 Index (org.elasticsearch.index.Index)2 ReceiveTimeoutTransportException (org.elasticsearch.transport.ReceiveTimeoutTransportException)2 Map (java.util.Map)1 AtomicReferenceArray (java.util.concurrent.atomic.AtomicReferenceArray)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1