org.elasticsearch.action.NoShardAvailableActionException Java Examples

The following examples show how to use org.elasticsearch.action.NoShardAvailableActionException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlobTableInfo.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
private void processShardRouting(Map<String, Map<String, List<Integer>>> locations, ShardRouting shardRouting, ShardId shardId) {
    String node;
    if (shardRouting == null) {
        throw new NoShardAvailableActionException(shardId);
    }
    node = shardRouting.currentNodeId();
    Map<String, List<Integer>> nodeMap = locations.get(node);
    if (nodeMap == null) {
        nodeMap = new TreeMap<>();
        locations.put(shardRouting.currentNodeId(), nodeMap);
    }

    List<Integer> shards = nodeMap.get(shardRouting.getIndex());
    if (shards == null) {
        shards = new ArrayList<>();
        nodeMap.put(shardRouting.getIndex(), shards);
    }
    shards.add(shardRouting.id());
}
 
Example #2
Source File: AbstractSearchAsyncAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public void start() {
    if (expectedSuccessfulOps == 0) {
        // no search shards to search on, bail with empty response (it happens with search across _all with no indices around and consistent with broadcast operations)
        listener.onResponse(new SearchResponse(InternalSearchResponse.empty(), null, 0, 0, buildTookInMillis(), ShardSearchFailure.EMPTY_ARRAY));
        return;
    }
    int shardIndex = -1;
    for (final ShardIterator shardIt : shardsIts) {
        shardIndex++;
        final ShardRouting shard = shardIt.nextOrNull();
        if (shard != null) {
            performFirstPhase(shardIndex, shardIt, shard);
        } else {
            // really, no shards active in this group
            onFirstPhaseResult(shardIndex, null, null, shardIt, new NoShardAvailableActionException(shardIt.shardId()));
        }
    }
}
 
Example #3
Source File: AbstractSearchAsyncAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
void performFirstPhase(final int shardIndex, final ShardIterator shardIt, final ShardRouting shard) {
    if (shard == null) {
        // no more active shards... (we should not really get here, but just for safety)
        onFirstPhaseResult(shardIndex, null, null, shardIt, new NoShardAvailableActionException(shardIt.shardId()));
    } else {
        final DiscoveryNode node = nodes.get(shard.currentNodeId());
        if (node == null) {
            onFirstPhaseResult(shardIndex, shard, null, shardIt, new NoShardAvailableActionException(shardIt.shardId()));
        } else {
            String[] filteringAliases = indexNameExpressionResolver.filteringAliases(clusterState, shard.index(), request.indices());
            sendExecuteFirstPhase(node, internalSearchRequest(shard, shardsIts.size(), request, filteringAliases, startTime()), new ActionListener<FirstResult>() {
                @Override
                public void onResponse(FirstResult result) {
                    onFirstPhaseResult(shardIndex, shard, result, shardIt);
                }

                @Override
                public void onFailure(Throwable t) {
                    onFirstPhaseResult(shardIndex, shard, node.id(), shardIt, t);
                }
            });
        }
    }
}
 
Example #4
Source File: TransportBroadcastAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public void start() {
    if (shardsIts.size() == 0) {
        // no shards
        try {
            listener.onResponse(newResponse(request, new AtomicReferenceArray(0), clusterState));
        } catch (Throwable e) {
            listener.onFailure(e);
        }
        return;
    }
    // count the local operations, and perform the non local ones
    int shardIndex = -1;
    for (final ShardIterator shardIt : shardsIts) {
        shardIndex++;
        final ShardRouting shard = shardIt.nextOrNull();
        if (shard != null) {
            performOperation(shardIt, shard, shardIndex);
        } else {
            // really, no shards active in this group
            onOperation(null, shardIt, shardIndex, new NoShardAvailableActionException(shardIt.shardId()));
        }
    }
}
 
Example #5
Source File: AbstractRetryableEsRequestTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * 初回リクエストでNoShardAvailableActionException、リトライ1回目で成功した場合、適切な復帰値が返ること.
 */
