You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sk...@apache.org on 2026/03/23 08:30:38 UTC
(ignite-3) branch main updated: IGNITE-27494 Implement write intent resolution primary replica path (commit partition side) (#7527)
This is an automated email from the ASF dual-hosted git repository.
sk0x50 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 55e63e39595 IGNITE-27494 Implement write intent resolution primary replica path (commit partition side) (#7527)
55e63e39595 is described below
commit 55e63e395953cc05c99a68660af11a202dd01bf9
Author: Denis Chudov <mo...@gmail.com>
AuthorDate: Mon Mar 23 10:30:32 2026 +0200
IGNITE-27494 Implement write intent resolution primary replica path (commit partition side) (#7527)
Co-authored-by: Alexander Polovtcev <al...@gmail.com>
---
.../index/FinalTransactionStateResolver.java | 14 +-
.../ignite/internal/index/IndexBuildTask.java | 34 +-
.../internal/index/IndexBuildingManager.java | 3 +-
.../RetryingFinalTransactionStateResolver.java | 39 +-
.../CommittedFinalTransactionStateResolver.java | 10 +-
.../internal/network/DefaultMessagingService.java | 20 +-
.../PartitionReplicaLifecycleManager.java | 8 +-
.../TableAwareReplicaRequestPreProcessor.java | 2 +
.../replicator/ZonePartitionReplicaListener.java | 3 +
...xStateCommitPartitionReplicaRequestHandler.java | 167 +++++-
.../raft/handlers/FinishTxCommandHandler.java | 8 +-
.../app/ItInProcessRestartApiReferencesTest.java | 5 +-
.../internal/ClusterPerClassIntegrationTest.java | 23 +-
.../apache/ignite/internal/storage/RowMeta.java | 29 +-
.../storage/AbstractMvPartitionStorageTest.java | 6 +-
.../storage/impl/TestMvPartitionStorage.java | 14 +-
.../mv/AbstractPageMemoryMvPartitionStorage.java | 12 +-
.../storage/rocksdb/RocksDbMvPartitionStorage.java | 25 +-
.../internal/table/RecordBinaryViewImpl.java | 8 +-
.../table/distributed/StorageUpdateHandler.java | 27 +
.../internal/table/distributed/TableManager.java | 5 +
.../replicator/PartitionReplicaListener.java | 191 ++++---
.../replication/PartitionReplicaListenerTest.java | 17 +-
.../ZonePartitionReplicaListenerTest.java | 12 +-
.../apache/ignite/distributed/ItTxTestCluster.java | 6 +-
.../table/impl/DummyInternalTableImpl.java | 2 +
modules/transactions/build.gradle | 2 +
.../distributed/ItTxWriteIntentResolutionTest.java | 587 +++++++++++++++++++++
...ChangeDuringWriteIntentResolutionException.java | 33 ++
.../org/apache/ignite/internal/tx/TxStateMeta.java | 28 +
.../ignite/internal/tx/TxStateMetaFinishing.java | 18 +
.../internal/tx/impl/TransactionStateResolver.java | 245 ++-------
.../internal/tx/impl/TxCleanupRequestSender.java | 8 +-
.../ignite/internal/tx/impl/TxManagerImpl.java | 3 +-
.../ignite/internal/tx/impl/TxMessageSender.java | 81 ++-
.../ignite/internal/tx/impl/TxRecoveryEngine.java | 4 +-
.../tx/impl/TxStateResolutionParameters.java | 339 ++++++++++++
.../tx/message/TxStateCommitPartitionRequest.java | 6 +
.../tx/impl/TransactionStateResolverTest.java | 118 ++---
.../internal/tx/test/ItTransactionTestUtils.java | 68 ++-
40 files changed, 1768 insertions(+), 462 deletions(-)
diff --git a/modules/index/src/main/java/org/apache/ignite/internal/index/FinalTransactionStateResolver.java b/modules/index/src/main/java/org/apache/ignite/internal/index/FinalTransactionStateResolver.java
index c6832089b1b..e016510ef44 100644
--- a/modules/index/src/main/java/org/apache/ignite/internal/index/FinalTransactionStateResolver.java
+++ b/modules/index/src/main/java/org/apache/ignite/internal/index/FinalTransactionStateResolver.java
@@ -19,8 +19,11 @@ package org.apache.ignite.internal.index;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
import org.apache.ignite.internal.replicator.ZonePartitionId;
+import org.apache.ignite.internal.storage.RowId;
import org.apache.ignite.internal.tx.TxState;
+import org.jetbrains.annotations.Nullable;
/**
* Resolves the final state of a transaction.
@@ -32,6 +35,15 @@ public interface FinalTransactionStateResolver {
*
* @param transactionId Transaction ID.
* @param commitGroupId Commit partition ID.
+ * @param senderGroupId Sender partition ID.
+ * @param rowId Row ID.
+ * @param newestCommitTimestamp Newest commit timestamp observed by the sender.
*/
- CompletableFuture<TxState> resolveFinalTxState(UUID transactionId, ZonePartitionId commitGroupId);
+ CompletableFuture<TxState> resolveFinalTxState(
+ UUID transactionId,
+ ZonePartitionId commitGroupId,
+ ZonePartitionId senderGroupId,
+ RowId rowId,
+ @Nullable HybridTimestamp newestCommitTimestamp
+ );
}
diff --git a/modules/index/src/main/java/org/apache/ignite/internal/index/IndexBuildTask.java b/modules/index/src/main/java/org/apache/ignite/internal/index/IndexBuildTask.java
index 1c81dcb96dc..d7ff797fbb9 100644
--- a/modules/index/src/main/java/org/apache/ignite/internal/index/IndexBuildTask.java
+++ b/modules/index/src/main/java/org/apache/ignite/internal/index/IndexBuildTask.java
@@ -320,7 +320,7 @@ class IndexBuildTask {
}
List<RowId> rowIds = new ArrayList<>(batchSize);
- Map<UUID, CommitPartitionId> transactionsToResolve = new HashMap<>();
+ Map<UUID, WriteIntentInfo> transactionsToResolve = new HashMap<>();
List<RowMeta> rows = nextRowIdToBuild == null ? List.of()
: partitionStorage.rowsStartingWith(nextRowIdToBuild, highestRowId, batchSize);
@@ -338,7 +338,7 @@ class IndexBuildTask {
if (txBeginTs.compareTo(indexCreationTs) < 0) {
transactionsToResolve.put(
row.transactionId(),
- new CommitPartitionId(row.commitZoneId(), row.commitPartitionId())
+ new WriteIntentInfo(row.commitZoneId(), row.commitPartitionId(), row.newestCommitTimestamp(), row.rowId())
);
}
}
@@ -361,12 +361,19 @@ class IndexBuildTask {
});
}
- private CompletableFuture<TxState> resolveFinalTxStateIfNeeded(UUID transactionId, CommitPartitionId commitPartitionId) {
- assert commitPartitionId.commitZoneId != null;
+ private CompletableFuture<TxState> resolveFinalTxStateIfNeeded(UUID transactionId, WriteIntentInfo writeIntentInfo) {
+ assert writeIntentInfo.commitZoneId != null;
- ZonePartitionId commitGroupId = new ZonePartitionId(commitPartitionId.commitZoneId, commitPartitionId.commitPartitionId);
+ ZonePartitionId commitGroupId = new ZonePartitionId(writeIntentInfo.commitZoneId, writeIntentInfo.commitPartitionId);
+ ZonePartitionId senderGroupId = new ZonePartitionId(taskId.getZoneId(), taskId.getPartitionId());
- return finalTransactionStateResolver.resolveFinalTxState(transactionId, commitGroupId)
+ return finalTransactionStateResolver.resolveFinalTxState(
+ transactionId,
+ commitGroupId,
+ senderGroupId,
+ writeIntentInfo.rowId,
+ writeIntentInfo.newestCommitTimestamp
+ )
.thenApply(statisticsLoggingListener::onWriteIntentResolved);
}
@@ -446,13 +453,22 @@ class IndexBuildTask {
}
}
- private static class CommitPartitionId {
+ private static class WriteIntentInfo {
private final @Nullable Integer commitZoneId;
private final int commitPartitionId;
-
- private CommitPartitionId(@Nullable Integer commitZoneId, int commitPartitionId) {
+ private final @Nullable HybridTimestamp newestCommitTimestamp;
+ private final RowId rowId;
+
+ private WriteIntentInfo(
+ @Nullable Integer commitZoneId,
+ int commitPartitionId,
+ @Nullable HybridTimestamp newestCommitTimestamp,
+ RowId rowId
+ ) {
this.commitZoneId = commitZoneId;
this.commitPartitionId = commitPartitionId;
+ this.newestCommitTimestamp = newestCommitTimestamp;
+ this.rowId = rowId;
}
}
}
diff --git a/modules/index/src/main/java/org/apache/ignite/internal/index/IndexBuildingManager.java b/modules/index/src/main/java/org/apache/ignite/internal/index/IndexBuildingManager.java
index 61f26216e67..a7d993f7e33 100644
--- a/modules/index/src/main/java/org/apache/ignite/internal/index/IndexBuildingManager.java
+++ b/modules/index/src/main/java/org/apache/ignite/internal/index/IndexBuildingManager.java
@@ -52,6 +52,7 @@ import org.apache.ignite.internal.replicator.ReplicaService;
import org.apache.ignite.internal.table.distributed.index.IndexMetaStorage;
import org.apache.ignite.internal.thread.IgniteThreadFactory;
import org.apache.ignite.internal.tx.TxManager;
+import org.apache.ignite.internal.tx.impl.PlacementDriverHelper;
import org.apache.ignite.internal.tx.impl.TransactionStateResolver;
import org.apache.ignite.internal.tx.impl.TxMessageSender;
import org.apache.ignite.internal.tx.impl.TxRecoveryEngine;
@@ -121,7 +122,7 @@ public class IndexBuildingManager implements IgniteComponent {
clockService,
clusterService.topologyService(),
clusterService.messagingService(),
- new ExecutorInclinedPlacementDriver(placementDriver, executor),
+ new PlacementDriverHelper(new ExecutorInclinedPlacementDriver(placementDriver, executor), clockService),
new TxMessageSender(clusterService.messagingService(), replicaService, clockService),
new TxRecoveryEngine(txManager, clusterService.topologyService()),
new Lazy<>(() -> clusterService.topologyService().localMember()),
diff --git a/modules/index/src/main/java/org/apache/ignite/internal/index/RetryingFinalTransactionStateResolver.java b/modules/index/src/main/java/org/apache/ignite/internal/index/RetryingFinalTransactionStateResolver.java
index 2da025e47ef..136f54529f9 100644
--- a/modules/index/src/main/java/org/apache/ignite/internal/index/RetryingFinalTransactionStateResolver.java
+++ b/modules/index/src/main/java/org/apache/ignite/internal/index/RetryingFinalTransactionStateResolver.java
@@ -21,16 +21,20 @@ import static java.util.concurrent.CompletableFuture.completedFuture;
import static java.util.concurrent.CompletableFuture.supplyAsync;
import static java.util.concurrent.TimeUnit.SECONDS;
import static java.util.function.Function.identity;
+import static org.apache.ignite.internal.tx.impl.TxStateResolutionParameters.txStateResolutionParameters;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
import org.apache.ignite.internal.placementdriver.PrimaryReplicaAwaitTimeoutException;
import org.apache.ignite.internal.replicator.ZonePartitionId;
+import org.apache.ignite.internal.storage.RowId;
import org.apache.ignite.internal.tx.TxState;
import org.apache.ignite.internal.tx.impl.TransactionStateResolver;
import org.apache.ignite.internal.util.CompletableFutures;
+import org.jetbrains.annotations.Nullable;
/**
* FinalTransactionStateResolver implementation using retries. Makes sense when the coordinator of the transaction is known
@@ -48,18 +52,32 @@ public class RetryingFinalTransactionStateResolver implements FinalTransactionSt
}
@Override
- public CompletableFuture<TxState> resolveFinalTxState(UUID transactionId, ZonePartitionId commitGroupId) {
- return stateResolver.resolveTxState(transactionId, commitGroupId, null, Long.MAX_VALUE, SECONDS, null, null)
+ public CompletableFuture<TxState> resolveFinalTxState(
+ UUID transactionId,
+ ZonePartitionId commitGroupId,
+ ZonePartitionId senderGroupId,
+ RowId rowId,
+ @Nullable HybridTimestamp newestCommitTimestamp
+ ) {
+ return stateResolver.resolveTxState(
+ txStateResolutionParameters()
+ .txId(transactionId)
+ .commitGroupId(commitGroupId)
+ .senderGroupId(senderGroupId)
+ .awaitCommitPartitionAvailabilityTimeout(Long.MAX_VALUE, SECONDS)
+ .rowIdAndNewestCommitTimestamp(rowId, newestCommitTimestamp)
+ .build()
+ )
.thenCompose(txMeta -> {
if (txMeta != null && TxState.isFinalState(txMeta.txState())) {
return completedFuture(txMeta.txState());
}
- return retryResolve(transactionId, commitGroupId);
+ return retryResolve(transactionId, commitGroupId, senderGroupId, rowId, newestCommitTimestamp);
})
.handle((res, ex) -> {
if (ex instanceof PrimaryReplicaAwaitTimeoutException) {
- return retryResolve(transactionId, commitGroupId);
+ return retryResolve(transactionId, commitGroupId, senderGroupId, rowId, newestCommitTimestamp);
}
return CompletableFutures.completedOrFailedFuture(res, ex);
@@ -67,8 +85,17 @@ public class RetryingFinalTransactionStateResolver implements FinalTransactionSt
.thenCompose(identity());
}
- private CompletableFuture<TxState> retryResolve(UUID transactionId, ZonePartitionId commitGroupId) {
- return supplyAsync(() -> resolveFinalTxState(transactionId, commitGroupId), delayedExecutor)
+ private CompletableFuture<TxState> retryResolve(
+ UUID transactionId,
+ ZonePartitionId commitGroupId,
+ ZonePartitionId senderGroupId,
+ RowId rowId,
+ @Nullable HybridTimestamp newestCommitTimestamp
+ ) {
+ return supplyAsync(
+ () -> resolveFinalTxState(transactionId, commitGroupId, senderGroupId, rowId, newestCommitTimestamp),
+ delayedExecutor
+ )
.thenCompose(identity());
}
}
diff --git a/modules/index/src/test/java/org/apache/ignite/internal/index/CommittedFinalTransactionStateResolver.java b/modules/index/src/test/java/org/apache/ignite/internal/index/CommittedFinalTransactionStateResolver.java
index 5b657cbcf7e..de91ed5b53b 100644
--- a/modules/index/src/test/java/org/apache/ignite/internal/index/CommittedFinalTransactionStateResolver.java
+++ b/modules/index/src/test/java/org/apache/ignite/internal/index/CommittedFinalTransactionStateResolver.java
@@ -19,7 +19,9 @@ package org.apache.ignite.internal.index;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
import org.apache.ignite.internal.replicator.ZonePartitionId;
+import org.apache.ignite.internal.storage.RowId;
import org.apache.ignite.internal.tx.TxState;
/**
@@ -27,7 +29,13 @@ import org.apache.ignite.internal.tx.TxState;
*/
public class CommittedFinalTransactionStateResolver implements FinalTransactionStateResolver {
@Override
- public CompletableFuture<TxState> resolveFinalTxState(UUID transactionId, ZonePartitionId commitGroupId) {
+ public CompletableFuture<TxState> resolveFinalTxState(
+ UUID transactionId,
+ ZonePartitionId commitGroupId,
+ ZonePartitionId senderGroupId,
+ RowId rowId,
+ HybridTimestamp newestCommitTimestamp
+ ) {
return CompletableFuture.completedFuture(TxState.COMMITTED);
}
}
diff --git a/modules/network/src/main/java/org/apache/ignite/internal/network/DefaultMessagingService.java b/modules/network/src/main/java/org/apache/ignite/internal/network/DefaultMessagingService.java
index 4794fac012c..a765aa078c1 100644
--- a/modules/network/src/main/java/org/apache/ignite/internal/network/DefaultMessagingService.java
+++ b/modules/network/src/main/java/org/apache/ignite/internal/network/DefaultMessagingService.java
@@ -307,8 +307,16 @@ public class DefaultMessagingService extends AbstractMessagingService {
return failedFuture(new NodeStoppingException());
}
+ boolean shouldDropMessage;
+
+ try {
+ shouldDropMessage = shouldDropMessage(recipient, msg);
+ } catch (Exception e) {
+ return failedFuture(e);
+ }
+
// TODO: IGNITE-18493 - remove/move this
- if (shouldDropMessage(recipient, msg)) {
+ if (shouldDropMessage) {
return nullCompletedFuture();
}
@@ -368,8 +376,16 @@ public class DefaultMessagingService extends AbstractMessagingService {
return failedFuture(new NodeStoppingException());
}
+ boolean shouldDropMessage;
+
+ try {
+ shouldDropMessage = shouldDropMessage(recipient, msg);
+ } catch (Exception e) {
+ return failedFuture(e);
+ }
+
// TODO: IGNITE-18493 - remove/move this
- if (shouldDropMessage(recipient, msg)) {
+ if (shouldDropMessage) {
return new CompletableFuture<NetworkMessage>().orTimeout(10, TimeUnit.MILLISECONDS);
}
diff --git a/modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/PartitionReplicaLifecycleManager.java b/modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/PartitionReplicaLifecycleManager.java
index 1764b1bbc6e..ee8ad0046f6 100644
--- a/modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/PartitionReplicaLifecycleManager.java
+++ b/modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/PartitionReplicaLifecycleManager.java
@@ -178,6 +178,7 @@ import org.apache.ignite.internal.storage.engine.StorageEngine;
import org.apache.ignite.internal.thread.ThreadUtils;
import org.apache.ignite.internal.tostring.S;
import org.apache.ignite.internal.tx.TxManager;
+import org.apache.ignite.internal.tx.impl.PlacementDriverHelper;
import org.apache.ignite.internal.tx.impl.TransactionStateResolver;
import org.apache.ignite.internal.tx.impl.TxMessageSender;
import org.apache.ignite.internal.tx.impl.TxRecoveryEngine;
@@ -287,6 +288,8 @@ public class PartitionReplicaLifecycleManager extends
private final TransactionStateResolver transactionStateResolver;
+ private final PlacementDriverHelper placementDriverHelper;
+
private final TxMessageSender txMessageSender;
private final TxRecoveryEngine txRecoveryEngine;
@@ -451,12 +454,14 @@ public class PartitionReplicaLifecycleManager extends
clockService
);
+ placementDriverHelper = new PlacementDriverHelper(executorInclinedPlacementDriver, clockService);
+
transactionStateResolver = new TransactionStateResolver(
txManager,
clockService,
topologyService,
messagingService,
- executorInclinedPlacementDriver,
+ placementDriverHelper,
txMessageSender,
txRecoveryEngine,
new Lazy<>(topologyService::localMember),
@@ -846,6 +851,7 @@ public class PartitionReplicaLifecycleManager extends
executorInclinedSchemaSyncService,
catalogService,
executorInclinedPlacementDriver,
+ placementDriverHelper,
topologyService,
new ExecutorInclinedRaftCommandRunner(raftClient, partitionOperationsExecutor),
failureProcessor,
diff --git a/modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/TableAwareReplicaRequestPreProcessor.java b/modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/TableAwareReplicaRequestPreProcessor.java
index b57d5b16cf4..09a39df18de 100644
--- a/modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/TableAwareReplicaRequestPreProcessor.java
+++ b/modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/TableAwareReplicaRequestPreProcessor.java
@@ -33,6 +33,7 @@ import org.apache.ignite.internal.replicator.message.TableAware;
import org.apache.ignite.internal.schema.SchemaSyncService;
import org.apache.ignite.internal.tx.TransactionIds;
import org.apache.ignite.internal.tx.message.TableWriteIntentSwitchReplicaRequest;
+import org.apache.ignite.internal.tx.message.TxStatePrimaryReplicaRequest;
import org.jetbrains.annotations.Nullable;
/**
@@ -85,6 +86,7 @@ public class TableAwareReplicaRequestPreProcessor {
assert txTs == null
? request instanceof GetEstimatedSizeRequest || request instanceof ScanCloseReplicaRequest
|| request instanceof BuildIndexReplicaRequest || request instanceof TableWriteIntentSwitchReplicaRequest
+ || request instanceof TxStatePrimaryReplicaRequest
: opTs.compareTo(txTs) >= 0 :
"Invalid request timestamps [request=" + request + ']';
diff --git a/modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/ZonePartitionReplicaListener.java b/modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/ZonePartitionReplicaListener.java
index 39fc89a5fde..d594b7e5ef5 100644
--- a/modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/ZonePartitionReplicaListener.java
+++ b/modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/ZonePartitionReplicaListener.java
@@ -55,6 +55,7 @@ import org.apache.ignite.internal.replicator.message.ReplicaSafeTimeSyncRequest;
import org.apache.ignite.internal.replicator.message.TableAware;
import org.apache.ignite.internal.schema.SchemaSyncService;
import org.apache.ignite.internal.tx.TxManager;
+import org.apache.ignite.internal.tx.impl.PlacementDriverHelper;
import org.apache.ignite.internal.tx.impl.TransactionStateResolver;
import org.apache.ignite.internal.tx.impl.TxMessageSender;
import org.apache.ignite.internal.tx.impl.TxRecoveryEngine;
@@ -114,6 +115,7 @@ public class ZonePartitionReplicaListener implements ReplicaListener {
SchemaSyncService schemaSyncService,
CatalogService catalogService,
LeasePlacementDriver placementDriver,
+ PlacementDriverHelper placementDriverHelper,
ClusterNodeResolver clusterNodeResolver,
RaftCommandRunner raftClient,
FailureProcessor failureProcessor,
@@ -173,6 +175,7 @@ public class ZonePartitionReplicaListener implements ReplicaListener {
clusterNodeResolver,
txRecoveryEngine,
txMessageSender,
+ placementDriverHelper,
replicationGroupId,
localNode
);
diff --git a/modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/handlers/TxStateCommitPartitionReplicaRequestHandler.java b/modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/handlers/TxStateCommitPartitionReplicaRequestHandler.java
index 105d25adddc..9648a012d8d 100644
--- a/modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/handlers/TxStateCommitPartitionReplicaRequestHandler.java
+++ b/modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/handlers/TxStateCommitPartitionReplicaRequestHandler.java
@@ -18,10 +18,16 @@
package org.apache.ignite.internal.partition.replicator.handlers;
import static java.util.concurrent.CompletableFuture.completedFuture;
+import static java.util.concurrent.TimeUnit.SECONDS;
import static org.apache.ignite.internal.tx.TxState.ABANDONED;
import static org.apache.ignite.internal.tx.TxState.FINISHING;
import static org.apache.ignite.internal.tx.TxState.PENDING;
import static org.apache.ignite.internal.tx.TxState.isFinalState;
+import static org.apache.ignite.internal.tx.TxStateMeta.finalizeState;
+import static org.apache.ignite.internal.tx.TxStateMetaFinishing.castToFinishing;
+import static org.apache.ignite.internal.tx.impl.PlacementDriverHelper.AWAIT_PRIMARY_REPLICA_TIMEOUT;
+import static org.apache.ignite.internal.tx.impl.TxStateResolutionParameters.txStateResolutionParameters;
+import static org.apache.ignite.internal.util.FastTimestamps.coarseCurrentTimeMillis;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@@ -31,11 +37,13 @@ import org.apache.ignite.internal.network.ClusterNodeResolver;
import org.apache.ignite.internal.network.InternalClusterNode;
import org.apache.ignite.internal.network.RecipientLeftException;
import org.apache.ignite.internal.replicator.ZonePartitionId;
+import org.apache.ignite.internal.storage.RowId;
+import org.apache.ignite.internal.tx.PrimaryReplicaChangeDuringWriteIntentResolutionException;
import org.apache.ignite.internal.tx.TransactionMeta;
import org.apache.ignite.internal.tx.TxManager;
import org.apache.ignite.internal.tx.TxMeta;
import org.apache.ignite.internal.tx.TxStateMeta;
-import org.apache.ignite.internal.tx.TxStateMetaFinishing;
+import org.apache.ignite.internal.tx.impl.PlacementDriverHelper;
import org.apache.ignite.internal.tx.impl.TxMessageSender;
import org.apache.ignite.internal.tx.impl.TxRecoveryEngine;
import org.apache.ignite.internal.tx.message.TxStateCommitPartitionRequest;
@@ -58,6 +66,8 @@ public class TxStateCommitPartitionReplicaRequestHandler {
private final InternalClusterNode localNode;
+ private final PlacementDriverHelper placementDriverHelper;
+
/** Constructor. */
public TxStateCommitPartitionReplicaRequestHandler(
TxStatePartitionStorage txStatePartitionStorage,
@@ -65,6 +75,7 @@ public class TxStateCommitPartitionReplicaRequestHandler {
ClusterNodeResolver clusterNodeResolver,
TxRecoveryEngine txRecoveryEngine,
TxMessageSender txMessageSender,
+ PlacementDriverHelper placementDriverHelper,
ZonePartitionId groupId,
InternalClusterNode localNode
) {
@@ -73,6 +84,7 @@ public class TxStateCommitPartitionReplicaRequestHandler {
this.clusterNodeResolver = clusterNodeResolver;
this.txRecoveryEngine = txRecoveryEngine;
this.txMessageSender = txMessageSender;
+ this.placementDriverHelper = placementDriverHelper;
this.groupId = groupId;
this.localNode = localNode;
}
@@ -90,21 +102,23 @@ public class TxStateCommitPartitionReplicaRequestHandler {
TxStateMeta txMeta = txManager.stateMeta(txId);
if (txMeta != null && txMeta.txState() == FINISHING) {
- assert txMeta instanceof TxStateMetaFinishing : txMeta;
-
- return ((TxStateMetaFinishing) txMeta).txFinishFuture();
+ return castToFinishing(txId, 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.
- ZonePartitionId zonePartitionId = request.senderGroupId() == null ? null : request.senderGroupId().asReplicationGroupId();
+ ZonePartitionId senderGroupId = request.senderGroupId() == null ? null : request.senderGroupId().asReplicationGroupId();
return triggerTxRecoveryOnTxStateResolutionIfNeeded(
txId,
+ request.tableId(),
+ (ZonePartitionId) request.groupId().asReplicationGroupId(),
txMeta,
request.readTimestamp(),
request.senderCurrentConsistencyToken(),
- zonePartitionId,
- senderId
+ senderGroupId,
+ senderId,
+ request.rowId().asRowId(),
+ request.newestCommitTimestamp()
);
} else {
return completedFuture(txMeta);
@@ -115,35 +129,57 @@ public class TxStateCommitPartitionReplicaRequestHandler {
* Checks whether tx recovery is needed with given tx meta and triggers it of needed.
*
* @param txId Transaction id.
+ * @param tableId Table id.
+ * @param commitGroupId Commit group id.
* @param txStateMeta Transaction meta.
* @param readTimestamp If the recovery is triggered by RO transaction, the the read timestamp of that transaction,
* otherwise {@code null}.
* @param senderCurrentConsistencyToken See {@link TxStateCommitPartitionRequest#senderCurrentConsistencyToken()}.
* @param senderGroupId See {@link TxStateCommitPartitionRequest#senderGroupId()}.
+ * @param rowId Row id.
+ * @param newestCommitTimestamp Newest commit timestamp.
* @return Tx recovery future, or completed future if the recovery isn't needed, or failed future if the recovery is not possible.
*/
private CompletableFuture<TransactionMeta> triggerTxRecoveryOnTxStateResolutionIfNeeded(
UUID txId,
+ Integer tableId,
+ ZonePartitionId commitGroupId,
@Nullable TxStateMeta txStateMeta,
@Nullable HybridTimestamp readTimestamp,
@Nullable Long senderCurrentConsistencyToken,
- @Nullable ZonePartitionId senderGroupId,
- UUID senderId
+ ZonePartitionId senderGroupId,
+ UUID senderId,
+ @Nullable RowId rowId,
+ @Nullable HybridTimestamp newestCommitTimestamp
) {
- // The state is either null or PENDING or ABANDONED, other states have been filtered out previously.
+ // The state is either null or PENDING or ABANDONED, other states have been filtered out previously
assert txStateMeta == null || txStateMeta.txState() == PENDING || txStateMeta.txState() == ABANDONED
: "Unexpected transaction state: " + txStateMeta;
- TxMeta txMeta = txStatePartitionStorage.get(txId);
+ TxMeta txMetaPersistent = txStatePartitionStorage.get(txId);
- if (txMeta == null) {
+ if (txMetaPersistent == null) {
InternalClusterNode coordinator = (txStateMeta == null || txStateMeta.txCoordinatorId() == null)
? null
: clusterNodeResolver.getById(txStateMeta.txCoordinatorId());
- // This means the transaction is pending and we should trigger the recovery if there is no tx coordinator in topology.
- if (txStateMeta == null
- || txStateMeta.txState() == ABANDONED
+ if (txStateMeta == null) {
+ // This means one of two:
+ // - txn is not finished, volatile state is lost
+ // - txn was finished, state was vacuumized
+ // both mean primary replica resolution path.
+ return resolveTxStateFromPrimaryReplica(
+ txId,
+ tableId,
+ commitGroupId,
+ senderGroupId,
+ senderId,
+ senderCurrentConsistencyToken,
+ readTimestamp,
+ rowId,
+ newestCommitTimestamp
+ );
+ } else if (txStateMeta.txState() == ABANDONED
|| txStateMeta.txCoordinatorId() == null
|| coordinator == null) {
// This means that primary replica for commit partition has changed, since the local node doesn't have the volatile tx
@@ -157,18 +193,17 @@ public class TxStateCommitPartitionReplicaRequestHandler {
HybridTimestamp timestamp = readTimestamp == null ? HybridTimestamp.MIN_VALUE : readTimestamp;
return txMessageSender.resolveTxStateFromCoordinator(
- coordinator,
- groupId,
- txId,
- timestamp,
- senderCurrentConsistencyToken,
- senderGroupId
+ txStateResolutionParameters().txId(txId)
+ .readTimestamp(timestamp)
+ .senderGroupId(senderGroupId)
+ .senderCurrentConsistencyToken(senderCurrentConsistencyToken)
+ .commitGroupId(groupId)
+ .build(),
+ coordinator
)
.handle((response, e) -> {
if (e == null) {
if (response.txStateMeta() == null) {
- // TODO: https://issues.apache.org/jira/browse/IGNITE-21910 should be fixed correctly by
- // WI resolution primary replica path.
// This may be possible if tx cleanup command was already committed in partition's replication group,
// and tx state was vacuumized on coordinator. This transaction already had a final state,
// but tx cleanup was not applied on replica yet due to replication lag. To prevent switching of
@@ -192,14 +227,92 @@ public class TxStateCommitPartitionReplicaRequestHandler {
return completedFuture(txStateMeta);
}
} else {
- // Recovery is not needed.
- // TODO https://issues.apache.org/jira/browse/IGNITE-27494 Add UNKNOWN state handling.
- assert isFinalState(txMeta.txState()) : "Unexpected transaction state: " + txMeta;
+ // Recovery is not needed. Persistent meta always contains final state.
+ assert isFinalState(txMetaPersistent.txState()) : "Unexpected transaction state: " + txMetaPersistent;
- return completedFuture(txMeta);
+ return completedFuture(txMetaPersistent);
}
}
+ private CompletableFuture<TransactionMeta> resolveTxStateFromPrimaryReplica(
+ UUID txId,
+ int tableId,
+ ZonePartitionId commitGroupId,
+ ZonePartitionId senderGroupId,
+ UUID senderId,
+ @Nullable Long senderCurrentConsistencyToken,
+ @Nullable HybridTimestamp readTimestamp,
+ RowId rowId,
+ @Nullable HybridTimestamp newestCommitTimestamp
+ ) {
+ return placementDriverHelper.awaitPrimaryReplicaWithExceptionHandling(
+ senderGroupId,
+ AWAIT_PRIMARY_REPLICA_TIMEOUT,
+ SECONDS
+ )
+ .thenCompose(replicaMeta -> {
+ long consistencyToken = replicaMeta.getStartTime().longValue();
+
+ if (senderCurrentConsistencyToken != null) {
+ if (consistencyToken == senderCurrentConsistencyToken) {
+ // This is request from actual primary
+ // (probably the primary was moved to the sender node after it did the request or whatever).
+ if (readTimestamp == null || readTimestamp.equals(HybridTimestamp.MIN_VALUE)) {
+ // The request doesn't have read timestamp - this means it's from RW txn.
+ // Sender node is current primary, it has the most recent state of the row, and there is WI
+ // so it was not cleaned up on group majority - this means the txn was never finished
+ // and can be aborted.
+ // The fact that it was not cleaned up on group majority follows from the absence of persistent
+ // state on the commit partition primary, which is possible only if
+ // - tx was never finished
+ // - or tx was previously aborted due to recovery (so one more abort won't break the data).
+ return txRecoveryEngine.triggerTxRecovery(
+ txId,
+ commitGroupId,
+ localNode.name(),
+ senderGroupId,
+ senderId
+ );
+ }
+ } else {
+ // The primary replica that sent the request has already expired.
+ if (readTimestamp == null || readTimestamp.equals(HybridTimestamp.MIN_VALUE)) {
+ // The request doesn't have read timestamp - this means it's from RW txn.
+ // Respond with error, sender must abort its operation and respond with error to client
+ // (primary changed, the current transaction will not be able to be committed).
+ throw new PrimaryReplicaChangeDuringWriteIntentResolutionException();
+ }
+ }
+ }
+
+ String primaryNode = replicaMeta.getLeaseholder();
+
+ return txMessageSender.resolveTxStateFromPrimaryReplica(
+ txStateResolutionParameters()
+ .txId(txId)
+ .tableId(tableId)
+ .commitGroupId(commitGroupId)
+ .senderGroupId(senderGroupId)
+ .readTimestamp(readTimestamp)
+ .rowIdAndNewestCommitTimestamp(rowId, newestCommitTimestamp)
+ .build(),
+ primaryNode,
+ consistencyToken
+ );
+ })
+ .whenComplete((txMeta, e) -> {
+ if (e == null && isFinalState(txMeta.txState())) {
+ // Cache tx state in case of other tx state resolution requests.
+ // Cleanup completion timestamp is set because write intents were switched on majority,
+ // so it can be vacuumized.
+ txManager.updateTxMeta(
+ txId,
+ old -> finalizeState(old, txMeta.txState(), txMeta.commitTimestamp(), coarseCurrentTimeMillis())
+ );
+ }
+ });
+ }
+
/**
* Marks the transaction as abandoned due to the absence of coordinator.
*
diff --git a/modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/raft/handlers/FinishTxCommandHandler.java b/modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/raft/handlers/FinishTxCommandHandler.java
index be46f3c948f..9f1de274a27 100644
--- a/modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/raft/handlers/FinishTxCommandHandler.java
+++ b/modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/raft/handlers/FinishTxCommandHandler.java
@@ -134,13 +134,15 @@ public class FinishTxCommandHandler extends AbstractCommandHandler<FinishTxComma
return list;
}
- private static void logTxStateStorageCasFail(UUID txId, TxMeta txMetaBeforeCas, TxMeta txMetaToSet) {
+ private void logTxStateStorageCasFail(UUID txId, TxMeta txMetaBeforeCas, TxMeta txMetaToSet) {
String errorMsg = format("Finish command skipped, transaction txId = {}, because transaction state is already set,"
- + " existing state = {}, state to set = {}",
+ + " existing state = {}, state to set = {}, groupId = {}",
txId,
txMetaBeforeCas,
- txMetaToSet
+ txMetaToSet,
+ replicationGroupId
);
+
LOG.info(errorMsg);
}
diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/app/ItInProcessRestartApiReferencesTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/app/ItInProcessRestartApiReferencesTest.java
index b2a9180a9f9..226766ce736 100644
--- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/app/ItInProcessRestartApiReferencesTest.java
+++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/app/ItInProcessRestartApiReferencesTest.java
@@ -17,7 +17,6 @@
package org.apache.ignite.internal.app;
-import static org.apache.ignite.compute.JobTarget.anyNode;
import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
@@ -25,6 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import java.util.concurrent.CompletableFuture;
import org.apache.ignite.compute.JobDescriptor;
import org.apache.ignite.compute.JobExecution;
+import org.apache.ignite.compute.JobTarget;
import org.apache.ignite.internal.ClusterPerClassIntegrationTest;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -63,9 +63,10 @@ class ItInProcessRestartApiReferencesTest extends ClusterPerClassIntegrationTest
}
@Test
+
void submitStaysLocalAfterRestart() {
CompletableFuture<JobExecution<String>> executionFut = beforeRestart.compute.submitAsync(
- anyNode(beforeRestart.clusterNodes),
+ JobTarget.anyNode(beforeRestart.clusterNodes),
JobDescriptor.builder(NoOpJob.class).build(),
null
);
diff --git a/modules/runner/src/testFixtures/java/org/apache/ignite/internal/ClusterPerClassIntegrationTest.java b/modules/runner/src/testFixtures/java/org/apache/ignite/internal/ClusterPerClassIntegrationTest.java
index 990fd4c6e30..f42509e563c 100644
--- a/modules/runner/src/testFixtures/java/org/apache/ignite/internal/ClusterPerClassIntegrationTest.java
+++ b/modules/runner/src/testFixtures/java/org/apache/ignite/internal/ClusterPerClassIntegrationTest.java
@@ -17,6 +17,7 @@
package org.apache.ignite.internal;
+import static java.util.stream.Collectors.toList;
import static org.apache.ignite.internal.ConfigTemplates.NODE_BOOTSTRAP_CFG_TEMPLATE;
import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl;
import static org.apache.ignite.internal.catalog.descriptors.CatalogIndexStatus.AVAILABLE;
@@ -720,6 +721,26 @@ public abstract class ClusterPerClassIntegrationTest extends BaseIgniteAbstractT
return CLUSTER.node(index);
}
+ protected static Stream<Ignite> runningNodesStream() {
+ return CLUSTER.runningNodes();
+ }
+
+ protected static List<IgniteImpl> runningNodesList() {
+ return CLUSTER.runningNodes().map(TestWrappers::unwrapIgniteImpl).collect(toList());
+ }
+
+ protected final IgniteImpl anyNode() {
+ return unwrapIgniteImpl(CLUSTER.runningNodes().findAny().orElseThrow());
+ }
+
+ protected final IgniteImpl findNode(Predicate<IgniteImpl> pred) {
+ return CLUSTER.runningNodes()
+ .map(TestWrappers::unwrapIgniteImpl)
+ .filter(pred)
+ .findFirst()
+ .orElseThrow();
+ }
+
protected static IgniteImpl igniteImpl(int index) {
return unwrapIgniteImpl(node(index));
}
@@ -769,7 +790,7 @@ public abstract class ClusterPerClassIntegrationTest extends BaseIgniteAbstractT
}
private static void dumpClusterState() {
- List<Ignite> nodes = CLUSTER.runningNodes().collect(Collectors.toList());
+ List<Ignite> nodes = CLUSTER.runningNodes().collect(toList());
for (Ignite node : nodes) {
unwrapIgniteImpl(node).dumpClusterState();
}
diff --git a/modules/storage-api/src/main/java/org/apache/ignite/internal/storage/RowMeta.java b/modules/storage-api/src/main/java/org/apache/ignite/internal/storage/RowMeta.java
index f8faf9657ce..90701dc4615 100644
--- a/modules/storage-api/src/main/java/org/apache/ignite/internal/storage/RowMeta.java
+++ b/modules/storage-api/src/main/java/org/apache/ignite/internal/storage/RowMeta.java
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.storage;
import java.util.Objects;
import java.util.UUID;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
import org.apache.ignite.internal.tostring.S;
import org.jetbrains.annotations.Nullable;
@@ -32,17 +33,29 @@ public class RowMeta {
private final @Nullable Integer commitZoneId;
private final int commitPartitionId;
- /** Creates a RowMeta instance for a row without a write intent. */
+ private final HybridTimestamp newestCommitTimestamp;
+
+ /**
+ * Creates a RowMeta instance for a row without a write intent. Newest commit timestamp is not needed because this doesn't require
+ * write intent resolution.
+ */
public static RowMeta withoutWriteIntent(RowId rowId) {
- return new RowMeta(rowId, null, null, ReadResult.UNDEFINED_COMMIT_PARTITION_ID);
+ return new RowMeta(rowId, null, null, ReadResult.UNDEFINED_COMMIT_PARTITION_ID, null);
}
/** Constructor. */
- public RowMeta(RowId rowId, @Nullable UUID transactionId, @Nullable Integer commitZoneId, int commitPartitionId) {
+ public RowMeta(
+ RowId rowId,
+ @Nullable UUID transactionId,
+ @Nullable Integer commitZoneId,
+ int commitPartitionId,
+ @Nullable HybridTimestamp newestCommitTimestamp
+ ) {
this.rowId = rowId;
this.transactionId = transactionId;
this.commitZoneId = commitZoneId;
this.commitPartitionId = commitPartitionId;
+ this.newestCommitTimestamp = newestCommitTimestamp;
}
/** Returns the row ID. */
@@ -70,6 +83,16 @@ public class RowMeta {
return commitPartitionId;
}
+ /**
+ * Returns the newest commit timestamp if this row has a write intent, or {@code null} otherwise.
+ *
+ * @return Newest commit timestamp.
+ */
+ @Nullable
+ public HybridTimestamp newestCommitTimestamp() {
+ return newestCommitTimestamp;
+ }
+
@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
diff --git a/modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageTest.java b/modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageTest.java
index adb1304d0b8..c725a375778 100644
--- a/modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageTest.java
+++ b/modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageTest.java
@@ -1613,8 +1613,8 @@ public abstract class AbstractMvPartitionStorageTest extends BaseMvPartitionStor
RowId rowId1 = new RowId(PARTITION_ID, 1, 0);
RowId rowId2 = new RowId(PARTITION_ID, 1, 1);
- RowMeta expectedRowMeta1 = new RowMeta(rowId1, txId, COMMIT_ZONE_ID, PARTITION_ID);
- RowMeta expectedRowMeta2 = new RowMeta(rowId2, txId, COMMIT_ZONE_ID, PARTITION_ID);
+ RowMeta expectedRowMeta1 = new RowMeta(rowId1, txId, COMMIT_ZONE_ID, PARTITION_ID, HybridTimestamp.MIN_VALUE);
+ RowMeta expectedRowMeta2 = new RowMeta(rowId2, txId, COMMIT_ZONE_ID, PARTITION_ID, HybridTimestamp.MIN_VALUE);
addWrite(rowId1, binaryRow, txId);
addWrite(rowId2, binaryRow2, txId);
@@ -1656,7 +1656,7 @@ public abstract class AbstractMvPartitionStorageTest extends BaseMvPartitionStor
void testClosestRowReconstruction() {
RowId rowId = new RowId(PARTITION_ID, 0x1234567890ABCDEFL, 0xFEDCBA0987654321L);
- RowMeta expectedRowMeta = new RowMeta(rowId, txId, COMMIT_ZONE_ID, PARTITION_ID);
+ RowMeta expectedRowMeta = new RowMeta(rowId, txId, COMMIT_ZONE_ID, PARTITION_ID, HybridTimestamp.MIN_VALUE);
addWrite(rowId, binaryRow, txId);
diff --git a/modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/impl/TestMvPartitionStorage.java b/modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/impl/TestMvPartitionStorage.java
index 9b1dfb7590c..7ad0dc861e0 100644
--- a/modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/impl/TestMvPartitionStorage.java
+++ b/modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/impl/TestMvPartitionStorage.java
@@ -695,7 +695,19 @@ public class TestMvPartitionStorage implements MvPartitionStorage {
VersionChain versionChain = entry.getValue();
- return new RowMeta(versionChain.rowId, versionChain.txId, versionChain.commitZoneId, versionChain.commitPartitionId);
+ HybridTimestamp newestCommitTimestamp = null;
+
+ if (versionChain.isWriteIntent() && versionChain.next != null) {
+ newestCommitTimestamp = versionChain.next.ts;
+ }
+
+ return new RowMeta(
+ versionChain.rowId,
+ versionChain.txId,
+ versionChain.commitZoneId,
+ versionChain.commitPartitionId,
+ newestCommitTimestamp
+ );
}
@Override
diff --git a/modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/mv/AbstractPageMemoryMvPartitionStorage.java b/modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/mv/AbstractPageMemoryMvPartitionStorage.java
index 724ed4cbb75..c4b211941e5 100644
--- a/modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/mv/AbstractPageMemoryMvPartitionStorage.java
+++ b/modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/mv/AbstractPageMemoryMvPartitionStorage.java
@@ -643,12 +643,22 @@ public abstract class AbstractPageMemoryMvPartitionStorage implements MvPartitio
for (int i = 0; i < limit && cursor.hasNext(); i++) {
VersionChain versionChain = cursor.next();
+
+ HybridTimestamp newestCommitTs = null;
+
+ if (versionChain.hasCommittedVersions()) {
+ long newestCommitLink = versionChain.newestCommittedLink();
+ newestCommitTs = readRowVersion(newestCommitLink, DONT_LOAD_VALUE).timestamp();
+ }
+
RowMeta row = new RowMeta(
versionChain.rowId(),
versionChain.transactionId(),
versionChain.commitZoneId(),
- versionChain.commitPartitionId()
+ versionChain.commitPartitionId(),
+ newestCommitTs
);
+
result.add(row);
}
diff --git a/modules/storage-rocksdb/src/main/java/org/apache/ignite/internal/storage/rocksdb/RocksDbMvPartitionStorage.java b/modules/storage-rocksdb/src/main/java/org/apache/ignite/internal/storage/rocksdb/RocksDbMvPartitionStorage.java
index d6dc35b1083..b21517cf2ca 100644
--- a/modules/storage-rocksdb/src/main/java/org/apache/ignite/internal/storage/rocksdb/RocksDbMvPartitionStorage.java
+++ b/modules/storage-rocksdb/src/main/java/org/apache/ignite/internal/storage/rocksdb/RocksDbMvPartitionStorage.java
@@ -1188,6 +1188,7 @@ public class RocksDbMvPartitionStorage implements MvPartitionStorage {
RowId rowId = getRowId(keyBuf);
RowMeta row;
+
if (isWriteIntent) {
ByteBuffer transactionState = ByteBuffer.wrap(it.value());
@@ -1196,14 +1197,34 @@ public class RocksDbMvPartitionStorage implements MvPartitionStorage {
int commitZoneId = transactionState.getInt();
int commitPartitionId = Short.toUnsignedInt(transactionState.getShort());
- row = new RowMeta(rowId, txId, commitZoneId, commitPartitionId);
+ it.next();
+
+ HybridTimestamp newestCommitTimestamp = null;
+
+ if (it.isValid()) {
+ ByteBuffer dataIdKey = DIRECT_DATA_ID_KEY_BUFFER.get().clear();
+
+ int keyLen = it.key(dataIdKey);
+
+ dataIdKey.position(0).limit(keyLen);
+
+ // Continue searching through committed versions to extract the most recent commit timestamp.
+ if (matches(rowId, dataIdKey)) {
+ newestCommitTimestamp = readTimestampDesc(dataIdKey);
+ }
+ }
+
+ row = new RowMeta(rowId, txId, commitZoneId, commitPartitionId, newestCommitTimestamp);
} else {
row = RowMeta.withoutWriteIntent(rowId);
}
result.add(row);
- it.next();
+ // If write intent, it.next() was done already.
+ if (!isWriteIntent) {
+ it.next();
+ }
}
} catch (RocksDBException e) {
throw new IgniteRocksDbException("Error finding following Row IDs", e);
diff --git a/modules/table/src/main/java/org/apache/ignite/internal/table/RecordBinaryViewImpl.java b/modules/table/src/main/java/org/apache/ignite/internal/table/RecordBinaryViewImpl.java
index 76fdd135fc2..01c3e4ed66e 100644
--- a/modules/table/src/main/java/org/apache/ignite/internal/table/RecordBinaryViewImpl.java
+++ b/modules/table/src/main/java/org/apache/ignite/internal/table/RecordBinaryViewImpl.java
@@ -54,7 +54,6 @@ import org.apache.ignite.table.Tuple;
import org.apache.ignite.tx.Transaction;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
-import org.jetbrains.annotations.VisibleForTesting;
/**
* Table view implementation for binary objects.
@@ -451,15 +450,15 @@ public class RecordBinaryViewImpl extends AbstractTableView<Tuple> implements Re
*
* @param tx Transaction, if present.
* @param rec Tuple record.
+ * @param keyOnly Marshal key part only.
* @return A future, with row as a result.
*/
@TestOnly
- @VisibleForTesting
- public CompletableFuture<BinaryRowEx> tupleToBinaryRow(@Nullable Transaction tx, Tuple rec) {
+ public CompletableFuture<BinaryRowEx> tupleToBinaryRow(@Nullable Transaction tx, Tuple rec, boolean keyOnly) {
Objects.requireNonNull(rec);
return doOperation(tx, schemaVersion -> {
- Row row = marshal(rec, schemaVersion, false);
+ Row row = marshal(rec, schemaVersion, keyOnly);
return completedFuture(row);
});
@@ -473,7 +472,6 @@ public class RecordBinaryViewImpl extends AbstractTableView<Tuple> implements Re
* @return A future, with tuple as a result.
*/
@TestOnly
- @VisibleForTesting
public CompletableFuture<Tuple> binaryRowToTuple(@Nullable Transaction tx, BinaryRow row) {
return doOperation(tx, schemaVersion -> completedFuture(wrap(row, schemaVersion)));
}
diff --git a/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/StorageUpdateHandler.java b/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/StorageUpdateHandler.java
index a3a652a1cac..11ac9946efa 100644
--- a/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/StorageUpdateHandler.java
+++ b/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/StorageUpdateHandler.java
@@ -83,6 +83,9 @@ public class StorageUpdateHandler {
/** Transaction manager to retrieve labels for logging. */
private final TxManager txManager;
+ @TestOnly
+ private boolean writeIntentSwitchBlocked;
+
/**
* The constructor.
*
@@ -427,6 +430,17 @@ public class StorageUpdateHandler {
@Nullable Runnable onApplication,
@Nullable List<Integer> indexIds
) {
+ if (writeIntentSwitchBlocked) {
+ if (onApplication != null) {
+ storage.runConsistently(locker -> {
+ onApplication.run();
+ return true;
+ });
+ }
+
+ return;
+ }
+
Set<RowId> pendingRowIds = pendingRows.removePendingRowIds(txId);
assert !(commit && commitTimestamp == null) : "Commit timestamp cant be null when tx is set to commit: " + txId;
@@ -674,4 +688,17 @@ public class StorageUpdateHandler {
public void eraseVolatileState(UUID txId) {
this.pendingRows.removePendingRowIds(txId);
}
+
+ /**
+ * Blocks or unblocks the switching of write intents to regular values in tests.
+ * When blocked, the method {@link #switchWriteIntents} will do nothing. For test purposes only.
+ *
+ * @param blocked if {@code true} then switching of write intents will be blocked, if {@code false} then it will be unblocked.
+ */
+ @TestOnly
+ public void writeIntentSwitchBlocked(boolean blocked) {
+ LOG.info("Test: write intent switch is {}", blocked ? "blocked" : "unblocked");
+
+ this.writeIntentSwitchBlocked = blocked;
+ }
}
diff --git a/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java b/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java
index 2500445985b..df6bee33931 100644
--- a/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java
+++ b/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java
@@ -1691,6 +1691,11 @@ public class TableManager implements IgniteTablesInternal, IgniteComponent {
return anyOf(future, stopManagerFuture).thenApply(o -> (T) o);
}
+ @TestOnly
+ public ReplicaService replicaService() {
+ return replicaSvc;
+ }
+
/** Internal event. */
private static class DestroyTableEvent {
final int catalogVersion;
diff --git a/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java b/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java
index 9bf053157e9..2ed35daba4b 100644
--- a/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java
+++ b/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java
@@ -45,7 +45,9 @@ import static org.apache.ignite.internal.tx.TxState.PENDING;
import static org.apache.ignite.internal.tx.TxState.UNKNOWN;
import static org.apache.ignite.internal.tx.TxState.isFinalState;
import static org.apache.ignite.internal.tx.TxStateMeta.builder;
+import static org.apache.ignite.internal.tx.TxStateMetaFinishing.castToFinishing;
import static org.apache.ignite.internal.tx.TxStateMetaUnknown.txStateMetaUnknown;
+import static org.apache.ignite.internal.tx.impl.TxStateResolutionParameters.txStateResolutionParameters;
import static org.apache.ignite.internal.util.CollectionUtils.nullOrEmpty;
import static org.apache.ignite.internal.util.CompletableFutures.allOfToList;
import static org.apache.ignite.internal.util.CompletableFutures.emptyCollectionCompletedFuture;
@@ -195,6 +197,7 @@ import org.apache.ignite.internal.tx.LockKey;
import org.apache.ignite.internal.tx.LockManager;
import org.apache.ignite.internal.tx.LockMode;
import org.apache.ignite.internal.tx.OutdatedReadOnlyTransactionInternalException;
+import org.apache.ignite.internal.tx.PrimaryReplicaChangeDuringWriteIntentResolutionException;
import org.apache.ignite.internal.tx.TransactionMeta;
import org.apache.ignite.internal.tx.TxManager;
import org.apache.ignite.internal.tx.TxState;
@@ -2247,9 +2250,21 @@ public class PartitionReplicaListener implements ReplicaTableProcessor {
}
private CompletableFuture<TransactionMeta> processTxStatePrimaryReplicaRequest(TxStatePrimaryReplicaRequest request) {
+ UUID txId = request.txId();
+
+ TxStateMeta txMeta = txManager.stateMeta(txId);
+
+ if (txMeta != null) {
+ if (isFinalState(txMeta.txState())) {
+ return completedFuture(txMeta);
+ } else if (txMeta.txState() == FINISHING) {
+ return castToFinishing(txId, txMeta).txFinishFuture();
+ }
+ }
+
return completedFuture(txMetaFromStorage(
request.rowId().asRowId(),
- request.txId(),
+ txId,
request.newestCommitTimestamp(),
request.readTimestamp()
));
@@ -2312,7 +2327,7 @@ public class PartitionReplicaListener implements ReplicaTableProcessor {
requireNonNull(readResult, "Read result must not be null.");
- if (isWriteIntentBelongingToThisTx(readResult, txId)) {
+ if (isWriteIntentBelongingToThisTx(readResult, txId, readTimestamp)) {
return builder(PENDING).build();
} else if (isNewCommittedVersionBeforeReadTimestamp(readResult, newestCommitTimestamp, readTimestamp)) {
return builder(COMMITTED).commitTimestamp(readResult.commitTimestamp()).build();
@@ -2330,8 +2345,9 @@ public class PartitionReplicaListener implements ReplicaTableProcessor {
}
}
- private static boolean isWriteIntentBelongingToThisTx(ReadResult rr, UUID txId) {
- return rr.isWriteIntent() && rr.transactionId() != null && rr.transactionId().equals(txId);
+ private static boolean isWriteIntentBelongingToThisTx(ReadResult rr, UUID txId, @Nullable HybridTimestamp readTimestamp) {
+ return (readTimestamp == null || readTimestamp.equals(HybridTimestamp.MIN_VALUE))
+ && rr.isWriteIntent() && rr.transactionId() != null && rr.transactionId().equals(txId);
}
private static boolean isCommittedVersion(ReadResult rr) {
@@ -2363,69 +2379,73 @@ public class PartitionReplicaListener implements ReplicaTableProcessor {
@Nullable HybridTimestamp newestCommitTimestamp,
HybridTimestamp readTimestamp
) {
- ReadResult anyCommittedAfterReadTs = null;
- ReadResult wi = null;
-
- try (Cursor<ReadResult> versions = mvDataStorage.scanVersions(rowId)) {
- for (ReadResult rr : versions) {
- if (rr != null && !rr.isEmpty()) {
- if (rr.isWriteIntent()) {
- wi = rr;
- } else {
- requireNonNull(rr.commitTimestamp(), "Committed read result must have commit timestamp");
-
- long commitTs = rr.commitTimestamp().longValue();
-
- // newestCommitTimestamp comes from requesting replica and is always less than read timestamp (if not null).
- if (newestCommitTimestamp == null || commitTs > newestCommitTimestamp.longValue()) {
- if (commitTs <= readTimestamp.longValue()) {
- // This means, the write intent for this committed version was created before read timestamp,
- // and requesting replica has seen it, so this is committed write intent for sought transaction.
- // Commit timestamp is checked on the requesting replica.
- return builder(COMMITTED).commitTimestamp(rr.commitTimestamp()).build();
- } else {
- anyCommittedAfterReadTs = rr;
+ return mvDataStorage.runConsistently(locker -> {
+ locker.lock(rowId);
+
+ ReadResult anyCommittedAfterReadTs = null;
+ ReadResult wi = null;
+
+ try (Cursor<ReadResult> versions = mvDataStorage.scanVersions(rowId)) {
+ for (ReadResult rr : versions) {
+ if (rr != null && !rr.isEmpty()) {
+ if (rr.isWriteIntent()) {
+ wi = rr;
+ } else {
+ requireNonNull(rr.commitTimestamp(), "Committed read result must have commit timestamp");
+
+ long commitTs = rr.commitTimestamp().longValue();
+
+ // newestCommitTimestamp comes from requesting replica and is always less than read timestamp (if not null).
+ if (newestCommitTimestamp == null || commitTs > newestCommitTimestamp.longValue()) {
+ if (commitTs <= readTimestamp.longValue()) {
+ // This means, the write intent for this committed version was created before read timestamp,
+ // and requesting replica has seen it, so this is committed write intent for sought transaction.
+ // Commit timestamp is checked on the requesting replica.
+ return builder(COMMITTED).commitTimestamp(rr.commitTimestamp()).build();
+ } else {
+ anyCommittedAfterReadTs = rr;
+ }
}
}
}
}
}
- }
- if (wi != null && isWriteIntentBelongingToThisTx(wi, txId)) {
- return builder(PENDING).build();
- } else if (isReadTimestampOutdated(readTimestamp, newestCommitTimestamp)) {
- // In this case we can't be sure about anything that happened before read timestamp.
- throw new OutdatedReadOnlyTransactionInternalException(readTimestamp, lowWatermark.getLowWatermark());
- } else if (anyCommittedAfterReadTs != null) {
- // This means that state of the sought transaction is unrecoverable from storage state because committed versions don't
- // contain tx id.
- // Consider the examples:
- // Example 1:
- // - wi created at t1 by tx1
- // - read ts is t2, backup replica waits for t2
- // - tx1 is committed at t5, commit ts is t5
- // - commit write is replicated at t6
- // - now is t7
- // - on primary replica, we see committed version with commit ts t5
- // Example 2:
- // - wi1 created at t1 by tx1
- // - read ts is t2, backup replica waits for t2
- // - tx1 is aborted at t3
- // - tx2 creates wi2 on primary at t4
- // - tx2 is committed at t5, commit ts is t5
- // - commit write is replicated at t6
- // - now is t7
- // - on primary replica, we see committed version with commit ts t5
- // In 1st example tx1 was committed and in 2nd it was aborted but in both examples the state of the storage is the same.
- // So the state of tx1 is unknown.
- // However, the write intent should be ignored by the requesting replica because nothing was committed
- // with commit timestamp less than read timestamp.
- return txStateMetaUnknown();
- } else {
- // These can be only versions known to requesting replica.
- return builder(ABORTED).build();
- }
+ if (wi != null && isWriteIntentBelongingToThisTx(wi, txId, readTimestamp)) {
+ return builder(PENDING).build();
+ } else if (isReadTimestampOutdated(readTimestamp, newestCommitTimestamp)) {
+ // In this case we can't be sure about anything that happened before read timestamp.
+ throw new OutdatedReadOnlyTransactionInternalException(readTimestamp, lowWatermark.getLowWatermark());
+ } else if (anyCommittedAfterReadTs != null) {
+ // This means that state of the sought transaction is unrecoverable from storage state because committed versions don't
+ // contain tx id.
+ // Consider the examples:
+ // Example 1:
+ // - wi created at t1 by tx1
+ // - read ts is t2, backup replica waits for t2
+ // - tx1 is committed at t5, commit ts is t5
+ // - commit write is replicated at t6
+ // - now is t7
+ // - on primary replica, we see committed version with commit ts t5
+ // Example 2:
+ // - wi1 created at t1 by tx1
+ // - read ts is t2, backup replica waits for t2
+ // - tx1 is aborted at t3
+ // - tx2 creates wi2 on primary at t4
+ // - tx2 is committed at t5, commit ts is t5
+ // - commit write is replicated at t6
+ // - now is t7
+ // - on primary replica, we see committed version with commit ts t5
+ // In 1st example tx1 was committed and in 2nd it was aborted but in both examples the state of the storage is the same.
+ // So the state of tx1 is unknown.
+ // However, the write intent should be ignored by the requesting replica because nothing was committed
+ // with commit timestamp less than read timestamp.
+ return txStateMetaUnknown();
+ } else {
+ // These can be only versions known to requesting replica.
+ return builder(ABORTED).build();
+ }
+ });
}
private static <T> boolean allElementsAreNull(List<T> list) {
@@ -3524,18 +3544,22 @@ public class PartitionReplicaListener implements ReplicaTableProcessor {
ZonePartitionId commitPartitionId = new ZonePartitionId(writeIntent.commitZoneId(), writeIntent.commitPartitionId());
return transactionStateResolver.resolveTxState(
- txId,
- commitPartitionId,
- timestamp,
- currentConsistencyToken,
- replicationGroupId
+ txStateResolutionParameters()
+ .txId(txId)
+ .tableId(tableId)
+ .commitGroupId(commitPartitionId)
+ .readTimestamp(timestamp)
+ .senderGroupId(replicationGroupId)
+ .senderCurrentConsistencyToken(currentConsistencyToken)
+ .rowIdAndNewestCommitTimestamp(writeIntent.rowId(), writeIntent.newestCommitTimestamp())
+ .build()
)
.thenApply(transactionMeta -> {
boolean writeIntentReadable = canReadFromWriteIntent(txId, txManager, transactionMeta, timestamp);
if (isFinalState(transactionMeta.txState())) {
scheduleAsyncWriteIntentSwitch(txId, writeIntent.rowId(), transactionMeta);
- } else if (timestamp == null) {
+ } else if (timestamp == null && transactionMeta.txState() == PENDING) {
// If it's resolution by RW txn.
LOG.info(
"Received non-final transaction state after tx state resolution [txId={}, groupId={}, txMeta={}, "
@@ -3551,6 +3575,28 @@ public class PartitionReplicaListener implements ReplicaTableProcessor {
}
return new WriteIntentResolutionResult(writeIntentReadable, transactionMeta);
+ })
+ .handle((v, e) -> {
+ if (e != null) {
+ Throwable cause = unwrapCause(e);
+
+ if (cause instanceof PrimaryReplicaChangeDuringWriteIntentResolutionException) {
+ throw new PrimaryReplicaMissException(
+ localNode.name(),
+ null,
+ localNode.id(),
+ null,
+ currentConsistencyToken,
+ null,
+ replicationGroupId,
+ cause
+ );
+ } else {
+ sneakyThrow(cause);
+ }
+ }
+
+ return v;
});
}
@@ -3569,7 +3615,6 @@ public class PartitionReplicaListener implements ReplicaTableProcessor {
: format("Unexpected state defined by write intent resolution [{}, txMeta={}].",
formatTxInfo(txId, txManager, false), txMeta);
- // TODO IGNITE-27494 double check UNKNOWN state works correctly here.
if (txMeta.txState() == COMMITTED) {
boolean readLatest = timestamp == null;
@@ -4076,6 +4121,16 @@ public class PartitionReplicaListener implements ReplicaTableProcessor {
storageUpdateHandler.switchWriteIntents(txId, commit, commitTimestamp, null);
}
+ @TestOnly
+ public PendingComparableValuesTracker<HybridTimestamp, Void> safeTime() {
+ return safeTime;
+ }
+
+ @TestOnly
+ public StorageUpdateHandler storageUpdateHandler() {
+ return storageUpdateHandler;
+ }
+
private static class WriteIntentResolutionResult {
/**
* This value is assigned with awareness of read timestamp in case of WI resolution by read-only transaction. It is {@code true}
diff --git a/modules/table/src/test/java/org/apache/ignite/internal/table/distributed/replication/PartitionReplicaListenerTest.java b/modules/table/src/test/java/org/apache/ignite/internal/table/distributed/replication/PartitionReplicaListenerTest.java
index 3f40636db2e..bd3c90aa524 100644
--- a/modules/table/src/test/java/org/apache/ignite/internal/table/distributed/replication/PartitionReplicaListenerTest.java
+++ b/modules/table/src/test/java/org/apache/ignite/internal/table/distributed/replication/PartitionReplicaListenerTest.java
@@ -171,7 +171,6 @@ import org.apache.ignite.internal.partition.replicator.raft.snapshot.PartitionDa
import org.apache.ignite.internal.partition.replicator.schema.FullTableSchema;
import org.apache.ignite.internal.partition.replicator.schema.ValidationSchemasSource;
import org.apache.ignite.internal.partition.replicator.schemacompat.IncompatibleSchemaVersionException;
-import org.apache.ignite.internal.placementdriver.PlacementDriver;
import org.apache.ignite.internal.placementdriver.TestPlacementDriver;
import org.apache.ignite.internal.placementdriver.TestReplicaMetaImpl;
import org.apache.ignite.internal.raft.Command;
@@ -238,6 +237,7 @@ import org.apache.ignite.internal.tx.TxStateMeta;
import org.apache.ignite.internal.tx.TxStateMetaAbandoned;
import org.apache.ignite.internal.tx.UpdateCommandResult;
import org.apache.ignite.internal.tx.impl.HeapLockManager;
+import org.apache.ignite.internal.tx.impl.PlacementDriverHelper;
import org.apache.ignite.internal.tx.impl.RemotelyTriggeredResourceRegistry;
import org.apache.ignite.internal.tx.impl.TransactionStateResolver;
import org.apache.ignite.internal.tx.impl.TxMessageSender;
@@ -644,7 +644,7 @@ public class PartitionReplicaListenerTest extends IgniteAbstractTest {
clockService,
clusterNodeResolver,
messagingService,
- mock(PlacementDriver.class),
+ mock(PlacementDriverHelper.class),
new TxMessageSender(
messagingService,
mock(ReplicaService.class),
@@ -2892,9 +2892,16 @@ public class PartitionReplicaListenerTest extends IgniteAbstractTest {
newestCommitTsIsPresent
);
- HybridTimestamp readTs = outdatedReadTs
- ? new HybridTimestamp(clockService.maxClockSkewMillis() - 1, 0)
- : new HybridTimestamp(100, 0);
+ HybridTimestamp readTs;
+
+ if (writeIntentHasThisTxId) {
+ readTs = HybridTimestamp.MIN_VALUE;
+ } else {
+ readTs = outdatedReadTs
+ ? new HybridTimestamp(clockService.maxClockSkewMillis() - 1, 0)
+ : new HybridTimestamp(100, 0);
+ }
+
HybridTimestamp newestCommitTs = newestCommitTsIsPresent ? new HybridTimestamp(50, 0) : null;
TxStatePrimaryReplicaRequest request = TX_MESSAGES_FACTORY.txStatePrimaryReplicaRequest()
diff --git a/modules/table/src/test/java/org/apache/ignite/internal/table/distributed/replication/ZonePartitionReplicaListenerTest.java b/modules/table/src/test/java/org/apache/ignite/internal/table/distributed/replication/ZonePartitionReplicaListenerTest.java
index b0ddc123a86..0695ab2fd61 100644
--- a/modules/table/src/test/java/org/apache/ignite/internal/table/distributed/replication/ZonePartitionReplicaListenerTest.java
+++ b/modules/table/src/test/java/org/apache/ignite/internal/table/distributed/replication/ZonePartitionReplicaListenerTest.java
@@ -140,7 +140,6 @@ import org.apache.ignite.internal.partition.replicator.schema.FullTableSchema;
import org.apache.ignite.internal.partition.replicator.schema.ValidationSchemasSource;
import org.apache.ignite.internal.partition.replicator.schemacompat.IncompatibleSchemaVersionException;
import org.apache.ignite.internal.partition.replicator.schemacompat.InternalSchemaVersionMismatchException;
-import org.apache.ignite.internal.placementdriver.PlacementDriver;
import org.apache.ignite.internal.placementdriver.TestPlacementDriver;
import org.apache.ignite.internal.placementdriver.TestReplicaMetaImpl;
import org.apache.ignite.internal.raft.Command;
@@ -205,6 +204,7 @@ import org.apache.ignite.internal.tx.TxStateMeta;
import org.apache.ignite.internal.tx.UpdateCommandResult;
import org.apache.ignite.internal.tx.impl.EnlistedPartitionGroup;
import org.apache.ignite.internal.tx.impl.HeapLockManager;
+import org.apache.ignite.internal.tx.impl.PlacementDriverHelper;
import org.apache.ignite.internal.tx.impl.RemotelyTriggeredResourceRegistry;
import org.apache.ignite.internal.tx.impl.TransactionStateResolver;
import org.apache.ignite.internal.tx.impl.TxMessageSender;
@@ -612,7 +612,7 @@ public class ZonePartitionReplicaListenerTest extends IgniteAbstractTest {
clockService,
clusterNodeResolver,
messagingService,
- mock(PlacementDriver.class),
+ mock(PlacementDriverHelper.class),
new TxMessageSender(
messagingService,
mock(ReplicaService.class),
@@ -652,6 +652,7 @@ public class ZonePartitionReplicaListenerTest extends IgniteAbstractTest {
schemaSyncService,
catalogService,
placementDriver,
+ new PlacementDriverHelper(placementDriver, clockService),
clusterNodeResolver,
mockRaftClient,
failureManager,
@@ -1380,6 +1381,10 @@ public class ZonePartitionReplicaListenerTest extends IgniteAbstractTest {
.groupId(zonePartitionIdMessage(grpId))
.txId(newTxId())
.enlistmentConsistencyToken(ANY_ENLISTMENT_CONSISTENCY_TOKEN)
+ .rowId(TX_MESSAGES_FACTORY.rowIdMessage().partitionId(PART_ID).uuid(randomUUID()).build())
+ .tableId(TABLE_ID)
+ .senderGroupId(zonePartitionIdMessage(grpId))
+ .senderCurrentConsistencyToken(ANY_ENLISTMENT_CONSISTENCY_TOKEN)
.build(), randomUUID());
assertThat(fut, willSucceedFast());
@@ -1404,6 +1409,7 @@ public class ZonePartitionReplicaListenerTest extends IgniteAbstractTest {
.groupId(zonePartitionIdMessage(grpId))
.txId(txId)
.enlistmentConsistencyToken(ANY_ENLISTMENT_CONSISTENCY_TOKEN)
+ .rowId(TX_MESSAGES_FACTORY.rowIdMessage().partitionId(PART_ID).uuid(randomUUID()).build())
.build(), localNode.id());
assertThat(fut, willSucceedFast());
@@ -1655,6 +1661,7 @@ public class ZonePartitionReplicaListenerTest extends IgniteAbstractTest {
.groupId(zonePartitionIdMessage(grpId))
.txId(newTxId())
.enlistmentConsistencyToken(10L)
+ .rowId(TX_MESSAGES_FACTORY.rowIdMessage().partitionId(PART_ID).uuid(randomUUID()).build())
.build(), localNode.id());
assertThrowsWithCause(
@@ -1672,6 +1679,7 @@ public class ZonePartitionReplicaListenerTest extends IgniteAbstractTest {
.groupId(zonePartitionIdMessage(grpId))
.txId(newTxId())
.enlistmentConsistencyToken(ANY_ENLISTMENT_CONSISTENCY_TOKEN)
+ .rowId(TX_MESSAGES_FACTORY.rowIdMessage().partitionId(PART_ID).uuid(randomUUID()).build())
.build(), localNode.id());
assertThrowsWithCause(
diff --git a/modules/table/src/testFixtures/java/org/apache/ignite/distributed/ItTxTestCluster.java b/modules/table/src/testFixtures/java/org/apache/ignite/distributed/ItTxTestCluster.java
index 9e440becf70..4d0c6caf49a 100644
--- a/modules/table/src/testFixtures/java/org/apache/ignite/distributed/ItTxTestCluster.java
+++ b/modules/table/src/testFixtures/java/org/apache/ignite/distributed/ItTxTestCluster.java
@@ -174,6 +174,7 @@ import org.apache.ignite.internal.tx.TxStateMeta;
import org.apache.ignite.internal.tx.configuration.TransactionConfiguration;
import org.apache.ignite.internal.tx.impl.HeapLockManager;
import org.apache.ignite.internal.tx.impl.IgniteTransactionsImpl;
+import org.apache.ignite.internal.tx.impl.PlacementDriverHelper;
import org.apache.ignite.internal.tx.impl.RemotelyTriggeredResourceRegistry;
import org.apache.ignite.internal.tx.impl.ResourceVacuumManager;
import org.apache.ignite.internal.tx.impl.TransactionIdGenerator;
@@ -746,7 +747,7 @@ public class ItTxTestCluster {
clockServices.get(assignment),
nodeResolver,
clusterServices.get(assignment).messagingService(),
- placementDriver,
+ new PlacementDriverHelper(placementDriver, clockServices.get(assignment)),
txMessageSender,
txRecoveryEngine,
new Lazy<>(() -> mock(InternalClusterNode.class)),
@@ -995,6 +996,7 @@ public class ItTxTestCluster {
schemaSyncService,
catalogService,
placementDriver,
+ new PlacementDriverHelper(placementDriver, clockService),
clusterNodeResolver,
raftClient,
new NoOpFailureManager(),
@@ -1345,7 +1347,7 @@ public class ItTxTestCluster {
clientClockService,
nodeResolver,
client.messagingService(),
- placementDriver,
+ new PlacementDriverHelper(placementDriver, clientClockService),
new TxMessageSender(
client.messagingService(),
clientReplicaSvc,
diff --git a/modules/table/src/testFixtures/java/org/apache/ignite/internal/table/impl/DummyInternalTableImpl.java b/modules/table/src/testFixtures/java/org/apache/ignite/internal/table/impl/DummyInternalTableImpl.java
index 428cc88459a..55f4f56340d 100644
--- a/modules/table/src/testFixtures/java/org/apache/ignite/internal/table/impl/DummyInternalTableImpl.java
+++ b/modules/table/src/testFixtures/java/org/apache/ignite/internal/table/impl/DummyInternalTableImpl.java
@@ -135,6 +135,7 @@ import org.apache.ignite.internal.tx.InternalTransaction;
import org.apache.ignite.internal.tx.TxManager;
import org.apache.ignite.internal.tx.configuration.TransactionConfiguration;
import org.apache.ignite.internal.tx.impl.HeapLockManager;
+import org.apache.ignite.internal.tx.impl.PlacementDriverHelper;
import org.apache.ignite.internal.tx.impl.RemotelyTriggeredResourceRegistry;
import org.apache.ignite.internal.tx.impl.TransactionIdGenerator;
import org.apache.ignite.internal.tx.impl.TransactionInflights;
@@ -526,6 +527,7 @@ public class DummyInternalTableImpl extends InternalTableImpl {
schemaSyncService,
catalogService,
placementDriver,
+ new PlacementDriverHelper(placementDriver, CLOCK_SERVICE),
mock(ClusterNodeResolver.class),
svc,
mock(FailureProcessor.class),
diff --git a/modules/transactions/build.gradle b/modules/transactions/build.gradle
index fae253133f6..24328a56fc9 100644
--- a/modules/transactions/build.gradle
+++ b/modules/transactions/build.gradle
@@ -107,6 +107,8 @@ dependencies {
testFixturesImplementation project(':ignite-placement-driver-api')
testFixturesImplementation project(':ignite-distribution-zones')
testFixturesImplementation project(':ignite-table')
+ testFixturesImplementation project(':ignite-replicator')
+ testFixturesImplementation project(':ignite-partition-replicator')
testFixturesImplementation testFixtures(project(':ignite-core'))
}
diff --git a/modules/transactions/src/integrationTest/java/org/apache/ignite/tx/distributed/ItTxWriteIntentResolutionTest.java b/modules/transactions/src/integrationTest/java/org/apache/ignite/tx/distributed/ItTxWriteIntentResolutionTest.java
new file mode 100644
index 00000000000..a910050222b
--- /dev/null
+++ b/modules/transactions/src/integrationTest/java/org/apache/ignite/tx/distributed/ItTxWriteIntentResolutionTest.java
@@ -0,0 +1,587 @@
+/*
+ * 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.tx.distributed;
+
+import static java.util.stream.Collectors.toList;
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.lang.IgniteStringFormatter.format;
+import static org.apache.ignite.internal.partition.replicator.network.replication.RequestType.RO_GET;
+import static org.apache.ignite.internal.replicator.message.ReplicaMessageUtils.toZonePartitionIdMessage;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runInExecutor;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureExceptionMatcher.willThrow;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureExceptionMatcher.willThrowWithCauseOrSuppressed;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.binaryRowToTuple;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.partitionReplicaListener;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.tupleToBinaryRow;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.zoneId;
+import static org.apache.ignite.internal.util.CompletableFutures.allOf;
+import static org.apache.ignite.internal.util.IgniteUtils.flatArray;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.apache.ignite.internal.wrapper.Wrappers.unwrap;
+import static org.awaitility.Awaitility.await;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.params.provider.Arguments.argumentSet;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.stream.Stream;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerClassIntegrationTest;
+import org.apache.ignite.internal.ConfigOverride;
+import org.apache.ignite.internal.TestWrappers;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.lang.IgniteBiTuple;
+import org.apache.ignite.internal.partition.replicator.network.PartitionReplicationMessagesFactory;
+import org.apache.ignite.internal.partition.replicator.network.replication.ReadOnlySingleRowPkReplicaRequest;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.ZonePartitionId;
+import org.apache.ignite.internal.replicator.exception.PrimaryReplicaMissException;
+import org.apache.ignite.internal.replicator.message.ReplicaMessagesFactory;
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.apache.ignite.internal.schema.BinaryRowEx;
+import org.apache.ignite.internal.table.InternalTable;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.TxState;
+import org.apache.ignite.internal.tx.TxStateMeta;
+import org.apache.ignite.internal.tx.impl.ReadOnlyTransactionImpl;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxStateCommitPartitionRequest;
+import org.apache.ignite.internal.tx.message.TxStateCoordinatorRequest;
+import org.apache.ignite.internal.tx.storage.state.TxStatePartitionStorage;
+import org.apache.ignite.internal.util.FastTimestamps;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.apache.ignite.tx.TransactionOptions;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * Test for write intent resolution in distributed transactions.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "20")
+@ConfigOverride(name = "ignite.system.properties.txnResourceTtl", value = "0")
+public class ItTxWriteIntentResolutionTest extends ClusterPerClassIntegrationTest {
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ /** Table messages factory. */
+ private static final PartitionReplicationMessagesFactory TABLE_MESSAGES_FACTORY = new PartitionReplicationMessagesFactory();
+
+ /** Replica messages factory. */
+ private static final ReplicaMessagesFactory REPLICA_MESSAGES_FACTORY = new ReplicaMessagesFactory();
+
+ private static final String TABLE_NAME = "TEST_TABLE";
+
+ private static final String ZONE_NAME = "TEST_ZONE";
+
+ private static final String TABLE_NAME_CP = "TEST_TABLE_CP";
+
+ private static final String ZONE_NAME_CP = "TEST_ZONE_CP";
+
+ private static final int REPLICAS = 3;
+
+ private static final String VALUE_OLD = "old";
+ private static final String VALUE_WRITE_INTENT = "writeIntent";
+ private static final String VALUE_AFTER_READ_TS = "versionAfterReadTs";
+
+ private final ExecutorService storageExecutor = Executors.newSingleThreadExecutor(
+ IgniteThreadFactory.create(
+ "test",
+ "storage-test-pool-itwirt",
+ log,
+ ThreadOperation.STORAGE_READ,
+ ThreadOperation.STORAGE_WRITE
+ )
+ );
+
+ private Tuple tuple = INITIAL_TUPLE;
+ private Tuple keyTuple;
+
+ @Override
+ protected int[] cmgMetastoreNodes() {
+ return new int[]{0, 1, 2};
+ }
+
+ @Override
+ protected int initialNodes() {
+ return 3;
+ }
+
+ @Override
+ protected void configureInitParameters(InitParametersBuilder builder) {
+ super.configureInitParameters(builder);
+
+ builder.clusterConfiguration("ignite {"
+ + " system.properties.txnResourceTtl: \"0\""
+ + "}");
+ }
+
+ @BeforeEach
+ public void setup() {
+ runningNodesList().forEach(n -> n.dropMessages(null));
+
+ sql(format("create zone if not exists {} (partitions 1, replicas {}) storage profiles ['{}']",
+ ZONE_NAME, REPLICAS, DEFAULT_STORAGE_PROFILE));
+ sql(format("create table if not exists {} (key bigint primary key, val varchar(20)) zone {}", TABLE_NAME, ZONE_NAME));
+
+ sql(format("create zone if not exists {} (partitions 1, replicas {}) storage profiles ['{}']",
+ ZONE_NAME_CP, 1, DEFAULT_STORAGE_PROFILE));
+ sql(format("create table if not exists {} (key bigint primary key, val varchar(20)) zone {}", TABLE_NAME_CP, ZONE_NAME_CP));
+
+ tuple = NEXT_TUPLE.apply(tuple);
+ keyTuple = Tuple.create().set("key", tuple.longValue("key"));
+ }
+
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(storageExecutor, 10, TimeUnit.SECONDS);
+ }
+
+ @ParameterizedTest
+ @MethodSource("testArgFactory")
+ public void writeIntentResolutionPrimaryReplicaPathTest(
+ boolean requestByRwTxn,
+ boolean writeIntentHasThisTxId,
+ boolean keepWriteIntent,
+ boolean commitWriteIntent,
+ boolean newestCommitTsIsPresent,
+ boolean addVersionAfterReadTs,
+ boolean changePrimaryOnWiResolution,
+ IgniteBiTuple<Class<Exception>, String> expected
+ ) {
+ int zoneCpId = zoneId(anyNode(), TABLE_NAME_CP);
+ ZonePartitionId commitPartitionId = new ZonePartitionId(zoneCpId, 0);
+
+ ReplicaMeta commmitPartitionReplicaMeta = waitAndGetPrimaryReplica(anyNode(), commitPartitionId);
+ IgniteImpl commitPartitionPrimaryNode = findNode(node -> node.id().equals(commmitPartitionReplicaMeta.getLeaseholderId()));
+
+ IgniteImpl coordinator = commitPartitionPrimaryNode;
+
+ int zoneId = zoneId(coordinator, TABLE_NAME);
+ int tableId = tableId(coordinator, TABLE_NAME);
+
+ Tuple wiTuple = tuple;
+ ZonePartitionId wiGroupId = new ZonePartitionId(zoneId, 0);
+
+ blockCleanup(null, wiGroupId, tableId, false);
+
+ ReplicaMeta wiPartitionReplicaMeta = waitAndGetPrimaryReplica(coordinator, wiGroupId);
+ IgniteImpl wiPrimaryNode;
+
+ if (wiPartitionReplicaMeta.getLeaseholderId().equals(commitPartitionPrimaryNode.id())) {
+ wiPrimaryNode = findNode(node -> !node.id().equals(commitPartitionPrimaryNode.id()));
+ transferPrimary(runningNodesList(), wiGroupId, node -> node.equals(wiPrimaryNode.name()));
+ } else {
+ wiPrimaryNode = findNode(node -> node.id().equals(wiPartitionReplicaMeta.getLeaseholderId()));
+ }
+
+ IgniteImpl wiBackupNode =
+ findNode(node -> !node.id().equals(wiPrimaryNode.id()) && !node.id().equals(commitPartitionPrimaryNode.id()));
+
+ log.info("Test: coordinator={}, commitPartitionPrimaryNode={}, wiPrimaryNode={}, wiBackupNode={}",
+ coordinator.name(), commitPartitionPrimaryNode.name(), wiPrimaryNode.name(), wiBackupNode.name());
+
+ RecordView<Tuple> viewCp = coordinator.tables().table(TABLE_NAME_CP).recordView();
+ RecordView<Tuple> view = coordinator.tables().table(TABLE_NAME).recordView();
+
+ if (newestCommitTsIsPresent) {
+ view.upsert(null, wiTuple.set("val", VALUE_OLD));
+ }
+
+ Transaction rwTx = coordinator.transactions().begin();
+ Transaction wiCreator = writeIntentHasThisTxId ? rwTx : coordinator.transactions().begin();
+ UUID wiCreatorTxId = txId(wiCreator);
+
+ viewCp.upsert(wiCreator, tuple);
+ view.upsert(wiCreator, tuple.set("val", VALUE_WRITE_INTENT));
+ // Don't finish wiCreator.
+
+ waitForReplication(wiGroupId, tableId);
+
+ log.info("Test: write intent creator txId={}", wiCreatorTxId);
+
+ Collection<IgniteImpl> nodesToClearMeta = List.of(coordinator, wiPrimaryNode, wiBackupNode);
+
+ if (!keepWriteIntent) {
+ blockCleanup(wiBackupNode, wiGroupId, tableId, true);
+
+ if (commitWriteIntent) {
+ wiCreator.commit();
+ } else {
+ wiCreator.rollback();
+ }
+
+ waitForReplication(wiGroupId, tableId, nodesToClearMeta);
+ waitForTxStateVacuum(nodesToClearMeta, wiCreatorTxId, 0, true, 10_000);
+ }
+
+ // Delete tx meta from coordinator and commit partition to force primary replica path for WI resolution.
+ runningNodesList().forEach(node -> node.txManager().updateTxMeta(wiCreatorTxId, old -> null));
+ coordinator.txManager().updateTxMeta(wiCreatorTxId, old -> null);
+ commitPartitionPrimaryNode.txManager().updateTxMeta(wiCreatorTxId, old -> null);
+
+ log.info("Test: tx state metas deleted.");
+
+ if (requestByRwTxn) {
+ transferPrimary(runningNodesList(), wiGroupId, node -> node.equals(wiBackupNode.name()));
+
+ Transaction readerTx = coordinator.transactions().begin();
+
+ wiBackupNode.dropMessages((rcp, msg) -> {
+ if (msg instanceof TxStateCoordinatorRequest) {
+ throw new RuntimeException("test");
+ }
+
+ return false;
+ });
+
+ if (changePrimaryOnWiResolution) {
+ wiBackupNode.dropMessages((rcp, msg) -> {
+ if (msg instanceof TxStateCommitPartitionRequest) {
+ // Change back.
+ transferPrimary(runningNodesList(), wiGroupId, node -> node.equals(wiPrimaryNode.name()));
+ }
+
+ return false;
+ });
+ }
+
+ CompletableFuture<Tuple> tupleFut = view.getAsync(readerTx, keyTuple);
+
+ if (expected.get1() != null) {
+ assertThat(tupleFut, willThrowWithCauseOrSuppressed(expected.get1()));
+ } else {
+ assertThat(tupleFut, willCompleteSuccessfully());
+ Tuple t = tupleFut.join();
+ assertEquals(VALUE_OLD, t.stringValue("val"));
+ }
+ } else {
+ Transaction roTx = coordinator.transactions().begin(new TransactionOptions().readOnly(true));
+ HybridTimestamp readTs = unwrap(roTx, ReadOnlyTransactionImpl.class).readTimestamp();
+
+ if (addVersionAfterReadTs) {
+ view.upsert(null, wiTuple.set("val", VALUE_AFTER_READ_TS));
+ }
+
+ UUID roTxId = txId(roTx);
+
+ ReadOnlySingleRowPkReplicaRequest req = roGetRequest(coordinator, wiGroupId, tableId, keyTuple, roTxId, readTs);
+ CompletableFuture<?> reqFut = wiBackupNode.distributedTableManager().replicaService().invoke(wiBackupNode.name(), req);
+
+ if (expected.get1() != null) {
+ assertThat(reqFut, willThrow(expected.get1()));
+ } else {
+ assertThat(reqFut, willCompleteSuccessfully());
+ Object resp = reqFut.join();
+
+ if (expected.get2() == null) {
+ assertNull(resp);
+ } else {
+ assertThat(resp, instanceOf(BinaryRow.class));
+ Tuple t = binaryRowToTuple(anyNode(), TABLE_NAME, (BinaryRow) resp, null);
+ assertEquals(expected.get2(), t.stringValue("val"));
+ }
+ }
+ }
+ }
+
+ private static Stream<Arguments> testArgFactory() {
+ boolean[] rwTxnWriteIntentOwn = { true, true };
+ boolean[] rwTxnWriteIntentAnotherTxn = { true, false };
+ boolean[] roTxn = { false, false };
+
+ boolean[] keep = { true, false };
+ boolean[] commit = { false, true };
+ boolean[] abort = { false, false };
+
+ boolean newestAbsent = false;
+ boolean newestPresent = true;
+
+ boolean addVersionAfter = true;
+ boolean noVersionAfter = false;
+
+ boolean noChangePrimary = false;
+ boolean changePrimaryOnWiResolution = true;
+
+ var abortedNoOld = expectedTxStateArg(null);
+ var abortedWithOld = expectedTxStateArg(VALUE_OLD);
+ var committed = expectedTxStateArg(VALUE_WRITE_INTENT);
+ var rwException = new IgniteBiTuple<>(PrimaryReplicaMissException.class, null);
+
+ return Stream.of(
+ argumentSet(
+ "ro txn, keep WI, no old version, no version after read ts",
+ flatArray(roTxn, keep, newestAbsent, noVersionAfter, noChangePrimary, abortedNoOld)
+ ),
+ argumentSet(
+ "ro txn, keep WI, add old version, no version after read ts",
+ flatArray(roTxn, keep, newestPresent, noVersionAfter, noChangePrimary, abortedWithOld)
+ ),
+ argumentSet(
+ "ro txn, commit WI, no old version, no version after read ts",
+ flatArray(roTxn, commit, newestAbsent, noVersionAfter, noChangePrimary, committed)
+ ),
+ argumentSet(
+ "ro txn, commit WI, add old version, no version after read ts",
+ flatArray(roTxn, commit, newestPresent, noVersionAfter, noChangePrimary, committed)
+ ),
+ argumentSet(
+ "ro txn, commit WI, add old version, add version after read ts",
+ flatArray(roTxn, commit, newestPresent, addVersionAfter, noChangePrimary, committed)
+ ),
+ argumentSet(
+ "ro txn, abort WI, no old version, no version after read ts",
+ flatArray(roTxn, abort, newestAbsent, noVersionAfter, noChangePrimary, abortedNoOld)
+ ),
+ argumentSet(
+ "ro txn, abort WI, add old version, no version after read ts",
+ flatArray(roTxn, abort, newestPresent, noVersionAfter, noChangePrimary, abortedWithOld)
+ ),
+ argumentSet(
+ "ro txn, abort WI, add old version, add version after read ts",
+ flatArray(roTxn, abort, newestPresent, addVersionAfter, noChangePrimary, abortedWithOld)
+ ),
+ argumentSet(
+ "rw txn, keep WI",
+ flatArray(rwTxnWriteIntentAnotherTxn, keep, newestPresent, noVersionAfter, noChangePrimary, abortedWithOld)
+ ),
+ argumentSet(
+ "rw txn, keep WI, own WI",
+ flatArray(rwTxnWriteIntentOwn, keep, newestPresent, noVersionAfter, noChangePrimary, abortedWithOld)
+ ),
+ argumentSet(
+ "rw txn, keep WI, change primary on WI resolution",
+ flatArray(rwTxnWriteIntentAnotherTxn, keep, newestPresent, noVersionAfter, changePrimaryOnWiResolution,
+ rwException)
+ )
+ );
+ }
+
+ private void blockCleanup(@Nullable IgniteImpl node, ZonePartitionId groupId, int tableId, boolean blocked) {
+ if (node != null) {
+ partitionReplicaListener(node, groupId, tableId).storageUpdateHandler().writeIntentSwitchBlocked(blocked);
+ } else {
+ runningNodesStream().forEach(n -> {
+ partitionReplicaListener(unwrapIgniteImpl(n), groupId, tableId).storageUpdateHandler().writeIntentSwitchBlocked(blocked);
+ });
+ }
+ }
+
+ private ReadOnlySingleRowPkReplicaRequest roGetRequest(
+ IgniteImpl coordinator,
+ ZonePartitionId groupId,
+ int tableId,
+ Tuple keyTuple,
+ UUID txId,
+ HybridTimestamp readTs
+ ) {
+ BinaryRowEx keyRow = tupleToBinaryRow(anyNode(), TABLE_NAME, keyTuple, null, true);
+
+ return TABLE_MESSAGES_FACTORY.readOnlySingleRowPkReplicaRequest()
+ .groupId(toZonePartitionIdMessage(REPLICA_MESSAGES_FACTORY, groupId))
+ .tableId(tableId)
+ .schemaVersion(keyRow.schemaVersion())
+ .primaryKey(keyRow.tupleSlice())
+ .requestType(RO_GET)
+ .readTimestamp(readTs)
+ .transactionId(txId)
+ .coordinatorId(coordinator.id())
+ .build();
+ }
+
+ private static IgniteBiTuple<Class<Exception>, String> expectedTxStateArg(@Nullable String value) {
+ return new IgniteBiTuple<>(null, value);
+ }
+
+ private void waitForReplication(ZonePartitionId groupId, int tableId) {
+ waitForReplication(groupId, tableId, runningNodesStream().map(TestWrappers::unwrapIgniteImpl).collect(toList()));
+ }
+
+ private void waitForReplication(ZonePartitionId groupId, int tableId, Collection<IgniteImpl> nodes) {
+ ReplicaMeta replicaMeta = waitAndGetPrimaryReplica(anyNode(), groupId);
+
+ IgniteImpl leaseholder = findNode(node -> node.name().equals(replicaMeta.getLeaseholder()));
+
+ HybridTimestamp primaryTime = partitionReplicaListener(leaseholder, groupId, tableId).safeTime().current()
+ .tick();
+
+ log.info("Test: waiting for replication to all nodes with primaryTime={}", primaryTime);
+
+ List<CompletableFuture<Void>> futures = nodes.stream()
+ .map(node -> partitionReplicaListener(unwrapIgniteImpl(node), groupId, tableId).safeTime().waitFor(primaryTime))
+ .collect(toList());
+
+ assertThat(allOf(futures), willCompleteSuccessfully());
+ }
+
+ /**
+ * Waits for vacuum of volatile (and if needed, persistent) state of the given tx on the given nodes.
+ *
+ * @param nodes Nodes.
+ * @param txId Transaction id.
+ * @param partId Commit partition id to check the persistent tx state storage of this partition.
+ * @param checkPersistent Whether to wait for vacuum of persistent tx state as well.
+ * @param timeMs Time to wait.
+ */
+ private void waitForTxStateVacuum(Collection<IgniteImpl> nodes, UUID txId, int partId, boolean checkPersistent, long timeMs) {
+ try {
+ await()
+ .atMost(timeMs, TimeUnit.MILLISECONDS)
+ .until(() -> txStateIsAbsent(nodes, txId, TABLE_NAME, partId, checkPersistent, false));
+ } catch (AssertionError e) {
+ logCurrentTxState(nodes, txId, TABLE_NAME, partId);
+ throw e;
+ }
+ }
+
+ /**
+ * Checks whether the tx state is absent on all of the given nodes.
+ *
+ * @param nodes Nodes.
+ * @param txId Transaction id.
+ * @param tableName Table name of the table that commit partition belongs to.
+ * @param partId Commit partition id.
+ * @param checkPersistent Whether the persistent state should be checked.
+ * @param checkCpPrimaryOnly If {@code} true, the persistent state should be checked only on the commit partition primary,
+ * otherwise it would be checked on every given node.
+ * @return {@code true} if tx state is absent, {@code false} otherwise. Call {@link #logCurrentTxState(Collection, UUID, String, int)}
+ * for details.
+ */
+ private boolean txStateIsAbsent(
+ Collection<IgniteImpl> nodes,
+ UUID txId,
+ String tableName,
+ int partId,
+ boolean checkPersistent,
+ boolean checkCpPrimaryOnly
+ ) {
+ boolean result = true;
+
+ UUID cpPrimaryId = null;
+
+ if (checkCpPrimaryOnly) {
+ IgniteImpl node = anyNode();
+
+ ZonePartitionId partitionGroupId = new ZonePartitionId(zoneId(node, tableName), partId);
+
+ CompletableFuture<ReplicaMeta> replicaFut = node.placementDriver().getPrimaryReplica(partitionGroupId, node.clock().now());
+ assertThat(replicaFut, willCompleteSuccessfully());
+
+ ReplicaMeta replicaMeta = replicaFut.join();
+ // The test doesn't make sense if there is no primary right now.
+ assertNotNull(replicaMeta);
+
+ cpPrimaryId = replicaMeta.getLeaseholderId();
+ }
+
+ for (Iterator<IgniteImpl> iterator = nodes.iterator(); iterator.hasNext();) {
+ IgniteImpl node = iterator.next();
+
+ result = result
+ && volatileTxState(node, txId) == null
+ && (!checkPersistent || !node.id().equals(cpPrimaryId) || persistentTxState(node, txId, tableName, partId) == null);
+ }
+
+ return result;
+ }
+
+ private void logCurrentTxState(Collection<IgniteImpl> nodes, UUID txId, String table, int partId) {
+ nodes.stream()
+ .map(TestWrappers::unwrapIgniteImpl)
+ .forEach(node -> {
+ log.info("Test: volatile state [tx={}, node={}, state={}].", txId, node.name(), volatileTxState(node, txId));
+ log.info(
+ "Test: persistent state [tx={}, node={}, state={}].",
+ txId, node.name(), persistentTxState(node, txId, table, partId)
+ );
+ });
+ }
+
+ @Nullable
+ private static TransactionMeta volatileTxState(IgniteImpl node, UUID txId) {
+ TxManagerImpl txManager = (TxManagerImpl) node.txManager();
+
+ TxStateMeta txInMemoryState = txManager.stateMeta(txId);
+
+ if (txInMemoryState == null) {
+ return null;
+ }
+
+ if (TxState.isFinalState(txInMemoryState.txState())) {
+ long current = FastTimestamps.coarseCurrentTimeMillis();
+
+ Long initialTs = txInMemoryState.initialVacuumObservationTimestamp();
+
+ assertNotNull(initialTs);
+
+ assertTrue(current >= initialTs);
+ }
+
+ return txInMemoryState;
+ }
+
+ @Nullable
+ private TransactionMeta persistentTxState(IgniteImpl node, UUID txId, String tableName, int partId) {
+ return runInExecutor(storageExecutor, () -> {
+ InternalTable internalTable = table(node, tableName).internalTable();
+
+ TxStatePartitionStorage txStatePartitionStorage = node
+ .partitionReplicaLifecycleManager()
+ .txStatePartitionStorage(internalTable.zoneId(), partId);
+
+ assertNotNull(txStatePartitionStorage);
+
+ return txStatePartitionStorage.get(txId);
+ });
+ }
+}
diff --git a/modules/transactions/src/main/java/org/apache/ignite/internal/tx/PrimaryReplicaChangeDuringWriteIntentResolutionException.java b/modules/transactions/src/main/java/org/apache/ignite/internal/tx/PrimaryReplicaChangeDuringWriteIntentResolutionException.java
new file mode 100644
index 00000000000..e7b7b80275a
--- /dev/null
+++ b/modules/transactions/src/main/java/org/apache/ignite/internal/tx/PrimaryReplicaChangeDuringWriteIntentResolutionException.java
@@ -0,0 +1,33 @@
+/*
+ * 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.tx;
+
+import org.apache.ignite.internal.lang.IgniteInternalException;
+import org.apache.ignite.internal.replicator.exception.ExpectedReplicationException;
+import org.apache.ignite.internal.replicator.exception.PrimaryReplicaMissException;
+
+/**
+ * Exception indicating that primary replica of sender partition has changed during write intent resolution requested by
+ * read-write transaction. This means, that the requesting transaction won't be able to be committed, which is effectively equal
+ * to the case of primary replica change during the handling of primary replica request, so this exception should cause
+ * {@link PrimaryReplicaMissException} on the sender partition.
+ */
+public class PrimaryReplicaChangeDuringWriteIntentResolutionException extends IgniteInternalException
+ implements ExpectedReplicationException {
+ private static final long serialVersionUID = -8387939050713325533L;
+}
diff --git a/modules/transactions/src/main/java/org/apache/ignite/internal/tx/TxStateMeta.java b/modules/transactions/src/main/java/org/apache/ignite/internal/tx/TxStateMeta.java
index 49c2fc93b78..db187b74b08 100644
--- a/modules/transactions/src/main/java/org/apache/ignite/internal/tx/TxStateMeta.java
+++ b/modules/transactions/src/main/java/org/apache/ignite/internal/tx/TxStateMeta.java
@@ -308,6 +308,34 @@ public class TxStateMeta implements TransactionMeta {
return new TxStateMetaBuilder(this);
}
+ /**
+ * Finalizes transaction state meta.
+ *
+ * @param old Old meta.
+ * @param finalState Final transaction state.
+ * @param commitTimestamp Commit timestamp, if present.
+ * @return Finalized transaction state meta.
+ */
+ public static TxStateMeta finalizeState(
+ @Nullable TxStateMeta old,
+ TxState finalState,
+ @Nullable HybridTimestamp commitTimestamp,
+ @Nullable Long cleanupCompletionTimestamp
+ ) {
+ TxStateMetaBuilder builder = old == null ? builder(finalState) : old.mutate().txState(finalState);
+
+ if (commitTimestamp != null) {
+ builder.commitTimestamp(commitTimestamp);
+ }
+
+ if (cleanupCompletionTimestamp != null) {
+ builder.initialVacuumObservationTimestamp(cleanupCompletionTimestamp);
+ builder.cleanupCompletionTimestamp(cleanupCompletionTimestamp);
+ }
+
+ return builder.build();
+ }
+
/**
* Builder for TxStateMeta.
*/
diff --git a/modules/transactions/src/main/java/org/apache/ignite/internal/tx/TxStateMetaFinishing.java b/modules/transactions/src/main/java/org/apache/ignite/internal/tx/TxStateMetaFinishing.java
index 9472905ef36..1f02103ca41 100644
--- a/modules/transactions/src/main/java/org/apache/ignite/internal/tx/TxStateMetaFinishing.java
+++ b/modules/transactions/src/main/java/org/apache/ignite/internal/tx/TxStateMetaFinishing.java
@@ -17,6 +17,8 @@
package org.apache.ignite.internal.tx;
+import static org.apache.ignite.internal.lang.IgniteStringFormatter.format;
+
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import org.apache.ignite.internal.hlc.HybridTimestamp;
@@ -111,6 +113,22 @@ public class TxStateMetaFinishing extends TxStateMeta {
return new TxStateMetaFinishingBuilder(this);
}
+ /**
+ * Casts given meta to {@link TxStateMetaFinishing} if it's instance of it, throws {@link AssertionError} otherwise.
+ *
+ * @param txId Transaction id.
+ * @param txMeta Meta to cast.
+ * @return Given meta cast to {@link TxStateMetaFinishing}.
+ */
+ public static TxStateMetaFinishing castToFinishing(UUID txId, TransactionMeta txMeta) {
+ if (txMeta instanceof TxStateMetaFinishing) {
+ return (TxStateMetaFinishing) txMeta;
+ } else {
+ throw new AssertionError(format("Unexpected tx meta type for FINISHING state [txId={}, type={}, txMeta={}] ",
+ txId, txMeta.getClass().getName(), txMeta));
+ }
+ }
+
/**
* Builder for {@link TxStateMetaAbandoned} instances.
*/
diff --git a/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TransactionStateResolver.java b/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TransactionStateResolver.java
index ba2036382ea..541582d5ca4 100644
--- a/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TransactionStateResolver.java
+++ b/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TransactionStateResolver.java
@@ -19,14 +19,13 @@ package org.apache.ignite.internal.tx.impl;
import static java.util.concurrent.CompletableFuture.completedFuture;
import static java.util.concurrent.CompletableFuture.failedFuture;
-import static java.util.concurrent.TimeUnit.SECONDS;
import static org.apache.ignite.internal.lang.IgniteStringFormatter.format;
import static org.apache.ignite.internal.tx.TxState.ABANDONED;
import static org.apache.ignite.internal.tx.TxState.FINISHING;
import static org.apache.ignite.internal.tx.TxState.PENDING;
import static org.apache.ignite.internal.tx.TxState.UNKNOWN;
import static org.apache.ignite.internal.tx.TxState.isFinalState;
-import static org.apache.ignite.internal.tx.impl.PlacementDriverHelper.AWAIT_PRIMARY_REPLICA_TIMEOUT;
+import static org.apache.ignite.internal.tx.TxStateMetaFinishing.castToFinishing;
import static org.apache.ignite.internal.util.ExceptionUtils.unwrapCause;
import static org.apache.ignite.lang.ErrorGroups.Common.INTERNAL_ERR;
@@ -35,7 +34,6 @@ import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
-import java.util.concurrent.TimeUnit;
import org.apache.ignite.internal.hlc.ClockService;
import org.apache.ignite.internal.hlc.HybridTimestamp;
import org.apache.ignite.internal.lang.IgniteInternalException;
@@ -47,7 +45,6 @@ import org.apache.ignite.internal.network.InternalClusterNode;
import org.apache.ignite.internal.network.MessagingService;
import org.apache.ignite.internal.network.NetworkMessage;
import org.apache.ignite.internal.network.RecipientLeftException;
-import org.apache.ignite.internal.placementdriver.PlacementDriver;
import org.apache.ignite.internal.placementdriver.ReplicaMeta;
import org.apache.ignite.internal.replicator.ZonePartitionId;
import org.apache.ignite.internal.replicator.exception.PrimaryReplicaMissException;
@@ -56,11 +53,9 @@ import org.apache.ignite.internal.tx.TransactionMeta;
import org.apache.ignite.internal.tx.TxManager;
import org.apache.ignite.internal.tx.TxState;
import org.apache.ignite.internal.tx.TxStateMeta;
-import org.apache.ignite.internal.tx.TxStateMetaFinishing;
import org.apache.ignite.internal.tx.message.TransactionMetaMessage;
import org.apache.ignite.internal.tx.message.TxMessageGroup;
import org.apache.ignite.internal.tx.message.TxMessagesFactory;
-import org.apache.ignite.internal.tx.message.TxStateCommitPartitionRequest;
import org.apache.ignite.internal.tx.message.TxStateCoordinatorRequest;
import org.apache.ignite.internal.util.Lazy;
import org.jetbrains.annotations.Nullable;
@@ -110,7 +105,7 @@ public class TransactionStateResolver {
* @param clockService Clock service.
* @param clusterNodeResolver Cluster node resolver.
* @param messagingService Messaging service.
- * @param placementDriver Placement driver.
+ * @param placementDriverHelper Placement drive helper.
* @param txMessageSender Tx message sender.
* @param txRecoveryEngine Transaction recovery engine.
* @param localNode Local cluster node.
@@ -121,7 +116,7 @@ public class TransactionStateResolver {
ClockService clockService,
ClusterNodeResolver clusterNodeResolver,
MessagingService messagingService,
- PlacementDriver placementDriver,
+ PlacementDriverHelper placementDriverHelper,
TxMessageSender txMessageSender,
TxRecoveryEngine txRecoveryEngine,
Lazy<InternalClusterNode> localNode,
@@ -131,7 +126,7 @@ public class TransactionStateResolver {
this.clockService = clockService;
this.clusterNodeResolver = clusterNodeResolver;
this.messagingService = messagingService;
- this.placementDriverHelper = new PlacementDriverHelper(placementDriver, clockService);
+ this.placementDriverHelper = placementDriverHelper;
this.txMessageSender = txMessageSender;
this.txRecoveryEngine = txRecoveryEngine;
this.localNode = localNode;
@@ -170,79 +165,27 @@ public class TransactionStateResolver {
/**
* Resolves transaction state locally, if possible, or distributively, if needed.
*
- * @param txId Transaction id.
- * @param commitGrpId Commit partition group id.
- * @param timestamp Timestamp.
- * @param senderCurrentConsistencyToken See {@link TxStateCommitPartitionRequest#senderCurrentConsistencyToken()}.
- * @param senderGroupId See {@link TxStateCommitPartitionRequest#senderGroupId()}.
- * @return Future with the transaction state meta as a result.
- */
- public CompletableFuture<TransactionMeta> resolveTxState(
- UUID txId,
- ZonePartitionId commitGrpId,
- @Nullable HybridTimestamp timestamp,
- @Nullable Long senderCurrentConsistencyToken,
- @Nullable ZonePartitionId senderGroupId
- ) {
- return resolveTxState(
- txId,
- commitGrpId,
- timestamp,
- AWAIT_PRIMARY_REPLICA_TIMEOUT,
- SECONDS,
- senderCurrentConsistencyToken,
- senderGroupId
- );
- }
-
- /**
- * Resolves transaction state locally, if possible, or distributively, if needed.
- *
- * @param txId Transaction id.
- * @param commitGrpId Commit partition group id.
- * @param timestamp Timestamp.
- * @param awaitCommitPartitionAvailabilityTimeout Timeout for awaiting commit partition primary replica.
- * @param awaitCommitPartitionAvailabilityTimeUnit Time unit for awaiting commit partition primary replica timeout.
- * @param senderCurrentConsistencyToken See {@link TxStateCommitPartitionRequest#senderCurrentConsistencyToken()}.
- * @param senderGroupId See {@link TxStateCommitPartitionRequest#senderGroupId()}.
+ * @param p Parameters for tx state resolution.
* @return Future with the transaction state meta as a result.
*/
- public CompletableFuture<TransactionMeta> resolveTxState(
- UUID txId,
- ZonePartitionId commitGrpId,
- @Nullable HybridTimestamp timestamp,
- long awaitCommitPartitionAvailabilityTimeout,
- TimeUnit awaitCommitPartitionAvailabilityTimeUnit,
- @Nullable Long senderCurrentConsistencyToken,
- @Nullable ZonePartitionId senderGroupId
- ) {
- TxStateMeta localMeta = txManager.stateMeta(txId);
+ public CompletableFuture<TransactionMeta> resolveTxState(TxStateResolutionParameters p) {
+ TxStateMeta localMeta = txManager.stateMeta(p.txId());
if (localMeta != null && isFinalState(localMeta.txState())) {
return completedFuture(localMeta);
}
- CompletableFuture<TransactionMeta> future = txStateFutures.compute(txId, (k, v) -> {
+ CompletableFuture<TransactionMeta> future = txStateFutures.compute(p.txId(), (k, v) -> {
if (v == null) {
v = new CompletableFuture<>();
- resolveDistributiveTxState(
- txId,
- localMeta,
- commitGrpId,
- timestamp,
- awaitCommitPartitionAvailabilityTimeout,
- awaitCommitPartitionAvailabilityTimeUnit,
- senderCurrentConsistencyToken,
- senderGroupId,
- v
- );
+ resolveDistributiveTxState(p, localMeta, v);
}
return v;
});
- future.whenComplete((v, e) -> txStateFutures.remove(txId));
+ future.whenComplete((v, e) -> txStateFutures.remove(p.txId()));
return future;
}
@@ -250,56 +193,26 @@ public class TransactionStateResolver {
/**
* Resolve the transaction state distributively. This method doesn't process final tx states.
*
- * @param txId Transaction id.
+ * @param p Parameters for tx state resolution.
* @param localMeta Local tx meta.
- * @param commitGrpId Commit partition group id.
- * @param timestamp Timestamp to pass to target node.
- * @param awaitCommitPartitionAvailabilityTimeout Timeout for awaiting commit partition primary replica.
- * @param awaitCommitPartitionAvailabilityTimeUnit Time unit for awaiting commit partition primary replica timeout.
- * @param senderCurrentConsistencyToken See {@link TxStateCommitPartitionRequest#senderCurrentConsistencyToken()}.
- * @param senderGroupId See {@link TxStateCommitPartitionRequest#senderGroupId()}
* @param txMetaFuture Tx meta future to complete with the result.
*/
private void resolveDistributiveTxState(
- UUID txId,
+ TxStateResolutionParameters p,
@Nullable TxStateMeta localMeta,
- ZonePartitionId commitGrpId,
- @Nullable HybridTimestamp timestamp,
- long awaitCommitPartitionAvailabilityTimeout,
- TimeUnit awaitCommitPartitionAvailabilityTimeUnit,
- @Nullable Long senderCurrentConsistencyToken,
- @Nullable ZonePartitionId senderGroupId,
CompletableFuture<TransactionMeta> txMetaFuture
) {
- assert localMeta == null || !isFinalState(localMeta.txState()) : "Unexpected tx meta [txId" + txId + ", meta=" + localMeta + ']';
-
- HybridTimestamp timestamp0 = timestamp == null ? HybridTimestamp.MIN_VALUE : timestamp;
+ if (localMeta != null && isFinalState(localMeta.txState())) {
+ throw new IllegalArgumentException("Unexpected tx meta [txId" + p.txId() + ", meta=" + localMeta + ']');
+ }
if (localMeta == null) {
// Fallback to commit partition path, because we don't have coordinator id.
- resolveTxStateFromCommitPartition(
- txId,
- commitGrpId,
- awaitCommitPartitionAvailabilityTimeout,
- awaitCommitPartitionAvailabilityTimeUnit,
- txMetaFuture,
- senderCurrentConsistencyToken,
- senderGroupId
- );
+ resolveTxStateFromCommitPartition(p, txMetaFuture);
} else if (localMeta.txState() == PENDING) {
- resolveTxStateFromTxCoordinator(
- txId,
- localMeta.txCoordinatorId(),
- commitGrpId,
- timestamp0,
- senderCurrentConsistencyToken,
- senderGroupId,
- txMetaFuture
- );
+ resolveTxStateFromTxCoordinator(p, localMeta.txCoordinatorId(), txMetaFuture);
} else if (localMeta.txState() == FINISHING) {
- assert localMeta instanceof TxStateMetaFinishing;
-
- ((TxStateMetaFinishing) localMeta).txFinishFuture().whenComplete((v, e) -> {
+ castToFinishing(p.txId(), localMeta).txFinishFuture().whenComplete((v, e) -> {
if (e == null) {
txMetaFuture.complete(v);
} else {
@@ -307,57 +220,38 @@ public class TransactionStateResolver {
}
});
} else {
- assert localMeta.txState() == ABANDONED : "Unexpected transaction state [txId=" + txId + ", txStateMeta=" + localMeta + ']';
+ assert localMeta.txState() == ABANDONED : "Unexpected transaction state [txId=" + p.txId() + ", txStateMeta=" + localMeta + ']';
// Still try to resolve the state from commit partition.
- resolveTxStateFromCommitPartition(txId,
- commitGrpId,
- senderCurrentConsistencyToken,
- senderGroupId,
- txMetaFuture
- );
+ resolveTxStateFromCommitPartition(p, txMetaFuture);
}
}
private void resolveTxStateFromTxCoordinator(
- UUID txId,
+ TxStateResolutionParameters p,
@Nullable UUID coordinatorId,
- ZonePartitionId commitGrpId,
- HybridTimestamp timestamp,
- @Nullable Long senderCurrentConsistencyToken,
- @Nullable ZonePartitionId senderGroupId,
CompletableFuture<TransactionMeta> txMetaFuture
) {
- updateLocalTxMapAfterDistributedStateResolved(txId, txMetaFuture);
+ updateLocalTxMapAfterDistributedStateResolved(p.txId(), txMetaFuture);
InternalClusterNode coordinator = coordinatorId == null ? null : clusterNodeResolver.getById(coordinatorId);
if (coordinator == null) {
// This means the coordinator node have either left the cluster or restarted.
- markAbandoned(txId);
+ markAbandoned(p.txId());
- resolveTxStateFromCommitPartition(txId, commitGrpId, senderCurrentConsistencyToken, senderGroupId, txMetaFuture);
+ resolveTxStateFromCommitPartition(p, txMetaFuture);
} else {
- txMessageSender.resolveTxStateFromCoordinator(
- coordinator,
- commitGrpId,
- txId,
- timestamp,
- senderCurrentConsistencyToken,
- senderGroupId
- )
+ txMessageSender.resolveTxStateFromCoordinator(p, coordinator)
.whenComplete((response, e) -> {
if (e == null && response.txStateMeta() != null && response.txStateMeta().txState() != UNKNOWN) {
txMetaFuture.complete(response.txStateMeta().asTransactionMeta());
} else {
if (e != null && e.getCause() instanceof RecipientLeftException) {
- markAbandoned(txId);
+ markAbandoned(p.txId());
}
resolveTxStateFromCommitPartition(
- txId,
- commitGrpId,
- senderCurrentConsistencyToken,
- senderGroupId,
+ p,
txMetaFuture
);
}
@@ -365,44 +259,10 @@ public class TransactionStateResolver {
}
}
- private void resolveTxStateFromCommitPartition(
- UUID txId,
- ZonePartitionId commitGrpId,
- @Nullable Long senderCurrentConsistencyToken,
- @Nullable ZonePartitionId senderGroupId,
- CompletableFuture<TransactionMeta> txMetaFuture
- ) {
- resolveTxStateFromCommitPartition(
- txId,
- commitGrpId,
- AWAIT_PRIMARY_REPLICA_TIMEOUT,
- SECONDS,
- txMetaFuture,
- senderCurrentConsistencyToken,
- senderGroupId
- );
- }
+ private void resolveTxStateFromCommitPartition(TxStateResolutionParameters p, CompletableFuture<TransactionMeta> txMetaFuture) {
+ updateLocalTxMapAfterDistributedStateResolved(p.txId(), txMetaFuture);
- private void resolveTxStateFromCommitPartition(
- UUID txId,
- ZonePartitionId commitGrpId,
- long awaitPrimaryReplicaTimeout,
- TimeUnit awaitPrimaryReplicaTimeUnit,
- CompletableFuture<TransactionMeta> txMetaFuture,
- @Nullable Long senderCurrentConsistencyToken,
- @Nullable ZonePartitionId senderGroupId
- ) {
- updateLocalTxMapAfterDistributedStateResolved(txId, txMetaFuture);
-
- sendAndRetry(
- txMetaFuture,
- commitGrpId,
- txId,
- awaitPrimaryReplicaTimeout,
- awaitPrimaryReplicaTimeUnit,
- senderCurrentConsistencyToken,
- senderGroupId
- );
+ sendAndRetry(p, txMetaFuture);
}
/**
@@ -425,32 +285,23 @@ public class TransactionStateResolver {
/**
* Tries to send a request to primary replica of the replication group.
*
+ * @param p Transaction state resolution parameters.
* @param resFut Response future.
- * @param replicaGrp Replication group id.
- * @param txId Transaction id.
- * @param awaitPrimaryReplicaTimeout Primary replica await timeout.
- * @param awaitPrimaryReplicaTimeUnit Primary replica await timeout time unit.
- * @param senderCurrentConsistencyToken See {@link TxStateCommitPartitionRequest#senderCurrentConsistencyToken()}.
- * @param senderGroupId See {@link TxStateCommitPartitionRequest#senderGroupId()}
*/
private void sendAndRetry(
- CompletableFuture<TransactionMeta> resFut,
- ZonePartitionId replicaGrp,
- UUID txId,
- long awaitPrimaryReplicaTimeout,
- TimeUnit awaitPrimaryReplicaTimeUnit,
- @Nullable Long senderCurrentConsistencyToken,
- @Nullable ZonePartitionId senderGroupId
+ TxStateResolutionParameters p,
+ CompletableFuture<TransactionMeta> resFut
) {
- placementDriverHelper.awaitPrimaryReplicaWithExceptionHandling(replicaGrp, awaitPrimaryReplicaTimeout, awaitPrimaryReplicaTimeUnit)
+ placementDriverHelper.awaitPrimaryReplicaWithExceptionHandling(
+ p.commitGroupId(),
+ p.awaitCommitPartitionAvailabilityTimeout(),
+ p.awaitCommitPartitionAvailabilityTimeUnit()
+ )
.thenCompose(replicaMeta ->
txMessageSender.resolveTxStateFromCommitPartition(
+ p,
replicaMeta.getLeaseholder(),
- txId,
- replicaGrp,
- replicaMeta.getStartTime().longValue(),
- senderCurrentConsistencyToken,
- senderGroupId
+ replicaMeta.getStartTime().longValue()
))
.whenComplete((txMeta, e) -> {
if (e == null) {
@@ -459,15 +310,7 @@ public class TransactionStateResolver {
resFut.complete(txMeta);
} else {
if (e instanceof PrimaryReplicaMissException) {
- sendAndRetry(
- resFut,
- replicaGrp,
- txId,
- awaitPrimaryReplicaTimeout,
- awaitPrimaryReplicaTimeUnit,
- senderCurrentConsistencyToken,
- senderGroupId
- );
+ sendAndRetry(p, resFut);
} else {
resFut.completeExceptionally(e);
}
@@ -497,11 +340,7 @@ public class TransactionStateResolver {
if (isFinalState(txStateMeta.txState())) {
return completedFuture(txStateMeta);
} else if (txStateMeta.txState() == FINISHING) {
- assert txStateMeta instanceof TxStateMetaFinishing;
-
- TxStateMetaFinishing txStateMetaFinishing = (TxStateMetaFinishing) txStateMeta;
-
- return txStateMetaFinishing.txFinishFuture();
+ return castToFinishing(request.txId(), txStateMeta).txFinishFuture();
} else if (request.readTimestamp() == null || request.readTimestamp().equals(HybridTimestamp.MIN_VALUE)) {
// If txn is in non-final state and resolution is requested by RW txn.
Long currentConsistencyToken = request.senderCurrentConsistencyToken();
diff --git a/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TxCleanupRequestSender.java b/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TxCleanupRequestSender.java
index 3912d52699d..b132d5851c9 100644
--- a/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TxCleanupRequestSender.java
+++ b/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TxCleanupRequestSender.java
@@ -24,6 +24,7 @@ import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;
import static org.apache.ignite.internal.logger.Loggers.toThrottledLogger;
import static org.apache.ignite.internal.tx.TxStateMeta.builder;
+import static org.apache.ignite.internal.tx.impl.TxStateResolutionParameters.txStateResolutionParameters;
import static org.apache.ignite.internal.util.ExceptionUtils.sneakyThrow;
import static org.apache.ignite.internal.util.IgniteUtils.scheduleRetry;
@@ -156,12 +157,9 @@ public class TxCleanupRequestSender {
String primaryNode = replicaMeta.getLeaseholder();
HybridTimestamp startTime = replicaMeta.getStartTime();
return txMessageSender.resolveTxStateFromCommitPartition(
+ txStateResolutionParameters().txId(txId).commitGroupId(commitPartitionId).build(),
primaryNode,
- txId,
- commitPartitionId,
- startTime.longValue(),
- null,
- null
+ startTime.longValue()
)
.thenApply(TransactionMeta::commitTimestamp);
}
diff --git a/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TxManagerImpl.java b/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TxManagerImpl.java
index be03cc8af9b..22824425b02 100644
--- a/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TxManagerImpl.java
+++ b/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TxManagerImpl.java
@@ -36,6 +36,7 @@ import static org.apache.ignite.internal.tx.TxState.FINISHING;
import static org.apache.ignite.internal.tx.TxState.PENDING;
import static org.apache.ignite.internal.tx.TxState.isFinalState;
import static org.apache.ignite.internal.tx.TxStateMeta.builder;
+import static org.apache.ignite.internal.tx.TxStateMetaFinishing.castToFinishing;
import static org.apache.ignite.internal.util.CompletableFutures.falseCompletedFuture;
import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
import static org.apache.ignite.internal.util.ExceptionUtils.isFinishedDueToTimeout;
@@ -709,7 +710,7 @@ public class TxManagerImpl implements TxManager, NetworkMessageHandler, SystemVi
if (finishingStateMeta != stateMeta) {
// If the state is FINISHING then someone else is in the middle of finishing this tx.
if (stateMeta.txState() == FINISHING) {
- return ((TxStateMetaFinishing) stateMeta).txFinishFuture()
+ return castToFinishing(txId, stateMeta).txFinishFuture()
.thenCompose(meta -> checkTxOutcome(commitIntent, txId, meta));
} else {
// The TX has already been finished. Check whether it finished with the same outcome.
diff --git a/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TxMessageSender.java b/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TxMessageSender.java
index b36af61a5b5..5435ca76bb0 100644
--- a/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TxMessageSender.java
+++ b/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TxMessageSender.java
@@ -17,6 +17,7 @@
package org.apache.ignite.internal.tx.impl;
+import static java.util.Objects.requireNonNull;
import static org.apache.ignite.internal.replicator.message.ReplicaMessageUtils.toZonePartitionIdMessage;
import static org.apache.ignite.internal.replicator.message.ReplicaMessageUtils.toZonePartitionIdMessageNullable;
@@ -42,8 +43,8 @@ import org.apache.ignite.internal.tx.TransactionMeta;
import org.apache.ignite.internal.tx.TransactionResult;
import org.apache.ignite.internal.tx.message.EnlistedPartitionGroupMessage;
import org.apache.ignite.internal.tx.message.PartitionEnlistmentMessage;
+import org.apache.ignite.internal.tx.message.RowIdMessage;
import org.apache.ignite.internal.tx.message.TxMessagesFactory;
-import org.apache.ignite.internal.tx.message.TxStateCommitPartitionRequest;
import org.apache.ignite.internal.tx.message.TxStateResponse;
import org.apache.ignite.internal.tx.message.WriteIntentSwitchReplicatedInfo;
import org.jetbrains.annotations.Nullable;
@@ -185,30 +186,28 @@ public class TxMessageSender {
/**
* Send TxStateCommitPartitionRequest.
*
+ * @param p Transaction state resolution parameters.
* @param primaryConsistentId Node id to send the request to.
- * @param txId Transaction id.
- * @param commitGrpId Partition to store a transaction state.
* @param consistencyToken Enlistment consistency token.
- * @param senderCurrentConsistencyToken See {@link TxStateCommitPartitionRequest#senderCurrentConsistencyToken()}.
- * @param senderGroupId See {@link TxStateCommitPartitionRequest#senderGroupId()}.
* @return Completable future of {@link TransactionMeta}.
*/
public CompletableFuture<TransactionMeta> resolveTxStateFromCommitPartition(
+ TxStateResolutionParameters p,
String primaryConsistentId,
- UUID txId,
- ZonePartitionId commitGrpId,
- Long consistencyToken,
- @Nullable Long senderCurrentConsistencyToken,
- @Nullable ZonePartitionId senderGroupId
+ Long consistencyToken
) {
return replicaService.invoke(
primaryConsistentId,
TX_MESSAGES_FACTORY.txStateCommitPartitionRequest()
- .groupId(toZonePartitionIdMessage(REPLICA_MESSAGES_FACTORY, commitGrpId))
- .txId(txId)
+ .groupId(toZonePartitionIdMessage(REPLICA_MESSAGES_FACTORY, p.commitGroupId()))
+ .txId(p.txId())
+ .tableId(p.tableId())
+ .readTimestamp(p.readTimestamp())
.enlistmentConsistencyToken(consistencyToken)
- .senderCurrentConsistencyToken(senderCurrentConsistencyToken)
- .senderGroupId(toZonePartitionIdMessageNullable(REPLICA_MESSAGES_FACTORY, senderGroupId))
+ .senderCurrentConsistencyToken(p.senderCurrentConsistencyToken())
+ .senderGroupId(toZonePartitionIdMessageNullable(REPLICA_MESSAGES_FACTORY, p.senderGroupId()))
+ .rowId(p.rowIdMessage(TX_MESSAGES_FACTORY))
+ .newestCommitTimestamp(p.newestCommitTimestamp())
.build()
);
}
@@ -216,29 +215,22 @@ public class TxMessageSender {
/**
* Send TxStateCoordinatorRequest.
*
+ * @param p Transaction state resolution parameters.
* @param coordinatorClusterNode Node to send the request to.
- * @param txId Transaction id.
- * @param timestamp Timestamp to pass to target node.
- * @param senderCurrentConsistencyToken See {@link TxStateCommitPartitionRequest#senderCurrentConsistencyToken()}.
- * @param senderGroupId See {@link TxStateCommitPartitionRequest#senderGroupId()}
* @return Completable future of {@link TxStateResponse}.
*/
public CompletableFuture<TxStateResponse> resolveTxStateFromCoordinator(
- InternalClusterNode coordinatorClusterNode,
- ZonePartitionId commitGrpId,
- UUID txId,
- HybridTimestamp timestamp,
- @Nullable Long senderCurrentConsistencyToken,
- @Nullable ZonePartitionId senderGroupId
+ TxStateResolutionParameters p,
+ InternalClusterNode coordinatorClusterNode
) {
return messagingService.invoke(
coordinatorClusterNode,
TX_MESSAGES_FACTORY.txStateCoordinatorRequest()
- .readTimestamp(timestamp)
- .txId(txId)
- .senderCurrentConsistencyToken(senderCurrentConsistencyToken)
- .senderGroupId(toZonePartitionIdMessageNullable(REPLICA_MESSAGES_FACTORY, senderGroupId))
- .commitPartitionId(toZonePartitionIdMessage(REPLICA_MESSAGES_FACTORY, commitGrpId))
+ .readTimestamp(p.readTimestamp())
+ .txId(p.txId())
+ .senderCurrentConsistencyToken(p.senderCurrentConsistencyToken())
+ .senderGroupId(toZonePartitionIdMessageNullable(REPLICA_MESSAGES_FACTORY, p.senderGroupId()))
+ .commitPartitionId(toZonePartitionIdMessage(REPLICA_MESSAGES_FACTORY, p.commitGroupId()))
.build(),
RPC_TIMEOUT_MILLIS)
.thenApply(resp -> {
@@ -248,6 +240,37 @@ public class TxMessageSender {
});
}
+ /**
+ * Send TxStateCommitPartitionRequest.
+ *
+ * @param p Transaction state resolution parameters.
+ * @param primaryConsistentId Node id to send the request to.
+ * @param consistencyToken Enlistment consistency token.
+ * @return Completable future of {@link TransactionMeta}.
+ */
+ public CompletableFuture<TransactionMeta> resolveTxStateFromPrimaryReplica(
+ TxStateResolutionParameters p,
+ String primaryConsistentId,
+ Long consistencyToken
+ ) {
+ RowIdMessage rowId = p.rowIdMessage(TX_MESSAGES_FACTORY);
+
+ requireNonNull(rowId, "RowIdMessage is required to resolve transaction state from primary replica");
+
+ return replicaService.invoke(
+ primaryConsistentId,
+ TX_MESSAGES_FACTORY.txStatePrimaryReplicaRequest()
+ .groupId(toZonePartitionIdMessage(REPLICA_MESSAGES_FACTORY, p.senderGroupId()))
+ .txId(p.txId())
+ .enlistmentConsistencyToken(consistencyToken)
+ .rowId(rowId)
+ .readTimestamp(p.readTimestamp())
+ .newestCommitTimestamp(p.newestCommitTimestamp())
+ .tableId(p.tableId())
+ .build()
+ );
+ }
+
/**
* Send TxCleanupRecoveryRequest.
*
diff --git a/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TxRecoveryEngine.java b/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TxRecoveryEngine.java
index 27b86f19821..70f9ab8bc21 100644
--- a/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TxRecoveryEngine.java
+++ b/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TxRecoveryEngine.java
@@ -24,6 +24,7 @@ import static org.apache.ignite.internal.tx.TransactionLogUtils.formatTxInfo;
import static org.apache.ignite.internal.tx.TxState.ABORTED;
import static org.apache.ignite.internal.tx.TxState.FINISHING;
import static org.apache.ignite.internal.tx.TxState.isFinalState;
+import static org.apache.ignite.internal.tx.TxStateMetaFinishing.castToFinishing;
import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
import static org.apache.ignite.internal.util.ExceptionUtils.sneakyThrow;
import static org.apache.ignite.lang.ErrorGroups.Transactions.TX_ROLLBACK_ERR;
@@ -41,7 +42,6 @@ import org.apache.ignite.internal.tx.TransactionInternalException;
import org.apache.ignite.internal.tx.TransactionMeta;
import org.apache.ignite.internal.tx.TxManager;
import org.apache.ignite.internal.tx.TxStateMeta;
-import org.apache.ignite.internal.tx.TxStateMetaFinishing;
import org.jetbrains.annotations.Nullable;
/**
@@ -108,7 +108,7 @@ public class TxRecoveryEngine {
if (isFinalState(txStateMeta.txState())) {
res = completedFuture(txStateMeta);
} else if (txStateMeta.txState() == FINISHING) {
- res = ((TxStateMetaFinishing) txStateMeta).txFinishFuture();
+ res = castToFinishing(txId, txStateMeta).txFinishFuture();
} else {
res = failedFuture(new TransactionInternalException(TX_ROLLBACK_ERR, format("Unexpected transaction "
+ "state after recovery [{}, txMeta={}].", formatTxInfo(txId, txManager, false), txStateMeta)));
diff --git a/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TxStateResolutionParameters.java b/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TxStateResolutionParameters.java
new file mode 100644
index 00000000000..f07bc500956
--- /dev/null
+++ b/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TxStateResolutionParameters.java
@@ -0,0 +1,339 @@
+/*
+ * 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.tx.impl;
+
+import static java.util.Objects.requireNonNull;
+import static org.apache.ignite.internal.tx.impl.PlacementDriverHelper.AWAIT_PRIMARY_REPLICA_TIMEOUT;
+
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.replicator.ZonePartitionId;
+import org.apache.ignite.internal.storage.RowId;
+import org.apache.ignite.internal.tx.message.RowIdMessage;
+import org.apache.ignite.internal.tx.message.TxMessagesFactory;
+import org.apache.ignite.internal.tx.message.TxStateCommitPartitionRequest;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Parameters for transaction state resolution request.
+ */
+public class TxStateResolutionParameters {
+ private final UUID txId;
+
+ private final int tableId;
+
+ private final ZonePartitionId commitGroupId;
+
+ private final HybridTimestamp readTimestamp;
+
+ @Nullable
+ private final Long senderCurrentConsistencyToken;
+
+ @Nullable
+ private final ZonePartitionId senderGroupId;
+
+ @Nullable
+ private final HybridTimestamp newestCommitTimestamp;
+
+ @Nullable
+ private final RowId rowId;
+
+ private final long awaitCommitPartitionAvailabilityTimeout;
+
+ private final TimeUnit awaitCommitPartitionAvailabilityTimeUnit;
+
+ private TxStateResolutionParameters(
+ UUID txId,
+ int tableId,
+ ZonePartitionId commitGroupId,
+ HybridTimestamp readTimestamp,
+ @Nullable Long senderCurrentConsistencyToken,
+ @Nullable ZonePartitionId senderGroupId,
+ @Nullable HybridTimestamp newestCommitTimestamp,
+ @Nullable RowId rowId,
+ long awaitCommitPartitionAvailabilityTimeout,
+ TimeUnit awaitCommitPartitionAvailabilityTimeUnit
+ ) {
+ this.txId = txId;
+ this.tableId = tableId;
+ this.commitGroupId = commitGroupId;
+ this.readTimestamp = readTimestamp;
+ this.senderCurrentConsistencyToken = senderCurrentConsistencyToken;
+ this.senderGroupId = senderGroupId;
+ this.newestCommitTimestamp = newestCommitTimestamp;
+ this.rowId = rowId;
+ this.awaitCommitPartitionAvailabilityTimeout = awaitCommitPartitionAvailabilityTimeout;
+ this.awaitCommitPartitionAvailabilityTimeUnit = awaitCommitPartitionAvailabilityTimeUnit;
+ }
+
+ /**
+ * Transaction ID.
+ *
+ * @return Transaction ID.
+ */
+ public UUID txId() {
+ return txId;
+ }
+
+ /**
+ * Table ID.
+ *
+ * @return Table ID.
+ */
+ public int tableId() {
+ return tableId;
+ }
+
+ /**
+ * Commit group ID.
+ *
+ * @return Commit group ID.
+ */
+ public ZonePartitionId commitGroupId() {
+ return commitGroupId;
+ }
+
+ /**
+ * Read timestamp.
+ *
+ * @return Read timestamp.
+ */
+ public HybridTimestamp readTimestamp() {
+ return readTimestamp;
+ }
+
+ /**
+ * Sender's current consistency token. See {@link TxStateCommitPartitionRequest#senderCurrentConsistencyToken()}.
+ *
+ * @return Sender's current consistency token.
+ */
+ public @Nullable Long senderCurrentConsistencyToken() {
+ return senderCurrentConsistencyToken;
+ }
+
+ /**
+ * Sender's group ID. See {@link TxStateCommitPartitionRequest#senderGroupId()}.
+ *
+ * @return Sender's group ID.
+ */
+ public @Nullable ZonePartitionId senderGroupId() {
+ return senderGroupId;
+ }
+
+ /**
+ * Newest commit timestamp known to the sender. Should NOT be {@code null} if present and {@link #rowId} is not {@code null}.
+ *
+ * @return Newest commit timestamp known to the sender.
+ */
+ public @Nullable HybridTimestamp newestCommitTimestamp() {
+ return newestCommitTimestamp;
+ }
+
+ /**
+ * Row ID.
+ *
+ * @return Row ID.
+ */
+ public @Nullable RowId rowId() {
+ return rowId;
+ }
+
+ /**
+ * Creates a {@link RowIdMessage} from the {@link #rowId()}.
+ *
+ * @param txMessagesFactory Transaction messages factory.
+ * @return Row ID message or {@code null} if {@link #rowId()} is {@code null}.
+ */
+ public @Nullable RowIdMessage rowIdMessage(TxMessagesFactory txMessagesFactory) {
+ return rowId == null
+ ? null
+ : txMessagesFactory.rowIdMessage().uuid(rowId.uuid()).partitionId(rowId.partitionId()).build();
+ }
+
+ /**
+ * Get await commit partition availability time unit.
+ *
+ * @return Time unit.
+ */
+ public TimeUnit awaitCommitPartitionAvailabilityTimeUnit() {
+ return awaitCommitPartitionAvailabilityTimeUnit;
+ }
+
+ /**
+ * Get await commit partition availability timeout.
+ *
+ * @return Timeout.
+ */
+ public long awaitCommitPartitionAvailabilityTimeout() {
+ return awaitCommitPartitionAvailabilityTimeout;
+ }
+
+ public static TxStateResolutionTxStateResolutionParametersBuilder txStateResolutionParameters() {
+ return new TxStateResolutionTxStateResolutionParametersBuilder();
+ }
+
+ /**
+ * Builder for {@link TxStateResolutionParameters}.
+ */
+ public static class TxStateResolutionTxStateResolutionParametersBuilder {
+ private UUID txId;
+ private int tableId;
+ private ZonePartitionId commitGroupId;
+ private HybridTimestamp readTimestamp = HybridTimestamp.MIN_VALUE;
+ private Long senderCurrentConsistencyToken;
+ private ZonePartitionId senderGroupId;
+ private HybridTimestamp newestCommitTimestamp;
+ private RowId rowId;
+ private Long awaitCommitPartitionAvailabilityTimeout = (long) AWAIT_PRIMARY_REPLICA_TIMEOUT;
+ private TimeUnit awaitCommitPartitionAvailabilityTimeUnit = TimeUnit.SECONDS;
+
+ /**
+ * Transaction ID.
+ *
+ * @param txId Transaction ID.
+ * @return This builder.
+ */
+ public TxStateResolutionTxStateResolutionParametersBuilder txId(UUID txId) {
+ this.txId = txId;
+
+ return this;
+ }
+
+ /**
+ * Table ID.
+ *
+ * @param tableId Table ID.
+ * @return This builder.
+ */
+ public TxStateResolutionTxStateResolutionParametersBuilder tableId(int tableId) {
+ this.tableId = tableId;
+
+ return this;
+ }
+
+ /**
+ * Commit group ID.
+ *
+ * @param commitGroupId Commit group ID.
+ * @return This builder.
+ */
+ public TxStateResolutionTxStateResolutionParametersBuilder commitGroupId(ZonePartitionId commitGroupId) {
+ this.commitGroupId = commitGroupId;
+
+ return this;
+ }
+
+ /**
+ * Read timestamp.
+ *
+ * @param readTimestamp Read timestamp.
+ * @return This builder.
+ */
+ public TxStateResolutionTxStateResolutionParametersBuilder readTimestamp(HybridTimestamp readTimestamp) {
+ if (readTimestamp != null) {
+ this.readTimestamp = readTimestamp;
+ }
+
+ return this;
+ }
+
+ /**
+ * Sender's group ID.
+ *
+ * @param senderGroupId Sender's group ID.
+ * @return This builder.
+ */
+ public TxStateResolutionTxStateResolutionParametersBuilder senderGroupId(ZonePartitionId senderGroupId) {
+ this.senderGroupId = senderGroupId;
+
+ return this;
+ }
+
+ /**
+ * Sender's current consistency token.
+ *
+ * @param senderCurrentConsistencyToken Sender's current consistency token.
+ * @return This builder.
+ */
+ public TxStateResolutionTxStateResolutionParametersBuilder senderCurrentConsistencyToken(
+ @Nullable Long senderCurrentConsistencyToken
+ ) {
+ this.senderCurrentConsistencyToken = senderCurrentConsistencyToken;
+
+ return this;
+ }
+
+ /**
+ * Row ID and newest commit timestamp known to the sender.
+ *
+ * @param rowId Row ID.
+ * @param newestCommitTimestamp Newest commit timestamp known to the sender.
+ * @return This builder.
+ */
+ public TxStateResolutionTxStateResolutionParametersBuilder rowIdAndNewestCommitTimestamp(
+ RowId rowId,
+ @Nullable HybridTimestamp newestCommitTimestamp
+ ) {
+ this.rowId = rowId;
+ this.newestCommitTimestamp = newestCommitTimestamp;
+
+ return this;
+ }
+
+ /**
+ * Await commit partition availability timeout and time unit.
+ *
+ * @param awaitCommitPartitionAvailabilityTimeout Await commit partition availability timeout.
+ * @param awaitCommitPartitionAvailabilityTimeUnit Await commit partition availability time unit.
+ * @return This builder.
+ */
+ public TxStateResolutionTxStateResolutionParametersBuilder awaitCommitPartitionAvailabilityTimeout(
+ long awaitCommitPartitionAvailabilityTimeout,
+ TimeUnit awaitCommitPartitionAvailabilityTimeUnit
+ ) {
+ this.awaitCommitPartitionAvailabilityTimeout = awaitCommitPartitionAvailabilityTimeout;
+ this.awaitCommitPartitionAvailabilityTimeUnit = awaitCommitPartitionAvailabilityTimeUnit;
+
+ return this;
+ }
+
+ /**
+ * Builds the parameters.
+ *
+ * @return Parameters.
+ */
+ public TxStateResolutionParameters build() {
+ requireNonNull(txId, "txId cannot be null");
+ requireNonNull(commitGroupId, "commitGroupId cannot be null");
+
+ return new TxStateResolutionParameters(
+ txId,
+ tableId,
+ commitGroupId,
+ readTimestamp,
+ senderCurrentConsistencyToken,
+ senderGroupId,
+ newestCommitTimestamp,
+ rowId,
+ awaitCommitPartitionAvailabilityTimeout,
+ awaitCommitPartitionAvailabilityTimeUnit
+ );
+ }
+ }
+}
diff --git a/modules/transactions/src/main/java/org/apache/ignite/internal/tx/message/TxStateCommitPartitionRequest.java b/modules/transactions/src/main/java/org/apache/ignite/internal/tx/message/TxStateCommitPartitionRequest.java
index 46352279e49..b001e2175d0 100644
--- a/modules/transactions/src/main/java/org/apache/ignite/internal/tx/message/TxStateCommitPartitionRequest.java
+++ b/modules/transactions/src/main/java/org/apache/ignite/internal/tx/message/TxStateCommitPartitionRequest.java
@@ -48,4 +48,10 @@ public interface TxStateCommitPartitionRequest extends PrimaryReplicaRequest {
* @return Group id of the sender partition, or {@code null} if the request is not caused by write intent resolution.
*/
@Nullable ZonePartitionIdMessage senderGroupId();
+
+ @Nullable RowIdMessage rowId();
+
+ @Nullable HybridTimestamp newestCommitTimestamp();
+
+ @Nullable Integer tableId();
}
diff --git a/modules/transactions/src/test/java/org/apache/ignite/internal/tx/impl/TransactionStateResolverTest.java b/modules/transactions/src/test/java/org/apache/ignite/internal/tx/impl/TransactionStateResolverTest.java
index f1632b1241a..38a8ff4ded8 100644
--- a/modules/transactions/src/test/java/org/apache/ignite/internal/tx/impl/TransactionStateResolverTest.java
+++ b/modules/transactions/src/test/java/org/apache/ignite/internal/tx/impl/TransactionStateResolverTest.java
@@ -20,10 +20,12 @@ package org.apache.ignite.internal.tx.impl;
import static java.util.concurrent.CompletableFuture.completedFuture;
import static org.apache.ignite.internal.hlc.HybridTimestamp.hybridTimestamp;
import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.impl.TxStateResolutionParameters.txStateResolutionParameters;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.lenient;
@@ -104,7 +106,7 @@ public class TransactionStateResolverTest extends BaseIgniteAbstractTest {
clockService,
clusterNodeResolver,
messagingService,
- placementDriver,
+ new PlacementDriverHelper(placementDriver, clockService),
txMessageSender,
new TxRecoveryEngine(txManager, mock(ClusterNodeResolver.class)),
new Lazy<>(() -> mock(InternalClusterNode.class)),
@@ -139,32 +141,28 @@ public class TransactionStateResolverTest extends BaseIgniteAbstractTest {
.build();
when(txMessageSender.resolveTxStateFromCoordinator(
- any(InternalClusterNode.class),
- eq(commitPartitionId),
- eq(txId),
- any(HybridTimestamp.class),
- any(Long.class),
- any(ZonePartitionId.class)
+ argThat(p -> txId.equals(p.txId())),
+ any(InternalClusterNode.class)
))
.thenReturn(completedFuture(response));
// Mock the commit partition resolution to complete the future.
when(txMessageSender.resolveTxStateFromCommitPartition(
+ any(TxStateResolutionParameters.class),
any(String.class),
- eq(txId),
- eq(commitPartitionId),
- any(Long.class),
- any(Long.class),
- any(ZonePartitionId.class))
+ any(Long.class))
)
.thenReturn(completedFuture(pendingMeta));
CompletableFuture<TransactionMeta> result = resolver.resolveTxState(
- txId,
- commitPartitionId,
- timestamp,
- timestamp.longValue(),
- commitPartitionId
+ txStateResolutionParameters()
+ .txId(txId)
+ .tableId(1)
+ .commitGroupId(commitPartitionId)
+ .readTimestamp(timestamp)
+ .senderGroupId(commitPartitionId)
+ .senderCurrentConsistencyToken(timestamp.longValue())
+ .build()
);
assertThat(result, willCompleteSuccessfully());
@@ -172,23 +170,16 @@ public class TransactionStateResolverTest extends BaseIgniteAbstractTest {
// Verify that coordinator was called with InternalClusterNode.
ArgumentCaptor<InternalClusterNode> nodeCaptor = ArgumentCaptor.forClass(InternalClusterNode.class);
verify(txMessageSender).resolveTxStateFromCoordinator(
- nodeCaptor.capture(),
- eq(commitPartitionId),
- eq(txId),
- any(HybridTimestamp.class),
- any(Long.class),
- any()
+ argThat(p -> txId.equals(p.txId())),
+ nodeCaptor.capture()
);
assertEquals(COORDINATOR_NODE, nodeCaptor.getValue());
// Verify fallback to commit partition was called.
verify(txMessageSender).resolveTxStateFromCommitPartition(
+ argThat(p -> txId.equals(p.txId()) && commitPartitionId.equals(p.commitGroupId())),
any(String.class),
- eq(txId),
- eq(commitPartitionId),
- any(Long.class),
- any(Long.class),
- any()
+ any(Long.class)
);
}
@@ -207,32 +198,28 @@ public class TransactionStateResolverTest extends BaseIgniteAbstractTest {
CompletableFuture<TxStateResponse> failedFuture = CompletableFuture.failedFuture(new RecipientLeftException());
when(txMessageSender.resolveTxStateFromCoordinator(
- any(InternalClusterNode.class),
- eq(commitPartitionId),
- eq(txId),
- any(HybridTimestamp.class),
- any(Long.class),
- any(ZonePartitionId.class))
+ argThat(p -> txId.equals(p.txId())),
+ any(InternalClusterNode.class))
)
.thenReturn(failedFuture);
// Mock the commit partition resolution to complete the future.
TxStateMeta abandonedMeta = new TxStateMeta(TxState.ABANDONED, coordinatorId, commitPartitionId, null, null, null);
when(txMessageSender.resolveTxStateFromCommitPartition(
+ argThat(p -> txId.equals(p.txId()) && commitPartitionId.equals(p.commitGroupId())),
any(String.class),
- eq(txId),
- eq(commitPartitionId),
- any(Long.class),
- any(Long.class),
- any(ZonePartitionId.class)
+ any(Long.class)
))
.thenReturn(completedFuture(abandonedMeta));
CompletableFuture<TransactionMeta> result = resolver.resolveTxState(
- txId,
- commitPartitionId,
- timestamp,
- timestamp.longValue(),
- commitPartitionId
+ txStateResolutionParameters()
+ .txId(txId)
+ .tableId(1)
+ .commitGroupId(commitPartitionId)
+ .readTimestamp(timestamp)
+ .senderGroupId(commitPartitionId)
+ .senderCurrentConsistencyToken(timestamp.longValue())
+ .build()
);
assertThat(result, willCompleteSuccessfully());
@@ -244,12 +231,9 @@ public class TransactionStateResolverTest extends BaseIgniteAbstractTest {
assertEquals(TxState.ABANDONED, afterUpdateState.txState());
// Verify fallback to commit partition was called.
verify(txMessageSender).resolveTxStateFromCommitPartition(
+ argThat(p -> txId.equals(p.txId()) && commitPartitionId.equals(p.commitGroupId())),
any(String.class),
- eq(txId),
- eq(commitPartitionId),
- any(Long.class),
- any(Long.class),
- any()
+ any(Long.class)
);
}
@@ -278,21 +262,20 @@ public class TransactionStateResolverTest extends BaseIgniteAbstractTest {
.build();
when(txMessageSender.resolveTxStateFromCoordinator(
- any(InternalClusterNode.class),
- eq(commitPartitionId),
- eq(txId),
- any(HybridTimestamp.class),
- any(Long.class),
- any(ZonePartitionId.class)
+ argThat(p -> txId.equals(p.txId())),
+ any(InternalClusterNode.class)
))
.thenReturn(completedFuture(response));
CompletableFuture<TransactionMeta> result = resolver.resolveTxState(
- txId,
- commitPartitionId,
- timestamp,
- timestamp.longValue(),
- commitPartitionId
+ txStateResolutionParameters()
+ .txId(txId)
+ .tableId(1)
+ .commitGroupId(commitPartitionId)
+ .readTimestamp(timestamp)
+ .senderGroupId(commitPartitionId)
+ .senderCurrentConsistencyToken(timestamp.longValue())
+ .build()
);
assertThat(result, willCompleteSuccessfully());
@@ -300,24 +283,17 @@ public class TransactionStateResolverTest extends BaseIgniteAbstractTest {
// Verify that coordinator was called with InternalClusterNode.
ArgumentCaptor<InternalClusterNode> nodeCaptor = ArgumentCaptor.forClass(InternalClusterNode.class);
verify(txMessageSender).resolveTxStateFromCoordinator(
- nodeCaptor.capture(),
- eq(commitPartitionId),
- eq(txId),
- any(HybridTimestamp.class),
- any(Long.class),
- any()
+ argThat(p -> txId.equals(p.txId())),
+ nodeCaptor.capture()
);
assertEquals(COORDINATOR_NODE, nodeCaptor.getValue());
// Verify that commit partition fallback was NOT called.
verify(txMessageSender, never())
.resolveTxStateFromCommitPartition(
+ argThat(p -> txId.equals(p.txId()) && commitPartitionId.equals(p.commitGroupId())),
any(String.class),
- eq(txId),
- eq(commitPartitionId),
- any(Long.class),
- any(Long.class),
- any()
+ any(Long.class)
);
// Verify that the transaction meta was updated.
diff --git a/modules/transactions/src/testFixtures/java/org/apache/ignite/internal/tx/test/ItTransactionTestUtils.java b/modules/transactions/src/testFixtures/java/org/apache/ignite/internal/tx/test/ItTransactionTestUtils.java
index a16ea498f51..468168f7cdc 100644
--- a/modules/transactions/src/testFixtures/java/org/apache/ignite/internal/tx/test/ItTransactionTestUtils.java
+++ b/modules/transactions/src/testFixtures/java/org/apache/ignite/internal/tx/test/ItTransactionTestUtils.java
@@ -22,6 +22,7 @@ import static java.util.concurrent.TimeUnit.SECONDS;
import static java.util.stream.Collectors.toSet;
import static org.apache.ignite.internal.distributionzones.rebalance.ZoneRebalanceUtil.stablePartAssignmentsKey;
import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willSucceedFast;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -37,15 +38,19 @@ import org.apache.ignite.internal.app.IgniteImpl;
import org.apache.ignite.internal.lang.ByteArray;
import org.apache.ignite.internal.metastorage.Entry;
import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.apache.ignite.internal.partition.replicator.ZonePartitionReplicaListener;
import org.apache.ignite.internal.partitiondistribution.Assignment;
import org.apache.ignite.internal.partitiondistribution.Assignments;
import org.apache.ignite.internal.placementdriver.ReplicaMeta;
import org.apache.ignite.internal.replicator.PartitionGroupId;
+import org.apache.ignite.internal.replicator.Replica;
import org.apache.ignite.internal.replicator.ZonePartitionId;
+import org.apache.ignite.internal.schema.BinaryRow;
import org.apache.ignite.internal.schema.BinaryRowEx;
import org.apache.ignite.internal.table.RecordBinaryViewImpl;
import org.apache.ignite.internal.table.TableImpl;
-import org.apache.ignite.internal.tx.impl.ReadWriteTransactionImpl;
+import org.apache.ignite.internal.table.distributed.replicator.PartitionReplicaListener;
+import org.apache.ignite.internal.tx.impl.IgniteAbstractTransactionImpl;
import org.apache.ignite.internal.wrapper.Wrappers;
import org.apache.ignite.table.RecordView;
import org.apache.ignite.table.Table;
@@ -96,13 +101,49 @@ public class ItTransactionTestUtils {
*/
public static int partitionIdForTuple(IgniteImpl node, String tableName, Tuple tuple, @Nullable Transaction tx) {
TableImpl table = table(node, tableName);
+
+ BinaryRowEx row = tupleToBinaryRow(node, tableName, tuple, tx, false);
+
+ return table.internalTable().partitionId(row);
+ }
+
+ /**
+ * Calculate the partition id on which the given tuple would be placed.
+ *
+ * @param node Any node in the cluster.
+ * @param tableName Table name.
+ * @param tuple Data tuple.
+ * @param tx Transaction, if present.
+ * @param keyOnly If should serialize only key columns of the tuple.
+ * @return Binary row.
+ */
+ public static BinaryRowEx tupleToBinaryRow(IgniteImpl node, String tableName, Tuple tuple, @Nullable Transaction tx, boolean keyOnly) {
+ TableImpl table = table(node, tableName);
RecordBinaryViewImpl view = unwrapRecordBinaryViewImpl(table.recordView());
- CompletableFuture<BinaryRowEx> rowFut = view.tupleToBinaryRow(tx, tuple);
+ CompletableFuture<BinaryRowEx> rowFut = view.tupleToBinaryRow(tx, tuple, keyOnly);
assertThat(rowFut, willCompleteSuccessfully());
- BinaryRowEx row = rowFut.join();
- return table.internalTable().partitionId(row);
+ return rowFut.join();
+ }
+
+ /**
+ * Calculate the partition id on which the given tuple would be placed.
+ *
+ * @param node Any node in the cluster.
+ * @param tableName Table name.
+ * @param row Data row.
+ * @param tx Transaction, if present.
+ * @return Tuple.
+ */
+ public static Tuple binaryRowToTuple(IgniteImpl node, String tableName, BinaryRow row, @Nullable Transaction tx) {
+ TableImpl table = table(node, tableName);
+ RecordBinaryViewImpl view = unwrapRecordBinaryViewImpl(table.recordView());
+
+ CompletableFuture<Tuple> tupleFut = view.binaryRowToTuple(tx, row);
+ assertThat(tupleFut, willCompleteSuccessfully());
+
+ return tupleFut.join();
}
/**
@@ -205,7 +246,7 @@ public class ItTransactionTestUtils {
* @return Transaction id.
*/
public static UUID txId(Transaction tx) {
- return ((ReadWriteTransactionImpl) unwrapIgniteTransaction(tx)).id();
+ return ((IgniteAbstractTransactionImpl) unwrapIgniteTransaction(tx)).id();
}
/**
@@ -228,6 +269,23 @@ public class ItTransactionTestUtils {
return primaryReplicaFut.join();
}
+ /**
+ * Returns partition replica listener instance from the given node for the given partition and table.
+ *
+ * @param node Ignite node.
+ * @param groupId Group id.
+ * @param tableId Table id.
+ * @return Partition replica listener.
+ */
+ public static PartitionReplicaListener partitionReplicaListener(IgniteImpl node, ZonePartitionId groupId, int tableId) {
+ CompletableFuture<Replica> replicaFut = node.replicaManager().replica(groupId);
+ assertThat(replicaFut, willSucceedFast());
+ Replica replica = replicaFut.join();
+
+ ZonePartitionReplicaListener listener = (ZonePartitionReplicaListener) replica.listener();
+ return (PartitionReplicaListener) listener.tableReplicaProcessors().get(tableId);
+ }
+
/**
* Executes a closure in a transaction.
*