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();
}
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;
}
}
Aggregations