tkalkirill commented on code in PR #13080:
URL: https://github.com/apache/ignite/pull/13080#discussion_r3154062125
##########
docs/_docs/code-snippets/java/src/main/java/org/apache/ignite/snippets/PerformingTransactions.java:
##########
@@ -98,6 +99,36 @@ public static void executingTransactionsExample() {
}
}
+ public static void transactionSavepointsExample() {
+ try (Ignite ignite = Ignition.start()) {
+ // tag::savepoints[]
+ CacheConfiguration<String, Integer> cfg = new
CacheConfiguration<>();
+ cfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
+ cfg.setName("myCache");
+
+ IgniteCache<String, Integer> cache = ignite.getOrCreateCache(cfg);
+
+ try (Transaction tx =
ignite.transactions().txStart(TransactionConcurrency.PESSIMISTIC,
+ TransactionIsolation.REPEATABLE_READ)) {
+ cache.put("order:1", 10);
+
+ tx.savepoint("before-shipping");
+
+ cache.put("shipping:1", 5);
+ cache.put("order:1", 15);
+
+ tx.rollbackToSavepoint("before-shipping");
+
+ cache.put("order:1", 11);
+
+ tx.releaseSavepoint("before-shipping");
+
+ tx.commit();
+ }
+ // end::savepoints[]
+ }
Review Comment:
Please add the output that will be in the cache for the updated keys.
##########
modules/core/src/main/java/org/apache/ignite/transactions/Transaction.java:
##########
@@ -290,6 +290,57 @@ public interface Transaction extends AutoCloseable,
IgniteAsyncSupport {
*/
public void suspend() throws IgniteException;
+ /**
+ * Creates a savepoint in the current transaction.
+ * <p>
+ * Savepoints are supported only for explicit transactions with
+ * {@link TransactionConcurrency#PESSIMISTIC} concurrency. The savepoint
keeps the current transaction state and can
+ * later be used by {@link #rollbackToSavepoint(String)} to discard
changes made after it was created.
+ *
+ * @param name Savepoint name.
+ * @throws IllegalArgumentException If savepoint with the same name
already exists.
Review Comment:
I suggest throwing `org.apache.ignite.transactions.TransactionException`
instead of the suggested ones.
##########
modules/core/src/main/java/org/apache/ignite/transactions/Transaction.java:
##########
@@ -290,6 +290,57 @@ public interface Transaction extends AutoCloseable,
IgniteAsyncSupport {
*/
public void suspend() throws IgniteException;
+ /**
+ * Creates a savepoint in the current transaction.
+ * <p>
+ * Savepoints are supported only for explicit transactions with
+ * {@link TransactionConcurrency#PESSIMISTIC} concurrency. The savepoint
keeps the current transaction state and can
+ * later be used by {@link #rollbackToSavepoint(String)} to discard
changes made after it was created.
+ *
+ * @param name Savepoint name.
+ * @throws IllegalArgumentException If savepoint with the same name
already exists.
+ * @throws IgniteException If savepoints are not supported for this
transaction.
+ */
+ public void savepoint(String name);
+
+ /**
+ * Creates a savepoint in the current transaction.
+ * <p>
+ * Savepoints are supported only for explicit transactions with
+ * {@link TransactionConcurrency#PESSIMISTIC} concurrency. If {@code
overwrite} is {@code true} and a savepoint with
+ * the same name exists, the existing savepoint is replaced with a
snapshot of the current transaction state.
+ *
+ * @param name Savepoint name.
+ * @param overwrite Whether to overwrite an existing savepoint with the
same name.
+ * @throws IllegalArgumentException If savepoint with the same name
already exists and {@code overwrite} is
+ * {@code false}.
+ * @throws IgniteException If savepoints are not supported for this
transaction.
+ */
+ public void savepoint(String name, boolean overwrite);
Review Comment:
The same documentation notes as above.
##########
modules/core/src/main/java/org/apache/ignite/transactions/Transaction.java:
##########
@@ -290,6 +290,57 @@ public interface Transaction extends AutoCloseable,
IgniteAsyncSupport {
*/
public void suspend() throws IgniteException;
+ /**
+ * Creates a savepoint in the current transaction.
Review Comment:
Can you just point out that this is a short form of the "savepoint(name,
false)" call so as not to duplicate similar documentation?
##########
modules/core/src/main/java/org/apache/ignite/transactions/Transaction.java:
##########
@@ -290,6 +290,57 @@ public interface Transaction extends AutoCloseable,
IgniteAsyncSupport {
*/
public void suspend() throws IgniteException;
+ /**
+ * Creates a savepoint in the current transaction.
+ * <p>
+ * Savepoints are supported only for explicit transactions with
+ * {@link TransactionConcurrency#PESSIMISTIC} concurrency. The savepoint
keeps the current transaction state and can
+ * later be used by {@link #rollbackToSavepoint(String)} to discard
changes made after it was created.
Review Comment:
Can you also mention the release here?
##########
modules/core/src/main/java/org/apache/ignite/transactions/Transaction.java:
##########
@@ -290,6 +290,57 @@ public interface Transaction extends AutoCloseable,
IgniteAsyncSupport {
*/
public void suspend() throws IgniteException;
+ /**
+ * Creates a savepoint in the current transaction.
+ * <p>
+ * Savepoints are supported only for explicit transactions with
+ * {@link TransactionConcurrency#PESSIMISTIC} concurrency. The savepoint
keeps the current transaction state and can
+ * later be used by {@link #rollbackToSavepoint(String)} to discard
changes made after it was created.
+ *
+ * @param name Savepoint name.
+ * @throws IllegalArgumentException If savepoint with the same name
already exists.
+ * @throws IgniteException If savepoints are not supported for this
transaction.
+ */
+ public void savepoint(String name);
+
+ /**
+ * Creates a savepoint in the current transaction.
+ * <p>
+ * Savepoints are supported only for explicit transactions with
+ * {@link TransactionConcurrency#PESSIMISTIC} concurrency. If {@code
overwrite} is {@code true} and a savepoint with
+ * the same name exists, the existing savepoint is replaced with a
snapshot of the current transaction state.
+ *
+ * @param name Savepoint name.
+ * @param overwrite Whether to overwrite an existing savepoint with the
same name.
+ * @throws IllegalArgumentException If savepoint with the same name
already exists and {@code overwrite} is
+ * {@code false}.
+ * @throws IgniteException If savepoints are not supported for this
transaction.
+ */
+ public void savepoint(String name, boolean overwrite);
+
+ /**
+ * Rolls back transaction changes to the specified savepoint.
+ * <p>
+ * Changes made after the savepoint was created are discarded. Savepoints
created after the specified savepoint are
+ * released. The transaction remains active and can be committed or rolled
back after this method returns.
+ *
+ * @param name Savepoint name.
+ * @throws IllegalArgumentException If savepoint with the given name does
not exist.
Review Comment:
The same notes on exceptions as above.
##########
modules/core/src/main/java/org/apache/ignite/transactions/Transaction.java:
##########
@@ -290,6 +290,57 @@ public interface Transaction extends AutoCloseable,
IgniteAsyncSupport {
*/
public void suspend() throws IgniteException;
+ /**
+ * Creates a savepoint in the current transaction.
+ * <p>
+ * Savepoints are supported only for explicit transactions with
+ * {@link TransactionConcurrency#PESSIMISTIC} concurrency. The savepoint
keeps the current transaction state and can
+ * later be used by {@link #rollbackToSavepoint(String)} to discard
changes made after it was created.
+ *
+ * @param name Savepoint name.
+ * @throws IllegalArgumentException If savepoint with the same name
already exists.
+ * @throws IgniteException If savepoints are not supported for this
transaction.
+ */
+ public void savepoint(String name);
+
+ /**
+ * Creates a savepoint in the current transaction.
+ * <p>
+ * Savepoints are supported only for explicit transactions with
+ * {@link TransactionConcurrency#PESSIMISTIC} concurrency. If {@code
overwrite} is {@code true} and a savepoint with
+ * the same name exists, the existing savepoint is replaced with a
snapshot of the current transaction state.
+ *
+ * @param name Savepoint name.
+ * @param overwrite Whether to overwrite an existing savepoint with the
same name.
+ * @throws IllegalArgumentException If savepoint with the same name
already exists and {@code overwrite} is
+ * {@code false}.
+ * @throws IgniteException If savepoints are not supported for this
transaction.
+ */
+ public void savepoint(String name, boolean overwrite);
+
+ /**
+ * Rolls back transaction changes to the specified savepoint.
+ * <p>
+ * Changes made after the savepoint was created are discarded. Savepoints
created after the specified savepoint are
+ * released. The transaction remains active and can be committed or rolled
back after this method returns.
+ *
+ * @param name Savepoint name.
+ * @throws IllegalArgumentException If savepoint with the given name does
not exist.
+ * @throws IgniteException If savepoints are not supported for this
transaction.
+ */
+ public void rollbackToSavepoint(String name);
+
+ /**
+ * Releases a savepoint. If savepoint does not exist this operation does
nothing.
+ * <p>
+ * Releasing a savepoint does not roll back transaction changes. It only
removes the marker so it can no longer be
+ * used by {@link #rollbackToSavepoint(String)}.
+ *
+ * @param name Savepoint name.
+ * @throws IgniteException If savepoints are not supported for this
transaction.
Review Comment:
The same notes on exceptions as above.
##########
modules/core/src/main/java/org/apache/ignite/transactions/Transaction.java:
##########
@@ -290,6 +290,57 @@ public interface Transaction extends AutoCloseable,
IgniteAsyncSupport {
*/
public void suspend() throws IgniteException;
+ /**
+ * Creates a savepoint in the current transaction.
+ * <p>
+ * Savepoints are supported only for explicit transactions with
+ * {@link TransactionConcurrency#PESSIMISTIC} concurrency. The savepoint
keeps the current transaction state and can
+ * later be used by {@link #rollbackToSavepoint(String)} to discard
changes made after it was created.
+ *
+ * @param name Savepoint name.
+ * @throws IllegalArgumentException If savepoint with the same name
already exists.
+ * @throws IgniteException If savepoints are not supported for this
transaction.
+ */
+ public void savepoint(String name);
+
+ /**
+ * Creates a savepoint in the current transaction.
+ * <p>
+ * Savepoints are supported only for explicit transactions with
+ * {@link TransactionConcurrency#PESSIMISTIC} concurrency. If {@code
overwrite} is {@code true} and a savepoint with
+ * the same name exists, the existing savepoint is replaced with a
snapshot of the current transaction state.
+ *
+ * @param name Savepoint name.
+ * @param overwrite Whether to overwrite an existing savepoint with the
same name.
+ * @throws IllegalArgumentException If savepoint with the same name
already exists and {@code overwrite} is
+ * {@code false}.
+ * @throws IgniteException If savepoints are not supported for this
transaction.
+ */
+ public void savepoint(String name, boolean overwrite);
+
+ /**
+ * Rolls back transaction changes to the specified savepoint.
+ * <p>
+ * Changes made after the savepoint was created are discarded. Savepoints
created after the specified savepoint are
+ * released. The transaction remains active and can be committed or rolled
back after this method returns.
+ *
+ * @param name Savepoint name.
+ * @throws IllegalArgumentException If savepoint with the given name does
not exist.
+ * @throws IgniteException If savepoints are not supported for this
transaction.
+ */
+ public void rollbackToSavepoint(String name);
+
+ /**
+ * Releases a savepoint. If savepoint does not exist this operation does
nothing.
Review Comment:
I think it's worth throwing an exception if there's no savepoint.
##########
modules/core/src/main/java/org/apache/ignite/transactions/Transaction.java:
##########
@@ -290,6 +290,57 @@ public interface Transaction extends AutoCloseable,
IgniteAsyncSupport {
*/
public void suspend() throws IgniteException;
+ /**
+ * Creates a savepoint in the current transaction.
+ * <p>
+ * Savepoints are supported only for explicit transactions with
+ * {@link TransactionConcurrency#PESSIMISTIC} concurrency. The savepoint
keeps the current transaction state and can
+ * later be used by {@link #rollbackToSavepoint(String)} to discard
changes made after it was created.
+ *
+ * @param name Savepoint name.
+ * @throws IllegalArgumentException If savepoint with the same name
already exists.
+ * @throws IgniteException If savepoints are not supported for this
transaction.
+ */
+ public void savepoint(String name);
+
+ /**
+ * Creates a savepoint in the current transaction.
+ * <p>
+ * Savepoints are supported only for explicit transactions with
+ * {@link TransactionConcurrency#PESSIMISTIC} concurrency. If {@code
overwrite} is {@code true} and a savepoint with
+ * the same name exists, the existing savepoint is replaced with a
snapshot of the current transaction state.
+ *
+ * @param name Savepoint name.
+ * @param overwrite Whether to overwrite an existing savepoint with the
same name.
+ * @throws IllegalArgumentException If savepoint with the same name
already exists and {@code overwrite} is
+ * {@code false}.
+ * @throws IgniteException If savepoints are not supported for this
transaction.
+ */
+ public void savepoint(String name, boolean overwrite);
+
+ /**
+ * Rolls back transaction changes to the specified savepoint.
+ * <p>
+ * Changes made after the savepoint was created are discarded. Savepoints
created after the specified savepoint are
+ * released. The transaction remains active and can be committed or rolled
back after this method returns.
+ *
+ * @param name Savepoint name.
+ * @throws IllegalArgumentException If savepoint with the given name does
not exist.
+ * @throws IgniteException If savepoints are not supported for this
transaction.
+ */
+ public void rollbackToSavepoint(String name);
+
+ /**
+ * Releases a savepoint. If savepoint does not exist this operation does
nothing.
+ * <p>
+ * Releasing a savepoint does not roll back transaction changes. It only
removes the marker so it can no longer be
Review Comment:
Let's say we have several save points, say 4, and we relese the 3rd one.
What happens to 1 and 2, will their changes also be released?
##########
modules/core/src/main/java/org/apache/ignite/transactions/Transaction.java:
##########
@@ -290,6 +290,57 @@ public interface Transaction extends AutoCloseable,
IgniteAsyncSupport {
*/
public void suspend() throws IgniteException;
+ /**
+ * Creates a savepoint in the current transaction.
+ * <p>
+ * Savepoints are supported only for explicit transactions with
+ * {@link TransactionConcurrency#PESSIMISTIC} concurrency. The savepoint
keeps the current transaction state and can
+ * later be used by {@link #rollbackToSavepoint(String)} to discard
changes made after it was created.
+ *
+ * @param name Savepoint name.
+ * @throws IllegalArgumentException If savepoint with the same name
already exists.
+ * @throws IgniteException If savepoints are not supported for this
transaction.
+ */
+ public void savepoint(String name);
+
+ /**
+ * Creates a savepoint in the current transaction.
+ * <p>
+ * Savepoints are supported only for explicit transactions with
+ * {@link TransactionConcurrency#PESSIMISTIC} concurrency. If {@code
overwrite} is {@code true} and a savepoint with
+ * the same name exists, the existing savepoint is replaced with a
snapshot of the current transaction state.
+ *
+ * @param name Savepoint name.
+ * @param overwrite Whether to overwrite an existing savepoint with the
same name.
+ * @throws IllegalArgumentException If savepoint with the same name
already exists and {@code overwrite} is
+ * {@code false}.
+ * @throws IgniteException If savepoints are not supported for this
transaction.
+ */
+ public void savepoint(String name, boolean overwrite);
+
+ /**
+ * Rolls back transaction changes to the specified savepoint.
+ * <p>
+ * Changes made after the savepoint was created are discarded. Savepoints
created after the specified savepoint are
Review Comment:
Let's say we have several savepoints, say 4, and we rolled back the 3rd one.
What happens to 1 and 2, will their changes also be rolled back?
--
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]