Skip to content

Commit

Permalink
Addressed Ankit's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Alfonsi committed Oct 19, 2023
1 parent 4dcc13c commit ac6afd3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void preProcess(SearchContext context) {
}

public void execute(SearchContext searchContext) throws QueryPhaseExecutionException {
long startTime = System.nanoTime();
final long startTime = System.nanoTime();
if (searchContext.hasOnlySuggest()) {
suggestProcessor.process(searchContext);
searchContext.queryResult()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import org.apache.lucene.search.FieldDoc;
import org.apache.lucene.search.TotalHits;
import org.opensearch.Version;
import org.opensearch.common.io.stream.DelayableWriteable;
import org.opensearch.common.lucene.search.TopDocsAndMaxScore;
import org.opensearch.core.common.io.stream.StreamInput;
Expand Down Expand Up @@ -88,6 +89,7 @@ public final class QuerySearchResult extends SearchPhaseResult {

private final boolean isNull;
private long tookTimeNanos;
private final static Version minimumTookTimeVersion = Version.V_3_0_0;

public QuerySearchResult() {
this(false);
Expand Down Expand Up @@ -365,7 +367,11 @@ public void readFromWithId(ShardSearchContextId id, StreamInput in) throws IOExc
nodeQueueSize = in.readInt();
setShardSearchRequest(in.readOptionalWriteable(ShardSearchRequest::new));
setRescoreDocIds(new RescoreDocIds(in));
tookTimeNanos = in.readVLong();
if (in.getVersion().onOrAfter(minimumTookTimeVersion)) {
tookTimeNanos = in.readVLong();
} else {
tookTimeNanos = -1L;
}
}

@Override
Expand Down Expand Up @@ -408,7 +414,9 @@ public void writeToNoId(StreamOutput out) throws IOException {
out.writeInt(nodeQueueSize);
out.writeOptionalWriteable(getShardSearchRequest());
getRescoreDocIds().writeTo(out);
out.writeVLong(tookTimeNanos); // VLong as took time should always be positive
if (out.getVersion().onOrAfter(minimumTookTimeVersion)) {
out.writeVLong(tookTimeNanos); // VLong as took time should always be positive
}
}

public TotalHits getTotalHits() {
Expand All @@ -423,7 +431,7 @@ public long getTookTimeNanos() {
return tookTimeNanos;
}

public void setTookTimeNanos(long tookTime) {
void setTookTimeNanos(long tookTime) {
tookTimeNanos = tookTime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ public void testQueryTimeoutChecker() throws Exception {
}

public void testQuerySearchResultTookTime() throws IOException {
int sleepMillis = randomIntBetween(500, 4000); // between 0.5 and 4 sec
int sleepMillis = randomIntBetween(10, 100); // between 0.01 and 0.1 sec
DelayedQueryPhaseSearcher delayedQueryPhaseSearcher = new DelayedQueryPhaseSearcher(sleepMillis);

// we need to test queryPhase.execute(), not executeInternal(), since that's what the timer wraps around
Expand Down

0 comments on commit ac6afd3

Please sign in to comment.