Search in sources :

Example 1 with RaftGroupMemberId

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

the class MemoryRaftLogTest method testEntryPerformTruncation.

@Test
public void testEntryPerformTruncation() throws Exception {
    final RaftProperties prop = new RaftProperties();
    prop.setClass(MiniRaftCluster.STATEMACHINE_CLASS_KEY, SimpleStateMachine4Testing.class, StateMachine.class);
    final RaftPeerId peerId = RaftPeerId.valueOf("s0");
    final RaftGroupId groupId = RaftGroupId.randomId();
    final RaftGroupMemberId memberId = RaftGroupMemberId.valueOf(peerId, groupId);
    MemoryRaftLog raftLog = new MemoryRaftLog(memberId, () -> -1, prop);
    raftLog.open(RaftLog.INVALID_LOG_INDEX, null);
    LogEntryProto[] entries1 = new LogEntryProto[2];
    entries1[0] = LogEntryProto.newBuilder().setIndex(0).setTerm(0).build();
    entries1[1] = LogEntryProto.newBuilder().setIndex(1).setTerm(0).build();
    raftLog.append(entries1).forEach(CompletableFuture::join);
    LogEntryProto[] entries2 = new LogEntryProto[1];
    entries2[0] = LogEntryProto.newBuilder().setIndex(0).setTerm(2).build();
    raftLog.append(entries2).forEach(CompletableFuture::join);
    final LogEntryHeader[] termIndices = raftLog.getEntries(0, 10);
    assertEquals(1, termIndices.length);
    assertEquals(entries2[0].getIndex(), termIndices[0].getIndex());
    assertEquals(entries2[0].getTerm(), termIndices[0].getTerm());
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) LogEntryProto(org.apache.ratis.proto.RaftProtos.LogEntryProto) LogEntryHeader(org.apache.ratis.server.raftlog.LogEntryHeader) RaftProperties(org.apache.ratis.conf.RaftProperties) RaftGroupId(org.apache.ratis.protocol.RaftGroupId) RaftPeerId(org.apache.ratis.protocol.RaftPeerId) RaftGroupMemberId(org.apache.ratis.protocol.RaftGroupMemberId) Test(org.junit.Test) BaseTest(org.apache.ratis.BaseTest)

Example 2 with RaftGroupMemberId

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

the class TestLeaderElectionMetrics method setUp.

@BeforeClass
public static void setUp() {
    RaftGroupId raftGroupId = RaftGroupId.randomId();
    RaftPeerId raftPeerId = RaftPeerId.valueOf("TestId");
    RaftGroupMemberId raftGroupMemberId = RaftGroupMemberId.valueOf(raftPeerId, raftGroupId);
    leaderElectionMetrics = LeaderElectionMetrics.getLeaderElectionMetrics(raftGroupMemberId, () -> 1000L);
    ratisMetricRegistry = leaderElectionMetrics.getRegistry();
}
Also used : RaftGroupId(org.apache.ratis.protocol.RaftGroupId) RaftPeerId(org.apache.ratis.protocol.RaftPeerId) RaftGroupMemberId(org.apache.ratis.protocol.RaftGroupMemberId) BeforeClass(org.junit.BeforeClass)

Example 3 with RaftGroupMemberId

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

the class TestLogAppenderMetrics method setup.

@Before
public void setup() {
    RaftGroupId raftGroupId = RaftGroupId.randomId();
    raftPeerId = RaftPeerId.valueOf("TestId");
    RaftGroupMemberId raftGroupMemberId = RaftGroupMemberId.valueOf(raftPeerId, raftGroupId);
    followerInfo = new MyFollowerInfo(100L);
    LogAppenderMetrics logAppenderMetrics = new LogAppenderMetrics(raftGroupMemberId);
    ratisMetricRegistry = logAppenderMetrics.getRegistry();
    logAppenderMetrics.addFollowerGauges(raftPeerId, followerInfo::getNextIndex, followerInfo::getMatchIndex, followerInfo::getLastRpcTime);
}
Also used : LogAppenderMetrics(org.apache.ratis.server.metrics.LogAppenderMetrics) RaftGroupId(org.apache.ratis.protocol.RaftGroupId) RaftGroupMemberId(org.apache.ratis.protocol.RaftGroupMemberId) Before(org.junit.Before)

Example 4 with RaftGroupMemberId

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

