xtern commented on code in PR #2846:
URL: https://github.com/apache/ignite-3/pull/2846#discussion_r1411817001


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/tx/ScriptTransactionWrapper.java:
##########
@@ -0,0 +1,178 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.sql.engine.tx;
+
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Function;
+import org.apache.ignite.internal.sql.engine.SqlQueryType;
+import org.apache.ignite.internal.sql.engine.util.Commons;
+import org.apache.ignite.internal.tx.InternalTransaction;
+import org.apache.ignite.internal.util.AsyncCursor;
+import org.apache.ignite.tx.Transaction;
+
+/**
+ * Wraps a transaction, which is managed by SQL engine via {@link 
SqlQueryType#TX_CONTROL} statements.
+ * Responsible for tracking and releasing resources associated with this 
transaction.
+ */
+class ScriptTransactionWrapper implements QueryTransactionWrapper {
+    private final InternalTransaction transaction;
+
+    /** Future completes when all cursors associated with the current 
transaction are closed. */
+    private final CompletableFuture<Void> txFinishFuture = new 
CompletableFuture<>();
+
+    /** Opened cursors that must be closed before the transaction can 
complete. */
+    private final Map<UUID, CompletableFuture<? extends AsyncCursor<?>>> 
openedCursors = new ConcurrentHashMap<>();
+
+    /** Transaction action (commit or rollback) that will be performed when 
all dependent cursors are closed. */
+    private final AtomicReference<Function<InternalTransaction, 
CompletableFuture<Void>>> finishTxAction = new AtomicReference<>();
+
+    ScriptTransactionWrapper(InternalTransaction transaction) {
+        this.transaction = transaction;
+    }
+
+    @Override
+    public InternalTransaction unwrap() {
+        return transaction;
+    }
+
+    @Override
+    public CompletableFuture<Void> commitImplicit() {
+        return Commons.completedFuture();
+    }
+
+    @Override
+    public CompletableFuture<Void> rollback(Throwable cause) {

Review Comment:
   > i see that Throwable cause is ignored in more cases, is it ok ?
   
   In general, I added this exception only to not introduce another method to 
roll back the transaction when the script ends :pensive: .
   If an exception is passed, it means there was an error and we must close the 
associated cursors.
   If an exception is not passed, then there was no error and we are trying to 
roll back the transaction opened in the script, in this case we should wait 
until the user subtracts all the cursors before rollback transaction.
   
   Those. it's better to add a separate method. But I’m still stuck with its 
name. "tryRollbackScript" maybe or just "rollbackScript"?



-- 
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]

Reply via email to