This is an automated email from the ASF dual-hosted git repository. jackietien pushed a commit to branch NotificationThreadStuck-1.3 in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit d9ec7bdaebd6bd9d3d0ad8bf21e8bb12e5fa17dc Author: JackieTien97 <[email protected]> AuthorDate: Sat Nov 9 15:56:53 2024 +0800 Fix query resource clear async thread stuck bug --- .../db/queryengine/execution/driver/Driver.java | 31 ++++++++++++++++------ .../apache/iotdb/library/dprofile/UDAFMedian.java | 14 +++++++--- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/driver/Driver.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/driver/Driver.java index 812c84298fc..ac353e32213 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/driver/Driver.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/driver/Driver.java @@ -51,6 +51,7 @@ import java.util.function.Supplier; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Throwables.throwIfUnchecked; +import static com.google.common.base.Verify.verify; import static com.google.common.util.concurrent.MoreExecutors.directExecutor; import static java.lang.Boolean.TRUE; import static org.apache.iotdb.db.queryengine.execution.operator.Operator.NOT_BLOCKED; @@ -321,15 +322,16 @@ public abstract class Driver implements IDriver { return Optional.empty(); } - Optional<T> result; + T result = null; + Throwable failure = null; try { - result = Optional.of(task.get()); + result = task.get(); + // opportunistic check to avoid unnecessary lock reacquisition + destroyIfNecessary(); + } catch (Throwable t) { + failure = t; } finally { - try { - destroyIfNecessary(); - } finally { - exclusiveLock.unlock(); - } + exclusiveLock.unlock(); } // We need to recheck whether the state is NEED_DESTRUCTION, if so, destroy the driver. @@ -342,12 +344,25 @@ public abstract class Driver implements IDriver { if (state.get() == State.NEED_DESTRUCTION && exclusiveLock.tryLock(interruptOnClose)) { try { destroyIfNecessary(); + } catch (Throwable t) { + if (failure == null) { + failure = t; + } else if (failure != t) { + failure.addSuppressed(t); + } } finally { exclusiveLock.unlock(); } } - return result; + if (failure != null) { + throwIfUnchecked(failure); + // should never happen + throw new AssertionError(failure); + } + + verify(result != null, "result is null"); + return Optional.of(result); } @SuppressWarnings({"squid:S1181", "squid:S112"}) diff --git a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFMedian.java b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFMedian.java index 89f43fdccc7..9c78bd316e5 100644 --- a/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFMedian.java +++ b/library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFMedian.java @@ -31,6 +31,8 @@ import org.apache.iotdb.udf.api.customizer.parameter.UDFParameters; import org.apache.iotdb.udf.api.customizer.strategy.RowByRowAccessStrategy; import org.apache.iotdb.udf.api.type.Type; +import java.util.NoSuchElementException; + /** calculate the exact or approximate median. */ public class UDAFMedian implements UDTF { @@ -73,10 +75,14 @@ public class UDAFMedian implements UDTF { @Override public void terminate(PointCollector collector) throws Exception { - if (exact) { - collector.putDouble(0, statistics.getMedian()); - } else { - collector.putDouble(0, sketch.query(0.5)); + try { + if (exact) { + collector.putDouble(0, statistics.getMedian()); + } else { + collector.putDouble(0, sketch.query(0.5)); + } + } catch (NoSuchElementException e) { + // just ignore it } } }