@Test
public void 初回リクエストでNoShardAvailableActionException_リトライ1回目で成功した場合_適切な復帰値が返ること() {

    TestRequest requestMock = Mockito.spy(new TestRequest());

    NoShardAvailableActionException toBeThrown = Mockito.mock(NoShardAvailableActionException.class);
    Mockito.doThrow(toBeThrown)
            .doReturn(SUCCESS_RESPONSE)
            .when(requestMock)
            .doProcess();

    String result = requestMock.doRequest();
    assertEquals(SUCCESS_RESPONSE, result);
    Mockito.verify(requestMock, Mockito.times(2)).doProcess();
    Mockito.verify(requestMock, Mockito.times(0)).onParticularError(Mockito.any(ElasticsearchException.class));
}
 
Example #6
Source File: AbstractRetryableEsRequestTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * NoNodeAvailableExceptionが続き, リトライ3回目で成功した場合、適切な復帰値が返ること.
 */
@Test
public void NoShardAvailableActionExceptionが続き_リトライ4回目で成功した場合_適切な復帰値が返ること() {

    TestRequest requestMock = Mockito.spy(new TestRequest());

    NoShardAvailableActionException toBeThrown = Mockito.mock(NoShardAvailableActionException.class);
    Mockito.doThrow(toBeThrown) // 初回
            .doThrow(toBeThrown) // リトライ1回目
            .doThrow(toBeThrown) // リトライ2回目
            .doThrow(toBeThrown) // リトライ3回目
            .doReturn(SUCCESS_RESPONSE) // リトライ4回目で正常復帰
            .when(requestMock)
            .doProcess();

    String result = requestMock.doRequest();
    assertEquals(SUCCESS_RESPONSE, result);
    // doProcessが5回呼び出されるはず
    Mockito.verify(requestMock, Mockito.times(5)).doProcess();
    Mockito.verify(requestMock, Mockito.times(0)).onParticularError(Mockito.any(ElasticsearchException.class));
}
 
Example #7
Source File: AbstractRetryableEsRequestTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * 初回リクエストでNoShardAvailableActionException、リトライ1回目で成功した場合、適切な復帰値が返ること.
 */
@Test
public void 初回リクエストでNoShardAvailableActionException_リトライ1回目で成功した場合_適切な復帰値が返ること() {

    TestRequest requestMock = Mockito.spy(new TestRequest());

    NoShardAvailableActionException toBeThrown = Mockito.mock(NoShardAvailableActionException.class);
    Mockito.doThrow(toBeThrown)
            .doReturn(SUCCESS_RESPONSE)
            .when(requestMock)
            .doProcess();

    String result = requestMock.doRequest();
    assertEquals(SUCCESS_RESPONSE, result);
    Mockito.verify(requestMock, Mockito.times(2)).doProcess();
    Mockito.verify(requestMock, Mockito.times(0)).onParticularError(Mockito.any(ElasticsearchException.class));
}
 
Example #8
Source File: AbstractRetryableEsRequestTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * NoNodeAvailableExceptionが続き, リトライ3回目で成功した場合、適切な復帰値が返ること.
 */
@Test
public void NoShardAvailableActionExceptionが続き_リトライ4回目で成功した場合_適切な復帰値が返ること() {

    TestRequest requestMock = Mockito.spy(new TestRequest());

    NoShardAvailableActionException toBeThrown = Mockito.mock(NoShardAvailableActionException.class);
    Mockito.doThrow(toBeThrown) // 初回
            .doThrow(toBeThrown) // リトライ1回目
            .doThrow(toBeThrown) // リトライ2回目
            .doThrow(toBeThrown) // リトライ3回目
            .doReturn(SUCCESS_RESPONSE) // リトライ4回目で正常復帰
            .when(requestMock)
            .doProcess();

    String result = requestMock.doRequest();
    assertEquals(SUCCESS_RESPONSE, result);
    // doProcessが5回呼び出されるはず
    Mockito.verify(requestMock, Mockito.times(5)).doProcess();
    Mockito.verify(requestMock, Mockito.times(0)).onParticularError(Mockito.any(ElasticsearchException.class));
}
 
