org.elasticsearch.ExceptionsHelper Java Examples

The following examples show how to use org.elasticsearch.ExceptionsHelper. 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: ValidatingDispatcher.java    From deprecated-security-ssl with Apache License 2.0 6 votes vote down vote up
protected void checkRequest(final RestRequest request, final RestChannel channel) {
    
    if(SSLRequestHelper.containsBadHeader(threadContext, "_opendistro_security_ssl_")) {
        final ElasticsearchException exception = ExceptionUtils.createBadHeaderException();
        errorHandler.logError(exception, request, 1);
        throw exception;
    }
    
    try {
        if(SSLRequestHelper.getSSLInfo(settings, configPath, request, null) == null) {
            logger.error("Not an SSL request");
            throw new ElasticsearchSecurityException("Not an SSL request", RestStatus.INTERNAL_SERVER_ERROR);
        }
    } catch (SSLPeerUnverifiedException e) {
        logger.error("No client certificates found but such are needed (Security 8).");
        errorHandler.logError(e, request, 0);
        throw ExceptionsHelper.convertToElastic(e);
    }
}
 
Example #2
Source File: UpsertByIdTask.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
private void createIndexAndExecuteUpsertRequest(final UpsertByIdNode.Item item,
                                                final SettableFuture<TaskResult> futureResult) {
    transportCreateIndexAction.execute(
            new CreateIndexRequest(item.index()).cause("upsert single item"),
            new ActionListener<CreateIndexResponse>() {
        @Override
        public void onResponse(CreateIndexResponse createIndexResponse) {
            executeUpsertRequest(item, futureResult);
        }

        @Override
        public void onFailure(Throwable e) {
            e = ExceptionsHelper.unwrapCause(e);
            if (e instanceof IndexAlreadyExistsException) {
                executeUpsertRequest(item, futureResult);
            } else {
                futureResult.setException(e);
            }

        }
    });
}
 
Example #3
Source File: LuceneQueryBuilder.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
private Query queryFromInnerFunction(Function function, Context context) {
    for (Symbol symbol : function.arguments()) {
        if (symbol.symbolType() == SymbolType.FUNCTION) {
            String functionName = ((Function) symbol).info().ident().name();
            InnerFunctionToQuery functionToQuery = innerFunctions.get(functionName);
            if (functionToQuery != null) {
                try {
                    Query query = functionToQuery.apply(function, (Function)symbol, context);
                    if (query != null) {
                        return query;
                    }
                } catch (IOException e) {
                    throw ExceptionsHelper.convertToRuntime(e);
                }
            }
        }
    }
    return null;
}
 
Example #4
Source File: BlobRecoverySource.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
synchronized void cancel(IndexShard shard, String reason) {
    final Set<RecoverySourceHandler> shardRecoveryHandlers = ongoingRecoveries.get(shard);
    if (shardRecoveryHandlers != null) {
        final List<Exception> failures = new ArrayList<>();
        for (RecoverySourceHandler handlers : shardRecoveryHandlers) {
            try {
                handlers.cancel(reason);
            } catch (Exception ex) {
                failures.add(ex);
            } finally {
                shard.recoveryStats().decCurrentAsSource();
            }
        }
        ExceptionsHelper.maybeThrowRuntimeAndSuppress(failures);
    }
}
 
Example #5
Source File: TransportDeleteAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
protected void doExecute(final Task task, final DeleteRequest request, final ActionListener<DeleteResponse> listener) {
    ClusterState state = clusterService.state();
    if (autoCreateIndex.shouldAutoCreate(request.index(), state)) {
        createIndexAction.execute(task, new CreateIndexRequest(request).index(request.index()).cause("auto(delete api)")
            .masterNodeTimeout(request.timeout()), new ActionListener<CreateIndexResponse>() {
            @Override
            public void onResponse(CreateIndexResponse result) {
                innerExecute(task, request, listener);
            }

            @Override
            public void onFailure(Throwable e) {
                if (ExceptionsHelper.unwrapCause(e) instanceof IndexAlreadyExistsException) {
                    // we have the index, do it
                    innerExecute(task, request, listener);
                } else {
                    listener.onFailure(e);
                }
            }
        });
    } else {
        innerExecute(task, request, listener);
    }
}
 
