Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for timing out long-running queries (disabled by default) #290

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/core/TsdbQuery.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ final class ScannerCB implements Callback<Object,
boolean seenAnnotation = false; boolean seenAnnotation = false;
int hbase_time = 0; // milliseconds. int hbase_time = 0; // milliseconds.
long starttime = System.nanoTime(); long starttime = System.nanoTime();
long timeout = tsdb.getConfig().getLong("tsd.query.timeout");


/** /**
* Starts the scanner and is called recursively to fetch the next set of * Starts the scanner and is called recursively to fetch the next set of
Expand Down Expand Up @@ -403,6 +404,10 @@ public Object call(final ArrayList<ArrayList<KeyValue>> rows)
return null; return null;
} }


if (timeout > 0 && hbase_time > timeout) {
throw new InterruptedException("Query timeout exceeded!");
}

for (final ArrayList<KeyValue> row : rows) { for (final ArrayList<KeyValue> row : rows) {
final byte[] key = row.get(0).key(); final byte[] key = row.get(0).key();
if (Bytes.memcmp(metric, key, 0, metric_width) != 0) { if (Bytes.memcmp(metric, key, 0, metric_width) != 0) {
Expand Down
1 change: 1 addition & 0 deletions src/utils/Config.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ protected void setDefaults() {
default_map.put("tsd.http.request.cors_headers", "Authorization, " default_map.put("tsd.http.request.cors_headers", "Authorization, "
+ "Content-Type, Accept, Origin, User-Agent, DNT, Cache-Control, " + "Content-Type, Accept, Origin, User-Agent, DNT, Cache-Control, "
+ "X-Mx-ReqToken, Keep-Alive, X-Requested-With, If-Modified-Since"); + "X-Mx-ReqToken, Keep-Alive, X-Requested-With, If-Modified-Since");
default_map.put("tsd.query.timeout", "0");


for (Map.Entry<String, String> entry : default_map.entrySet()) { for (Map.Entry<String, String> entry : default_map.entrySet()) {
if (!properties.containsKey(entry.getKey())) if (!properties.containsKey(entry.getKey()))
Expand Down