Search in sources :

Example 6 with RaftGroup

use of org.apache.ratis.protocol.RaftGroup in project incubator-ratis by apache.

the class ReinitializationBaseTest method testReinitialize.

@Test
public void testReinitialize() throws Exception {
    final MiniRaftCluster cluster = getCluster(0);
    LOG.info("Start testReinitialize" + cluster.printServers());
    // Start server with an empty conf
    final RaftGroupId groupId = RaftGroupId.randomId();
    final RaftGroup group = new RaftGroup(groupId);
    final List<RaftPeerId> ids = Arrays.stream(MiniRaftCluster.generateIds(3, 0)).map(RaftPeerId::valueOf).collect(Collectors.toList());
    ids.forEach(id -> cluster.putNewServer(id, group, true));
    LOG.info("putNewServer: " + cluster.printServers());
    cluster.start();
    LOG.info("start: " + cluster.printServers());
    // Make sure that there are no leaders.
    TimeUnit.SECONDS.sleep(1);
    Assert.assertNull(cluster.getLeader());
    // Reinitialize servers
    final RaftGroup newGroup = new RaftGroup(groupId, cluster.getPeers());
    final RaftClient client = cluster.createClient(newGroup);
    for (RaftPeer p : newGroup.getPeers()) {
        client.reinitialize(newGroup, p.getId());
    }
    Assert.assertNotNull(RaftTestUtil.waitForLeader(cluster, true));
    cluster.shutdown();
}
Also used : MiniRaftCluster(org.apache.ratis.MiniRaftCluster) RaftGroupId(org.apache.ratis.protocol.RaftGroupId) RaftGroup(org.apache.ratis.protocol.RaftGroup) RaftPeerId(org.apache.ratis.protocol.RaftPeerId) RaftPeer(org.apache.ratis.protocol.RaftPeer) RaftClient(org.apache.ratis.client.RaftClient) Test(org.junit.Test) BaseTest(org.apache.ratis.BaseTest)

Example 7 with RaftGroup

use of org.apache.ratis.protocol.RaftGroup in project alluxio by Alluxio.

the class RaftJournalSystem method getCurrentGroup.

/**
 * @return current raft group
 */
@VisibleForTesting
public synchronized RaftGroup getCurrentGroup() {
    try {
        Iterator<RaftGroup> groupIter = mServer.getGroups().iterator();
        Preconditions.checkState(groupIter.hasNext(), "no group info found");
        RaftGroup group = groupIter.next();
        Preconditions.checkState(group.getGroupId() == RAFT_GROUP_ID, String.format("Invalid group id %s, expecting %s", group.getGroupId(), RAFT_GROUP_ID));
        return group;
    } catch (IOException | IllegalStateException e) {
        LogUtils.warnWithException(LOG, "Failed to get raft group, falling back to initial group", e);
        return mRaftGroup;
    }
}
Also used : RaftGroup(org.apache.ratis.protocol.RaftGroup) IOException(java.io.IOException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

RaftGroup (org.apache.ratis.protocol.RaftGroup)7 IOException (java.io.IOException)3 RaftClient (org.apache.ratis.client.RaftClient)3 RaftProperties (org.apache.ratis.conf.RaftProperties)3 RaftPeer (org.apache.ratis.protocol.RaftPeer)3 RaftPeerId (org.apache.ratis.protocol.RaftPeerId)3 BaseTest (org.apache.ratis.BaseTest)2 MiniRaftCluster (org.apache.ratis.MiniRaftCluster)2 RaftGroupId (org.apache.ratis.protocol.RaftGroupId)2 Test (org.junit.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 Level (org.apache.log4j.Level)1 RaftTestUtil (org.apache.ratis.RaftTestUtil)1