Example #6
Source File: ElasticsearchAssertions.java    From crate with Apache License 2.0 6 votes vote down vote up
public static void assertThrows(ActionFuture future, RestStatus status, String extraInfo) {
    boolean fail = false;
    extraInfo = extraInfo == null || extraInfo.isEmpty() ? "" : extraInfo + ": ";
    extraInfo += "expected a " + status + " status exception to be thrown";

    try {
        future.actionGet();
        fail = true;
    } catch (Exception e) {
        assertThat(extraInfo, ExceptionsHelper.status(e), equalTo(status));
    }
    // has to be outside catch clause to get a proper message
    if (fail) {
        throw new AssertionError(extraInfo);
    }
}
 
Example #7
Source File: AbstractScopedSettings.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * Validates that all settings are registered and valid.
 *
 * @param settings                       the settings
 * @param validateDependencies           true if dependent settings should be validated
 * @param ignorePrivateSettings          true if private settings should be ignored during validation
 * @param ignoreArchivedSettings         true if archived settings should be ignored during validation
 * @param validateInternalOrPrivateIndex true if index internal settings should be validated
 * @see Setting#getSettingsDependencies(String)
 */
public final void validate(
        final Settings settings,
        final boolean validateDependencies,
        final boolean ignorePrivateSettings,
        final boolean ignoreArchivedSettings,
        final boolean validateInternalOrPrivateIndex) {
    final List<RuntimeException> exceptions = new ArrayList<>();
    for (final String key : settings.keySet()) { // settings iterate in deterministic fashion
        final Setting<?> setting = getRaw(key);
        if (((isPrivateSetting(key) || (setting != null && setting.isPrivateIndex())) && ignorePrivateSettings)) {
            continue;
        }
        if (key.startsWith(ARCHIVED_SETTINGS_PREFIX) && ignoreArchivedSettings) {
            continue;
        }
        try {
            validate(key, settings, validateDependencies, validateInternalOrPrivateIndex);
        } catch (final RuntimeException ex) {
            exceptions.add(ex);
        }
    }
    ExceptionsHelper.rethrowAndSuppress(exceptions);
}
 
Example #8
Source File: PeerRecoverySourceService.java    From crate with Apache License 2.0 6 votes vote down vote up
synchronized void cancel(IndexShard shard, String reason) {
    final ShardRecoveryContext shardRecoveryContext = ongoingRecoveries.get(shard);
    if (shardRecoveryContext != null) {
        final List<Exception> failures = new ArrayList<>();
        for (RecoverySourceHandler handlers : shardRecoveryContext.recoveryHandlers) {
            try {
                handlers.cancel(reason);
            } catch (Exception ex) {
                failures.add(ex);
            } finally {
                shard.recoveryStats().decCurrentAsSource();
            }
        }
        ExceptionsHelper.maybeThrowRuntimeAndSuppress(failures);
    }
}
 
Example #9
Source File: SearchPhaseExecutionException.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
protected void innerToXContent(XContentBuilder builder, Params params) throws IOException {
    builder.field("phase", phaseName);
    final boolean group = params.paramAsBoolean("group_shard_failures", true); // we group by default
    builder.field("grouped", group); // notify that it's grouped
    builder.field("failed_shards");
    builder.startArray();
    ShardOperationFailedException[] failures = params.paramAsBoolean("group_shard_failures", true) ? ExceptionsHelper.groupBy(shardFailures) : shardFailures;
    for (ShardOperationFailedException failure : failures) {
        builder.startObject();
        failure.toXContent(builder, params);
        builder.endObject();
    }
    builder.endArray();
    super.innerToXContent(builder, params);
}
 
Example #10
Source File: MatchedQueriesFetchSubPhase.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public void hitExecute(SearchContext context, HitContext hitContext) {
    List<String> matchedQueries = new ArrayList<>(2);

    try {
        addMatchedQueries(hitContext, context.parsedQuery().namedFilters(), matchedQueries);

        if (context.parsedPostFilter() != null) {
            addMatchedQueries(hitContext, context.parsedPostFilter().namedFilters(), matchedQueries);
        }
    } catch (IOException e) {
        throw ExceptionsHelper.convertToElastic(e);
    } finally {
        SearchContext.current().clearReleasables(Lifetime.COLLECTION);
    }

    hitContext.hit().matchedQueries(matchedQueries.toArray(new String[matchedQueries.size()]));
}
 
