aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSalim Achouche <sachouche2@gmail.com>2018-07-02 19:13:26 -0700
committerSorabh Hamirwasia <sorabh@apache.org>2018-07-12 13:40:53 -0700
commitcfe61eb9b6ed4d636a26c76dbd12df26f38ba672 (patch)
treeab3700d85bf5914306ecda824960548908fea16c
parentc64436774387e80fd9b0ff6e9cd7d42c9aa7a961 (diff)
DRILL-6578: Handle query cancellation in Parquet reader
closes #1360
-rw-r--r--common/src/main/java/org/apache/drill/common/exceptions/DrillRuntimeException.java18
-rw-r--r--exec/vector/src/main/codegen/templates/VariableLengthVectors.java4
2 files changed, 21 insertions, 1 deletions
diff --git a/common/src/main/java/org/apache/drill/common/exceptions/DrillRuntimeException.java b/common/src/main/java/org/apache/drill/common/exceptions/DrillRuntimeException.java
index 98b1a9d03..b6ced84d0 100644
--- a/common/src/main/java/org/apache/drill/common/exceptions/DrillRuntimeException.java
+++ b/common/src/main/java/org/apache/drill/common/exceptions/DrillRuntimeException.java
@@ -48,4 +48,22 @@ public class DrillRuntimeException extends RuntimeException {
public static void format(Throwable cause, String format, Object...args) {
throw new DrillRuntimeException(String.format(format, args), cause);
}
+
+ /**
+ * This method can be called within loops to check whether the current thread has been
+ * interrupted; it ensures that operator implementation can respond to query cancellation
+ * in a timely manner.
+ *
+ * <p>Calling this method will result in the following behavior:
+ * <ul>
+ * <li>Throws a runtime exception if current thread interrupt flag has been set
+ * <li>Clears current thread interrupt flag
+ * </ul>
+ */
+ public static void checkInterrupted() {
+ if (Thread.interrupted()) {
+ // This exception will ensure the control layer will immediately get back control
+ throw new DrillRuntimeException("Interrupt received; aborting current operation");
+ }
+ }
}
diff --git a/exec/vector/src/main/codegen/templates/VariableLengthVectors.java b/exec/vector/src/main/codegen/templates/VariableLengthVectors.java
index c35728ec2..8dd8eb19a 100644
--- a/exec/vector/src/main/codegen/templates/VariableLengthVectors.java
+++ b/exec/vector/src/main/codegen/templates/VariableLengthVectors.java
@@ -19,7 +19,7 @@ import java.lang.Override;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Set;
-
+import org.apache.drill.common.exceptions.DrillRuntimeException;
import org.apache.drill.exec.exception.OutOfMemoryException;
import org.apache.drill.exec.memory.AllocationManager.BufferLedger;
import org.apache.drill.exec.vector.BaseDataValueVector;
@@ -641,6 +641,8 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
if (callback != null) {
callback.onNewBulkEntry(entry);
}
+
+ DrillRuntimeException.checkInterrupted(); // Ensures fast handling of query cancellation
}
// Flush any data not yet copied to this VL container