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

sanpwc 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 3bfa91b863 IGNITE-20681 Remove limit on write intent switch attempts 
(#3052)
3bfa91b863 is described below

commit 3bfa91b863416ebe5cc9741728b5920aa1845b9c
Author: Cyrill <cyrill.si...@gmail.com>
AuthorDate: Wed Jan 17 12:19:39 2024 +0300

    IGNITE-20681 Remove limit on write intent switch attempts (#3052)
---
 .../tx/impl/WriteIntentSwitchProcessor.java        | 29 +++++++---------------
 1 file changed, 9 insertions(+), 20 deletions(-)

diff --git 
a/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/WriteIntentSwitchProcessor.java
 
b/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/WriteIntentSwitchProcessor.java
index 82b7905c1c..f811e579a9 100644
--- 
a/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/WriteIntentSwitchProcessor.java
+++ 
b/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/WriteIntentSwitchProcessor.java
@@ -24,7 +24,9 @@ import org.apache.ignite.internal.hlc.HybridTimestamp;
 import org.apache.ignite.internal.logger.IgniteLogger;
 import org.apache.ignite.internal.logger.Loggers;
 import org.apache.ignite.internal.replicator.TablePartitionId;
+import 
org.apache.ignite.internal.tx.impl.TxManagerImpl.TransactionFailureHandler;
 import org.apache.ignite.internal.util.CompletableFutures;
+import org.apache.ignite.internal.util.ExceptionUtils;
 import org.apache.ignite.network.TopologyService;
 import org.jetbrains.annotations.Nullable;
 
@@ -35,8 +37,6 @@ public class WriteIntentSwitchProcessor {
     /** The logger. */
     private static final IgniteLogger LOG = 
Loggers.forClass(WriteIntentSwitchProcessor.class);
 
-    private static final int ATTEMPTS_TO_SWITCH_WI = 5;
-
     /** Placement driver helper. */
     private final PlacementDriverHelper placementDriverHelper;
 
@@ -84,33 +84,22 @@ public class WriteIntentSwitchProcessor {
             @Nullable HybridTimestamp commitTimestamp,
             UUID txId,
             TablePartitionId partitionId
-    ) {
-        return switchWriteIntentsWithRetry(commit, commitTimestamp, txId, 
partitionId, ATTEMPTS_TO_SWITCH_WI);
-    }
-
-    // TODO https://issues.apache.org/jira/browse/IGNITE-20681 remove attempts 
count.
-    private CompletableFuture<Void> switchWriteIntentsWithRetry(
-            boolean commit,
-            @Nullable HybridTimestamp commitTimestamp,
-            UUID txId,
-            TablePartitionId partitionId,
-            int attempts
     ) {
         return 
placementDriverHelper.awaitPrimaryReplicaWithExceptionHandling(partitionId)
                 .thenCompose(leaseHolder ->
                         
txMessageSender.switchWriteIntents(leaseHolder.getLeaseholder(), partitionId, 
txId, commit, commitTimestamp))
                 .handle((res, ex) -> {
                     if (ex != null) {
-                        if (attempts > 0) {
-                            LOG.warn("Failed to switch write intents for Tx. 
The operation will be retried [txId={}].", txId, ex);
-                        } else {
-                            LOG.warn("Failed to switch write intents for Tx 
[txId={}].", txId, ex);
-                        }
+                        Throwable cause = ExceptionUtils.unwrapCause(ex);
 
-                        if (attempts > 0) {
-                            return switchWriteIntentsWithRetry(commit, 
commitTimestamp, txId, partitionId, attempts - 1);
+                        if (TransactionFailureHandler.isRecoverable(cause)) {
+                            LOG.info("Failed to switch write intents for Tx. 
The operation will be retried [txId={}].", txId, ex);
+
+                            return switchWriteIntentsWithRetry(commit, 
commitTimestamp, txId, partitionId);
                         }
 
+                        LOG.info("Failed to switch write intents for Tx 
[txId={}].", txId, ex);
+
                         return CompletableFuture.<Void>failedFuture(ex);
                     }
 

Reply via email to