Example #11
Source File: LuceneQueryBuilder.java    From crate with Apache License 2.0 6 votes vote down vote up
private Query queryFromInnerFunction(Function function, Context context) {
    for (Symbol symbol : function.arguments()) {
        if (symbol.symbolType() == SymbolType.FUNCTION) {
            String functionName = ((Function) symbol).name();
            InnerFunctionToQuery functionToQuery = innerFunctions.get(functionName);
            if (functionToQuery != null) {
                try {
                    Query query = functionToQuery.apply(function, (Function) symbol, context);
                    if (query != null) {
                        return query;
                    }
                } catch (IOException e) {
                    throw ExceptionsHelper.convertToRuntime(e);
                }
            }
        }
    }
    return null;
}
 
Example #12
Source File: MetaDataStateFormat.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * Tries to load the state of particular generation from the given data-locations. If any of data locations contain state files with
 * given generation, state will be loaded from these state files.
 *
 * @param logger a logger instance.
 * @param generation the generation to be loaded.
 * @param dataLocations the data-locations to try.
 * @return the state of asked generation or <code>null</code> if no state was found.
 */
public T loadGeneration(Logger logger, NamedXContentRegistry namedXContentRegistry, long generation, Path... dataLocations) {
    List<Path> stateFiles = findStateFilesByGeneration(generation, dataLocations);

    final List<Throwable> exceptions = new ArrayList<>();
    for (Path stateFile : stateFiles) {
        try {
            T state = read(namedXContentRegistry, stateFile);
            logger.trace("generation id [{}] read from [{}]", generation, stateFile.getFileName());
            return state;
        } catch (Exception e) {
            exceptions.add(new IOException("failed to read " + stateFile.toAbsolutePath(), e));
            logger.debug(() -> new ParameterizedMessage(
                    "{}: failed to read [{}], ignoring...", stateFile.toAbsolutePath(), prefix), e);
        }
    }
    // if we reach this something went wrong
    ExceptionsHelper.maybeThrowRuntimeAndSuppress(exceptions);
    if (stateFiles.size() > 0) {
        // We have some state files but none of them gave us a usable state
        throw new IllegalStateException("Could not find a state file to recover from among " +
                stateFiles.stream().map(Path::toAbsolutePath).map(Object::toString).collect(Collectors.joining(", ")));
    }
    return null;
}
 
Example #13
Source File: NettyTransport.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
/**
 * Disconnects from a node if a channel is found as part of that nodes channels.
 */
protected void disconnectFromNodeChannel(final Channel channel, final Throwable failure) {
    threadPool().generic().execute(new Runnable() {

        @Override
        public void run() {
            for (DiscoveryNode node : connectedNodes.keySet()) {
                if (disconnectFromNode(node, channel, ExceptionsHelper.detailedMessage(failure))) {
                    // if we managed to find this channel and disconnect from it, then break, no need to check on
                    // the rest of the nodes
                    break;
                }
            }
        }
    });
}
 
Example #14
Source File: TransportClientNodesService.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public void onFailure(Throwable e) {
    if (ExceptionsHelper.unwrapCause(e) instanceof ConnectTransportException) {
        int i = ++this.i;
        if (i >= nodes.size()) {
            listener.onFailure(new NoNodeAvailableException("None of the configured nodes were available: " + nodes, e));
        } else {
            try {
                callback.doWithNode(nodes.get((index + i) % nodes.size()), this);
            } catch(final Throwable t) {
                // this exception can't come from the TransportService as it doesn't throw exceptions at all
                listener.onFailure(t);
            }
        }
    } else {
        listener.onFailure(e);
    }
}
 
Example #15
Source File: BlobStoreIndexShardRepository.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void snapshot(SnapshotId snapshotId, ShardId shardId, SnapshotIndexCommit snapshotIndexCommit, IndexShardSnapshotStatus snapshotStatus) {
    SnapshotContext snapshotContext = new SnapshotContext(snapshotId, shardId, snapshotStatus);
    snapshotStatus.startTime(System.currentTimeMillis());

    try {
        snapshotContext.snapshot(snapshotIndexCommit);
        snapshotStatus.time(System.currentTimeMillis() - snapshotStatus.startTime());
        snapshotStatus.updateStage(IndexShardSnapshotStatus.Stage.DONE);
    } catch (Throwable e) {
        snapshotStatus.time(System.currentTimeMillis() - snapshotStatus.startTime());
        snapshotStatus.updateStage(IndexShardSnapshotStatus.Stage.FAILURE);
        snapshotStatus.failure(ExceptionsHelper.detailedMessage(e));
        if (e instanceof IndexShardSnapshotFailedException) {
            throw (IndexShardSnapshotFailedException) e;
        } else {
            throw new IndexShardSnapshotFailedException(shardId, e.getMessage(), e);
        }
    }
}
 
