use of com.hazelcast.config.cp.RaftAlgorithmConfig in project hazelcast by hazelcast.
the class YamlConfigBuilderTest method testCPSubsystemConfig.
@Override
@Test
public void testCPSubsystemConfig() {
String yaml = "" + "hazelcast:\n" + " cp-subsystem:\n" + " cp-member-count: 10\n" + " group-size: 5\n" + " session-time-to-live-seconds: 15\n" + " session-heartbeat-interval-seconds: 3\n" + " missing-cp-member-auto-removal-seconds: 120\n" + " fail-on-indeterminate-operation-state: true\n" + " persistence-enabled: true\n" + " base-dir: /mnt/cp-data\n" + " data-load-timeout-seconds: 30\n" + " raft-algorithm:\n" + " leader-election-timeout-in-millis: 500\n" + " leader-heartbeat-period-in-millis: 100\n" + " max-missed-leader-heartbeat-count: 3\n" + " append-request-max-entry-count: 25\n" + " commit-index-advance-count-to-snapshot: 250\n" + " uncommitted-entry-count-to-reject-new-appends: 75\n" + " append-request-backoff-timeout-in-millis: 50\n" + " semaphores:\n" + " sem1:\n" + " jdk-compatible: true\n" + " initial-permits: 1\n" + " sem2:\n" + " jdk-compatible: false\n" + " initial-permits: 2\n" + " locks:\n" + " lock1:\n" + " lock-acquire-limit: 1\n" + " lock2:\n" + " lock-acquire-limit: 2\n";
Config config = buildConfig(yaml);
CPSubsystemConfig cpSubsystemConfig = config.getCPSubsystemConfig();
assertEquals(10, cpSubsystemConfig.getCPMemberCount());
assertEquals(5, cpSubsystemConfig.getGroupSize());
assertEquals(15, cpSubsystemConfig.getSessionTimeToLiveSeconds());
assertEquals(3, cpSubsystemConfig.getSessionHeartbeatIntervalSeconds());
assertEquals(120, cpSubsystemConfig.getMissingCPMemberAutoRemovalSeconds());
assertTrue(cpSubsystemConfig.isFailOnIndeterminateOperationState());
assertTrue(cpSubsystemConfig.isPersistenceEnabled());
assertEquals(new File("/mnt/cp-data").getAbsoluteFile(), cpSubsystemConfig.getBaseDir().getAbsoluteFile());
assertEquals(30, cpSubsystemConfig.getDataLoadTimeoutSeconds());
RaftAlgorithmConfig raftAlgorithmConfig = cpSubsystemConfig.getRaftAlgorithmConfig();
assertEquals(500, raftAlgorithmConfig.getLeaderElectionTimeoutInMillis());
assertEquals(100, raftAlgorithmConfig.getLeaderHeartbeatPeriodInMillis());
assertEquals(3, raftAlgorithmConfig.getMaxMissedLeaderHeartbeatCount());
assertEquals(25, raftAlgorithmConfig.getAppendRequestMaxEntryCount());
assertEquals(250, raftAlgorithmConfig.getCommitIndexAdvanceCountToSnapshot());
assertEquals(75, raftAlgorithmConfig.getUncommittedEntryCountToRejectNewAppends());
assertEquals(50, raftAlgorithmConfig.getAppendRequestBackoffTimeoutInMillis());
SemaphoreConfig semaphoreConfig1 = cpSubsystemConfig.findSemaphoreConfig("sem1");
SemaphoreConfig semaphoreConfig2 = cpSubsystemConfig.findSemaphoreConfig("sem2");
assertNotNull(semaphoreConfig1);
assertNotNull(semaphoreConfig2);
assertTrue(semaphoreConfig1.isJDKCompatible());
assertFalse(semaphoreConfig2.isJDKCompatible());
assertEquals(1, semaphoreConfig1.getInitialPermits());
assertEquals(2, semaphoreConfig2.getInitialPermits());
FencedLockConfig lockConfig1 = cpSubsystemConfig.findLockConfig("lock1");
FencedLockConfig lockConfig2 = cpSubsystemConfig.findLockConfig("lock2");
assertNotNull(lockConfig1);
assertNotNull(lockConfig2);
assertEquals(1, lockConfig1.getLockAcquireLimit());
assertEquals(2, lockConfig2.getLockAcquireLimit());
}
use of com.hazelcast.config.cp.RaftAlgorithmConfig in project hazelcast by hazelcast.
the class RaftService method restoreRaftNode.
public RaftNodeImpl restoreRaftNode(RaftGroupId groupId, RestoredRaftState restoredState, LogFileStructure logFileStructure) {
int partitionId = getCPGroupPartitionId(groupId);
RaftIntegration integration = new NodeEngineRaftIntegration(nodeEngine, groupId, restoredState.localEndpoint(), partitionId);
RaftAlgorithmConfig raftAlgorithmConfig = config.getRaftAlgorithmConfig();
RaftStateStore stateStore = getCPPersistenceService().createRaftStateStore(groupId, logFileStructure);
RaftNodeImpl node = RaftNodeImpl.restoreRaftNode(groupId, restoredState, raftAlgorithmConfig, integration, stateStore);
// no need to lock here...
RaftNode prev = nodes.putIfAbsent(groupId, node);
checkState(prev == null, "Could not restore " + groupId + " because its Raft node already exists!");
node.start();
logger.info("RaftNode[" + groupId + "] is restored.");
return node;
}
use of com.hazelcast.config.cp.RaftAlgorithmConfig in project hazelcast by hazelcast.
the class PersistenceTest method when_followerIsRestarted_then_itAppliesPreviouslyCommittedMemberList.
@Test
public void when_followerIsRestarted_then_itAppliesPreviouslyCommittedMemberList() throws ExecutionException, InterruptedException {
RaftAlgorithmConfig config = new RaftAlgorithmConfig().setLeaderHeartbeatPeriodInMillis(SECONDS.toMillis(30));
group = new LocalRaftGroupBuilder(3, config).setAppendNopEntryOnLeaderElection(true).setRaftStateStoreFactory(RAFT_STATE_STORE_FACTORY).build();
group.start();
final RaftNodeImpl leader = group.waitUntilLeaderElected();
RaftNodeImpl[] followers = group.getNodesExcept(leader.getLocalMember());
RaftNodeImpl removedFollower = followers[0];
RaftNodeImpl terminatedFollower = followers[1];
group.terminateNode(removedFollower.getLocalMember());
leader.replicate(new ApplyRaftRunnable("val")).get();
leader.replicateMembershipChange(removedFollower.getLocalMember(), REMOVE).get();
RaftEndpoint terminatedEndpoint = terminatedFollower.getLocalMember();
InMemoryRaftStateStore stateStore = getRaftStateStore(terminatedFollower);
RestoredRaftState terminatedState = stateStore.toRestoredRaftState();
group.terminateNode(terminatedEndpoint);
final RaftNodeImpl restartedNode = group.createNewRaftNode(terminatedState, stateStore);
assertTrueEventually(() -> {
assertEquals(getCommitIndex(leader), getCommitIndex(restartedNode));
assertEquals(getLastApplied(leader), getLastApplied(restartedNode));
assertEquals(new ArrayList<>(getCommittedGroupMembers(leader).members()), new ArrayList<>(getCommittedGroupMembers(restartedNode).members()));
assertEquals(new ArrayList<>(getLastGroupMembers(leader).members()), new ArrayList<>(getLastGroupMembers(restartedNode).members()));
});
}
use of com.hazelcast.config.cp.RaftAlgorithmConfig in project hazelcast by hazelcast.
the class PersistenceTest method when_leaderIsRestarted_then_itRestoresItsRaftStateWithSnapshotAndBecomesLeader.
@Test
public void when_leaderIsRestarted_then_itRestoresItsRaftStateWithSnapshotAndBecomesLeader() throws ExecutionException, InterruptedException {
final int committedEntryCountToSnapshot = 50;
RaftAlgorithmConfig config = new RaftAlgorithmConfig().setCommitIndexAdvanceCountToSnapshot(committedEntryCountToSnapshot);
group = new LocalRaftGroupBuilder(3, config).setAppendNopEntryOnLeaderElection(true).setRaftStateStoreFactory(RAFT_STATE_STORE_FACTORY).build();
group.start();
RaftNodeImpl leader = group.waitUntilLeaderElected();
for (int i = 0; i <= committedEntryCountToSnapshot; i++) {
leader.replicate(new ApplyRaftRunnable("val" + i)).get();
}
assertTrue(getSnapshotEntry(leader).index() > 0);
final int term = getTerm(leader);
final long commitIndex = getCommitIndex(leader);
RaftEndpoint terminatedEndpoint = leader.getLocalMember();
InMemoryRaftStateStore stateStore = getRaftStateStore(leader);
RestoredRaftState terminatedState = stateStore.toRestoredRaftState();
// Block voting between followers
// to avoid a leader election before leader restarts.
blockVotingBetweenFollowers();
group.terminateNode(terminatedEndpoint);
RaftNodeImpl restartedNode = group.createNewRaftNode(terminatedState, stateStore);
RaftNodeImpl newLeader = group.waitUntilLeaderElected();
assertSame(restartedNode, newLeader);
assertTrueEventually(() -> {
assertTrue(getTerm(restartedNode) > term);
assertEquals(commitIndex + 1, getCommitIndex(restartedNode));
RaftDataService service = group.getService(restartedNode);
Object[] values = service.valuesArray();
assertThat(values, arrayWithSize(committedEntryCountToSnapshot + 1));
for (int i = 0; i <= committedEntryCountToSnapshot; i++) {
assertEquals("val" + i, values[i]);
}
});
}
use of com.hazelcast.config.cp.RaftAlgorithmConfig in project hazelcast by hazelcast.
the class PersistenceTest method testSnapshotIsPersisted.
@Test
public void testSnapshotIsPersisted() throws ExecutionException, InterruptedException {
final int committedEntryCountToSnapshot = 50;
RaftAlgorithmConfig config = new RaftAlgorithmConfig().setCommitIndexAdvanceCountToSnapshot(committedEntryCountToSnapshot);
group = new LocalRaftGroupBuilder(3, config).setRaftStateStoreFactory(RAFT_STATE_STORE_FACTORY).build();
group.start();
final RaftNodeImpl leader = group.waitUntilLeaderElected();
for (int i = 0; i < committedEntryCountToSnapshot; i++) {
leader.replicate(new ApplyRaftRunnable("val" + i)).get();
}
assertTrueEventually(() -> {
assertEquals(committedEntryCountToSnapshot, getSnapshotEntry(leader).index());
for (RaftNodeImpl node : group.getNodes()) {
RestoredRaftState restoredState = getRestoredState(node);
SnapshotEntry snapshot = restoredState.snapshot();
assertNotNull(snapshot);
assertEquals(committedEntryCountToSnapshot, snapshot.index());
}
});
}
Aggregations