Search in sources :

Example 66 with Supplier

use of org.apache.logging.log4j.util.Supplier 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 67 with Supplier

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

the class Engine method getSegmentFileSizes.

private ImmutableOpenMap<String, Long> getSegmentFileSizes(SegmentReader segmentReader) {
    Directory directory = null;
    SegmentCommitInfo segmentCommitInfo = segmentReader.getSegmentInfo();
    boolean useCompoundFile = segmentCommitInfo.info.getUseCompoundFile();
    if (useCompoundFile) {
        try {
            directory = engineConfig.getCodec().compoundFormat().getCompoundReader(segmentReader.directory(), segmentCommitInfo.info, IOContext.READ);
        } catch (IOException e) {
            logger.warn((Supplier<?>) () -> new ParameterizedMessage("Error when opening compound reader for Directory [{}] and SegmentCommitInfo [{}]", segmentReader.directory(), segmentCommitInfo), e);
            return ImmutableOpenMap.of();
        }
    } else {
        directory = segmentReader.directory();
    }
    assert directory != null;
    String[] files;
    if (useCompoundFile) {
        try {
            files = directory.listAll();
        } catch (IOException e) {
            final Directory finalDirectory = directory;
            logger.warn((Supplier<?>) () -> new ParameterizedMessage("Couldn't list Compound Reader Directory [{}]", finalDirectory), e);
            return ImmutableOpenMap.of();
        }
    } else {
        try {
            files = segmentReader.getSegmentInfo().files().toArray(new String[] {});
        } catch (IOException e) {
            logger.warn((Supplier<?>) () -> new ParameterizedMessage("Couldn't list Directory from SegmentReader [{}] and SegmentInfo [{}]", segmentReader, segmentReader.getSegmentInfo()), e);
            return ImmutableOpenMap.of();
        }
    }
    ImmutableOpenMap.Builder<String, Long> map = ImmutableOpenMap.builder();
    for (String file : files) {
        String extension = IndexFileNames.getExtension(file);
        long length = 0L;
        try {
            length = directory.fileLength(file);
        } catch (NoSuchFileException | FileNotFoundException e) {
            final Directory finalDirectory = directory;
            logger.warn((Supplier<?>) () -> new ParameterizedMessage("Tried to query fileLength but file is gone [{}] [{}]", finalDirectory, file), e);
        } catch (IOException e) {
            final Directory finalDirectory = directory;
            logger.warn((Supplier<?>) () -> new ParameterizedMessage("Error when trying to query fileLength [{}] [{}]", finalDirectory, file), e);
        }
        if (length == 0L) {
            continue;
        }
        map.put(extension, length);
    }
    if (useCompoundFile && directory != null) {
        try {
            directory.close();
        } catch (IOException e) {
            final Directory finalDirectory = directory;
            logger.warn((Supplier<?>) () -> new ParameterizedMessage("Error when closing compound reader on Directory [{}]", finalDirectory), e);
        }
    }
    return map.build();
}
Also used : SegmentCommitInfo(org.apache.lucene.index.SegmentCommitInfo) NoSuchFileException(java.nio.file.NoSuchFileException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) Directory(org.apache.lucene.store.Directory)

Example 68 with Supplier

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

the class TransportPutMappingAction method masterOperation.

@Override
protected void masterOperation(final PutMappingRequest request, final ClusterState state, final ActionListener<PutMappingResponse> listener) {
    try {
        final Index[] concreteIndices = request.getConcreteIndex() == null ? indexNameExpressionResolver.concreteIndices(state, request) : new Index[] { request.getConcreteIndex() };
        PutMappingClusterStateUpdateRequest updateRequest = new PutMappingClusterStateUpdateRequest().ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout()).indices(concreteIndices).type(request.type()).updateAllTypes(request.updateAllTypes()).source(request.source());
        metaDataMappingService.putMapping(updateRequest, new ActionListener<ClusterStateUpdateResponse>() {

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

            @Override
            public void onFailure(Exception t) {
                logger.debug((Supplier<?>) () -> new ParameterizedMessage("failed to put mappings on indices [{}], type [{}]", concreteIndices, request.type()), t);
                listener.onFailure(t);
            }
        });
    } catch (IndexNotFoundException ex) {
        logger.debug((Supplier<?>) () -> new ParameterizedMessage("failed to put mappings on indices [{}], type [{}]", request.indices(), request.type()), ex);
        throw ex;
    }
}
Also used : IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) 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) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException)

Example 69 with Supplier

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

the class TransportClusterUpdateSettingsAction method masterOperation.

