sanpwc commented on code in PR #2751: URL: https://github.com/apache/ignite-3/pull/2751#discussion_r1382870025
########## modules/runner/src/integrationTest/java/org/apache/ignite/internal/table/NodeUtils.java: ########## @@ -0,0 +1,142 @@ +/* + * 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.table; + +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.IntFunction; +import org.apache.ignite.internal.app.IgniteImpl; +import org.apache.ignite.internal.logger.IgniteLogger; +import org.apache.ignite.internal.logger.Loggers; +import org.apache.ignite.internal.placementdriver.ReplicaMeta; +import org.apache.ignite.internal.raft.Peer; +import org.apache.ignite.internal.raft.service.RaftGroupService; +import org.apache.ignite.internal.replicator.TablePartitionId; +import org.apache.ignite.internal.testframework.IgniteTestUtils; +import org.apache.ignite.table.Tuple; +import org.jetbrains.annotations.Nullable; + +/** + * A helper class to manipulate Ignite nodes in tests. + */ +public class NodeUtils { Review Comment: Class name seems to be confusing. In any case, because we know that transferPrimary will be added as @TestOnly one to PlacementDriver, I'd rather add current static helper method to the TestPlacementDriver. Minor though, because anyway it'll be refactored soon. ########## modules/table/src/integrationTest/java/org/apache/ignite/distributed/ItTxDistributedTestSingleNode.java: ########## @@ -238,6 +238,7 @@ protected boolean assertPartitionsSame(TableImpl table, int partId) { protected void injectFailureOnNextOperation(TableImpl accounts) { InternalTable internalTable = accounts.internalTable(); ReplicaService replicaService = IgniteTestUtils.getFieldValue(internalTable, "replicaSvc"); + Mockito.doReturn(CompletableFuture.failedFuture(new Exception())).when(replicaService).invoke((String) any(), any()); Mockito.doReturn(CompletableFuture.failedFuture(new Exception())).when(replicaService).invoke((ClusterNode) any(), any()); Review Comment: Do we still have ClusterNode parametrized call? ########## modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java: ########## @@ -233,6 +234,8 @@ public class PartitionReplicaListener implements ReplicaListener { private final Supplier<Map<Integer, IndexLocker>> indexesLockers; + private final ConcurrentMap<UUID, CompletableFuture<Void>> txDurableFinishFutures = new ConcurrentHashMap<>(); Review Comment: Please add an explanation why we need given futures. And by the way (I didn't check it yet) why we really need them? Finish operation is idempotent, we will retry it rather rare. ########## modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java: ########## @@ -1437,6 +1450,49 @@ private CompletableFuture<Void> finishAndCleanup( UUID txId, String txCoordinatorId ) { + TxMeta txMeta = txStateStorage.get(txId); + + // Check that a transaction has already been finished. + boolean transactionAlreadyFinished = txMeta != null && isFinalState(txMeta.txState()); + + // Check locksReleased flag. If it is already set, do nothing and return a successful result. + // Even if the outcome is different (the transaction was aborted, but we want to commit it), + // we return 'success' to be in alignment with common transaction handling. + if (transactionAlreadyFinished) { + if (txMeta.locksReleased()) { + return completedFuture(null); + } + + assert !(txMeta.txState() == COMMITED && !commit) : "Not allowed to abort an already committed transaction."; Review Comment: Original option seems more clear. And I'd also add an explanation why it's not valid to have abort request over already committed transaction, while it's fine to have e.g. commit over aborted. ########## modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java: ########## @@ -572,7 +573,8 @@ public class IgniteImpl implements Ignite { new TransactionIdGenerator(() -> clusterSvc.nodeName().hashCode()), () -> clusterSvc.topologyService().localMember().id(), placementDriverMgr.placementDriver(), - partitionIdleSafeTimePropagationPeriodMsSupplier + partitionIdleSafeTimePropagationPeriodMsSupplier, + new SimpleFailHandler() Review Comment: We don't even know who will actually handle unrecoverable finish exceptions: tx coordinator, commit partition or someone else? We(at least I) also don't know how it'll be propagated to classes, e.g. it might be some static helper class. For know it's better just to log the exception without pretending that we will somehow handle it fail handler. In any case it should be covered within separate ticket. ########## modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java: ########## @@ -1437,6 +1450,49 @@ private CompletableFuture<Void> finishAndCleanup( UUID txId, String txCoordinatorId ) { + TxMeta txMeta = txStateStorage.get(txId); + + // Check that a transaction has already been finished. Review Comment: Minor. "Check that" -> "Check whether" -- 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]
