You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2024/11/09 07:57:06 UTC
(iotdb) branch NotificationThreadStuck created (now c772f4b568b)
This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a change to branch NotificationThreadStuck
in repository https://gitbox.apache.org/repos/asf/iotdb.git
at c772f4b568b Fix query resource clear async thread stuck bug
This branch includes the following new commits:
new c772f4b568b Fix query resource clear async thread stuck bug
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(iotdb) 01/01: Fix query resource clear async thread stuck bug
Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a commit to branch NotificationThreadStuck
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit c772f4b568bb623d5c55e454fbff809d0aa257b6
Author: JackieTien97 <ja...@gmail.com>
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 248cce28240..356a632d8ba 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;
@@ -325,15 +326,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.
@@ -346,12 +348,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
}
}
}