You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "tkalkirill (via GitHub)" <gi...@apache.org> on 2023/05/31 13:54:30 UTC

[GitHub] [ignite-3] tkalkirill commented on a diff in pull request #2120: IGNITE-19053 Handle the case of changing the leader of the raft group when building the index

tkalkirill commented on code in PR #2120:
URL: https://github.com/apache/ignite-3/pull/2120#discussion_r1211760247


##########
modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItBuildIndexTest.java:
##########
@@ -46,13 +65,103 @@ public class ItBuildIndexTest extends ClusterPerClassIntegrationTest {
     void tearDown() {
         sql("DROP TABLE IF EXISTS " + TABLE_NAME);
         sql("DROP ZONE IF EXISTS " + ZONE_NAME);
+
+        CLUSTER_NODES.stream()
+                .map(IgniteImpl.class::cast)
+                .forEach(IgniteImpl::stopDroppingMessages);
     }
 
     @ParameterizedTest(name = "replicas : {0}")
     @MethodSource("replicas")
     void testBuildIndexOnStableTopology(int replicas) throws Exception {
         int partitions = 2;
 
+        createAndPopulateTable(replicas, partitions);
+
+        createIndex(INDEX_NAME);
+
+        checkIndexBuild(partitions, replicas, INDEX_NAME);
+
+        assertQuery(IgniteStringFormatter.format("SELECT * FROM {} WHERE i1 > 0", TABLE_NAME))
+                .matches(containsIndexScan("PUBLIC", TABLE_NAME.toUpperCase(), INDEX_NAME.toUpperCase()))
+                .returns(1, 1)
+                .returns(2, 2)
+                .returns(3, 3)
+                .returns(4, 4)
+                .returns(5, 5)
+                .check();
+    }
+
+    @Test
+    void testChangePrimaryReplicaOnMiddleBuildIndex() throws Exception {
+        prepareBuildIndexToChangePrimaryReplica();
+
+        // Let's change the primary replica for partition 0.
+        List<Peer> peers = collectPeers(0);
+
+        Peer newPrimaryPeer = peers.get(1);
+
+        IgniteImpl newPrimary = findByConsistentId(newPrimaryPeer.consistentId());
+        assertNotNull(newPrimary);
+
+        CompletableFuture<Integer> sendBuildIndexCommandFuture = new CompletableFuture<>();
+
+        newPrimary.dropMessages(waitSendBuildIndexCommand(sendBuildIndexCommandFuture, false));
+
+        RaftGroupService raftClient = getRaftClient(newPrimary, 0);
+
+        assertThat(raftClient.transferLeadership(newPrimaryPeer), willSucceedFast());
+
+        // Make sure that the index build command will be sent from the new primary replica.
+        assertThat(sendBuildIndexCommandFuture, willSucceedFast());
+
+        // Let's make sure that the indexes are eventually built.
+        checkIndexBuild(1, nodes(), INDEX_NAME);
+    }
+
+    /**
+     * Prepares an index build for a primary replica change.
+     * <ul>
+     *     <li>Creates a table (replicas = {@link #nodes()}, partitions = 1) and populates it;</li>
+     *     <li>Creates an index;</li>
+     *     <li>Drop send {@link BuildIndexCommand} from the primary replica.</li>

Review Comment:
   I'll leave it as is.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

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