AMashenkov commented on code in PR #2846:
URL: https://github.com/apache/ignite-3/pull/2846#discussion_r1422561744
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/api/SessionImpl.java:
##########
@@ -543,55 +548,77 @@ List<AsyncSqlCursor<?>> openedCursors() {
}
private class ScriptHandler {
+ private final CompletableFuture<Void> resFut = new
CompletableFuture<>();
- private final CompletableFuture<Void> resFut;
+ private final AtomicReference<Throwable> cursorCloseErrHolder = new
AtomicReference<>();
- private ScriptHandler(CompletableFuture<Void> resFut) {
- this.resFut = resFut;
+ CompletableFuture<Void> resultFuture() {
+ return resFut;
}
- void processFirstResult(AsyncSqlCursor<InternalSqlRow> cursor,
Throwable t) {
- if (t != null) {
- resFut.completeExceptionally(t);
- } else {
- int cursorId = registerCursor(cursor);
- processCursor(cursor, cursorId);
+ void processCursor(AsyncSqlCursor<InternalSqlRow> cursor, Throwable
scriptError) {
+ if (scriptError != null) {
+ // Stop script execution.
+ completeScriptExecution(scriptError);
+
+ return;
}
+
+ cursor.closeAsync().whenComplete((ignored, cursorCloseError) -> {
+ if (cursorCloseError != null) {
+ // Just save the error for later and continue fetching
cursors.
+ saveError(cursorCloseError);
+ }
+
+ if (!busyLock.enterBusy()) {
+ completeScriptExecution(sessionIsClosedException());
+ return;
+ }
+
+ try {
+ if (cursor.hasNextResult()) {
+
cursor.nextResult().whenCompleteAsync(this::processCursor);
+ } else {
+ completeScriptExecution(null);
+ }
+ } finally {
+ busyLock.leaveBusy();
+ }
+ });
}
- void processCursor(AsyncSqlCursor<InternalSqlRow> cursor, int
cursorId) {
- if (!busyLock.enterBusy()) {
- closeCursor(cursor, cursorId);
+ private void completeScriptExecution(@Nullable Throwable err) {
+ Throwable savedError = cursorCloseErrHolder.get();
+
+ if (err == null && savedError == null) {
+ resFut.complete(null);
Review Comment:
```suggestion
private void completeScriptExecution(@Nullable Throwable err) {
Throwable savedError = cursorCloseErrHolder.get();
if (savedError == null) {
resFut.complete(null);
} else {
resFut.completeExceptionally(savedError);
}
```
--
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]