@Override
protected void masterOperation(final ClusterUpdateSettingsRequest request, final ClusterState state, final ActionListener<ClusterUpdateSettingsResponse> listener) {
    final SettingsUpdater updater = new SettingsUpdater(clusterSettings);
    clusterService.submitStateUpdateTask("cluster_update_settings", new AckedClusterStateUpdateTask<ClusterUpdateSettingsResponse>(Priority.IMMEDIATE, request, listener) {

        private volatile boolean changed = false;

        @Override
        protected ClusterUpdateSettingsResponse newResponse(boolean acknowledged) {
            return new ClusterUpdateSettingsResponse(acknowledged, updater.getTransientUpdates(), updater.getPersistentUpdate());
        }

        @Override
        public void onAllNodesAcked(@Nullable Exception e) {
            if (changed) {
                reroute(true);
            } else {
                super.onAllNodesAcked(e);
            }
        }

        @Override
        public void onAckTimeout() {
            if (changed) {
                reroute(false);
            } else {
                super.onAckTimeout();
            }
        }

        private void reroute(final boolean updateSettingsAcked) {
            // so we should *not* execute the reroute.
            if (!clusterService.state().nodes().isLocalNodeElectedMaster()) {
                logger.debug("Skipping reroute after cluster update settings, because node is no longer master");
                listener.onResponse(new ClusterUpdateSettingsResponse(updateSettingsAcked, updater.getTransientUpdates(), updater.getPersistentUpdate()));
                return;
            }
            // The reason the reroute needs to be send as separate update task, is that all the *cluster* settings are encapsulate
            // in the components (e.g. FilterAllocationDecider), so the changes made by the first call aren't visible
            // to the components until the ClusterStateListener instances have been invoked, but are visible after
            // the first update task has been completed.
            clusterService.submitStateUpdateTask("reroute_after_cluster_update_settings", new AckedClusterStateUpdateTask<ClusterUpdateSettingsResponse>(Priority.URGENT, request, listener) {

                @Override
                public boolean mustAck(DiscoveryNode discoveryNode) {
                    //we wait for the reroute ack only if the update settings was acknowledged
                    return updateSettingsAcked;
                }

                @Override
                protected // update settings was acknowledged
                ClusterUpdateSettingsResponse newResponse(boolean acknowledged) {
                    return new ClusterUpdateSettingsResponse(updateSettingsAcked && acknowledged, updater.getTransientUpdates(), updater.getPersistentUpdate());
                }

                @Override
                public void onNoLongerMaster(String source) {
                    logger.debug("failed to preform reroute after cluster settings were updated - current node is no longer a master");
                    listener.onResponse(new ClusterUpdateSettingsResponse(updateSettingsAcked, updater.getTransientUpdates(), updater.getPersistentUpdate()));
                }

                @Override
                public void onFailure(String source, Exception e) {
                    //if the reroute fails we only log
                    logger.debug((Supplier<?>) () -> new ParameterizedMessage("failed to perform [{}]", source), e);
                    listener.onFailure(new ElasticsearchException("reroute after update settings failed", e));
                }

                @Override
                public ClusterState execute(final ClusterState currentState) {
                    // now, reroute in case things that require it changed (e.g. number of replicas)
                    return allocationService.reroute(currentState, "reroute after cluster update settings");
                }
            });
        }

        @Override
        public void onFailure(String source, Exception e) {
            logger.debug((Supplier<?>) () -> new ParameterizedMessage("failed to perform [{}]", source), e);
            super.onFailure(source, e);
        }

        @Override
        public ClusterState execute(final ClusterState currentState) {
            ClusterState clusterState = updater.updateSettings(currentState, request.transientSettings(), request.persistentSettings());
            changed = clusterState != currentState;
            return clusterState;
        }
    });
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ElasticsearchException(org.elasticsearch.ElasticsearchException) ElasticsearchException(org.elasticsearch.ElasticsearchException) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) AckedClusterStateUpdateTask(org.elasticsearch.cluster.AckedClusterStateUpdateTask) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) Supplier(org.apache.logging.log4j.util.Supplier)

Example 70 with Supplier

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

the class TransportUpdateSettingsAction method masterOperation.

@Override
protected void masterOperation(final UpdateSettingsRequest request, final ClusterState state, final ActionListener<UpdateSettingsResponse> listener) {
    final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request);
    UpdateSettingsClusterStateUpdateRequest clusterStateUpdateRequest = new UpdateSettingsClusterStateUpdateRequest().indices(concreteIndices).settings(request.settings()).setPreserveExisting(request.isPreserveExisting()).ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout());
    updateSettingsService.updateSettings(clusterStateUpdateRequest, new ActionListener<ClusterStateUpdateResponse>() {

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

        @Override
        public void onFailure(Exception t) {
            logger.debug((Supplier<?>) () -> new ParameterizedMessage("failed to update settings on 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