Example #16
Source File: SearchService.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public ScrollQuerySearchResult executeQueryPhase(InternalScrollSearchRequest request) {
    final SearchContext context = findContext(request.id());
    ShardSearchStats shardSearchStats = context.indexShard().searchService();
    try {
        shardSearchStats.onPreQueryPhase(context);
        long time = System.nanoTime();
        contextProcessing(context);
        processScroll(request, context);
        queryPhase.execute(context);
        contextProcessedSuccessfully(context);
        shardSearchStats.onQueryPhase(context, System.nanoTime() - time);
        return new ScrollQuerySearchResult(context.queryResult(), context.shardTarget());
    } catch (Throwable e) {
        shardSearchStats.onFailedQueryPhase(context);
        logger.trace("Query phase failed", e);
        processFailure(context, e);
        throw ExceptionsHelper.convertToRuntime(e);
    } finally {
        cleanContext(context);
    }
}
 
Example #17
Source File: ReplicationOperation.java    From crate with Apache License 2.0 6 votes vote down vote up
private void onNoLongerPrimary(Exception failure) {
    final Throwable cause = ExceptionsHelper.unwrapCause(failure);
    final boolean nodeIsClosing =
        cause instanceof NodeClosedException ||
        (cause instanceof TransportException && "TransportService is closed stopped can't send request".equals(cause.getMessage()));

    final String message;
    if (nodeIsClosing) {
        message = String.format(Locale.ROOT,
            "node with primary [%s] is shutting down while failing replica shard", primary.routingEntry());
        // We prefer not to fail the primary to avoid unnecessary warning log
        // when the node with the primary shard is gracefully shutting down.
    } else {
        if (Assertions.ENABLED) {
            if (failure instanceof ShardStateAction.NoLongerPrimaryShardException == false) {
                throw new AssertionError("unexpected failure", failure);
            }
        }
        // we are no longer the primary, fail ourselves and start over
        message = String.format(Locale.ROOT, "primary shard [%s] was demoted while failing replica shard", primary.routingEntry());
        primary.failShard(message, failure);
    }
    finishAsFailed(new RetryOnPrimaryException(primary.routingEntry().shardId(), message, failure));
}
 
Example #18
Source File: TransportClient.java    From elasticsearch-helper with Apache License 2.0 6 votes vote down vote up
@Override
public void onFailure(Throwable e) {
    if (ExceptionsHelper.unwrapCause(e) instanceof ConnectTransportException) {
        int n = ++this.n;
        if (n >= nodes.size()) {
            listener.onFailure(new NoNodeAvailableException("none of the configured nodes were available: "
                    + nodes, e));
        } else {
            try {
                logger.warn("retrying on anoher node (n={}, nodes={})", n, nodes.size());
                callback.doWithNode(nodes.get((index + n) % nodes.size()), this);
            } catch (final Throwable t) {
                listener.onFailure(t);
            }
        }
    } else {
        listener.onFailure(e);
    }
}
 
Example #19
Source File: PropertyUtil.java    From elasticsearch-shield-kerberos-realm with Apache License 2.0 5 votes vote down vote up
@SuppressForbidden(reason = "sysout needed here cause krb debug also goes to sysout")
public static void initKerberosProps(final Settings settings, Path conf) {
    if (conf == null) {
        final Environment env = new Environment(settings);
        conf = env.configFile();
    }
    PropertyUtil.setSystemProperty(KrbConstants.USE_SUBJECT_CREDS_ONLY_PROP, "false", false);
    //PropertyUtil.setSystemProperty(KrbConstants.USE_SUBJECT_CREDS_ONLY_PROP, "true", false); //TODO make strict
    try {
        PropertyUtil.setSystemPropertyToRelativeFile(KrbConstants.KRB5_CONF_PROP, conf,
                settings.get(SettingConstants.KRB5_FILE_PATH, "/etc/krb5.conf"), false, true);
    } catch (final FileNotFoundException e) {
        ExceptionsHelper.convertToElastic(e);
    }

    final boolean krbDebug = settings.getAsBoolean(SettingConstants.KRB_DEBUG, false);

    if (krbDebug) {
        System.out.println("Kerberos Realm debug is enabled");
        log.error("NOT AN ERROR: Kerberos Realm debug is enabled");
        JaasKrbUtil.ENABLE_DEBUG = true;
        System.setProperty("sun.security.krb5.debug", "true");
        System.setProperty("java.security.debug", "all");
        System.setProperty("java.security.auth.debug", "all");
        System.setProperty("sun.security.spnego.debug", "true");
    } else {
        log.info("Kerberos Realm debug is disabled");
    }

    log.info(KrbConstants.KRB5_CONF_PROP + ": {}", System.getProperty(KrbConstants.KRB5_CONF_PROP));

}
 
