This is an automated email from the ASF dual-hosted git repository.

rpuch pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new 06f62ebd7a IGNITE-23012 Support IgniteTransactions transparency with 
respect to node restart (#4274)
06f62ebd7a is described below

commit 06f62ebd7abb76f9c24d171cf03bad26f21436ca
Author: Roman Puchkovskiy <[email protected]>
AuthorDate: Fri Aug 23 21:48:30 2024 +0400

    IGNITE-23012 Support IgniteTransactions transparency with respect to node 
restart (#4274)
---
 .../ignite/internal/app/AsyncApiOperation.java     |  8 ++-
 .../org/apache/ignite/internal/app/References.java |  4 ++
 .../ignite/internal/app/SyncApiOperation.java      |  9 +++-
 .../internal/restart/RestartProofIgnite.java       |  7 +--
 .../internal/restart/RestartProofIgniteTables.java |  2 +-
 .../restart/RestartProofIgniteTransactions.java    | 59 ++++++++++++++++++++++
 .../internal/restart/RestartProofKeyValueView.java |  2 +-
 .../restart/RestartProofPartitionManager.java      |  2 +-
 .../internal/restart/RestartProofRecordView.java   |  2 +-
 .../ignite/internal/restart/RestartProofTable.java |  2 +-
 10 files changed, 87 insertions(+), 10 deletions(-)

diff --git 
a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/app/AsyncApiOperation.java
 
b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/app/AsyncApiOperation.java
index 67f6e89efc..694dd388a4 100644
--- 
a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/app/AsyncApiOperation.java
+++ 
b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/app/AsyncApiOperation.java
@@ -21,6 +21,7 @@ import static 
org.apache.ignite.internal.app.ApiReferencesTestUtils.FULL_TUPLE;
 import static org.apache.ignite.internal.app.ApiReferencesTestUtils.KEY_TUPLE;
 import static 
org.apache.ignite.internal.app.ApiReferencesTestUtils.TEST_TABLE_NAME;
 import static 
org.apache.ignite.internal.app.ApiReferencesTestUtils.VALUE_TUPLE;
+import static 
org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
 
 import java.util.List;
 import java.util.Map;
@@ -110,7 +111,12 @@ enum AsyncApiOperation {
     PARTITION_MANAGER_PRIMARY_REPLICA(refs -> 
refs.partitionManager.primaryReplicaAsync(new HashPartition(0))),
     PARTITION_MANAGER_PRIMARY_REPLICAS(refs -> 
refs.partitionManager.primaryReplicasAsync()),
     PARTITION_MANAGER_PARTITION_BY_KEY(refs -> 
refs.partitionManager.partitionAsync(1, Mapper.of(Integer.class))),
-    PARTITION_MANAGER_PARTITION_BY_TUPLE(refs -> 
refs.partitionManager.partitionAsync(KEY_TUPLE));
+    PARTITION_MANAGER_PARTITION_BY_TUPLE(refs -> 
refs.partitionManager.partitionAsync(KEY_TUPLE)),
+
+    TRANSACTIONS_BEGIN(refs -> refs.transactions.beginAsync()),
+    TRANSACTIONS_BEGIN_WITH_OPTS(refs -> refs.transactions.beginAsync(null)),
+    TRANSACTIONS_RUN_IN_TRANSACTION(refs -> 
refs.transactions.runInTransactionAsync(tx -> nullCompletedFuture())),
+    TRANSACTIONS_RUN_IN_TRANSACTION_WITH_OPTS(refs -> 
refs.transactions.runInTransactionAsync(tx -> nullCompletedFuture(), null));
 
     private final Function<References, CompletableFuture<?>> action;
 
diff --git 
a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/app/References.java
 
b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/app/References.java
index 932935d0c3..c91dae875f 100644
--- 
a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/app/References.java
+++ 
b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/app/References.java
@@ -29,6 +29,7 @@ import org.apache.ignite.table.Table;
 import org.apache.ignite.table.Tuple;
 import org.apache.ignite.table.mapper.Mapper;
 import org.apache.ignite.table.partition.PartitionManager;
+import org.apache.ignite.tx.IgniteTransactions;
 
 /**
  * References to API objects extracted from an {@link IgniteServer} instance.
@@ -37,6 +38,7 @@ class References {
     final Ignite ignite;
 
     final IgniteTables tables;
+    final IgniteTransactions transactions;
 
     final Table table; // From table().
     final Table tableFromTableAsync;
@@ -57,6 +59,8 @@ class References {
         ignite = server.api();
 
         tables = ignite.tables();
+        transactions = ignite.transactions();
+
         table = tables.table(TEST_TABLE_NAME);
         tableFromTableAsync = tables.tableAsync(TEST_TABLE_NAME).get(10, 
SECONDS);
         tableFromTables = tables.tables().get(0);
diff --git 
a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/app/SyncApiOperation.java
 
b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/app/SyncApiOperation.java
index 0c1ccb8996..0f2e2c9988 100644
--- 
a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/app/SyncApiOperation.java
+++ 
b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/app/SyncApiOperation.java
@@ -103,7 +103,14 @@ enum SyncApiOperation {
 
     TYPED_RECORD_VIEW_GET(refs -> refs.typedRecordView.get(null, new Record(1, 
""))),
 
-    MAPPED_RECORD_VIEW_GET(refs -> refs.mappedRecordView.get(null, new 
Record(1, "")));
+    MAPPED_RECORD_VIEW_GET(refs -> refs.mappedRecordView.get(null, new 
Record(1, ""))),
+
+    TRANSACTIONS_BEGIN(refs -> refs.transactions.begin()),
+    TRANSACTIONS_BEGIN_WITH_OPTS(refs -> refs.transactions.begin(null)),
+    TRANSACTIONS_RUN_CONSUMER_IN_TRANSACTION(refs -> 
refs.transactions.runInTransaction(tx -> {})),
+    TRANSACTIONS_RUN_CONSUMER_IN_TRANSACTION_WITH_OPTS(refs -> 
refs.transactions.runInTransaction(tx -> {}, null)),
+    TRANSACTIONS_RUN_FUNCTION_IN_TRANSACTION(refs -> 
refs.transactions.runInTransaction(tx -> null)),
+    TRANSACTIONS_RUN_FUNCTION_IN_TRANSACTION_WITH_OPTS(refs -> 
refs.transactions.runInTransaction(tx -> null, null));
 
     private final Consumer<References> action;
 
diff --git 
a/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofIgnite.java
 
b/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofIgnite.java
index 8a5dfd8667..cee6c829cf 100644
--- 
a/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofIgnite.java
+++ 
b/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofIgnite.java
@@ -31,13 +31,14 @@ import org.apache.ignite.tx.IgniteTransactions;
 /**
  * Reference to a swappable {@link Ignite} instance. When a restart happens, 
this switches to the new Ignite instance.
  *
- * <p>API operations on this are linearized wrt node restarts. Normally 
(except for situations when timeouts trigger), user
+ * <p>API operations on this are linearized with respect to node restarts. 
Normally (except for situations when timeouts trigger), user
  * operations will not interact with detached objects.
  */
 public class RestartProofIgnite implements Ignite, Wrapper {
     private final IgniteAttachmentLock attachmentLock;
 
     private final IgniteTables tables;
+    private final IgniteTransactions transactions;
 
     /**
      * Constructor.
@@ -46,6 +47,7 @@ public class RestartProofIgnite implements Ignite, Wrapper {
         this.attachmentLock = attachmentLock;
 
         tables = new RestartProofIgniteTables(attachmentLock);
+        transactions = new RestartProofIgniteTransactions(attachmentLock);
     }
 
     @Override
@@ -60,8 +62,7 @@ public class RestartProofIgnite implements Ignite, Wrapper {
 
     @Override
     public IgniteTransactions transactions() {
-        // TODO: IGNITE-23012 - add a wrapper.
-        return attachmentLock.attached(Ignite::transactions);
+        return attachmentLock.attached(ignite -> transactions);
     }
 
     @Override
diff --git 
a/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofIgniteTables.java
 
b/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofIgniteTables.java
index 62d03d14dd..46633790d1 100644
--- 
a/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofIgniteTables.java
+++ 
b/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofIgniteTables.java
@@ -32,7 +32,7 @@ import org.jetbrains.annotations.Nullable;
  * Reference to {@link IgniteTables} under a swappable {@link Ignite} 
instance. When a restart happens, this switches to the new Ignite
  * instance.
  *
- * <p>API operations on this are linearized wrt node restarts. Normally 
(except for situations when timeouts trigger), user
+ * <p>API operations on this are linearized with respect to node restarts. 
Normally (except for situations when timeouts trigger), user
  * operations will not interact with detached objects.
  */
 class RestartProofIgniteTables implements IgniteTables, Wrapper {
diff --git 
a/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofIgniteTransactions.java
 
b/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofIgniteTransactions.java
new file mode 100644
index 0000000000..69d27da6b1
--- /dev/null
+++ 
b/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofIgniteTransactions.java
@@ -0,0 +1,59 @@
+/*
+ * 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.restart;
+
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.internal.wrapper.Wrapper;
+import org.apache.ignite.internal.wrapper.Wrappers;
+import org.apache.ignite.tx.IgniteTransactions;
+import org.apache.ignite.tx.Transaction;
+import org.apache.ignite.tx.TransactionOptions;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Reference to {@link IgniteTransactions} under a swappable {@link Ignite} 
instance. When a restart happens, this switches to
+ * the new Ignite instance.
+ *
+ * <p>API operations on this are linearized with respect to node restarts. 
Normally (except for situations when timeouts trigger), user
+ * operations will not interact with detached objects.
+ */
+class RestartProofIgniteTransactions implements IgniteTransactions, Wrapper {
+    private final IgniteAttachmentLock attachmentLock;
+
+    RestartProofIgniteTransactions(IgniteAttachmentLock attachmentLock) {
+        this.attachmentLock = attachmentLock;
+    }
+
+    @Override
+    public Transaction begin(@Nullable TransactionOptions options) {
+        // TODO: IGNITE-23061 - wrap in a restart-proof implementation of 
Transaction.
+        return attachmentLock.attached(ignite -> 
ignite.transactions().begin(options));
+    }
+
+    @Override
+    public CompletableFuture<Transaction> beginAsync(@Nullable 
TransactionOptions options) {
+        // TODO: IGNITE-23061 - wrap in a restart-proof implementation of 
Transaction.
+        return attachmentLock.attachedAsync(ignite -> 
ignite.transactions().beginAsync(options));
+    }
+
+    @Override
+    public <T> T unwrap(Class<T> classToUnwrap) {
+        return attachmentLock.attached(ignite -> 
Wrappers.unwrap(ignite.transactions(), classToUnwrap));
+    }
+}
diff --git 
a/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofKeyValueView.java
 
b/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofKeyValueView.java
index 8413e6c8af..58d59c444e 100644
--- 
a/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofKeyValueView.java
+++ 
b/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofKeyValueView.java
@@ -41,7 +41,7 @@ import org.jetbrains.annotations.Nullable;
  * Reference to {@link KeyValueView} under a swappable {@link Ignite} 
instance. When a restart happens, this switches to the new Ignite
  * instance.
  *
- * <p>API operations on this are linearized wrt node restarts. Normally 
(except for situations when timeouts trigger), user
+ * <p>API operations on this are linearized with respect to node restarts. 
Normally (except for situations when timeouts trigger), user
  * operations will not interact with detached objects.
  */
 class RestartProofKeyValueView<K, V> extends 
RestartProofApiObject<KeyValueView<K, V>> implements KeyValueView<K, V> {
diff --git 
a/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofPartitionManager.java
 
b/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofPartitionManager.java
index 2b299b434f..1193624ca4 100644
--- 
a/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofPartitionManager.java
+++ 
b/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofPartitionManager.java
@@ -31,7 +31,7 @@ import org.apache.ignite.table.partition.PartitionManager;
  * Reference to {@link PartitionManager} under a swappable {@link Ignite} 
instance. When a restart happens, this switches to the new Ignite
  * instance.
  *
- * <p>API operations on this are linearized wrt node restarts. Normally 
(except for situations when timeouts trigger), user
+ * <p>API operations on this are linearized with respect to node restarts. 
Normally (except for situations when timeouts trigger), user
  * operations will not interact with detached objects.
  */
 class RestartProofPartitionManager extends 
RestartProofApiObject<PartitionManager> implements PartitionManager {
diff --git 
a/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofRecordView.java
 
b/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofRecordView.java
index 4e2cf2e616..a7d8063fa6 100644
--- 
a/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofRecordView.java
+++ 
b/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofRecordView.java
@@ -41,7 +41,7 @@ import org.jetbrains.annotations.Nullable;
  * Reference to {@link RecordView} under a swappable {@link Ignite} instance. 
When a restart happens, this switches to the new Ignite
  * instance.
  *
- * <p>API operations on this are linearized wrt node restarts. Normally 
(except for situations when timeouts trigger), user
+ * <p>API operations on this are linearized with respect to node restarts. 
Normally (except for situations when timeouts trigger), user
  * operations will not interact with detached objects.
  */
 class RestartProofRecordView<R> extends RestartProofApiObject<RecordView<R>> 
implements RecordView<R>, Wrapper {
diff --git 
a/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofTable.java
 
b/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofTable.java
index f89c2e1153..0805387120 100644
--- 
a/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofTable.java
+++ 
b/modules/runner/src/main/java/org/apache/ignite/internal/restart/RestartProofTable.java
@@ -33,7 +33,7 @@ import org.apache.ignite.table.partition.PartitionManager;
  * Reference to {@link Table} under a swappable {@link Ignite} instance. When 
a restart happens, this switches to the new Ignite
  * instance.
  *
- * <p>API operations on this are linearized wrt node restarts. Normally 
(except for situations when timeouts trigger), user
+ * <p>API operations on this are linearized with respect to node restarts. 
Normally (except for situations when timeouts trigger), user
  * operations will not interact with detached objects.
  */
 class RestartProofTable implements Table, Wrapper {

Reply via email to