Search in sources :

Example 86 with ParameterizedMessage

use of org.apache.logging.log4j.message.ParameterizedMessage in project elasticsearch by elastic.

the class MetaStateService method writeIndex.

/**
     * Writes the index state.
     *
     * This method is public for testing purposes.
     */
public void writeIndex(String reason, IndexMetaData indexMetaData) throws IOException {
    final Index index = indexMetaData.getIndex();
    logger.trace("[{}] writing state, reason [{}]", index, reason);
    try {
        IndexMetaData.FORMAT.write(indexMetaData, nodeEnv.indexPaths(indexMetaData.getIndex()));
    } catch (Exception ex) {
        logger.warn((Supplier<?>) () -> new ParameterizedMessage("[{}]: failed to write index state", index), ex);
        throw new IOException("failed to write state for [" + index + "]", ex);
    }
}
Also used : Index(org.elasticsearch.index.Index) Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) IOException(java.io.IOException) IOException(java.io.IOException)

Example 87 with ParameterizedMessage

use of org.apache.logging.log4j.message.ParameterizedMessage in project elasticsearch by elastic.

the class PrimaryShardAllocator method buildNodeShardsResult.

/**
     * Builds a list of nodes. If matchAnyShard is set to false, only nodes that have an allocation id matching
     * inSyncAllocationIds are added to the list. Otherwise, any node that has a shard is added to the list, but
     * entries with matching allocation id are always at the front of the list.
     */
protected static NodeShardsResult buildNodeShardsResult(ShardRouting shard, boolean matchAnyShard, Set<String> ignoreNodes, Set<String> inSyncAllocationIds, FetchResult<NodeGatewayStartedShards> shardState, Logger logger) {
    List<NodeGatewayStartedShards> nodeShardStates = new ArrayList<>();
    int numberOfAllocationsFound = 0;
    for (NodeGatewayStartedShards nodeShardState : shardState.getData().values()) {
        DiscoveryNode node = nodeShardState.getNode();
        String allocationId = nodeShardState.allocationId();
        if (ignoreNodes.contains(node.getId())) {
            continue;
        }
        if (nodeShardState.storeException() == null) {
            if (allocationId == null) {
                logger.trace("[{}] on node [{}] has no shard state information", shard, nodeShardState.getNode());
            } else {
                logger.trace("[{}] on node [{}] has allocation id [{}]", shard, nodeShardState.getNode(), allocationId);
            }
        } else {
            final String finalAllocationId = allocationId;
            if (nodeShardState.storeException() instanceof ShardLockObtainFailedException) {
                logger.trace((Supplier<?>) () -> new ParameterizedMessage("[{}] on node [{}] has allocation id [{}] but the store can not be opened as it's locked, treating as valid shard", shard, nodeShardState.getNode(), finalAllocationId), nodeShardState.storeException());
            } else {
                logger.trace((Supplier<?>) () -> new ParameterizedMessage("[{}] on node [{}] has allocation id [{}] but the store can not be opened, treating as no allocation id", shard, nodeShardState.getNode(), finalAllocationId), nodeShardState.storeException());
                allocationId = null;
            }
        }
        if (allocationId != null) {
            assert nodeShardState.storeException() == null || nodeShardState.storeException() instanceof ShardLockObtainFailedException : "only allow store that can be opened or that throws a ShardLockObtainFailedException while being opened but got a store throwing " + nodeShardState.storeException();
            numberOfAllocationsFound++;
            if (matchAnyShard || inSyncAllocationIds.contains(nodeShardState.allocationId())) {
                nodeShardStates.add(nodeShardState);
            }
        }
    }
    // allocation preference
    final Comparator<NodeGatewayStartedShards> comparator;
    if (matchAnyShard) {
        // prefer shards with matching allocation ids
        Comparator<NodeGatewayStartedShards> matchingAllocationsFirst = Comparator.comparing((NodeGatewayStartedShards state) -> inSyncAllocationIds.contains(state.allocationId())).reversed();
        comparator = matchingAllocationsFirst.thenComparing(NO_STORE_EXCEPTION_FIRST_COMPARATOR).thenComparing(PRIMARY_FIRST_COMPARATOR);
    } else {
        comparator = NO_STORE_EXCEPTION_FIRST_COMPARATOR.thenComparing(PRIMARY_FIRST_COMPARATOR);
    }
    nodeShardStates.sort(comparator);
    if (logger.isTraceEnabled()) {
        logger.trace("{} candidates for allocation: {}", shard, nodeShardStates.stream().map(s -> s.getNode().getName()).collect(Collectors.joining(", ")));
    }
    return new NodeShardsResult(nodeShardStates, numberOfAllocationsFound);
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ArrayList(java.util.ArrayList) NodeGatewayStartedShards(org.elasticsearch.gateway.TransportNodesListGatewayStartedShards.NodeGatewayStartedShards) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) ShardLockObtainFailedException(org.elasticsearch.env.ShardLockObtainFailedException)

Example 88 with ParameterizedMessage

use of org.apache.logging.log4j.message.ParameterizedMessage in project elasticsearch by elastic.

the class NodeEnvironment method close.

@Override
public void close() {
    if (closed.compareAndSet(false, true) && locks != null) {
        for (Lock lock : locks) {
            try {
                logger.trace("releasing lock [{}]", lock);
                lock.close();
            } catch (IOException e) {
                logger.trace((Supplier<?>) () -> new ParameterizedMessage("failed to release lock [{}]", lock), e);
            }
        }
    }
}
Also used : Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) IOException(java.io.IOException) Lock(org.apache.lucene.store.Lock)

Example 89 with ParameterizedMessage

use of org.apache.logging.log4j.message.ParameterizedMessage in project elasticsearch by elastic.

