Skip to content

Commit a339a40

Browse files
committed
IGNITE-27117 In a multistatement query if an error occurs do not abort preceding statements
1 parent 63e6b1b commit a339a40

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItSqlMultiStatementTxTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,6 @@ void dmlFailsOnReadOnlyTransaction() {
303303
assertThrowsSqlException(RUNTIME_ERR, "DML cannot be started by using read only transactions.",
304304
() -> await(insCur.nextResult()));
305305

306-
expectQueryCancelled(new DrainCursor(insCur));
307-
308306
verifyFinishedTxCount(1);
309307
}
310308

modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/fsm/MultiStatementHandler.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,6 @@ CompletableFuture<AsyncSqlCursor<InternalSqlRow>> processNext() {
278278
}
279279

280280
private void cancelAll(Throwable cause) {
281-
query.cancel.cancel();
282-
283281
for (ScriptStatement scriptStatement : statements) {
284282
CompletableFuture<AsyncSqlCursor<InternalSqlRow>> fut = scriptStatement.cursorFuture;
285283

modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/tx/ScriptTransactionWrapperImpl.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
2121
import static org.apache.ignite.lang.ErrorGroups.Sql.EXECUTION_CANCELLED_ERR;
2222

23+
import java.util.Collection;
2324
import java.util.HashMap;
25+
import java.util.List;
2426
import java.util.Map;
2527
import java.util.UUID;
2628
import java.util.concurrent.CompletableFuture;
@@ -32,6 +34,7 @@
3234
import org.apache.ignite.internal.sql.engine.exec.AsyncDataCursor;
3335
import org.apache.ignite.internal.sql.engine.exec.TransactionalOperationTracker;
3436
import org.apache.ignite.internal.tx.InternalTransaction;
37+
import org.apache.ignite.internal.util.AsyncCursor;
3538
import org.apache.ignite.sql.SqlException;
3639
import org.jetbrains.annotations.Nullable;
3740

@@ -85,6 +88,7 @@ public CompletableFuture<Void> finalise() {
8588

8689
@Override
8790
public CompletableFuture<Void> finalise(Throwable error) {
91+
Collection<CompletableFuture<? extends AsyncCursor<?>>> cursorsToClose;
8892
assert error != null;
8993

9094
synchronized (mux) {
@@ -94,6 +98,17 @@ public CompletableFuture<Void> finalise(Throwable error) {
9498

9599
rollbackCause = error;
96100
txState = State.ROLLBACK;
101+
102+
cursorsToClose = List.copyOf(openedCursors.values());
103+
}
104+
105+
// Close all associated cursors on error.
106+
for (CompletableFuture<? extends AsyncCursor<?>> fut : cursorsToClose) {
107+
fut.whenComplete((cursor, ex) -> {
108+
if (cursor != null) {
109+
cursor.closeAsync();
110+
}
111+
});
97112
}
98113

99114
completeTx();

0 commit comments

Comments
 (0)