You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "denis-chudov (via GitHub)" <gi...@apache.org> on 2023/12/04 15:06:21 UTC

[PR] Ignite 20994 [ignite-3]

denis-chudov opened a new pull request, #2918:
URL: https://github.com/apache/ignite-3/pull/2918

   Thank you for submitting the pull request.
   
   To streamline the review process of the patch and ensure better code quality
   we ask both an author and a reviewer to verify the following:
   
   ### The Review Checklist
   - [ ] **Formal criteria:** TC status, codestyle, mandatory documentation. Also make sure to complete the following:  
   \- There is a single JIRA ticket related to the pull request.  
   \- The web-link to the pull request is attached to the JIRA ticket.  
   \- The JIRA ticket has the Patch Available state.  
   \- The description of the JIRA ticket explains WHAT was made, WHY and HOW.  
   \- The pull request title is treated as the final commit message. The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
   - [ ] **Design:** new code conforms with the design principles of the components it is added to.
   - [ ] **Patch quality:** patch cannot be split into smaller pieces, its size must be reasonable.
   - [ ] **Code quality:** code is clean and readable, necessary developer documentation is added if needed.
   - [ ] **Tests code quality:** test set covers positive/negative scenarios, happy/edge cases. Tests are effective in terms of execution time and resources.
   
   ### Notes
   - [Apache Ignite Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Java+Code+Style+Guide)


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20994 Adjust writeIntentResolution logic in order to initiate the recovery if coordinator is dead [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #2918:
URL: https://github.com/apache/ignite-3/pull/2918#discussion_r1423827573


##########
modules/transactions/src/test/java/org/apache/ignite/internal/tx/TxStateTest.java:
##########
@@ -116,8 +116,10 @@ void testTransitionsFromCommitted() {
      */
     @Test
     void testTransitionsFromAbandoned() {
-        // Allowed.
+        // Not allowed.

Review Comment:
   Fixed some.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20994 Adjust writeIntentResolution logic in order to initiate the recovery if coordinator is dead [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #2918:
URL: https://github.com/apache/ignite-3/pull/2918#discussion_r1422871031


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/TransactionStateResolver.java:
##########
@@ -201,14 +204,15 @@ private void resolveDistributiveTxState(
         } else {
             assert localMeta.txState() == ABANDONED : "Unexpected transaction state [txId=" + txId + ", txStateMeta=" + localMeta + ']';

Review Comment:
   Why do you think it's impossible? As long as we have this state, we should take into account the possibility of meeting it.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20994 Adjust writeIntentResolution logic in order to initiate the recovery if coordinator is dead [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #2918:
URL: https://github.com/apache/ignite-3/pull/2918#discussion_r1422745366


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java:
##########
@@ -521,8 +524,35 @@ private CompletableFuture<Void> processTxRecoveryAction(TxRecoveryMessage reques
 
         LOG.info("Orphan transaction has to be aborted [tx={}].", txId);
 
-        // TODO: IGNITE-20735 Implement initiate recovery handling logic.
-        return nullCompletedFuture();
+        return triggerTxRecovery(txId)
+                .thenApply(v -> null);
+    }
+
+    /**
+     * Starts tx recovery process. Returns the future containing transaction meta with its final state that completes
+     * when the recovery is completed.
+     *
+     * @param txId Transaction id.
+     * @return Tx recovery future, or failed future if the tx recovery is not possible.
+     */
+    private CompletableFuture<TransactionMeta> triggerTxRecovery(UUID txId) {

Review Comment:
   It will be done under IGNITE-20735



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20994 Adjust writeIntentResolution logic in order to initiate the recovery if coordinator is dead [ignite-3]

Posted by "vldpyatkov (via GitHub)" <gi...@apache.org>.
vldpyatkov commented on code in PR #2918:
URL: https://github.com/apache/ignite-3/pull/2918#discussion_r1423463932


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/TransactionStateResolver.java:
##########
@@ -218,18 +222,17 @@ private void resolveTxStateFromTxCoordinator(
 
         if (coordinator == null) {
             // This means the coordinator node have either left the cluster or restarted.
+            markAbandoned(txId);

Review Comment:
   I think we cannot avoid the write intent resolution procedure. It does not depend on the transaction state.
   Hence, the recovery happens each time we step into a write intent.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20994 Adjust writeIntentResolution logic in order to initiate the recovery if coordinator is dead [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #2918:
URL: https://github.com/apache/ignite-3/pull/2918#discussion_r1422748162


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java:
##########
@@ -731,27 +760,70 @@ private CompletableFuture<?> processOperationRequest(
      * @param request Transaction state request.
      * @return Result future.
      */
-    private CompletableFuture<LeaderOrTxState> processTxStateCommitPartitionRequest(TxStateCommitPartitionRequest request) {
+    private CompletableFuture<TransactionMeta> processTxStateCommitPartitionRequest(TxStateCommitPartitionRequest request) {
         return placementDriver.getPrimaryReplica(replicationGroupId, hybridClock.now())
-                .thenCompose(primaryReplicaMeta -> {
-                    if (primaryReplicaMeta == null) {
+                .thenCompose(replicaMeta -> {
+                    if (replicaMeta == null || replicaMeta.getLeaseholder() == null) {
                         return failedFuture(new PrimaryReplicaMissException(localNode.name(), null, null, null, null));
                     }
 
-                    if (!isLocalPeer(primaryReplicaMeta.getLeaseholder())) {
-                        return completedFuture(new LeaderOrTxState(primaryReplicaMeta.getLeaseholder(), null));
+                    if (!isLocalPeer(replicaMeta.getLeaseholder())) {
+                        return failedFuture(
+                                new PrimaryReplicaMissException(localNode.name(), replicaMeta.getLeaseholder(), null, null, null)
+                        );
                     }
 
-                    TransactionMeta txMeta = txManager.stateMeta(request.txId());
+                    UUID txId = request.txId();
 
-                    if (txMeta == null) {
-                        txMeta = txStateStorage.get(request.txId());
-                    }
+                    TxStateMeta txMeta = txManager.stateMeta(txId);
 
-                    return completedFuture(new LeaderOrTxState(null, txMeta));
+                    if (txMeta != null && txMeta.txState() == FINISHING) {
+                        assert txMeta instanceof TxStateMetaFinishing : txMeta;
+                        return ((TxStateMetaFinishing) txMeta).txFinishFuture();
+                    } else if (txMeta == null || !isFinalState(txMeta.txState())) {
+                        // Try to trigger recovery, if needed. If the transaction will be aborted, the proper ABORTED state will be sent
+                        // in response.
+                        return triggerTxRecoveryOnTxStateResolutionIfNeeded(txId, txMeta);
+                    } else {
+                        assert txMeta != null && isFinalState(txMeta.txState()) : txMeta;

Review Comment:
   ok removed



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20994 Adjust writeIntentResolution logic in order to initiate the recovery if coordinator is dead [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #2918:
URL: https://github.com/apache/ignite-3/pull/2918#discussion_r1422740374


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/PartitionListener.java:
##########
@@ -543,6 +532,56 @@ void handleBuildIndexCommand(BuildIndexCommand cmd, long commandIndex, long comm
         }
     }
 
+    /**
+     * Handles the {@link MarkLocksReleasedCommand}.
+     *
+     * @param cmd Command.
+     * @param commandIndex Command index.
+     * @param commandTerm Command term.
+     */
+    private void handleMarkLocksReleasedCommand(MarkLocksReleasedCommand cmd, long commandIndex, long commandTerm) {
+        UUID txId = cmd.txId();
+
+        TxMeta txMetaBeforeCas = txStateStorage.get(txId);
+
+        TxMeta txMetaToSet = new TxMeta(
+                txMetaBeforeCas.txState(),
+                txMetaBeforeCas.enlistedPartitions(),
+                txMetaBeforeCas.commitTimestamp(),
+                true
+        );
+
+        boolean txStateChangeRes = txStateStorage.compareAndSet(
+                txId,
+                null,
+                txMetaToSet,
+                commandIndex,
+                commandTerm
+        );
+
+        if (!txStateChangeRes) {
+            onTxStateStorageCasFail(txId, txMetaBeforeCas, txMetaToSet);
+        }
+    }
+
+    private static void onTxStateStorageCasFail(UUID txId, TxMeta txMetaBeforeCas, TxMeta txMetaToSet) {
+        UUID traceId = UUID.randomUUID();

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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20994 Adjust writeIntentResolution logic in order to initiate the recovery if coordinator is dead [ignite-3]

Posted by "vldpyatkov (via GitHub)" <gi...@apache.org>.
vldpyatkov commented on code in PR #2918:
URL: https://github.com/apache/ignite-3/pull/2918#discussion_r1422393980


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java:
##########
@@ -1670,11 +1668,6 @@ private CompletableFuture<Void> handleChangePendingAssignmentEvent(
 
         Set<Assignment> stableAssignments = ByteUtils.fromBytes(stableAssignmentsEntry.value());
 
-        transactionStateResolver.updateAssignment(
-                replicaGrpId,
-                stableAssignments.stream().filter(Assignment::isPeer).map(Assignment::consistentId).collect(toList())

Review Comment:
   What was it?



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java:
##########
@@ -409,15 +411,16 @@ private CompletableFuture<?> durableCleanup(UUID txId, TxMeta txMeta) {
                 .thenCompose(f -> f);
     }
 
-    private void markLocksReleased(
-            UUID txId,
-            Collection<TablePartitionId> enlistedPartitions,
-            TxState txState,
-            @Nullable HybridTimestamp commitTimestamp
-    ) {
-        TxMeta newTxMeta = new TxMeta(txState, enlistedPartitions, commitTimestamp, true);
+    private void markLocksReleased(UUID txId) {
+        reliableCatalogVersionFor(hybridClock.now()).thenAccept(catalogVersion -> {

Review Comment:
   I believe we can avoid waiting for the current timestamp.



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java:
##########
@@ -521,8 +524,35 @@ private CompletableFuture<Void> processTxRecoveryAction(TxRecoveryMessage reques
 
         LOG.info("Orphan transaction has to be aborted [tx={}].", txId);
 
-        // TODO: IGNITE-20735 Implement initiate recovery handling logic.
-        return nullCompletedFuture();
+        return triggerTxRecovery(txId)
+                .thenApply(v -> null);
+    }
+
+    /**
+     * Starts tx recovery process. Returns the future containing transaction meta with its final state that completes
+     * when the recovery is completed.
+     *
+     * @param txId Transaction id.
+     * @return Tx recovery future, or failed future if the tx recovery is not possible.
+     */
+    private CompletableFuture<TransactionMeta> triggerTxRecovery(UUID txId) {

Review Comment:
   I would have expected for call txStateMeta.finish() here.



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/PartitionListener.java:
##########
@@ -543,6 +532,56 @@ void handleBuildIndexCommand(BuildIndexCommand cmd, long commandIndex, long comm
         }
     }
 
+    /**
+     * Handles the {@link MarkLocksReleasedCommand}.
+     *
+     * @param cmd Command.
+     * @param commandIndex Command index.
+     * @param commandTerm Command term.
+     */
+    private void handleMarkLocksReleasedCommand(MarkLocksReleasedCommand cmd, long commandIndex, long commandTerm) {
+        UUID txId = cmd.txId();
+
+        TxMeta txMetaBeforeCas = txStateStorage.get(txId);
+
+        TxMeta txMetaToSet = new TxMeta(
+                txMetaBeforeCas.txState(),
+                txMetaBeforeCas.enlistedPartitions(),
+                txMetaBeforeCas.commitTimestamp(),
+                true
+        );
+
+        boolean txStateChangeRes = txStateStorage.compareAndSet(
+                txId,
+                null,
+                txMetaToSet,
+                commandIndex,
+                commandTerm
+        );
+
+        if (!txStateChangeRes) {
+            onTxStateStorageCasFail(txId, txMetaBeforeCas, txMetaToSet);
+        }
+    }
+
+    private static void onTxStateStorageCasFail(UUID txId, TxMeta txMetaBeforeCas, TxMeta txMetaToSet) {
+        UUID traceId = UUID.randomUUID();

Review Comment:
   Use a constructor that does not require the trace id `IgniteInternalException#IgniteInternalException(int, java.lang.String)`



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java:
##########
@@ -731,27 +761,70 @@ private CompletableFuture<?> processOperationRequest(
      * @param request Transaction state request.
      * @return Result future.
      */
-    private CompletableFuture<LeaderOrTxState> processTxStateCommitPartitionRequest(TxStateCommitPartitionRequest request) {
+    private CompletableFuture<TransactionMeta> processTxStateCommitPartitionRequest(TxStateCommitPartitionRequest request) {
         return placementDriver.getPrimaryReplica(replicationGroupId, hybridClock.now())
-                .thenCompose(primaryReplicaMeta -> {
-                    if (primaryReplicaMeta == null) {
+                .thenCompose(replicaMeta -> {

Review Comment:
   We should handle TxStateCommitPartitionRequest as it does for any other PrimaryReplicaRequest.



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/PartitionListener.java:
##########
@@ -205,6 +207,8 @@ public void onWrite(Iterator<CommandClosure<WriteCommand>> iterator) {
                     handleSafeTimeSyncCommand((SafeTimeSyncCommand) command, commandIndex, commandTerm);
                 } else if (command instanceof BuildIndexCommand) {
                     handleBuildIndexCommand((BuildIndexCommand) command, commandIndex, commandTerm);
+                } else if (command instanceof MarkLocksReleasedCommand) {

Review Comment:
   We have to have one round-trip transaction committed. If we replicate the lock release flag, it will double the transaction latency.



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java:
##########
@@ -731,27 +760,70 @@ private CompletableFuture<?> processOperationRequest(
      * @param request Transaction state request.
      * @return Result future.
      */
-    private CompletableFuture<LeaderOrTxState> processTxStateCommitPartitionRequest(TxStateCommitPartitionRequest request) {
+    private CompletableFuture<TransactionMeta> processTxStateCommitPartitionRequest(TxStateCommitPartitionRequest request) {
         return placementDriver.getPrimaryReplica(replicationGroupId, hybridClock.now())
-                .thenCompose(primaryReplicaMeta -> {
-                    if (primaryReplicaMeta == null) {
+                .thenCompose(replicaMeta -> {
+                    if (replicaMeta == null || replicaMeta.getLeaseholder() == null) {
                         return failedFuture(new PrimaryReplicaMissException(localNode.name(), null, null, null, null));
                     }
 
-                    if (!isLocalPeer(primaryReplicaMeta.getLeaseholder())) {
-                        return completedFuture(new LeaderOrTxState(primaryReplicaMeta.getLeaseholder(), null));
+                    if (!isLocalPeer(replicaMeta.getLeaseholder())) {
+                        return failedFuture(
+                                new PrimaryReplicaMissException(localNode.name(), replicaMeta.getLeaseholder(), null, null, null)
+                        );
                     }
 
-                    TransactionMeta txMeta = txManager.stateMeta(request.txId());
+                    UUID txId = request.txId();
 
-                    if (txMeta == null) {
-                        txMeta = txStateStorage.get(request.txId());
-                    }
+                    TxStateMeta txMeta = txManager.stateMeta(txId);
 
-                    return completedFuture(new LeaderOrTxState(null, txMeta));
+                    if (txMeta != null && txMeta.txState() == FINISHING) {
+                        assert txMeta instanceof TxStateMetaFinishing : txMeta;
+                        return ((TxStateMetaFinishing) txMeta).txFinishFuture();
+                    } else if (txMeta == null || !isFinalState(txMeta.txState())) {
+                        // Try to trigger recovery, if needed. If the transaction will be aborted, the proper ABORTED state will be sent
+                        // in response.
+                        return triggerTxRecoveryOnTxStateResolutionIfNeeded(txId, txMeta);
+                    } else {
+                        assert txMeta != null && isFinalState(txMeta.txState()) : txMeta;

Review Comment:
   It is a senseless assertion because it has already been written in the condition above.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20994 Adjust writeIntentResolution logic in order to initiate the recovery if coordinator is dead [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #2918:
URL: https://github.com/apache/ignite-3/pull/2918#discussion_r1423831148


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/TransactionStateResolver.java:
##########
@@ -218,18 +222,17 @@ private void resolveTxStateFromTxCoordinator(
 
         if (coordinator == null) {
             // This means the coordinator node have either left the cluster or restarted.
+            markAbandoned(txId);

Review Comment:
   The given example still shows the need of transition to ABANDONED.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20994 Adjust writeIntentResolution logic in order to initiate the recovery if coordinator is dead [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #2918:
URL: https://github.com/apache/ignite-3/pull/2918#discussion_r1422744503


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/PartitionListener.java:
##########
@@ -205,6 +207,8 @@ public void onWrite(Iterator<CommandClosure<WriteCommand>> iterator) {
                     handleSafeTimeSyncCommand((SafeTimeSyncCommand) command, commandIndex, commandTerm);
                 } else if (command instanceof BuildIndexCommand) {
                     handleBuildIndexCommand((BuildIndexCommand) command, commandIndex, commandTerm);
+                } else if (command instanceof MarkLocksReleasedCommand) {

Review Comment:
   No, we dont wait for replication here.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20994 Adjust writeIntentResolution logic in order to initiate the recovery if coordinator is dead [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #2918:
URL: https://github.com/apache/ignite-3/pull/2918#discussion_r1423833765


##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TxManagerImpl.java:
##########
@@ -293,8 +293,8 @@ public TxStateMeta stateMeta(UUID txId) {
     }
 
     @Override
-    public @Nullable TxStateMeta updateTxMeta(UUID txId, Function<TxStateMeta, TxStateMeta> updater) {
-        return inBusyLock(busyLock, () -> txStateVolatileStorage.updateMeta(txId, oldMeta -> {

Review Comment:
   It is now in `txStateVolatileStorage`.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20994 Adjust writeIntentResolution logic in order to initiate the recovery if coordinator is dead [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #2918:
URL: https://github.com/apache/ignite-3/pull/2918#discussion_r1422738872


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/PartitionListener.java:
##########
@@ -543,6 +532,56 @@ void handleBuildIndexCommand(BuildIndexCommand cmd, long commandIndex, long comm
         }
     }
 
+    /**
+     * Handles the {@link MarkLocksReleasedCommand}.
+     *
+     * @param cmd Command.
+     * @param commandIndex Command index.
+     * @param commandTerm Command term.
+     */
+    private void handleMarkLocksReleasedCommand(MarkLocksReleasedCommand cmd, long commandIndex, long commandTerm) {
+        UUID txId = cmd.txId();
+
+        TxMeta txMetaBeforeCas = txStateStorage.get(txId);
+
+        TxMeta txMetaToSet = new TxMeta(
+                txMetaBeforeCas.txState(),
+                txMetaBeforeCas.enlistedPartitions(),
+                txMetaBeforeCas.commitTimestamp(),
+                true
+        );
+
+        boolean txStateChangeRes = txStateStorage.compareAndSet(
+                txId,
+                null,
+                txMetaToSet,
+                commandIndex,
+                commandTerm
+        );
+
+        if (!txStateChangeRes) {
+            onTxStateStorageCasFail(txId, txMetaBeforeCas, txMetaToSet);
+        }
+    }
+
+    private static void onTxStateStorageCasFail(UUID txId, TxMeta txMetaBeforeCas, TxMeta txMetaToSet) {
+        UUID traceId = UUID.randomUUID();

Review Comment:
   why? I just moved this code



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20994 Adjust writeIntentResolution logic in order to initiate the recovery if coordinator is dead [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #2918:
URL: https://github.com/apache/ignite-3/pull/2918#discussion_r1422737733


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java:
##########
@@ -1670,11 +1668,6 @@ private CompletableFuture<Void> handleChangePendingAssignmentEvent(
 
         Set<Assignment> stableAssignments = ByteUtils.fromBytes(stableAssignmentsEntry.value());
 
-        transactionStateResolver.updateAssignment(
-                replicaGrpId,
-                stableAssignments.stream().filter(Assignment::isPeer).map(Assignment::consistentId).collect(toList())

Review Comment:
   not needed anymore - we rely on placement driver



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20994 Adjust writeIntentResolution logic in order to initiate the recovery if coordinator is dead [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #2918:
URL: https://github.com/apache/ignite-3/pull/2918#discussion_r1422738872


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/PartitionListener.java:
##########
@@ -543,6 +532,56 @@ void handleBuildIndexCommand(BuildIndexCommand cmd, long commandIndex, long comm
         }
     }
 
+    /**
+     * Handles the {@link MarkLocksReleasedCommand}.
+     *
+     * @param cmd Command.
+     * @param commandIndex Command index.
+     * @param commandTerm Command term.
+     */
+    private void handleMarkLocksReleasedCommand(MarkLocksReleasedCommand cmd, long commandIndex, long commandTerm) {
+        UUID txId = cmd.txId();
+
+        TxMeta txMetaBeforeCas = txStateStorage.get(txId);
+
+        TxMeta txMetaToSet = new TxMeta(
+                txMetaBeforeCas.txState(),
+                txMetaBeforeCas.enlistedPartitions(),
+                txMetaBeforeCas.commitTimestamp(),
+                true
+        );
+
+        boolean txStateChangeRes = txStateStorage.compareAndSet(
+                txId,
+                null,
+                txMetaToSet,
+                commandIndex,
+                commandTerm
+        );
+
+        if (!txStateChangeRes) {
+            onTxStateStorageCasFail(txId, txMetaBeforeCas, txMetaToSet);
+        }
+    }
+
+    private static void onTxStateStorageCasFail(UUID txId, TxMeta txMetaBeforeCas, TxMeta txMetaToSet) {
+        UUID traceId = UUID.randomUUID();

Review Comment:
   why? I just moved this code



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20994 Adjust writeIntentResolution logic in order to initiate the recovery if coordinator is dead [ignite-3]

Posted by "vldpyatkov (via GitHub)" <gi...@apache.org>.
vldpyatkov commented on code in PR #2918:
URL: https://github.com/apache/ignite-3/pull/2918#discussion_r1422760108


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/TransactionStateResolver.java:
##########
@@ -201,14 +204,15 @@ private void resolveDistributiveTxState(
         } else {
             assert localMeta.txState() == ABANDONED : "Unexpected transaction state [txId=" + txId + ", txStateMeta=" + localMeta + ']';

Review Comment:
   This is impossible because we have ABANDONED state in memory. If we have this state, that means we have locks, which we cannot face with write intents.



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/TransactionStateResolver.java:
##########
@@ -288,32 +291,28 @@ private void sendAndRetry(
             ReplicationGroupId replicaGrp,
             TxStateCommitPartitionRequest request
     ) {
-        ClusterNode nodeToSend = primaryReplicaMapping.get(replicaGrp).stream()
-                .map(clusterNodeResolver)
-                .filter(Objects::nonNull)
-                .findFirst()
-                .orElseThrow(() -> new IgniteInternalException("All replica nodes are unavailable"));
-
-        replicaService.invoke(nodeToSend, request).thenAccept(resp -> {
-            assert resp instanceof LeaderOrTxState : "Unsupported response type [type=" + resp.getClass().getSimpleName() + ']';
-
-            LeaderOrTxState stateOrLeader = (LeaderOrTxState) resp;
-
-            String nextNodeToSend = stateOrLeader.leaderName();
-
-            if (nextNodeToSend == null) {
-                resFut.complete(stateOrLeader.txMeta());
-            } else {
-                LinkedHashSet<String> newAssignment = new LinkedHashSet<>();
-
-                newAssignment.add(nextNodeToSend);
-                newAssignment.addAll(primaryReplicaMapping.get(replicaGrp));
-
-                primaryReplicaMapping.put(replicaGrp, newAssignment);
-
-                sendAndRetry(resFut, replicaGrp, request);
-            }
-        });
+        HybridTimestamp now = clock.now();
+
+        placementDriver.awaitPrimaryReplica(replicaGrp, now, AWAIT_PRIMARY_REPLICA_TIMEOUT, MILLISECONDS)

Review Comment:
   Can we use PlacementDriverHelper here?



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/TransactionStateResolver.java:
##########
@@ -218,18 +222,17 @@ private void resolveTxStateFromTxCoordinator(
 
         if (coordinator == null) {
             // This means the coordinator node have either left the cluster or restarted.
+            markAbandoned(txId);

Review Comment:
   This is not necessary because we will resolve the write intent despite the fact that the state ABANDONED or is not a final one.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20994 Adjust writeIntentResolution logic in order to initiate the recovery if coordinator is dead [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #2918:
URL: https://github.com/apache/ignite-3/pull/2918#discussion_r1423742045


##########
modules/transactions/src/test/java/org/apache/ignite/internal/tx/TxStateTest.java:
##########
@@ -116,8 +116,10 @@ void testTransitionsFromCommitted() {
      */
     @Test
     void testTransitionsFromAbandoned() {
-        // Allowed.
+        // Not allowed.

Review Comment:
   Please make sure other methods in this test class have correctly grouped assertions (for the readability sake)



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TxManagerImpl.java:
##########
@@ -293,8 +293,8 @@ public TxStateMeta stateMeta(UUID txId) {
     }
 
     @Override
-    public @Nullable TxStateMeta updateTxMeta(UUID txId, Function<TxStateMeta, TxStateMeta> updater) {
-        return inBusyLock(busyLock, () -> txStateVolatileStorage.updateMeta(txId, oldMeta -> {

Review Comment:
   So do you believe we don't need a busylock here?



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/OrphanDetector.java:
##########
@@ -176,7 +176,7 @@ private Void handleLockHolder(UUID txId) throws NodeStoppingException {
      * @param txId Transaction id that holds a lock.
      * @return Future to complete.
      */
-    private void handleLockHolderInternal(UUID txId) {
+    private void checkOrphanhoodInternal(UUID txId) {

Review Comment:
   `checkTxOrphanedInternal` looks more readable



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20994 Adjust writeIntentResolution logic in order to initiate the recovery if coordinator is dead [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #2918:
URL: https://github.com/apache/ignite-3/pull/2918#discussion_r1422743971


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java:
##########
@@ -409,15 +411,16 @@ private CompletableFuture<?> durableCleanup(UUID txId, TxMeta txMeta) {
                 .thenCompose(f -> f);
     }
 
-    private void markLocksReleased(
-            UUID txId,
-            Collection<TablePartitionId> enlistedPartitions,
-            TxState txState,
-            @Nullable HybridTimestamp commitTimestamp
-    ) {
-        TxMeta newTxMeta = new TxMeta(txState, enlistedPartitions, commitTimestamp, true);
+    private void markLocksReleased(UUID txId) {
+        reliableCatalogVersionFor(hybridClock.now()).thenAccept(catalogVersion -> {

Review Comment:
   I think it's not the thing that should be fixed in the current PR. We dont have another proper timestamp here.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20994 Adjust writeIntentResolution logic in order to initiate the recovery if coordinator is dead [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #2918:
URL: https://github.com/apache/ignite-3/pull/2918#discussion_r1422885146


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/TransactionStateResolver.java:
##########
@@ -218,18 +222,17 @@ private void resolveTxStateFromTxCoordinator(
 
         if (coordinator == null) {
             // This means the coordinator node have either left the cluster or restarted.
+            markAbandoned(txId);

Review Comment:
   We will, but we still should put the tx in this state because it's not correct not to do it. For example:
   - RO transaction tx0 resolves write intent belonging to the transaction tx1 and marks it as abandoned and starts the recovery;
   - after that RW transaction tx2 meets the lock belonging to tx1, sees that it's abandoned recently and doesn't start the recovery, minimizing redundant network messages.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20994 Adjust writeIntentResolution logic in order to initiate the recovery if coordinator is dead [ignite-3]

Posted by "vldpyatkov (via GitHub)" <gi...@apache.org>.
vldpyatkov merged PR #2918:
URL: https://github.com/apache/ignite-3/pull/2918


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20994 Adjust writeIntentResolution logic in order to initiate the recovery if coordinator is dead [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #2918:
URL: https://github.com/apache/ignite-3/pull/2918#discussion_r1422784020


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/TransactionStateResolver.java:
##########
@@ -288,32 +291,28 @@ private void sendAndRetry(
             ReplicationGroupId replicaGrp,
             TxStateCommitPartitionRequest request
     ) {
-        ClusterNode nodeToSend = primaryReplicaMapping.get(replicaGrp).stream()
-                .map(clusterNodeResolver)
-                .filter(Objects::nonNull)
-                .findFirst()
-                .orElseThrow(() -> new IgniteInternalException("All replica nodes are unavailable"));
-
-        replicaService.invoke(nodeToSend, request).thenAccept(resp -> {
-            assert resp instanceof LeaderOrTxState : "Unsupported response type [type=" + resp.getClass().getSimpleName() + ']';
-
-            LeaderOrTxState stateOrLeader = (LeaderOrTxState) resp;
-
-            String nextNodeToSend = stateOrLeader.leaderName();
-
-            if (nextNodeToSend == null) {
-                resFut.complete(stateOrLeader.txMeta());
-            } else {
-                LinkedHashSet<String> newAssignment = new LinkedHashSet<>();
-
-                newAssignment.add(nextNodeToSend);
-                newAssignment.addAll(primaryReplicaMapping.get(replicaGrp));
-
-                primaryReplicaMapping.put(replicaGrp, newAssignment);
-
-                sendAndRetry(resFut, replicaGrp, request);
-            }
-        });
+        HybridTimestamp now = clock.now();
+
+        placementDriver.awaitPrimaryReplica(replicaGrp, now, AWAIT_PRIMARY_REPLICA_TIMEOUT, MILLISECONDS)

Review Comment:
   done



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20994 Adjust writeIntentResolution logic in order to initiate the recovery if coordinator is dead [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #2918:
URL: https://github.com/apache/ignite-3/pull/2918#discussion_r1423959164


##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/OrphanDetector.java:
##########
@@ -176,7 +176,7 @@ private Void handleLockHolder(UUID txId) throws NodeStoppingException {
      * @param txId Transaction id that holds a lock.
      * @return Future to complete.
      */
-    private void handleLockHolderInternal(UUID txId) {
+    private void checkOrphanhoodInternal(UUID txId) {

Review Comment:
   renamed



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20994 Adjust writeIntentResolution logic in order to initiate the recovery if coordinator is dead [ignite-3]

Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #2918:
URL: https://github.com/apache/ignite-3/pull/2918#discussion_r1422746516


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java:
##########
@@ -731,27 +761,70 @@ private CompletableFuture<?> processOperationRequest(
      * @param request Transaction state request.
      * @return Result future.
      */
-    private CompletableFuture<LeaderOrTxState> processTxStateCommitPartitionRequest(TxStateCommitPartitionRequest request) {
+    private CompletableFuture<TransactionMeta> processTxStateCommitPartitionRequest(TxStateCommitPartitionRequest request) {
         return placementDriver.getPrimaryReplica(replicationGroupId, hybridClock.now())
-                .thenCompose(primaryReplicaMeta -> {
-                    if (primaryReplicaMeta == null) {
+                .thenCompose(replicaMeta -> {

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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org