the class AsyncShardFetch method processAsyncFetch.

/**
     * Called by the response handler of the async action to fetch data. Verifies that its still working
     * on the same cache generation, otherwise the results are discarded. It then goes and fills the relevant data for
     * the shard (response + failures), issuing a reroute at the end of it to make sure there will be another round
     * of allocations taking this new data into account.
     */
protected synchronized void processAsyncFetch(ShardId shardId, List<T> responses, List<FailedNodeException> failures) {
    if (closed) {
        // we are closed, no need to process this async fetch at all
        logger.trace("{} ignoring fetched [{}] results, already closed", shardId, type);
        return;
    }
    logger.trace("{} processing fetched [{}] results", shardId, type);
    if (responses != null) {
        for (T response : responses) {
            NodeEntry<T> nodeEntry = cache.get(response.getNode().getId());
            // if the entry is there, and not marked as failed already, process it
            if (nodeEntry == null) {
                continue;
            }
            if (nodeEntry.isFailed()) {
                logger.trace("{} node {} has failed for [{}] (failure [{}])", shardId, nodeEntry.getNodeId(), type, nodeEntry.getFailure());
            } else {
                logger.trace("{} marking {} as done for [{}], result is [{}]", shardId, nodeEntry.getNodeId(), type, response);
                nodeEntry.doneFetching(response);
            }
        }
    }
    if (failures != null) {
        for (FailedNodeException failure : failures) {
            logger.trace("{} processing failure {} for [{}]", shardId, failure, type);
            NodeEntry<T> nodeEntry = cache.get(failure.nodeId());
            // if the entry is there, and not marked as failed already, process it
            if (nodeEntry != null && nodeEntry.isFailed() == false) {
                Throwable unwrappedCause = ExceptionsHelper.unwrapCause(failure.getCause());
                // if the request got rejected or timed out, we need to try it again next time...
                if (unwrappedCause instanceof EsRejectedExecutionException || unwrappedCause instanceof ReceiveTimeoutTransportException || unwrappedCause instanceof ElasticsearchTimeoutException) {
                    nodeEntry.restartFetching();
                } else {
                    logger.warn((Supplier<?>) () -> new ParameterizedMessage("{}: failed to list shard for {} on node [{}]", shardId, type, failure.nodeId()), failure);
                    nodeEntry.doneFetching(failure.getCause());
                }
            }
        }
    }
    reroute(shardId, "post_response");
}
Also used : ReceiveTimeoutTransportException(org.elasticsearch.transport.ReceiveTimeoutTransportException) ElasticsearchTimeoutException(org.elasticsearch.ElasticsearchTimeoutException) FailedNodeException(org.elasticsearch.action.FailedNodeException) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)

Example 90 with ParameterizedMessage

use of org.apache.logging.log4j.message.ParameterizedMessage in project elasticsearch by elastic.

the class Engine method failEngine.

/**
     * fail engine due to some error. the engine will also be closed.
     * The underlying store is marked corrupted iff failure is caused by index corruption
     */
public void failEngine(String reason, @Nullable Exception failure) {
    if (failEngineLock.tryLock()) {
        store.incRef();
        try {
            if (failedEngine.get() != null) {
                logger.warn((Supplier<?>) () -> new ParameterizedMessage("tried to fail engine but engine is already failed. ignoring. [{}]", reason), failure);
                return;
            }
            // this must happen before we close IW or Translog such that we can check this state to opt out of failing the engine
            // again on any caught AlreadyClosedException
            failedEngine.set((failure != null) ? failure : new IllegalStateException(reason));
            try {
                // we just go and close this engine - no way to recover
                closeNoLock("engine failed on: [" + reason + "]");
            } finally {
                logger.warn((Supplier<?>) () -> new ParameterizedMessage("failed engine [{}]", reason), failure);
                // the shard is initializing
                if (Lucene.isCorruptionException(failure)) {
                    try {
                        store.markStoreCorrupted(new IOException("failed engine (reason: [" + reason + "])", ExceptionsHelper.unwrapCorruption(failure)));
                    } catch (IOException e) {
                        logger.warn("Couldn't mark store corrupted", e);
                    }
                }
                eventListener.onFailedEngine(reason, failure);
            }
        } catch (Exception inner) {
            if (failure != null)
                inner.addSuppressed(failure);
            // don't bubble up these exceptions up
            logger.warn("failEngine threw exception", inner);
        } finally {
            store.decRef();
        }
    } else {
        logger.debug((Supplier<?>) () -> new ParameterizedMessage("tried to fail engine but could not acquire lock - engine should be failed by now [{}]", reason), failure);
    }
}
Also used : ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) IOException(java.io.IOException) NoSuchFileException(java.nio.file.NoSuchFileException) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Aggregations

ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)131 Supplier (org.apache.logging.log4j.util.Supplier)90 IOException (java.io.IOException)75 ElasticsearchException (org.elasticsearch.ElasticsearchException)38 ArrayList (java.util.ArrayList)28 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)26 ClusterState (org.elasticsearch.cluster.ClusterState)25 HashMap (java.util.HashMap)16 TimeValue (org.elasticsearch.common.unit.TimeValue)14 TransportException (org.elasticsearch.transport.TransportException)14 List (java.util.List)13 Supplier (java.util.function.Supplier)13 Map (java.util.Map)12 CountDownLatch (java.util.concurrent.CountDownLatch)12 ExecutionException (java.util.concurrent.ExecutionException)12 Settings (org.elasticsearch.common.settings.Settings)12 EsRejectedExecutionException (org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)12 AbstractRunnable (org.elasticsearch.common.util.concurrent.AbstractRunnable)11 Index (org.elasticsearch.index.Index)11 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)10