sergeyuttsel commented on code in PR #1503:
URL: https://github.com/apache/ignite-3/pull/1503#discussion_r1070922077


##########
modules/client/src/main/java/org/apache/ignite/internal/client/tx/ClientTransaction.java:
##########
@@ -87,9 +82,18 @@ public void commit() throws TransactionException {
     /** {@inheritDoc} */
     @Override
     public CompletableFuture<Void> commitAsync() {
-        setState(STATE_COMMITTED);
+        if (!finishFut.compareAndSet(null, new CompletableFuture<>())) {
+            if (commitState) {
+                return finishFut.get();
+            } else {
+                return completedFuture(null);
+            }
+        }
+
+        commitState = true;
 
-        return ch.serviceAsync(ClientOp.TX_COMMIT, w -> w.out().packLong(id), 
r -> null);
+        return ch.serviceAsync(ClientOp.TX_COMMIT, w -> w.out().packLong(id), 
r -> null)
+                .thenRun(() -> finishFut.get().complete(null));

Review Comment:
   fixed



##########
modules/client/src/main/java/org/apache/ignite/internal/client/tx/ClientTransaction.java:
##########
@@ -31,23 +32,17 @@
  * Client transaction.
  */
 public class ClientTransaction implements Transaction {
-    /** Open state. */
-    private static final int STATE_OPEN = 0;
-
-    /** Committed state. */
-    private static final int STATE_COMMITTED = 1;
-
-    /** Rolled back state. */
-    private static final int STATE_ROLLED_BACK = 2;
-
     /** Channel that the transaction belongs to. */
     private final ClientChannel ch;
 
     /** Transaction id. */
     private final long id;
 
-    /** State. */
-    private final AtomicInteger state = new AtomicInteger(STATE_OPEN);
+    /** The future used on repeated commit/rollback. */
+    private AtomicReference<CompletableFuture<Void>> finishFut = new 
AtomicReference<>();
+
+    /** {@code true} if commit is started. */
+    private volatile boolean commitState;

Review Comment:
   fixed



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