Search in sources :

Example 1 with ThroughputSnapshotThrottle

use of org.apache.ignite.raft.jraft.storage.snapshot.ThroughputSnapshotThrottle in project ignite-3 by apache.

the class ItNodeTest method testInstallSnapshotWithThrottle.

@Test
public void testInstallSnapshotWithThrottle() throws Exception {
    List<PeerId> peers = TestUtils.generatePeers(3);
    cluster = new TestCluster("unitest", dataPath, peers, testInfo);
    for (PeerId peer : peers) assertTrue(cluster.start(peer.getEndpoint(), false, 200, false, new ThroughputSnapshotThrottle(1024, 1)));
    cluster.waitLeader();
    // get leader
    Node leader = cluster.getLeader();
    assertNotNull(leader);
    cluster.ensureLeader(leader);
    // apply tasks to leader
    sendTestTaskAndWait(leader);
    cluster.ensureSame();
    // stop follower1
    List<Node> followers = cluster.getFollowers();
    assertEquals(2, followers.size());
    Endpoint followerAddr = followers.get(0).getNodeId().getPeerId().getEndpoint();
    assertTrue(cluster.stop(followerAddr));
    cluster.waitLeader();
    // apply something more
    sendTestTaskAndWait(leader, 10, RaftError.SUCCESS);
    Thread.sleep(1000);
    // trigger leader snapshot
    triggerLeaderSnapshot(cluster, leader);
    // apply something more
    sendTestTaskAndWait(leader, 20, RaftError.SUCCESS);
    // trigger leader snapshot
    triggerLeaderSnapshot(cluster, leader, 2);
    // wait leader to compact logs
    Thread.sleep(1000);
    // restart follower.
    cluster.clean(followerAddr);
    assertTrue(cluster.start(followerAddr, true, 300, false, new ThroughputSnapshotThrottle(1024, 1)));
    Thread.sleep(2000);
    cluster.ensureSame();
    assertEquals(3, cluster.getFsms().size());
    for (MockStateMachine fsm : cluster.getFsms()) assertEquals(30, fsm.getLogs().size());
}
Also used : Endpoint(org.apache.ignite.raft.jraft.util.Endpoint) ThroughputSnapshotThrottle(org.apache.ignite.raft.jraft.storage.snapshot.ThroughputSnapshotThrottle) Node(org.apache.ignite.raft.jraft.Node) PeerId(org.apache.ignite.raft.jraft.entity.PeerId) Test(org.junit.jupiter.api.Test)

Example 2 with ThroughputSnapshotThrottle

use of org.apache.ignite.raft.jraft.storage.snapshot.ThroughputSnapshotThrottle in project ignite-3 by apache.

the class ItNodeTest method testInstallLargeSnapshotWithThrottle.

// TODO add test for timeout on snapshot install https://issues.apache.org/jira/browse/IGNITE-14832
@Test
@Disabled("https://issues.apache.org/jira/browse/IGNITE-16467")
public void testInstallLargeSnapshotWithThrottle() throws Exception {
    List<PeerId> peers = TestUtils.generatePeers(4);
    cluster = new TestCluster("unitest", dataPath, peers.subList(0, 3), testInfo);
    for (int i = 0; i < peers.size() - 1; i++) {
        PeerId peer = peers.get(i);
        boolean started = cluster.start(peer.getEndpoint(), false, 200, false);
        assertTrue(started);
    }
    cluster.waitLeader();
    // get leader
    Node leader = cluster.getLeader();
    assertNotNull(leader);
    cluster.ensureLeader(leader);
    // apply tasks to leader
    sendTestTaskAndWait(leader, 0, RaftError.SUCCESS);
    cluster.ensureSame();
    // apply something more
    for (int i = 1; i < 100; i++) sendTestTaskAndWait(leader, i * 10, RaftError.SUCCESS);
    Thread.sleep(1000);
    // trigger leader snapshot
    triggerLeaderSnapshot(cluster, leader);
    // apply something more
    for (int i = 100; i < 200; i++) sendTestTaskAndWait(leader, i * 10, RaftError.SUCCESS);
    // trigger leader snapshot
    triggerLeaderSnapshot(cluster, leader, 2);
    // wait leader to compact logs
    Thread.sleep(1000);
    // add follower
    PeerId newPeer = peers.get(3);
    SnapshotThrottle snapshotThrottle = new ThroughputSnapshotThrottle(128, 1);
    boolean started = cluster.start(newPeer.getEndpoint(), false, 300, false, snapshotThrottle);
    assertTrue(started);
    CountDownLatch latch = new CountDownLatch(1);
    leader.addPeer(newPeer, status -> {
        assertTrue(status.isOk(), status.toString());
        latch.countDown();
    });
    waitLatch(latch);
    cluster.ensureSame();
    assertEquals(4, cluster.getFsms().size());
    for (MockStateMachine fsm : cluster.getFsms()) assertEquals(2000, fsm.getLogs().size());
}
Also used : ThroughputSnapshotThrottle(org.apache.ignite.raft.jraft.storage.snapshot.ThroughputSnapshotThrottle) Node(org.apache.ignite.raft.jraft.Node) SnapshotThrottle(org.apache.ignite.raft.jraft.storage.SnapshotThrottle) ThroughputSnapshotThrottle(org.apache.ignite.raft.jraft.storage.snapshot.ThroughputSnapshotThrottle) CountDownLatch(java.util.concurrent.CountDownLatch) Endpoint(org.apache.ignite.raft.jraft.util.Endpoint) PeerId(org.apache.ignite.raft.jraft.entity.PeerId) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

Node (org.apache.ignite.raft.jraft.Node)2 PeerId (org.apache.ignite.raft.jraft.entity.PeerId)2 ThroughputSnapshotThrottle (org.apache.ignite.raft.jraft.storage.snapshot.ThroughputSnapshotThrottle)2 Endpoint (org.apache.ignite.raft.jraft.util.Endpoint)2 Test (org.junit.jupiter.api.Test)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 SnapshotThrottle (org.apache.ignite.raft.jraft.storage.SnapshotThrottle)1 Disabled (org.junit.jupiter.api.Disabled)1