From 9549b9c2d3cd4151a03bacebea13b96b19478291 Mon Sep 17 00:00:00 2001 From: kimchy Date: Fri, 9 Apr 2010 17:06:09 +0300 Subject: [PATCH] fix wrong handling of doc ids to load when request is not serialized --- build.gradle | 3 +++ .../org/elasticsearch/search/SearchService.java | 10 +++------- .../search/controller/SearchPhaseController.java | 2 +- .../elasticsearch/search/fetch/FetchPhase.java | 5 +++-- .../search/fetch/FetchSearchRequest.java | 10 +++++++--- .../search/internal/SearchContext.java | 16 +++++++++++++++- 6 files changed, 32 insertions(+), 14 deletions(-) diff --git a/build.gradle b/build.gradle index fda54ff29e9..3dc79acb03c 100644 --- a/build.gradle +++ b/build.gradle @@ -66,6 +66,9 @@ task explodedDist(dependsOn: [configurations.distLib], description: 'Builds a mi include 'README.textile' } + ant.delete { fileset(dir: explodedDistLibDir, includes: "$archivesBaseName-*-javadoc.jar") } + ant.delete { fileset(dir: explodedDistLibDir, includes: "$archivesBaseName-*-sources.jar") } + ant.chmod(dir: "$explodedDistDir/bin", perm: "ugo+rx", includes: "**/*") } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchService.java index 8649f5c6f9d..b37f425b665 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchService.java @@ -59,7 +59,6 @@ import org.elasticsearch.util.timer.Timeout; import org.elasticsearch.util.timer.TimerTask; import java.io.IOException; -import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -260,7 +259,7 @@ public class SearchService extends AbstractLifecycleComponent { public FetchSearchResult executeFetchPhase(FetchSearchRequest request) throws ElasticSearchException { SearchContext context = findContext(request.id()); try { - context.docIdsToLoad(request.docIds()); + context.docIdsToLoad(request.docIds(), 0, request.docIdsSize()); fetchPhase.execute(context); if (context.scroll() == null) { freeContext(request.id()); @@ -366,7 +365,7 @@ public class SearchService extends AbstractLifecycleComponent { TopDocs topDocs = context.queryResult().topDocs(); if (topDocs.scoreDocs.length < context.from()) { // no more docs... - context.docIdsToLoad(EMPTY_DOC_IDS); + context.docIdsToLoad(EMPTY_DOC_IDS, 0, 0); return; } int totalSize = context.from() + context.size(); @@ -380,10 +379,7 @@ public class SearchService extends AbstractLifecycleComponent { } counter++; } - if (counter < context.size()) { - docIdsToLoad = Arrays.copyOfRange(docIdsToLoad, 0, counter); - } - context.docIdsToLoad(docIdsToLoad); + context.docIdsToLoad(docIdsToLoad, 0, counter); } private void processScroll(InternalScrollSearchRequest request, SearchContext context) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/controller/SearchPhaseController.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/controller/SearchPhaseController.java index a2f69c40992..7ca0b7281d2 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/controller/SearchPhaseController.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/controller/SearchPhaseController.java @@ -139,7 +139,7 @@ public class SearchPhaseController { for (ShardDoc shardDoc : shardDocs) { ExtTIntArrayList list = result.get(shardDoc.shardTarget()); if (list == null) { - list = new ExtTIntArrayList(); + list = new ExtTIntArrayList(); // can't be shared!, uses unsafe on it later on result.put(shardDoc.shardTarget(), list); } list.add(shardDoc.docId()); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java index 59d907fbe8a..226bd498789 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java @@ -65,9 +65,10 @@ public class FetchPhase implements SearchPhase { public void execute(SearchContext context) { FieldSelector fieldSelector = buildFieldSelectors(context); - InternalSearchHit[] hits = new InternalSearchHit[context.docIdsToLoad().length]; + InternalSearchHit[] hits = new InternalSearchHit[context.docIdsToLoadSize()]; int index = 0; - for (int docId : context.docIdsToLoad()) { + for (int docIdIdx = context.docIdsToLoadFrom(); docIdIdx < context.docIdsToLoadSize(); docIdIdx++) { + int docId = context.docIdsToLoad()[docIdIdx]; Document doc = loadDocument(context, fieldSelector, docId); Uid uid = extractUid(context, doc); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/FetchSearchRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/FetchSearchRequest.java index 9f12324d329..8b93d57accd 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/FetchSearchRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/FetchSearchRequest.java @@ -27,7 +27,7 @@ import org.elasticsearch.util.trove.ExtTIntArrayList; import java.io.IOException; /** - * @author kimchy (Shay Banon) + * @author kimchy (shay.banon) */ public class FetchSearchRequest implements Streamable { @@ -35,7 +35,7 @@ public class FetchSearchRequest implements Streamable { private int[] docIds; - private transient int size; + private int size; public FetchSearchRequest() { } @@ -60,11 +60,15 @@ public class FetchSearchRequest implements Streamable { return docIds; } + public int docIdsSize() { + return size; + } + @Override public void readFrom(StreamInput in) throws IOException { id = in.readLong(); size = in.readVInt(); docIds = new int[size]; - for (int i = 0; i < docIds.length; i++) { + for (int i = 0; i < size; i++) { docIds[i] = in.readVInt(); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/SearchContext.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/SearchContext.java index ef16e6c6369..78591846174 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/SearchContext.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/SearchContext.java @@ -90,6 +90,10 @@ public class SearchContext implements Releasable { private int[] docIdsToLoad; + private int docsIdsToLoadFrom; + + private int docsIdsToLoadSize; + private SearchContextFacets facets; private SearchContextHighlight highlight; @@ -295,8 +299,18 @@ public class SearchContext implements Releasable { return docIdsToLoad; } - public SearchContext docIdsToLoad(int[] docIdsToLoad) { + public int docIdsToLoadFrom() { + return docsIdsToLoadFrom; + } + + public int docIdsToLoadSize() { + return docsIdsToLoadSize; + } + + public SearchContext docIdsToLoad(int[] docIdsToLoad, int docsIdsToLoadFrom, int docsIdsToLoadSize) { this.docIdsToLoad = docIdsToLoad; + this.docsIdsToLoadFrom = docsIdsToLoadFrom; + this.docsIdsToLoadSize = docsIdsToLoadSize; return this; }