This is an automated email from the ASF dual-hosted git repository. sorabh pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/drill.git
commit cfe61eb9b6ed4d636a26c76dbd12df26f38ba672 Author: Salim Achouche <sachouc...@gmail.com> AuthorDate: Mon Jul 2 19:13:26 2018 -0700 DRILL-6578: Handle query cancellation in Parquet reader closes #1360 --- .../drill/common/exceptions/DrillRuntimeException.java | 18 ++++++++++++++++++ .../main/codegen/templates/VariableLengthVectors.java | 4 +++- 2 files changed, 21 insertions(+), 1 deletion(-) 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 98b1a9d..b6ced84 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 c35728e..8dd8eb1 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