Example #9
Source File: TransportBroadcastByNodeAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private final Response newResponse(
        Request request,
        AtomicReferenceArray responses,
        List<NoShardAvailableActionException> unavailableShardExceptions,
        Map<String, List<ShardRouting>> nodes,
        ClusterState clusterState) {
    int totalShards = 0;
    int successfulShards = 0;
    List<ShardOperationResult> broadcastByNodeResponses = new ArrayList<>();
    List<ShardOperationFailedException> exceptions = new ArrayList<>();
    for (int i = 0; i < responses.length(); i++) {
        if (responses.get(i) instanceof FailedNodeException) {
            FailedNodeException exception = (FailedNodeException) responses.get(i);
            totalShards += nodes.get(exception.nodeId()).size();
            for (ShardRouting shard : nodes.get(exception.nodeId())) {
                exceptions.add(new DefaultShardOperationFailedException(shard.getIndex(), shard.getId(), exception));
            }
        } else {
            NodeResponse response = (NodeResponse) responses.get(i);
            broadcastByNodeResponses.addAll(response.results);
            totalShards += response.getTotalShards();
            successfulShards += response.getSuccessfulShards();
            for (BroadcastShardOperationFailedException throwable : response.getExceptions()) {
                if (!TransportActions.isShardNotAvailableException(throwable)) {
                    exceptions.add(new DefaultShardOperationFailedException(throwable.getIndex(), throwable.getShardId().getId(), throwable));
                }
            }
        }
    }
    totalShards += unavailableShardExceptions.size();
    int failedShards = exceptions.size();
    return newResponse(request, totalShards, successfulShards, failedShards, broadcastByNodeResponses, exceptions, clusterState);
}
 
Example #10
Source File: TransportActions.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public static boolean isShardNotAvailableException(Throwable t) {
    Throwable actual = ExceptionsHelper.unwrapCause(t);
    if (actual instanceof ShardNotFoundException ||
            actual instanceof IndexNotFoundException ||
            actual instanceof IllegalIndexShardStateException ||
            actual instanceof NoShardAvailableActionException ||
            actual instanceof UnavailableShardsException ||
            actual instanceof AlreadyClosedException) {
        return true;
    }
    return false;
}
 
Example #11
Source File: TransportBroadcastByNodeAction.java    From crate with Apache License 2.0 5 votes vote down vote up
private Response newResponse(
        Request request,
        AtomicReferenceArray responses,
        List<NoShardAvailableActionException> unavailableShardExceptions,
        Map<String, List<ShardRouting>> nodes,
        ClusterState clusterState) {
    int totalShards = 0;
    int successfulShards = 0;
    List<ShardOperationResult> broadcastByNodeResponses = new ArrayList<>();
    List<DefaultShardOperationFailedException> exceptions = new ArrayList<>();
    for (int i = 0; i < responses.length(); i++) {
        if (responses.get(i) instanceof FailedNodeException) {
            FailedNodeException exception = (FailedNodeException) responses.get(i);
            totalShards += nodes.get(exception.nodeId()).size();
            for (ShardRouting shard : nodes.get(exception.nodeId())) {
                exceptions.add(new DefaultShardOperationFailedException(shard.getIndexName(), shard.getId(), exception));
            }
        } else {
            NodeResponse response = (NodeResponse) responses.get(i);
            broadcastByNodeResponses.addAll(response.results);
            totalShards += response.getTotalShards();
            successfulShards += response.getSuccessfulShards();
            for (BroadcastShardOperationFailedException throwable : response.getExceptions()) {
                if (!TransportActions.isShardNotAvailableException(throwable)) {
                    exceptions.add(new DefaultShardOperationFailedException(throwable.getShardId().getIndexName(), throwable.getShardId().getId(), throwable));
                }
            }
        }
    }
    totalShards += unavailableShardExceptions.size();
    int failedShards = exceptions.size();
    return newResponse(request, totalShards, successfulShards, failedShards, broadcastByNodeResponses, exceptions, clusterState);
}
 
Example #12
Source File: TransportActions.java    From crate with Apache License 2.0 5 votes vote down vote up
public static boolean isShardNotAvailableException(final Throwable e) {
    final Throwable actual = ExceptionsHelper.unwrapCause(e);
    return (actual instanceof ShardNotFoundException ||
            actual instanceof IndexNotFoundException ||
            actual instanceof IllegalIndexShardStateException ||
            actual instanceof NoShardAvailableActionException ||
            actual instanceof UnavailableShardsException ||
            actual instanceof AlreadyClosedException);
}
 
