Skip to content

Commit 085ffc3

Browse files
authored
Change exception type when timing out waiting for specific seqno in fleet search api. (#114526)
Without this change request fails with `ElasticsearchTimeoutException` if waiting for seqno times out. This results in a 500 status code. With this change the `SearchTimeoutException` is used which results in a 504 status code. This is a more appropriate response code for time-outs. Closes #114395
1 parent f3cd890 commit 085ffc3

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

server/src/main/java/org/elasticsearch/search/SearchService.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.apache.lucene.search.Query;
1818
import org.apache.lucene.search.TopDocs;
1919
import org.elasticsearch.ElasticsearchException;
20-
import org.elasticsearch.ElasticsearchTimeoutException;
2120
import org.elasticsearch.action.ActionListener;
2221
import org.elasticsearch.action.ActionRunnable;
2322
import org.elasticsearch.action.ResolvedIndices;
@@ -33,6 +32,7 @@
3332
import org.elasticsearch.common.UUIDs;
3433
import org.elasticsearch.common.breaker.CircuitBreaker;
3534
import org.elasticsearch.common.component.AbstractLifecycleComponent;
35+
import org.elasticsearch.common.logging.LoggerMessageFormat;
3636
import org.elasticsearch.common.lucene.Lucene;
3737
import org.elasticsearch.common.settings.Setting;
3838
import org.elasticsearch.common.settings.Setting.Property;
@@ -112,6 +112,7 @@
112112
import org.elasticsearch.search.query.QuerySearchRequest;
113113
import org.elasticsearch.search.query.QuerySearchResult;
114114
import org.elasticsearch.search.query.ScrollQuerySearchResult;
115+
import org.elasticsearch.search.query.SearchTimeoutException;
115116
import org.elasticsearch.search.rank.feature.RankFeatureResult;
116117
import org.elasticsearch.search.rank.feature.RankFeatureShardPhase;
117118
import org.elasticsearch.search.rank.feature.RankFeatureShardRequest;
@@ -598,9 +599,13 @@ private <T extends RefCounted> void ensureAfterSeqNoRefreshed(
598599
final TimeValue timeout = request.getWaitForCheckpointsTimeout();
599600
final Scheduler.ScheduledCancellable timeoutTask = NO_TIMEOUT.equals(timeout) ? null : threadPool.schedule(() -> {
600601
if (isDone.compareAndSet(false, true)) {
601-
listener.onFailure(
602-
new ElasticsearchTimeoutException("Wait for seq_no [{}] refreshed timed out [{}]", waitForCheckpoint, timeout)
602+
var shardTarget = new SearchShardTarget(
603+
shard.routingEntry().currentNodeId(),
604+
shard.shardId(),
605+
request.getClusterAlias()
603606
);
607+
var message = LoggerMessageFormat.format("Wait for seq_no [{}] refreshed timed out [{}]", waitForCheckpoint, timeout);
608+
listener.onFailure(new SearchTimeoutException(shardTarget, message));
604609
}
605610
}, timeout, EsExecutors.DIRECT_EXECUTOR_SERVICE);
606611

0 commit comments

Comments
 (0)