Skip to content

Commit b33fc38

Browse files
authored
[To dev/1.3] Fix timeout didn't pass to client bug (#15743)
(cherry picked from commit 232e0c9)
1 parent 236c098 commit b33fc38

4 files changed

Lines changed: 55 additions & 7 deletions

File tree

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/exception/query/QueryTimeoutRuntimeException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,8 @@ public QueryTimeoutRuntimeException(long startTime, long currentTime, long timeo
2929
String.format(
3030
QUERY_TIMEOUT_EXCEPTION_MESSAGE, startTime, startTime + timeout, currentTime));
3131
}
32+
33+
public QueryTimeoutRuntimeException(String message) {
34+
super(message);
35+
}
3236
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/exchange/SharedTsBlockQueue.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
import javax.annotation.concurrent.NotThreadSafe;
3838

3939
import java.util.LinkedList;
40+
import java.util.Optional;
4041
import java.util.Queue;
42+
import java.util.concurrent.ExecutionException;
4143
import java.util.concurrent.ExecutorService;
4244

4345
import static com.google.common.util.concurrent.Futures.immediateVoidFuture;
@@ -81,6 +83,8 @@ public class SharedTsBlockQueue {
8183
private long maxBytesCanReserve =
8284
IoTDBDescriptor.getInstance().getConfig().getMaxBytesPerFragmentInstance();
8385

86+
private volatile Throwable abortedCause = null;
87+
8488
// used for SharedTsBlockQueue listener
8589
private final ExecutorService executorService;
8690

@@ -177,6 +181,18 @@ public void setNoMoreTsBlocks(boolean noMoreTsBlocks) {
177181
*/
178182
public TsBlock remove() {
179183
if (closed) {
184+
// try throw underlying exception instead of "Source handle is aborted."
185+
if (abortedCause != null) {
186+
throw new IllegalStateException(abortedCause);
187+
}
188+
try {
189+
blocked.get();
190+
} catch (InterruptedException e) {
191+
Thread.currentThread().interrupt();
192+
throw new IllegalStateException(e);
193+
} catch (ExecutionException e) {
194+
throw new IllegalStateException(e.getCause() == null ? e : e.getCause());
195+
}
180196
throw new IllegalStateException("queue has been destroyed");
181197
}
182198
TsBlock tsBlock = queue.remove();
@@ -332,6 +348,7 @@ public void abort(Throwable t) {
332348
if (closed) {
333349
return;
334350
}
351+
abortedCause = t;
335352
closed = true;
336353
if (!blocked.isDone()) {
337354
blocked.setException(t);
@@ -354,4 +371,8 @@ public void abort(Throwable t) {
354371
bufferRetainedSizeInBytes = 0;
355372
}
356373
}
374+
375+
public Optional<Throwable> getAbortedCause() {
376+
return Optional.ofNullable(abortedCause);
377+
}
357378
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/exchange/source/LocalSourceHandle.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import org.slf4j.LoggerFactory;
3737

3838
import java.nio.ByteBuffer;
39+
import java.util.Optional;
40+
import java.util.concurrent.ExecutionException;
3941

4042
import static com.google.common.util.concurrent.Futures.nonCancellationPropagating;
4143
import static org.apache.iotdb.db.queryengine.execution.exchange.MPPDataExchangeManager.createFullIdFrom;
@@ -156,6 +158,7 @@ public ByteBuffer getSerializedTsBlock() throws IoTDBException {
156158
@Override
157159
public boolean isFinished() {
158160
synchronized (queue) {
161+
checkSharedQueueIfAborted();
159162
return queue.hasNoMoreTsBlocks() && queue.isEmpty();
160163
}
161164
}
@@ -251,10 +254,28 @@ public void close() {
251254
}
252255

253256
private void checkState() {
254-
if (aborted) {
255-
throw new IllegalStateException("Source handle is aborted.");
256-
} else if (closed) {
257-
throw new IllegalStateException("Source Handle is closed.");
257+
if (aborted || closed) {
258+
checkSharedQueueIfAborted();
259+
if (queue.isBlocked().isDone()) {
260+
// try throw underlying exception instead of "Source handle is aborted."
261+
try {
262+
queue.isBlocked().get();
263+
} catch (InterruptedException e) {
264+
Thread.currentThread().interrupt();
265+
throw new IllegalStateException(e);
266+
} catch (ExecutionException e) {
267+
throw new IllegalStateException(e.getCause() == null ? e : e.getCause());
268+
}
269+
}
270+
throw new IllegalStateException(
271+
"LocalSinkChannel state is ." + (aborted ? "ABORTED" : "CLOSED"));
272+
}
273+
}
274+
275+
private void checkSharedQueueIfAborted() {
276+
Optional<Throwable> abortedCause = queue.getAbortedCause();
277+
if (abortedCause.isPresent()) {
278+
throw new IllegalStateException(abortedCause.get());
258279
}
259280
}
260281

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/fragment/FragmentInstanceManager.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.iotdb.commons.conf.CommonDescriptor;
2727
import org.apache.iotdb.commons.exception.IoTDBException;
2828
import org.apache.iotdb.db.conf.IoTDBDescriptor;
29+
import org.apache.iotdb.db.exception.query.QueryTimeoutRuntimeException;
2930
import org.apache.iotdb.db.queryengine.common.FragmentInstanceId;
3031
import org.apache.iotdb.db.queryengine.common.QueryId;
3132
import org.apache.iotdb.db.queryengine.execution.driver.IDriver;
@@ -56,7 +57,6 @@
5657
import java.util.concurrent.ExecutorService;
5758
import java.util.concurrent.ScheduledExecutorService;
5859
import java.util.concurrent.TimeUnit;
59-
import java.util.concurrent.TimeoutException;
6060
import java.util.concurrent.atomic.AtomicLong;
6161

6262
import static java.util.Objects.requireNonNull;
@@ -421,8 +421,10 @@ private void cancelTimeoutFlushingInstances() {
421421
execution
422422
.getStateMachine()
423423
.failed(
424-
new TimeoutException(
425-
"Query has executed more than " + execution.getTimeoutInMs() + "ms"));
424+
new QueryTimeoutRuntimeException(
425+
"Query has executed more than "
426+
+ execution.getTimeoutInMs()
427+
+ "ms, and now is in flushing state"));
426428
}
427429
});
428430
}

0 commit comments

Comments
 (0)