Example #13
Source File: TransportBroadcastByNodeAction.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
protected AsyncAction(Task task, Request request, ActionListener<Response> listener) {
    this.task = task;
    this.request = request;
    this.listener = listener;

    ClusterState state = clusterService.state();
    if (request.getHeader(LoginUserContext.TENANT_FILTER) != null) {
        state = AuthService.filterState(state, state.metaData(), (Long) request.getHeader(LoginUserContext.TENANT_FILTER));
    }
    clusterState = state;
    nodes = clusterState.nodes();

    ClusterBlockException globalBlockException = checkGlobalBlock(clusterState, request);
    if (globalBlockException != null) {
        throw globalBlockException;
    }

    String[] concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, request);
    ClusterBlockException requestBlockException = checkRequestBlock(clusterState, request, concreteIndices);
    if (requestBlockException != null) {
        throw requestBlockException;
    }

    if (logger.isTraceEnabled()) {
        logger.trace("resolving shards for [{}] based on cluster state version [{}]", actionName, clusterState.version());
    }
    ShardsIterator shardIt = shards(clusterState, request, concreteIndices);
    nodeIds = Maps.newHashMap();

    for (ShardRouting shard : shardIt.asUnordered()) {
        // send a request to the shard only if it is assigned to a node that is in the local node's cluster state
        // a scenario in which a shard can be assigned but to a node that is not in the local node's cluster state
        // is when the shard is assigned to the master node, the local node has detected the master as failed
        // and a new master has not yet been elected; in this situation the local node will have removed the
        // master node from the local cluster state, but the shards assigned to the master will still be in the
        // routing table as such
        if (shard.assignedToNode() && nodes.get(shard.currentNodeId()) != null) {
            String nodeId = shard.currentNodeId();
            if (!nodeIds.containsKey(nodeId)) {
                nodeIds.put(nodeId, new ArrayList<ShardRouting>());
            }
            nodeIds.get(nodeId).add(shard);
        } else {
            unavailableShardExceptions.add(
                    new NoShardAvailableActionException(
                            shard.shardId(),
                            " no shards available for shard " + shard.toString() + " while executing " + actionName
                    )
            );
        }
    }

    responses = new AtomicReferenceArray<>(nodeIds.size());
}
 
Example #14
Source File: TransportBroadcastByNodeAction.java    From crate with Apache License 2.0 4 votes vote down vote up
protected AsyncAction(Task task, Request request, ActionListener<Response> listener) {
    this.task = task;
    this.request = request;
    this.listener = listener;

    clusterState = clusterService.state();
    nodes = clusterState.nodes();

    ClusterBlockException globalBlockException = checkGlobalBlock(clusterState, request);
    if (globalBlockException != null) {
        throw globalBlockException;
    }

    String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request);
    ClusterBlockException requestBlockException = checkRequestBlock(clusterState, request, concreteIndices);
    if (requestBlockException != null) {
        throw requestBlockException;
    }

    if (logger.isTraceEnabled()) {
        logger.trace("resolving shards for [{}] based on cluster state version [{}]", actionName, clusterState.version());
    }
    ShardsIterator shardIt = shards(clusterState, request, concreteIndices);
    nodeIds = new HashMap<>();

    for (ShardRouting shard : shardIt) {
        // send a request to the shard only if it is assigned to a node that is in the local node's cluster state
        // a scenario in which a shard can be assigned but to a node that is not in the local node's cluster state
        // is when the shard is assigned to the master node, the local node has detected the master as failed
        // and a new master has not yet been elected; in this situation the local node will have removed the
        // master node from the local cluster state, but the shards assigned to the master will still be in the
        // routing table as such
        if (shard.assignedToNode() && nodes.get(shard.currentNodeId()) != null) {
            String nodeId = shard.currentNodeId();
            if (!nodeIds.containsKey(nodeId)) {
                nodeIds.put(nodeId, new ArrayList<>());
            }
            nodeIds.get(nodeId).add(shard);
        } else {
            unavailableShardExceptions.add(
                    new NoShardAvailableActionException(
                            shard.shardId(),
                            " no shards available for shard " + shard.toString() + " while executing " + actionName
                    )
            );
        }
    }

    responses = new AtomicReferenceArray<>(nodeIds.size());
}