From 03efbb0e023d5ddd5c7a9856a16c0ba372c4d028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20L=C3=A9aut=C3=A9?= Date: Tue, 22 Jul 2014 16:56:34 -0700 Subject: [PATCH] default query timeout to server idle timeout --- .../main/java/io/druid/server/QueryResource.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/server/src/main/java/io/druid/server/QueryResource.java b/server/src/main/java/io/druid/server/QueryResource.java index 4787b17465a..59ebf5b9441 100644 --- a/server/src/main/java/io/druid/server/QueryResource.java +++ b/server/src/main/java/io/druid/server/QueryResource.java @@ -41,6 +41,7 @@ import io.druid.query.DataSourceUtil; import io.druid.query.Query; import io.druid.query.QueryInterruptedException; import io.druid.query.QuerySegmentWalker; +import io.druid.server.initialization.ServerConfig; import io.druid.server.log.RequestLogger; import org.joda.time.DateTime; @@ -70,6 +71,7 @@ public class QueryResource public static final String APPLICATION_SMILE = "application/smile"; public static final String APPLICATION_JSON = "application/json"; + private final ServerConfig config; private final ObjectMapper jsonMapper; private final ObjectMapper smileMapper; private final QuerySegmentWalker texasRanger; @@ -79,6 +81,7 @@ public class QueryResource @Inject public QueryResource( + ServerConfig config, @Json ObjectMapper jsonMapper, @Smile ObjectMapper smileMapper, QuerySegmentWalker texasRanger, @@ -87,6 +90,7 @@ public class QueryResource QueryManager queryManager ) { + this.config = config; this.jsonMapper = jsonMapper.copy(); this.jsonMapper.getFactory().configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); @@ -135,6 +139,15 @@ public class QueryResource queryId = UUID.randomUUID().toString(); query = query.withId(queryId); } + if (query.getContextValue("timeout") == null) { + query = query.withOverriddenContext( + ImmutableMap.of( + "timeout", + config.getMaxIdleTime().toStandardDuration().getMillis() + ) + ); + } + if (log.isDebugEnabled()) { log.debug("Got query [%s]", query);