Example #20
Source File: Retry.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private boolean canRetry(BulkResponse bulkItemResponses) {
    if (!backoff.hasNext()) {
        return false;
    }
    for (BulkItemResponse bulkItemResponse : bulkItemResponses) {
        if (bulkItemResponse.isFailed()) {
            Throwable cause = bulkItemResponse.getFailure().getCause();
            Throwable rootCause = ExceptionsHelper.unwrapCause(cause);
            if (!rootCause.getClass().equals(retryOnThrowable)) {
                return false;
            }
        }
    }
    return true;
}
 
Example #21
Source File: SnapshotsService.java    From crate with Apache License 2.0 5 votes vote down vote up
private void cleanupAfterError(Exception exception) {
    threadPool.generic().execute(() -> {
        if (snapshotCreated) {
            repositoriesService.repository(snapshot.snapshot().getRepository()).finalizeSnapshot(snapshot.snapshot().getSnapshotId(),
                buildGenerations(snapshot),
                snapshot.startTime(),
                ExceptionsHelper.stackTrace(exception),
                0,
                Collections.emptyList(),
                snapshot.getRepositoryStateId(),
                snapshot.includeGlobalState(),
                metaDataForSnapshot(snapshot, clusterService.state().metaData()),
                snapshot.useShardGenerations(),
                ActionListener.runAfter(ActionListener.wrap(
                    ignored -> {},
                    inner -> {
                        inner.addSuppressed(exception);
                        LOGGER.warn(
                            () -> new ParameterizedMessage("[{}] failed to finalize snapshot in repository", snapshot.snapshot()), inner);
                    }),
                    () -> userCreateSnapshotListener.onFailure(e)
                )
            );
        } else {
            userCreateSnapshotListener.onFailure(e);
        }
    });
}
 
Example #22
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 #23
Source File: TransportIndexAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected void doExecute(final Task task, final IndexRequest request, final ActionListener<IndexResponse> listener) {
    // if we don't have a master, we don't have metadata, that's fine, let it find a master using create index API
    ClusterState state = clusterService.state();
    if (autoCreateIndex.shouldAutoCreate(request.index(), state)) {
        CreateIndexRequest createIndexRequest = new CreateIndexRequest(request);
        createIndexRequest.index(request.index());
        createIndexRequest.mapping(request.type());
        createIndexRequest.cause("auto(index api)");
        createIndexRequest.masterNodeTimeout(request.timeout());
        createIndexAction.execute(task, createIndexRequest, new ActionListener<CreateIndexResponse>() {
            @Override
            public void onResponse(CreateIndexResponse result) {
                innerExecute(task, request, listener);
            }

            @Override
            public void onFailure(Throwable e) {
                if (ExceptionsHelper.unwrapCause(e) instanceof IndexAlreadyExistsException) {
                    // we have the index, do it
                    try {
                        innerExecute(task, request, listener);
                    } catch (Throwable e1) {
                        listener.onFailure(e1);
                    }
                } else {
                    listener.onFailure(e);
                }
            }
        });
    } else {
        innerExecute(task, request, listener);
    }
}
 
Example #24
Source File: TransportUpdateAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected void doExecute(final UpdateRequest request, final ActionListener<UpdateResponse> listener) {
    // if we don't have a master, we don't have metadata, that's fine, let it find a master using create index API
    if (autoCreateIndex.shouldAutoCreate(request.index(), clusterService.state())) {
        createIndexAction.execute(new CreateIndexRequest(request).index(request.index()).cause("auto(update api)").masterNodeTimeout(request.timeout()), new ActionListener<CreateIndexResponse>() {
            @Override
            public void onResponse(CreateIndexResponse result) {
                innerExecute(request, listener);
            }

            @Override
            public void onFailure(Throwable e) {
                if (ExceptionsHelper.unwrapCause(e) instanceof IndexAlreadyExistsException) {
                    // we have the index, do it
                    try {
                        innerExecute(request, listener);
                    } catch (Throwable e1) {
                        listener.onFailure(e1);
                    }
                } else {
                    listener.onFailure(e);
                }
            }
        });
    } else {
        innerExecute(request, listener);
    }
}
 
