Search in sources :

Example 26 with Supplier

use of org.apache.logging.log4j.util.Supplier in project elasticsearch by elastic.

the class TaskManager method storeResult.

/**
     * Stores the task failure
     */
public <Response extends ActionResponse> void storeResult(Task task, Exception error, ActionListener<Response> listener) {
    DiscoveryNode localNode = lastDiscoveryNodes.getLocalNode();
    if (localNode == null) {
        // too early to store anything, shouldn't really be here - just pass the error along
        listener.onFailure(error);
        return;
    }
    final TaskResult taskResult;
    try {
        taskResult = task.result(localNode, error);
    } catch (IOException ex) {
        logger.warn((Supplier<?>) () -> new ParameterizedMessage("couldn't store error {}", ExceptionsHelper.detailedMessage(error)), ex);
        listener.onFailure(ex);
        return;
    }
    taskResultsService.storeResult(taskResult, new ActionListener<Void>() {

        @Override
        public void onResponse(Void aVoid) {
            listener.onFailure(error);
        }

        @Override
        public void onFailure(Exception e) {
            logger.warn((Supplier<?>) () -> new ParameterizedMessage("couldn't store error {}", ExceptionsHelper.detailedMessage(error)), e);
            listener.onFailure(e);
        }
    });
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) IOException(java.io.IOException) ElasticsearchException(org.elasticsearch.ElasticsearchException) IOException(java.io.IOException) ElasticsearchTimeoutException(org.elasticsearch.ElasticsearchTimeoutException)

Example 27 with Supplier

use of org.apache.logging.log4j.util.Supplier in project elasticsearch by elastic.

the class TaskManager method storeResult.

/**
     * Stores the task result
     */
public <Response extends ActionResponse> void storeResult(Task task, Response response, ActionListener<Response> listener) {
    DiscoveryNode localNode = lastDiscoveryNodes.getLocalNode();
    if (localNode == null) {
        // too early to store anything, shouldn't really be here - just pass the response along
        logger.warn("couldn't store response {}, the node didn't join the cluster yet", response);
        listener.onResponse(response);
        return;
    }
    final TaskResult taskResult;
    try {
        taskResult = task.result(localNode, response);
    } catch (IOException ex) {
        logger.warn((Supplier<?>) () -> new ParameterizedMessage("couldn't store response {}", response), ex);
        listener.onFailure(ex);
        return;
    }
    taskResultsService.storeResult(taskResult, new ActionListener<Void>() {

        @Override
        public void onResponse(Void aVoid) {
            listener.onResponse(response);
        }

        @Override
        public void onFailure(Exception e) {
            logger.warn((Supplier<?>) () -> new ParameterizedMessage("couldn't store response {}", response), e);
            listener.onFailure(e);
        }
    });
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) IOException(java.io.IOException) ElasticsearchException(org.elasticsearch.ElasticsearchException) IOException(java.io.IOException) ElasticsearchTimeoutException(org.elasticsearch.ElasticsearchTimeoutException)

Example 28 with Supplier

use of org.apache.logging.log4j.util.Supplier in project elasticsearch by elastic.

the class TcpTransport method handleException.

private void handleException(final TransportResponseHandler handler, Throwable error) {
    if (!(error instanceof RemoteTransportException)) {
        error = new RemoteTransportException(error.getMessage(), error);
    }
    final RemoteTransportException rtx = (RemoteTransportException) error;
    threadPool.executor(handler.executor()).execute(() -> {
        try {
            handler.handleException(rtx);
        } catch (Exception e) {
            logger.error((Supplier<?>) () -> new ParameterizedMessage("failed to handle exception response [{}]", handler), e);
        }
    });
}
Also used : Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) ElasticsearchException(org.elasticsearch.ElasticsearchException) NotCompressedException(org.elasticsearch.common.compress.NotCompressedException) StreamCorruptedException(java.io.StreamCorruptedException) CancelledKeyException(java.nio.channels.CancelledKeyException) NetworkExceptionHelper.isCloseConnectionException(org.elasticsearch.common.transport.NetworkExceptionHelper.isCloseConnectionException) BindException(java.net.BindException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException) NetworkExceptionHelper.isConnectException(org.elasticsearch.common.transport.NetworkExceptionHelper.isConnectException)

Example 29 with Supplier

use of org.apache.logging.log4j.util.Supplier in project elasticsearch by elastic.

the class TransportShardBulkAction method updateReplicaRequest.

