Java Code Examples for org.elasticsearch.common.util.concurrent.AtomicArray#Entry
The following examples show how to use
org.elasticsearch.common.util.concurrent.AtomicArray#Entry .
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 |
/** * 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
Source File: SearchScrollQueryThenFetchAsyncAction.java From Elasticsearch with Apache License 2.0 | 4 votes |
private void executeFetchPhase() throws Exception { sortedShardList = searchPhaseController.sortDocs(true, queryResults); AtomicArray<IntArrayList> docIdsToLoad = new AtomicArray<>(queryResults.length()); searchPhaseController.fillDocIdsToLoad(docIdsToLoad, sortedShardList); if (docIdsToLoad.asList().isEmpty()) { finishHim(); return; } final ScoreDoc[] lastEmittedDocPerShard = searchPhaseController.getLastEmittedDocPerShard(sortedShardList, queryResults.length()); final AtomicInteger counter = new AtomicInteger(docIdsToLoad.asList().size()); for (final AtomicArray.Entry<IntArrayList> entry : docIdsToLoad.asList()) { IntArrayList docIds = entry.value; final QuerySearchResult querySearchResult = queryResults.get(entry.index); ScoreDoc lastEmittedDoc = lastEmittedDocPerShard[entry.index]; ShardFetchRequest shardFetchRequest = new ShardFetchRequest(request, querySearchResult.id(), docIds, lastEmittedDoc); DiscoveryNode node = nodes.get(querySearchResult.shardTarget().nodeId()); searchService.sendExecuteFetchScroll(node, shardFetchRequest, new ActionListener<FetchSearchResult>() { @Override public void onResponse(FetchSearchResult result) { result.shardTarget(querySearchResult.shardTarget()); fetchResults.set(entry.index, result); if (counter.decrementAndGet() == 0) { finishHim(); } } @Override public void onFailure(Throwable t) { if (logger.isDebugEnabled()) { logger.debug("Failed to execute fetch phase", t); } successfulOps.decrementAndGet(); if (counter.decrementAndGet() == 0) { finishHim(); } } }); } }