Search in sources :

Example 1 with RaftConfiguration

use of org.apache.ratis.server.RaftConfiguration in project incubator-ratis by apache.

the class TestRaftConfiguration method testIsHighestPriority.

@Test
public void testIsHighestPriority() {
    Integer node1 = 0;
    Integer node2 = 1;
    Integer node3 = 2;
    PeerConfiguration peerConfig = new PeerConfiguration(raftPeersWithPriority(node1, node2, node3));
    RaftConfiguration config = RaftConfigurationImpl.newBuilder().setConf(peerConfig).build();
    RaftPeer[] allRaftPeers = peerConfig.getPeers().toArray(new RaftPeer[peerConfig.getPeers().size()]);
    // First member should not have highest priority
    Assert.assertFalse(RaftServerTestUtil.isHighestPriority(config, allRaftPeers[0].getId()));
    // Last member should have highest priority
    Assert.assertTrue(RaftServerTestUtil.isHighestPriority(config, allRaftPeers[allRaftPeers.length - 1].getId()));
    // Should return false for non existent peer id
    Assert.assertFalse(RaftServerTestUtil.isHighestPriority(config, RaftPeerId.valueOf("123456789")));
}
Also used : RaftConfiguration(org.apache.ratis.server.RaftConfiguration) RaftPeer(org.apache.ratis.protocol.RaftPeer) Test(org.junit.Test) BaseTest(org.apache.ratis.BaseTest)

Example 2 with RaftConfiguration

use of org.apache.ratis.server.RaftConfiguration in project incubator-ratis by apache.

the class LeaderProtoUtils method toInstallSnapshotRequestProtoBuilder.

private static InstallSnapshotRequestProto.Builder toInstallSnapshotRequestProtoBuilder(RaftServer.Division server, RaftPeerId replyId) {
    // term is not going to used by installSnapshot to update the RaftConfiguration
    final RaftConfiguration conf = server.getRaftConf();
    final LogEntryProto confLogEntryProto = LogProtoUtils.toLogEntryProto(conf, null, conf.getLogEntryIndex());
    return InstallSnapshotRequestProto.newBuilder().setServerRequest(ClientProtoUtils.toRaftRpcRequestProtoBuilder(server.getMemberId(), replyId)).setLeaderTerm(server.getInfo().getCurrentTerm()).setLastRaftConfigurationLogEntryProto(confLogEntryProto);
}
Also used : LogEntryProto(org.apache.ratis.proto.RaftProtos.LogEntryProto) RaftConfiguration(org.apache.ratis.server.RaftConfiguration)

Example 3 with RaftConfiguration

use of org.apache.ratis.server.RaftConfiguration in project incubator-ratis by apache.

the class ConfigurationManager method addConfiguration.

synchronized void addConfiguration(RaftConfiguration conf) {
    final long logIndex = conf.getLogEntryIndex();
    final RaftConfiguration found = configurations.get(logIndex);
    if (found != null) {
        Preconditions.assertTrue(found.equals(conf));
        return;
    }
    addRaftConfigurationImpl(logIndex, (RaftConfigurationImpl) conf);
}
Also used : RaftConfiguration(org.apache.ratis.server.RaftConfiguration)

Example 4 with RaftConfiguration

use of org.apache.ratis.server.RaftConfiguration in project incubator-ratis by apache.

the class RaftReconfigurationBaseTest method checkPriority.

private void checkPriority(CLUSTER cluster, RaftGroupId groupId, List<RaftPeer> peersWithPriority) throws InterruptedException {
    RaftTestUtil.waitForLeader(cluster, groupId);
    for (int i = 0; i < peersWithPriority.size(); i++) {
        RaftPeerId peerId = peersWithPriority.get(i).getId();
        final RaftServer.Division server = cluster.getDivision(peerId, groupId);
        final RaftConfiguration conf = server.getRaftConf();
        for (int j = 0; j < peersWithPriority.size(); j++) {
            int priorityInConf = conf.getPeer(peersWithPriority.get(j).getId()).getPriority();
            Assert.assertEquals(priorityInConf, peersWithPriority.get(j).getPriority());
        }
    }
}
Also used : RaftConfiguration(org.apache.ratis.server.RaftConfiguration) RaftServer(org.apache.ratis.server.RaftServer) RaftPeerId(org.apache.ratis.protocol.RaftPeerId)

Example 5 with RaftConfiguration

use of org.apache.ratis.server.RaftConfiguration in project incubator-ratis by apache.

the class RaftReconfigurationBaseTest method runTestNoChangeRequest.

void runTestNoChangeRequest(CLUSTER cluster) throws Exception {
    final RaftServer.Division leader = RaftTestUtil.waitForLeader(cluster);
    try (final RaftClient client = cluster.createClient(leader.getId())) {
        client.io().send(new SimpleMessage("m"));
        final RaftLog leaderLog = leader.getRaftLog();
        final long committedIndex = leaderLog.getLastCommittedIndex();
        final RaftConfiguration confBefore = cluster.getLeader().getRaftConf();
        // no real configuration change in the request
        final RaftClientReply reply = client.admin().setConfiguration(cluster.getPeers().toArray(RaftPeer.emptyArray()));
        Assert.assertTrue(reply.isSuccess());
        final long newCommittedIndex = leaderLog.getLastCommittedIndex();
        for (long i = committedIndex + 1; i <= newCommittedIndex; i++) {
            final LogEntryProto e = leaderLog.get(i);
            Assert.assertTrue(e.hasMetadataEntry());
        }
        Assert.assertSame(confBefore, cluster.getLeader().getRaftConf());
    }
}
Also used : LogEntryProto(org.apache.ratis.proto.RaftProtos.LogEntryProto) RaftClientReply(org.apache.ratis.protocol.RaftClientReply) RaftConfiguration(org.apache.ratis.server.RaftConfiguration) RaftServer(org.apache.ratis.server.RaftServer) SimpleMessage(org.apache.ratis.RaftTestUtil.SimpleMessage) RaftClient(org.apache.ratis.client.RaftClient) RaftLog(org.apache.ratis.server.raftlog.RaftLog)

Aggregations

RaftConfiguration (org.apache.ratis.server.RaftConfiguration)5 LogEntryProto (org.apache.ratis.proto.RaftProtos.LogEntryProto)2 RaftServer (org.apache.ratis.server.RaftServer)2 BaseTest (org.apache.ratis.BaseTest)1 SimpleMessage (org.apache.ratis.RaftTestUtil.SimpleMessage)1 RaftClient (org.apache.ratis.client.RaftClient)1 RaftClientReply (org.apache.ratis.protocol.RaftClientReply)1 RaftPeer (org.apache.ratis.protocol.RaftPeer)1 RaftPeerId (org.apache.ratis.protocol.RaftPeerId)1 RaftLog (org.apache.ratis.server.raftlog.RaftLog)1 Test (org.junit.Test)1