// Visible for unit testing
static Translog.Location updateReplicaRequest(BulkItemResultHolder bulkItemResult, final DocWriteRequest.OpType opType, final Translog.Location originalLocation, BulkShardRequest request) {
    final Engine.Result operationResult = bulkItemResult.operationResult;
    final DocWriteResponse response = bulkItemResult.response;
    final BulkItemRequest replicaRequest = bulkItemResult.replicaRequest;
    if (operationResult == null) {
        // in case of noop update operation
        assert response.getResult() == DocWriteResponse.Result.NOOP : "only noop updates can have a null operation";
        replicaRequest.setPrimaryResponse(new BulkItemResponse(replicaRequest.id(), opType, response));
        return originalLocation;
    } else if (operationResult.hasFailure() == false) {
        BulkItemResponse primaryResponse = new BulkItemResponse(replicaRequest.id(), opType, response);
        replicaRequest.setPrimaryResponse(primaryResponse);
        // set a blank ShardInfo so we can safely send it to the replicas. We won't use it in the real response though.
        primaryResponse.getResponse().setShardInfo(new ShardInfo());
        // The operation was successful, advance the translog
        return locationToSync(originalLocation, operationResult.getTranslogLocation());
    } else {
        DocWriteRequest docWriteRequest = replicaRequest.request();
        Exception failure = operationResult.getFailure();
        if (isConflictException(failure)) {
            logger.trace((Supplier<?>) () -> new ParameterizedMessage("{} failed to execute bulk item ({}) {}", request.shardId(), docWriteRequest.opType().getLowercase(), request), failure);
        } else {
            logger.debug((Supplier<?>) () -> new ParameterizedMessage("{} failed to execute bulk item ({}) {}", request.shardId(), docWriteRequest.opType().getLowercase(), request), failure);
        }
        // then just use the response we got from the failed execution
        if (replicaRequest.getPrimaryResponse() == null || isConflictException(failure) == false) {
            replicaRequest.setPrimaryResponse(new BulkItemResponse(replicaRequest.id(), docWriteRequest.opType(), // concrete index instead of an alias if used!
            new BulkItemResponse.Failure(request.index(), docWriteRequest.type(), docWriteRequest.id(), failure)));
        }
        return originalLocation;
    }
}
Also used : DocWriteResponse(org.elasticsearch.action.DocWriteResponse) LongSupplier(java.util.function.LongSupplier) Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) DocWriteRequest(org.elasticsearch.action.DocWriteRequest) Engine(org.elasticsearch.index.engine.Engine) VersionConflictEngineException(org.elasticsearch.index.engine.VersionConflictEngineException) MapperParsingException(org.elasticsearch.index.mapper.MapperParsingException) IOException(java.io.IOException) ShardInfo(org.elasticsearch.action.support.replication.ReplicationResponse.ShardInfo)

Example 30 with Supplier

use of org.apache.logging.log4j.util.Supplier in project elasticsearch by elastic.

the class TransportOpenIndexAction method masterOperation.

@Override
protected void masterOperation(final OpenIndexRequest request, final ClusterState state, final ActionListener<OpenIndexResponse> listener) {
    final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request);
    OpenIndexClusterStateUpdateRequest updateRequest = new OpenIndexClusterStateUpdateRequest().ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout()).indices(concreteIndices);
    indexStateService.openIndex(updateRequest, new ActionListener<ClusterStateUpdateResponse>() {

        @Override
        public void onResponse(ClusterStateUpdateResponse response) {
            listener.onResponse(new OpenIndexResponse(response.isAcknowledged()));
        }

        @Override
        public void onFailure(Exception t) {
            logger.debug((Supplier<?>) () -> new ParameterizedMessage("failed to open indices [{}]", (Object) concreteIndices), t);
            listener.onFailure(t);
        }
    });
}
Also used : Index(org.elasticsearch.index.Index) Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) ClusterStateUpdateResponse(org.elasticsearch.cluster.ack.ClusterStateUpdateResponse) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException)

Aggregations

Supplier (org.apache.logging.log4j.util.Supplier)94 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)91 IOException (java.io.IOException)55 ElasticsearchException (org.elasticsearch.ElasticsearchException)27 ArrayList (java.util.ArrayList)25 ClusterState (org.elasticsearch.cluster.ClusterState)21 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)21 TimeValue (org.elasticsearch.common.unit.TimeValue)14 HashMap (java.util.HashMap)12 Map (java.util.Map)11 Settings (org.elasticsearch.common.settings.Settings)11 TransportException (org.elasticsearch.transport.TransportException)11 List (java.util.List)10 ExecutionException (java.util.concurrent.ExecutionException)10 Index (org.elasticsearch.index.Index)10 CountDownLatch (java.util.concurrent.CountDownLatch)9 NotMasterException (org.elasticsearch.cluster.NotMasterException)8 ClusterStateUpdateResponse (org.elasticsearch.cluster.ack.ClusterStateUpdateResponse)8 ClusterBlockException (org.elasticsearch.cluster.block.ClusterBlockException)8 NoSuchFileException (java.nio.file.NoSuchFileException)7