Example #25
Source File: TransportCoordinateMultiSearchAction.java    From siren-join with GNU Affero General Public License v3.0 5 votes vote down vote up
private void doExecuteRequest(final MultiSearchRequest request, final ActionListener<MultiSearchResponse> listener,
                              final List<CoordinateSearchMetadata> metadatas) {
  ClusterState clusterState = clusterService.state();
  clusterState.blocks().globalBlockedRaiseException(ClusterBlockLevel.READ);

  final AtomicArray<CoordinateMultiSearchResponse.Item> responses = new AtomicArray<>(request.requests().size());
  final AtomicInteger counter = new AtomicInteger(responses.length());
  for (int i = 0; i < responses.length(); i++) {
    final int index = i;
    SearchRequest searchRequest = new SearchRequest(request.requests().get(i), request);
    searchAction.execute(searchRequest, new ActionListener<SearchResponse>() {

      @Override
      public void onResponse(SearchResponse searchResponse) {
        responses.set(index, new CoordinateMultiSearchResponse.Item(new CoordinateSearchResponse(searchResponse, metadatas.get(index)), null));
        if (counter.decrementAndGet() == 0) {
          finishHim();
        }
      }

      @Override
      public void onFailure(Throwable e) {
        responses.set(index, new CoordinateMultiSearchResponse.Item(null, ExceptionsHelper.detailedMessage(e)));
        if (counter.decrementAndGet() == 0) {
          finishHim();
        }
      }

      private void finishHim() {
        listener.onResponse(new CoordinateMultiSearchResponse(responses.toArray(new CoordinateMultiSearchResponse.Item[responses.length()])));
      }

    });
  }
}
 
Example #26
Source File: UnassignedInfo.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a string representation of the message and the failure if exists.
 */
@Nullable
public String getDetails() {
    if (message == null) {
        return null;
    }
    return message + (failure == null ? "" : ", failure " + ExceptionsHelper.detailedMessage(failure));
}
 
Example #27
Source File: BitsetFilterCache.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public BitSet getBitSet(LeafReaderContext context) throws IOException {
    try {
        return getAndLoadIfNotPresent(query, context);
    } catch (ExecutionException e) {
        throw ExceptionsHelper.convertToElastic(e);
    }
}
 
Example #28
Source File: Engine.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/** Check whether the engine should be failed */
protected boolean maybeFailEngine(String source, Throwable t) {
    if (Lucene.isCorruptionException(t)) {
        failEngine("corrupt file (source: [" + source + "])", t);
        return true;
    } else if (ExceptionsHelper.isOOM(t)) {
        failEngine("out of memory (source: [" + source + "])", t);
        return true;
    } else if (t instanceof RecoveryFromDistributedLogFailedException) {
        failEngine("recovery from distributed log service failed", t);
        return true;
    }
    return false;
}
 
Example #29
Source File: IndexFieldDataService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public synchronized void clearField(final String fieldName) {
    if (ParentFieldMapper.NAME.equals(fieldName)) {
        parentIndexFieldData = null;
    }
    List<Throwable> exceptions = new ArrayList<>(0);
    final IndexFieldDataCache cache = fieldDataCaches.remove(fieldName);
    if (cache != null) {
        try {
            cache.clear();
        } catch (Throwable t) {
            exceptions.add(t);
        }
    }
    ExceptionsHelper.maybeThrowRuntimeAndSuppress(exceptions);
}
 
Example #30
Source File: IndexFieldDataService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public synchronized void clear() {
    parentIndexFieldData = null;
    List<Throwable> exceptions = new ArrayList<>(0);
    final Collection<IndexFieldDataCache> fieldDataCacheValues = fieldDataCaches.values();
    for (IndexFieldDataCache cache : fieldDataCacheValues) {
        try {
            cache.clear();
        } catch (Throwable t) {
            exceptions.add(t);
        }
    }
    fieldDataCacheValues.clear();
    ExceptionsHelper.maybeThrowRuntimeAndSuppress(exceptions);
}