default query timeout to server idle timeout

This commit is contained in:
Xavier Léauté 2014-07-22 16:56:34 -07:00
parent e76561e400
commit 03efbb0e02
1 changed files with 13 additions and 0 deletions

View File

@ -41,6 +41,7 @@ import io.druid.query.DataSourceUtil;
import io.druid.query.Query; import io.druid.query.Query;
import io.druid.query.QueryInterruptedException; import io.druid.query.QueryInterruptedException;
import io.druid.query.QuerySegmentWalker; import io.druid.query.QuerySegmentWalker;
import io.druid.server.initialization.ServerConfig;
import io.druid.server.log.RequestLogger; import io.druid.server.log.RequestLogger;
import org.joda.time.DateTime; 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_SMILE = "application/smile";
public static final String APPLICATION_JSON = "application/json"; public static final String APPLICATION_JSON = "application/json";
private final ServerConfig config;
private final ObjectMapper jsonMapper; private final ObjectMapper jsonMapper;
private final ObjectMapper smileMapper; private final ObjectMapper smileMapper;
private final QuerySegmentWalker texasRanger; private final QuerySegmentWalker texasRanger;
@ -79,6 +81,7 @@ public class QueryResource
@Inject @Inject
public QueryResource( public QueryResource(
ServerConfig config,
@Json ObjectMapper jsonMapper, @Json ObjectMapper jsonMapper,
@Smile ObjectMapper smileMapper, @Smile ObjectMapper smileMapper,
QuerySegmentWalker texasRanger, QuerySegmentWalker texasRanger,
@ -87,6 +90,7 @@ public class QueryResource
QueryManager queryManager QueryManager queryManager
) )
{ {
this.config = config;
this.jsonMapper = jsonMapper.copy(); this.jsonMapper = jsonMapper.copy();
this.jsonMapper.getFactory().configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); this.jsonMapper.getFactory().configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
@ -135,6 +139,15 @@ public class QueryResource
queryId = UUID.randomUUID().toString(); queryId = UUID.randomUUID().toString();
query = query.withId(queryId); query = query.withId(queryId);
} }
if (query.getContextValue("timeout") == null) {
query = query.withOverriddenContext(
ImmutableMap.of(
"timeout",
config.getMaxIdleTime().toStandardDuration().getMillis()
)
);
}
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Got query [%s]", query); log.debug("Got query [%s]", query);