This is an automated email from the ASF dual-hosted git repository.
ibessonov 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 5269927cca IGNITE-18248 Introduce LeaderOrTxState class instead of
IgniteBiTuple (#1374)
5269927cca is described below
commit 5269927cca002b635b3768570aa9e2f1c7e06064
Author: Alexander Polovtcev <[email protected]>
AuthorDate: Thu Nov 24 13:18:06 2022 +0300
IGNITE-18248 Introduce LeaderOrTxState class instead of IgniteBiTuple
(#1374)
---
.../distributed/replicator/LeaderOrTxState.java | 57 ++++++++++++++++++++++
.../replicator/PartitionReplicaListener.java | 21 ++++----
.../distributed/replicator/PlacementDriver.java | 9 ++--
.../replication/PartitionReplicaListenerTest.java | 30 ++++++------
4 files changed, 85 insertions(+), 32 deletions(-)
diff --git
a/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/LeaderOrTxState.java
b/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/LeaderOrTxState.java
new file mode 100644
index 0000000000..d36859d084
--- /dev/null
+++
b/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/LeaderOrTxState.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.table.distributed.replicator;
+
+import java.io.Serializable;
+import org.apache.ignite.internal.tx.TxMeta;
+import org.apache.ignite.internal.tx.message.TxStateReplicaRequest;
+import org.apache.ignite.network.ClusterNode;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Response for the {@link TxStateReplicaRequest}. Can contain either the
Partition Group leader, which should be
+ * queried for the TX Meta, or the TX Meta itself.
+ */
+public class LeaderOrTxState implements Serializable {
+ private static final long serialVersionUID = -3555591755828355117L;
+
+ @Nullable
+ private final ClusterNode leader;
+
+ @Nullable
+ private final TxMeta txMeta;
+
+ /**
+ * Creates a response.
+ *
+ * @param leader Leader node.
+ * @param txMeta TX meta.
+ */
+ public LeaderOrTxState(@Nullable ClusterNode leader, @Nullable TxMeta
txMeta) {
+ this.leader = leader;
+ this.txMeta = txMeta;
+ }
+
+ public @Nullable ClusterNode leader() {
+ return leader;
+ }
+
+ public @Nullable TxMeta txMeta() {
+ return txMeta;
+ }
+}
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 b7bb6b3b91..dbc0c2585f 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
@@ -131,7 +131,7 @@ public class PartitionReplicaListener implements
ReplicaListener {
private final int partId;
/** Primary key index. */
- public final Lazy<TableSchemaAwareIndexStorage> pkIndexStorage;
+ private final Lazy<TableSchemaAwareIndexStorage> pkIndexStorage;
/** Secondary indices. */
private final Supplier<Map<UUID, TableSchemaAwareIndexStorage>>
secondaryIndexStorages;
@@ -303,19 +303,16 @@ public class PartitionReplicaListener implements
ReplicaListener {
private CompletableFuture<Object>
processTxStateReplicaRequest(TxStateReplicaRequest request) {
return raftClient.refreshAndGetLeaderWithTerm()
.thenCompose(replicaAndTerm -> {
- String leaderId =
replicaAndTerm.leader().consistentId();
+ Peer leader = replicaAndTerm.leader();
- if
(topologyService.localMember().name().equals(leaderId)) {
+ if (isLocalPeerChecker.apply(leader)) {
+ CompletableFuture<TxMeta> txStateFut =
getTxStateConcurrently(request);
- CompletableFuture<TxMeta> txStateFut =
getTxStateConcurrently(request);
-
- return txStateFut.thenApply(txMeta -> new
IgniteBiTuple<>(txMeta, null));
- } else {
- return completedFuture(
- new IgniteBiTuple<>(null,
topologyService.getByConsistentId(leaderId)));
- }
- }
- );
+ return txStateFut.thenApply(txMeta -> new
LeaderOrTxState(null, txMeta));
+ } else {
+ return completedFuture(new
LeaderOrTxState(topologyService.getByConsistentId(leader.consistentId()),
null));
+ }
+ });
}
/**
diff --git
a/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PlacementDriver.java
b/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PlacementDriver.java
index fc5fecee45..9710a5f0d8 100644
---
a/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PlacementDriver.java
+++
b/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PlacementDriver.java
@@ -26,7 +26,6 @@ import org.apache.ignite.internal.replicator.ReplicaService;
import org.apache.ignite.internal.replicator.ReplicationGroupId;
import org.apache.ignite.internal.tx.TxMeta;
import org.apache.ignite.internal.tx.message.TxStateReplicaRequest;
-import org.apache.ignite.lang.IgniteBiTuple;
import org.apache.ignite.network.ClusterNode;
/**
@@ -85,14 +84,14 @@ public class PlacementDriver {
ClusterNode nodeToSend =
primaryReplicaMapping.get(replicaGrp).iterator().next();
replicaService.invoke(nodeToSend, request).thenAccept(resp -> {
- assert resp instanceof IgniteBiTuple : "Unsupported response type
[type=" + resp.getClass().getSimpleName() + ']';
+ assert resp instanceof LeaderOrTxState : "Unsupported response
type [type=" + resp.getClass().getSimpleName() + ']';
- IgniteBiTuple<TxMeta, ClusterNode> stateAndLeader =
(IgniteBiTuple) resp;
+ LeaderOrTxState stateAndLeader = (LeaderOrTxState) resp;
- ClusterNode nextNodeToSend = stateAndLeader.get2();
+ ClusterNode nextNodeToSend = stateAndLeader.leader();
if (nextNodeToSend == null) {
- resFut.complete(stateAndLeader.get1());
+ resFut.complete(stateAndLeader.txMeta());
} else {
LinkedHashSet<ClusterNode> newAssignment = new
LinkedHashSet<>();
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 e01e07cd28..a042252642 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
@@ -70,6 +70,7 @@ import
org.apache.ignite.internal.table.distributed.IndexLocker;
import org.apache.ignite.internal.table.distributed.SortedIndexLocker;
import org.apache.ignite.internal.table.distributed.TableMessagesFactory;
import
org.apache.ignite.internal.table.distributed.TableSchemaAwareIndexStorage;
+import org.apache.ignite.internal.table.distributed.replicator.LeaderOrTxState;
import
org.apache.ignite.internal.table.distributed.replicator.PartitionReplicaListener;
import org.apache.ignite.internal.table.distributed.replicator.PlacementDriver;
import
org.apache.ignite.internal.table.distributed.replicator.TablePartitionId;
@@ -87,7 +88,6 @@ import
org.apache.ignite.internal.tx.message.TxMessagesFactory;
import org.apache.ignite.internal.tx.storage.state.test.TestTxStateStorage;
import org.apache.ignite.internal.util.Lazy;
import org.apache.ignite.internal.util.PendingComparableValuesTracker;
-import org.apache.ignite.lang.IgniteBiTuple;
import org.apache.ignite.lang.IgniteException;
import org.apache.ignite.network.ClusterNode;
import org.apache.ignite.network.NetworkAddress;
@@ -266,7 +266,7 @@ public class PartitionReplicaListenerTest extends
IgniteAbstractTest {
txStateStorage,
topologySrv,
placementDriver,
- peer -> true
+ peer -> localNode.name().equals(peer.consistentId())
);
marshallerFactory = new ReflectionMarshallerFactory();
@@ -295,16 +295,16 @@ public class PartitionReplicaListenerTest extends
IgniteAbstractTest {
@Test
public void testTxStateReplicaRequestEmptyState() {
- CompletableFuture fut =
partitionReplicaListener.invoke(TX_MESSAGES_FACTORY.txStateReplicaRequest()
+ CompletableFuture<Object> fut =
partitionReplicaListener.invoke(TX_MESSAGES_FACTORY.txStateReplicaRequest()
.groupId(grpId)
.commitTimestamp(clock.now())
.txId(Timestamp.nextVersion().toUuid())
.build());
- IgniteBiTuple<Peer, Long> tuple = (IgniteBiTuple<Peer, Long>)
fut.join();
+ LeaderOrTxState tuple = (LeaderOrTxState) fut.join();
- assertNull(tuple.get1());
- assertNull(tuple.get2());
+ assertNull(tuple.leader());
+ assertNull(tuple.txMeta());
}
@Test
@@ -315,33 +315,33 @@ public class PartitionReplicaListenerTest extends
IgniteAbstractTest {
HybridTimestamp readTimestamp = clock.now();
- CompletableFuture fut =
partitionReplicaListener.invoke(TX_MESSAGES_FACTORY.txStateReplicaRequest()
+ CompletableFuture<Object> fut =
partitionReplicaListener.invoke(TX_MESSAGES_FACTORY.txStateReplicaRequest()
.groupId(grpId)
.commitTimestamp(readTimestamp)
.txId(txId)
.build());
- IgniteBiTuple<TxMeta, ClusterNode> tuple = (IgniteBiTuple<TxMeta,
ClusterNode>) fut.join();
+ LeaderOrTxState tuple = (LeaderOrTxState) fut.join();
- assertEquals(TxState.COMMITED, tuple.get1().txState());
- assertTrue(readTimestamp.compareTo(tuple.get1().commitTimestamp()) >
0);
- assertNull(tuple.get2());
+ assertEquals(TxState.COMMITED, tuple.txMeta().txState());
+ assertTrue(readTimestamp.compareTo(tuple.txMeta().commitTimestamp()) >
0);
+ assertNull(tuple.leader());
}
@Test
public void testTxStateReplicaRequestMissLeaderMiss() {
localLeader = false;
- CompletableFuture fut =
partitionReplicaListener.invoke(TX_MESSAGES_FACTORY.txStateReplicaRequest()
+ CompletableFuture<Object> fut =
partitionReplicaListener.invoke(TX_MESSAGES_FACTORY.txStateReplicaRequest()
.groupId(grpId)
.commitTimestamp(clock.now())
.txId(Timestamp.nextVersion().toUuid())
.build());
- IgniteBiTuple<Peer, Long> tuple = (IgniteBiTuple<Peer, Long>)
fut.join();
+ LeaderOrTxState tuple = (LeaderOrTxState) fut.join();
- assertNull(tuple.get1());
- assertNotNull(tuple.get2());
+ assertNull(tuple.txMeta());
+ assertNotNull(tuple.leader());
}
@Test