korlov42 commented on code in PR #2241:
URL: https://github.com/apache/ignite-3/pull/2241#discussion_r1246212126
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ExecutionServiceImpl.java:
##########
@@ -826,45 +826,69 @@ private void enlist(SourceAwareIgniteRel rel) {
private CompletableFuture<Void> close(boolean cancel) {
if (!cancelled.compareAndSet(false, true)) {
- return cancelFut.thenApply(Function.identity());
+ return cancelFut;
}
CompletableFuture<Void> start = closeExecNode(cancel);
- start
- .thenCompose(tmp -> {
- CompletableFuture<Void> cancelResult = coordinator
- ? awaitFragmentInitialisationAndClose()
- : closeLocalFragments();
+ start.thenCompose(tmp -> {
+ CompletableFuture<Void> cancelResult = coordinator
+ ? awaitFragmentInitialisationAndClose()
+ : closeLocalFragments();
- var finalStepFut = cancelResult.whenComplete((r, e) ->
{
- queryManagerMap.remove(ctx.queryId());
+ var finalStepFut = cancelResult.whenComplete((r, e) -> {
+ if (e != null) {
+ Throwable ex = unwrapCause(e);
- try {
- ctx.cancel().cancel();
- } catch (Exception ignored) {
- // NO-OP
- }
+ LOG.warn("Exception raised during close", ex);
+ }
- cancelFut.complete(null);
- });
+ queryManagerMap.remove(ctx.queryId());
- return cancelResult.thenCombine(finalStepFut, (none1,
none2) -> null);
- });
+ ctx.cancel().cancel();
+
+ cancelFut.complete(null);
+ });
+
+ return cancelResult.thenCombine(finalStepFut, (none1, none2)
-> null);
+ })
+ .thenRun(() -> localFragments.forEach(f ->
f.context().cancel()));
start.completeAsync(() -> null, taskExecutor);
- return cancelFut.thenApply(Function.identity());
+ return cancelFut;
+ }
+
+ /**
+ * Synchronously closes the tree's execution iterator.
+ *
+ * @param cancel Forces execution to terminate with {@link
ExecutionCancelledException}.
+ * @return Completable future that should run asynchronously.
+ */
+ private CompletableFuture<Void> closeExecNode(boolean cancel) {
+ CompletableFuture<Void> start = new CompletableFuture<>();
+
+ if (!root.completeExceptionally(new ExecutionCancelledException())
&& !root.isCompletedExceptionally()) {
+ AsyncRootNode<RowT, List<Object>> node = root.getNow(null);
+
+ if (!cancel) {
+ CompletableFuture<Void> closeFut = node.closeAsync();
+
+ return start.thenCompose(v -> closeFut);
+ }
+
+ node.onError(new ExecutionCancelledException());
+ }
+
+ return start;
Review Comment:
is there any reason to move this method up? If no, let's just revert this
change
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]