the class TestRetryCacheMetrics method setUp.

@BeforeClass
public static void setUp() {
    RaftGroupId raftGroupId = RaftGroupId.randomId();
    RaftPeerId raftPeerId = RaftPeerId.valueOf("TestId");
    RaftGroupMemberId raftGroupMemberId = RaftGroupMemberId.valueOf(raftPeerId, raftGroupId);
    retryCache = new RetryCacheImpl(RaftServerConfigKeys.RetryCache.EXPIRY_TIME_DEFAULT, null);
    final RaftServerMetricsImpl raftServerMetrics = RaftServerMetricsImpl.computeIfAbsentRaftServerMetrics(raftGroupMemberId, () -> null, retryCache::getStatistics);
    ratisMetricRegistry = raftServerMetrics.getRegistry();
}
Also used : RaftGroupId(org.apache.ratis.protocol.RaftGroupId) RaftPeerId(org.apache.ratis.protocol.RaftPeerId) RaftGroupMemberId(org.apache.ratis.protocol.RaftGroupMemberId) RaftServerMetricsImpl(org.apache.ratis.server.metrics.RaftServerMetricsImpl) BeforeClass(org.junit.BeforeClass)

Example 5 with RaftGroupMemberId

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

the class LeaderElectionTests method createMockServer.

private static RaftServerImpl createMockServer(boolean alive) {
    final DivisionInfo info = mock(DivisionInfo.class);
    when(info.isAlive()).thenReturn(alive);
    when(info.isCandidate()).thenReturn(false);
    RaftServerImpl server = mock(RaftServerImpl.class);
    when(server.getInfo()).thenReturn(info);
    final RaftGroupMemberId memberId = RaftGroupMemberId.valueOf(RaftPeerId.valueOf("any"), RaftGroupId.randomId());
    when(server.getMemberId()).thenReturn(memberId);
    LeaderElectionMetrics leaderElectionMetrics = LeaderElectionMetrics.getLeaderElectionMetrics(memberId, () -> 0);
    when(server.getLeaderElectionMetrics()).thenReturn(leaderElectionMetrics);
    RaftServerProxy proxy = mock(RaftServerProxy.class);
    RaftProperties properties = new RaftProperties();
    RaftServerConfigKeys.LeaderElection.setPreVote(properties, true);
    when(proxy.getProperties()).thenReturn(properties);
    when(server.getRaftServer()).thenReturn(proxy);
    return server;
}
Also used : DivisionInfo(org.apache.ratis.server.DivisionInfo) RaftProperties(org.apache.ratis.conf.RaftProperties) RaftGroupMemberId(org.apache.ratis.protocol.RaftGroupMemberId) LeaderElectionMetrics(org.apache.ratis.server.metrics.LeaderElectionMetrics)

Aggregations

RaftGroupMemberId (org.apache.ratis.protocol.RaftGroupMemberId)9 RaftGroupId (org.apache.ratis.protocol.RaftGroupId)6 RaftPeerId (org.apache.ratis.protocol.RaftPeerId)5 RaftProperties (org.apache.ratis.conf.RaftProperties)4 CompletableFuture (java.util.concurrent.CompletableFuture)3 BaseTest (org.apache.ratis.BaseTest)3 LogEntryProto (org.apache.ratis.proto.RaftProtos.LogEntryProto)3 BeforeClass (org.junit.BeforeClass)3 Test (org.junit.Test)3 DivisionInfo (org.apache.ratis.server.DivisionInfo)2 LogEntryHeader (org.apache.ratis.server.raftlog.LogEntryHeader)2 Gauge (com.codahale.metrics.Gauge)1 File (java.io.File)1 GrpcServerMetrics (org.apache.ratis.grpc.metrics.GrpcServerMetrics)1 RaftServer (org.apache.ratis.server.RaftServer)1 LeaderElectionMetrics (org.apache.ratis.server.metrics.LeaderElectionMetrics)1 LogAppenderMetrics (org.apache.ratis.server.metrics.LogAppenderMetrics)1 RaftServerMetricsImpl (org.apache.ratis.server.metrics.RaftServerMetricsImpl)1 SegmentRange (org.apache.ratis.server.raftlog.segmented.TestSegmentedRaftLog.SegmentRange)1 RaftStorage (org.apache.ratis.server.storage.RaftStorage)1