org.elasticsearch.common.util.concurrent.AtomicArray Java Examples
The following examples show how to use
org.elasticsearch.common.util.concurrent.AtomicArray.
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: AbstractSearchAsyncAction.java From Elasticsearch with Apache License 2.0 | 6 votes |
protected final void addShardFailure(final int shardIndex, @Nullable SearchShardTarget shardTarget, Throwable t) { // we don't aggregate shard failures on non active shards (but do keep the header counts right) if (TransportActions.isShardNotAvailableException(t)) { return; } // lazily create shard failures, so we can early build the empty shard failure list in most cases (no failures) if (shardFailures == null) { synchronized (shardFailuresMutex) { if (shardFailures == null) { shardFailures = new AtomicArray<>(shardsIts.size()); } } } ShardSearchFailure failure = shardFailures.get(shardIndex); if (failure == null) { shardFailures.set(shardIndex, new ShardSearchFailure(t, shardTarget)); } else { // the failure is already present, try and not override it with an exception that is less meaningless // for example, getting illegal shard state if (TransportActions.isReadOverrideException(t)) { shardFailures.set(shardIndex, new ShardSearchFailure(t, shardTarget)); } } }
Example #2
Source File: TransportBulkAction.java From Elasticsearch with Apache License 2.0 | 6 votes |
private boolean setResponseFailureIfIndexMatches(AtomicArray<BulkItemResponse> responses, int idx, ActionRequest request, String index, Throwable e) { if (request instanceof IndexRequest) { IndexRequest indexRequest = (IndexRequest) request; if (index.equals(indexRequest.index())) { responses.set(idx, new BulkItemResponse(idx, "index", new BulkItemResponse.Failure(indexRequest.index(), indexRequest.type(), indexRequest.id(), e))); return true; } } else if (request instanceof DeleteRequest) { DeleteRequest deleteRequest = (DeleteRequest) request; if (index.equals(deleteRequest.index())) { responses.set(idx, new BulkItemResponse(idx, "delete", new BulkItemResponse.Failure(deleteRequest.index(), deleteRequest.type(), deleteRequest.id(), e))); return true; } } else if (request instanceof UpdateRequest) { UpdateRequest updateRequest = (UpdateRequest) request; if (index.equals(updateRequest.index())) { responses.set(idx, new BulkItemResponse(idx, "update", new BulkItemResponse.Failure(updateRequest.index(), updateRequest.type(), updateRequest.id(), e))); return true; } } else { throw new ElasticsearchException("Parsed unknown request in bulk actions: " + request.getClass().getSimpleName()); } return false; }
Example #3
Source File: AbstractSearchAsyncAction.java From Elasticsearch with Apache License 2.0 | 6 votes |
/** * Releases shard targets that are not used in the docsIdsToLoad. */ protected void releaseIrrelevantSearchContexts(AtomicArray<? extends QuerySearchResultProvider> queryResults, AtomicArray<IntArrayList> docIdsToLoad) { if (docIdsToLoad == null) { return; } // we only release search context that we did not fetch from if we are not scrolling if (request.scroll() == null) { for (AtomicArray.Entry<? extends QuerySearchResultProvider> entry : queryResults.asList()) { final TopDocs topDocs = entry.value.queryResult().queryResult().topDocs(); if (topDocs != null && topDocs.scoreDocs.length > 0 // the shard had matches && docIdsToLoad.get(entry.index) == null) { // but none of them made it to the global top docs try { DiscoveryNode node = nodes.get(entry.value.queryResult().shardTarget().nodeId()); sendReleaseSearchContext(entry.value.queryResult().id(), node); } catch (Throwable t1) { logger.trace("failed to release context", t1); } } } } }
Example #4
Source File: TransportDfsOnlyAction.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override protected DfsOnlyResponse newResponse(DfsOnlyRequest request, AtomicReferenceArray shardsResponses, ClusterState clusterState) { int successfulShards = 0; int failedShards = 0; List<ShardOperationFailedException> shardFailures = null; AtomicArray<DfsSearchResult> dfsResults = new AtomicArray<>(shardsResponses.length()); for (int i = 0; i < shardsResponses.length(); i++) { Object shardResponse = shardsResponses.get(i); if (shardResponse == null) { // simply ignore non active shards } else if (shardResponse instanceof BroadcastShardOperationFailedException) { failedShards++; if (shardFailures == null) { shardFailures = new ArrayList<>(); } shardFailures.add(new DefaultShardOperationFailedException((BroadcastShardOperationFailedException) shardResponse)); } else { dfsResults.set(i, ((ShardDfsOnlyResponse) shardResponse).getDfsSearchResult()); successfulShards++; } } AggregatedDfs dfs = searchPhaseController.aggregateDfs(dfsResults); return new DfsOnlyResponse(dfs, shardsResponses.length(), successfulShards, failedShards, shardFailures, buildTookInMillis(request)); }
Example #5
Source File: SearchDfsQueryThenFetchAsyncAction.java From Elasticsearch with Apache License 2.0 | 6 votes |
void innerExecuteFetchPhase() throws Exception { boolean useScroll = request.scroll() != null; sortedShardList = searchPhaseController.sortDocs(useScroll, queryResults); searchPhaseController.fillDocIdsToLoad(docIdsToLoad, sortedShardList); if (docIdsToLoad.asList().isEmpty()) { finishHim(); return; } final ScoreDoc[] lastEmittedDocPerShard = searchPhaseController.getLastEmittedDocPerShard( request, sortedShardList, firstResults.length() ); final AtomicInteger counter = new AtomicInteger(docIdsToLoad.asList().size()); for (final AtomicArray.Entry<IntArrayList> entry : docIdsToLoad.asList()) { QuerySearchResult queryResult = queryResults.get(entry.index); DiscoveryNode node = nodes.get(queryResult.shardTarget().nodeId()); ShardFetchSearchRequest fetchSearchRequest = createFetchRequest(queryResult, entry, lastEmittedDocPerShard); executeFetch(entry.index, queryResult.shardTarget(), counter, fetchSearchRequest, node); } }
Example #6
Source File: SearchQueryThenFetchAsyncAction.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override protected void moveToSecondPhase() throws Exception { boolean useScroll = request.scroll() != null; sortedShardList = searchPhaseController.sortDocs(useScroll, firstResults); searchPhaseController.fillDocIdsToLoad(docIdsToLoad, sortedShardList); if (docIdsToLoad.asList().isEmpty()) { finishHim(); return; } final ScoreDoc[] lastEmittedDocPerShard = searchPhaseController.getLastEmittedDocPerShard( request, sortedShardList, firstResults.length() ); final AtomicInteger counter = new AtomicInteger(docIdsToLoad.asList().size()); for (AtomicArray.Entry<IntArrayList> entry : docIdsToLoad.asList()) { QuerySearchResultProvider queryResult = firstResults.get(entry.index); DiscoveryNode node = nodes.get(queryResult.shardTarget().nodeId()); ShardFetchSearchRequest fetchSearchRequest = createFetchRequest(queryResult.queryResult(), entry, lastEmittedDocPerShard); executeFetch(entry.index, queryResult.shardTarget(), counter, fetchSearchRequest, node); } }
Example #7
Source File: SearchScrollScanAsyncAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
protected final ShardSearchFailure[] buildShardFailures() { if (shardFailures == null) { return ShardSearchFailure.EMPTY_ARRAY; } List<AtomicArray.Entry<ShardSearchFailure>> entries = shardFailures.asList(); ShardSearchFailure[] failures = new ShardSearchFailure[entries.size()]; for (int i = 0; i < failures.length; i++) { failures[i] = entries.get(i).value; } return failures; }
Example #8
Source File: SearchPhaseController.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public int compare(AtomicArray.Entry<? extends QuerySearchResultProvider> o1, AtomicArray.Entry<? extends QuerySearchResultProvider> o2) { int i = o1.value.shardTarget().index().compareTo(o2.value.shardTarget().index()); if (i == 0) { i = o1.value.shardTarget().shardId() - o2.value.shardTarget().shardId(); } return i; }
Example #9
Source File: SearchDfsQueryThenFetchAsyncAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
SearchDfsQueryThenFetchAsyncAction(ESLogger logger, SearchServiceTransportAction searchService, ClusterService clusterService, IndexNameExpressionResolver indexNameExpressionResolver, SearchPhaseController searchPhaseController, ThreadPool threadPool, SearchRequest request, ActionListener<SearchResponse> listener) { super(logger, searchService, clusterService, indexNameExpressionResolver, searchPhaseController, threadPool, request, listener); queryResults = new AtomicArray<>(firstResults.length()); fetchResults = new AtomicArray<>(firstResults.length()); docIdsToLoad = new AtomicArray<>(firstResults.length()); }
Example #10
Source File: SearchDfsQueryThenFetchAsyncAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override protected void moveToSecondPhase() { final AggregatedDfs dfs = searchPhaseController.aggregateDfs(firstResults); final AtomicInteger counter = new AtomicInteger(firstResults.asList().size()); for (final AtomicArray.Entry<DfsSearchResult> entry : firstResults.asList()) { DfsSearchResult dfsResult = entry.value; DiscoveryNode node = nodes.get(dfsResult.shardTarget().nodeId()); QuerySearchRequest querySearchRequest = new QuerySearchRequest(request, dfsResult.id(), dfs); executeQuery(entry.index, dfsResult, counter, querySearchRequest, node); } }
Example #11
Source File: SearchQueryThenFetchAsyncAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
SearchQueryThenFetchAsyncAction(ESLogger logger, SearchServiceTransportAction searchService, ClusterService clusterService, IndexNameExpressionResolver indexNameExpressionResolver, SearchPhaseController searchPhaseController, ThreadPool threadPool, SearchRequest request, ActionListener<SearchResponse> listener) { super(logger, searchService, clusterService, indexNameExpressionResolver, searchPhaseController, threadPool, request, listener); fetchResults = new AtomicArray<>(firstResults.length()); docIdsToLoad = new AtomicArray<>(firstResults.length()); }
Example #12
Source File: TransportSearchHelper.java From Elasticsearch with Apache License 2.0 | 5 votes |
static String buildScrollId(SearchType searchType, AtomicArray<? extends SearchPhaseResult> searchPhaseResults, @Nullable Map<String, String> attributes) throws IOException { if (searchType == SearchType.DFS_QUERY_THEN_FETCH || searchType == SearchType.QUERY_THEN_FETCH) { return buildScrollId(ParsedScrollId.QUERY_THEN_FETCH_TYPE, searchPhaseResults, attributes); } else if (searchType == SearchType.QUERY_AND_FETCH || searchType == SearchType.DFS_QUERY_AND_FETCH) { return buildScrollId(ParsedScrollId.QUERY_AND_FETCH_TYPE, searchPhaseResults, attributes); } else if (searchType == SearchType.SCAN) { return buildScrollId(ParsedScrollId.SCAN, searchPhaseResults, attributes); } else { throw new IllegalStateException("search_type [" + searchType + "] not supported"); } }
Example #13
Source File: SearchScrollScanAsyncAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
SearchScrollScanAsyncAction(ESLogger logger, ClusterService clusterService, SearchServiceTransportAction searchService, SearchPhaseController searchPhaseController, SearchScrollRequest request, ParsedScrollId scrollId, ActionListener<SearchResponse> listener) { this.logger = logger; this.searchService = searchService; this.clusterService = clusterService; this.searchPhaseController = searchPhaseController; this.request = request; this.listener = listener; this.scrollId = scrollId; this.nodes = clusterService.state().nodes(); this.successfulOps = new AtomicInteger(scrollId.getContext().length); this.counter = new AtomicInteger(scrollId.getContext().length); this.queryFetchResults = new AtomicArray<>(scrollId.getContext().length); }
Example #14
Source File: SearchScrollQueryThenFetchAsyncAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
protected final ShardSearchFailure[] buildShardFailures() { if (shardFailures == null) { return ShardSearchFailure.EMPTY_ARRAY; } List<AtomicArray.Entry<ShardSearchFailure>> entries = shardFailures.asList(); ShardSearchFailure[] failures = new ShardSearchFailure[entries.size()]; for (int i = 0; i < failures.length; i++) { failures[i] = entries.get(i).value; } return failures; }
Example #15
Source File: TransportBulkAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
private boolean addFailureIfIndexIsUnavailable(DocumentRequest request, BulkRequest bulkRequest, AtomicArray<BulkItemResponse> responses, int idx, final ConcreteIndices concreteIndices, final MetaData metaData) { String concreteIndex = concreteIndices.getConcreteIndex(request.index()); Exception unavailableException = null; if (concreteIndex == null) { try { concreteIndex = concreteIndices.resolveIfAbsent(request); } catch (IndexClosedException | IndexNotFoundException ex) { // Fix for issue where bulk request references an index that // cannot be auto-created see issue #8125 unavailableException = ex; } } if (unavailableException == null) { IndexMetaData indexMetaData = metaData.index(concreteIndex); if (indexMetaData.getState() == IndexMetaData.State.CLOSE) { unavailableException = new IndexClosedException(new Index(metaData.index(request.index()).getIndex())); } } if (unavailableException != null) { BulkItemResponse.Failure failure = new BulkItemResponse.Failure(request.index(), request.type(), request.id(), unavailableException); String operationType = "unknown"; if (request instanceof IndexRequest) { operationType = "index"; } else if (request instanceof DeleteRequest) { operationType = "delete"; } else if (request instanceof UpdateRequest) { operationType = "update"; } BulkItemResponse bulkItemResponse = new BulkItemResponse(idx, operationType, failure); responses.set(idx, bulkItemResponse); // make sure the request gets never processed again bulkRequest.requests.set(idx, null); return true; } return false; }
Example #16
Source File: TransportCoordinateMultiSearchAction.java From siren-join with GNU Affero General Public License v3.0 | 5 votes |
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 #17
Source File: GroupedActionListener.java From crate with Apache License 2.0 | 5 votes |
/** * Creates a new listener * @param delegate the delegate listener * @param groupSize the group size */ public GroupedActionListener(ActionListener<Collection<T>> delegate, int groupSize) { if (groupSize <= 0) { throw new IllegalArgumentException("groupSize must be greater than 0 but was " + groupSize); } results = new AtomicArray<>(groupSize); countDown = new CountDown(groupSize); this.delegate = delegate; }
Example #18
Source File: SearchCountAsyncAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override protected void moveToSecondPhase() throws Exception { // no need to sort, since we know we have no hits back final InternalSearchResponse internalResponse = searchPhaseController.merge(SearchPhaseController.EMPTY_DOCS, firstResults, (AtomicArray<? extends FetchSearchResultProvider>) AtomicArray.empty(), request); String scrollId = null; if (request.scroll() != null) { scrollId = TransportSearchHelper.buildScrollId(request.searchType(), firstResults, null); } listener.onResponse(new SearchResponse(internalResponse, scrollId, expectedSuccessfulOps, successfulOps.get(), buildTookInMillis(), buildShardFailures())); }
Example #19
Source File: AbstractSearchAsyncAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
protected AbstractSearchAsyncAction(ESLogger logger, SearchServiceTransportAction searchService, ClusterService clusterService, IndexNameExpressionResolver indexNameExpressionResolver, SearchPhaseController searchPhaseController, ThreadPool threadPool, SearchRequest request, ActionListener<SearchResponse> listener) { this.logger = logger; this.searchService = searchService; this.indexNameExpressionResolver = indexNameExpressionResolver; this.searchPhaseController = searchPhaseController; this.threadPool = threadPool; this.request = request; this.listener = listener; this.clusterState = clusterService.state(); nodes = clusterState.nodes(); clusterState.blocks().globalBlockedRaiseException(ClusterBlockLevel.READ); // TODO: I think startTime() should become part of ActionRequest and that should be used both for index name // date math expressions and $now in scripts. This way all apis will deal with now in the same way instead // of just for the _search api String[] concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, request.indicesOptions(), startTime(), request.indices()); for (String index : concreteIndices) { clusterState.blocks().indexBlockedRaiseException(ClusterBlockLevel.READ, index); } Map<String, Set<String>> routingMap = indexNameExpressionResolver.resolveSearchRouting(clusterState, request.routing(), request.indices()); shardsIts = clusterService.operationRouting().searchShards(clusterState, concreteIndices, routingMap, request.preference()); expectedSuccessfulOps = shardsIts.size(); // we need to add 1 for non active partition, since we count it in the total! expectedTotalOps = shardsIts.totalSizeWith1ForEmpty(); firstResults = new AtomicArray<>(shardsIts.size()); }
Example #20
Source File: AbstractSearchAsyncAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
protected final ShardSearchFailure[] buildShardFailures() { AtomicArray<ShardSearchFailure> shardFailures = this.shardFailures; if (shardFailures == null) { return ShardSearchFailure.EMPTY_ARRAY; } List<AtomicArray.Entry<ShardSearchFailure>> entries = shardFailures.asList(); ShardSearchFailure[] failures = new ShardSearchFailure[entries.size()]; for (int i = 0; i < failures.length; i++) { failures[i] = entries.get(i).value; } return failures; }
Example #21
Source File: AbstractSearchAsyncAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
private void raiseEarlyFailure(Throwable t) { for (AtomicArray.Entry<FirstResult> entry : firstResults.asList()) { try { DiscoveryNode node = nodes.get(entry.value.shardTarget().nodeId()); sendReleaseSearchContext(entry.value.id(), node); } catch (Throwable t1) { logger.trace("failed to release context", t1); } } listener.onFailure(t); }
Example #22
Source File: AbstractSearchAsyncAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
protected ShardFetchSearchRequest createFetchRequest(QuerySearchResult queryResult, AtomicArray.Entry<IntArrayList> entry, ScoreDoc[] lastEmittedDocPerShard) { if (lastEmittedDocPerShard != null) { ScoreDoc lastEmittedDoc = lastEmittedDocPerShard[entry.index]; return new ShardFetchSearchRequest(request, queryResult.id(), entry.value, lastEmittedDoc); } else { return new ShardFetchSearchRequest(request, queryResult.id(), entry.value); } }
Example #23
Source File: AbstractSearchAsyncAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
protected final void processFirstPhaseResult(int shardIndex, FirstResult result) { firstResults.set(shardIndex, result); if (logger.isTraceEnabled()) { logger.trace("got first-phase result from {}", result != null ? result.shardTarget() : null); } // clean a previous error on this shard group (note, this code will be serialized on the same shardIndex value level // so its ok concurrency wise to miss potentially the shard failures being created because of another failure // in the #addShardFailure, because by definition, it will happen on *another* shardIndex AtomicArray<ShardSearchFailure> shardFailures = this.shardFailures; if (shardFailures != null) { shardFailures.set(shardIndex, null); } }
Example #24
Source File: SearchScanAsyncAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override protected void moveToSecondPhase() throws Exception { final InternalSearchResponse internalResponse = searchPhaseController.merge(SearchPhaseController.EMPTY_DOCS, firstResults, (AtomicArray<? extends FetchSearchResultProvider>) AtomicArray.empty(), request); String scrollId = null; if (request.scroll() != null) { scrollId = TransportSearchHelper.buildScrollId(request.searchType(), firstResults, ImmutableMap.of("total_hits", Long.toString (internalResponse.hits().totalHits()))); } listener.onResponse(new SearchResponse(internalResponse, scrollId, expectedSuccessfulOps, successfulOps.get(), buildTookInMillis(), buildShardFailures())); }
Example #25
Source File: SearchDfsQueryAndFetchAsyncAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
SearchDfsQueryAndFetchAsyncAction(ESLogger logger, SearchServiceTransportAction searchService, ClusterService clusterService, IndexNameExpressionResolver indexNameExpressionResolver, SearchPhaseController searchPhaseController, ThreadPool threadPool, SearchRequest request, ActionListener<SearchResponse> listener) { super(logger, searchService, clusterService, indexNameExpressionResolver, searchPhaseController, threadPool, request, listener); queryFetchResults = new AtomicArray<>(firstResults.length()); }
Example #26
Source File: SearchDfsQueryAndFetchAsyncAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override protected void moveToSecondPhase() { final AggregatedDfs dfs = searchPhaseController.aggregateDfs(firstResults); final AtomicInteger counter = new AtomicInteger(firstResults.asList().size()); for (final AtomicArray.Entry<DfsSearchResult> entry : firstResults.asList()) { DfsSearchResult dfsResult = entry.value; DiscoveryNode node = nodes.get(dfsResult.shardTarget().nodeId()); QuerySearchRequest querySearchRequest = new QuerySearchRequest(request, dfsResult.id(), dfs); executeSecondPhase(entry.index, dfsResult, counter, node, querySearchRequest); } }
Example #27
Source File: SearchScrollQueryAndFetchAsyncAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
SearchScrollQueryAndFetchAsyncAction(ESLogger logger, ClusterService clusterService, SearchServiceTransportAction searchService, SearchPhaseController searchPhaseController, SearchScrollRequest request, ParsedScrollId scrollId, ActionListener<SearchResponse> listener) { this.logger = logger; this.searchPhaseController = searchPhaseController; this.searchService = searchService; this.request = request; this.listener = listener; this.scrollId = scrollId; this.nodes = clusterService.state().nodes(); this.successfulOps = new AtomicInteger(scrollId.getContext().length); this.counter = new AtomicInteger(scrollId.getContext().length); this.queryFetchResults = new AtomicArray<>(scrollId.getContext().length); }
Example #28
Source File: SearchScrollQueryAndFetchAsyncAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
protected final ShardSearchFailure[] buildShardFailures() { if (shardFailures == null) { return ShardSearchFailure.EMPTY_ARRAY; } List<AtomicArray.Entry<ShardSearchFailure>> entries = shardFailures.asList(); ShardSearchFailure[] failures = new ShardSearchFailure[entries.size()]; for (int i = 0; i < failures.length; i++) { failures[i] = entries.get(i).value; } return failures; }
Example #29
Source File: TransportMultiSearchAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override protected void doExecute(final MultiSearchRequest request, final ActionListener<MultiSearchResponse> listener) { ClusterState clusterState = clusterService.state(); clusterState.blocks().globalBlockedRaiseException(ClusterBlockLevel.READ); final AtomicArray<MultiSearchResponse.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 MultiSearchResponse.Item(searchResponse, null)); if (counter.decrementAndGet() == 0) { finishHim(); } } @Override public void onFailure(Throwable e) { responses.set(index, new MultiSearchResponse.Item(null, e)); if (counter.decrementAndGet() == 0) { finishHim(); } } private void finishHim() { listener.onResponse(new MultiSearchResponse(responses.toArray(new MultiSearchResponse.Item[responses.length()]))); } }); } }
Example #30
Source File: SearchScrollQueryThenFetchAsyncAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
SearchScrollQueryThenFetchAsyncAction(ESLogger logger, ClusterService clusterService, SearchServiceTransportAction searchService, SearchPhaseController searchPhaseController, SearchScrollRequest request, ParsedScrollId scrollId, ActionListener<SearchResponse> listener) { this.logger = logger; this.searchService = searchService; this.searchPhaseController = searchPhaseController; this.request = request; this.listener = listener; this.scrollId = scrollId; this.nodes = clusterService.state().nodes(); this.successfulOps = new AtomicInteger(scrollId.getContext().length); this.queryResults = new AtomicArray<>(scrollId.getContext().length); this.fetchResults = new AtomicArray<>(scrollId.getContext().length); }