use of com.hazelcast.cp.internal.raft.impl.RaftNodeImpl in project hazelcast by hazelcast.
the class LocalRaftIntegration method send.
@Override
public boolean send(VoteRequest request, RaftEndpoint target) {
assertNotEquals(localEndpoint, target);
RaftNodeImpl node = nodes.get(target);
if (node == null) {
return false;
}
if (shouldDrop(request, target)) {
return true;
}
node.handleVoteRequest(alterMessageIfNeeded(request, target));
return true;
}
use of com.hazelcast.cp.internal.raft.impl.RaftNodeImpl in project hazelcast by hazelcast.
the class RaftSessionServiceTest method testSnapshotRestore.
@Test
public void testSnapshotRestore() throws ExecutionException, InterruptedException, UnknownHostException {
HazelcastInstance leader = getLeaderInstance(instances, groupId);
HazelcastInstance follower = getRandomFollowerInstance(instances, groupId);
// the follower falls behind the leader. It neither append entries nor installs snapshots.
dropOperationsBetween(leader, follower, RaftServiceDataSerializerHook.F_ID, asList(RaftServiceDataSerializerHook.APPEND_REQUEST_OP, RaftServiceDataSerializerHook.INSTALL_SNAPSHOT_OP));
SessionResponse response = invocationManager.<SessionResponse>invoke(groupId, newCreateSessionOp()).get();
spawn(() -> {
for (int i = 0; i < 30; i++) {
invocationManager.invoke(groupId, new HeartbeatSessionOp(response.getSessionId())).joinInternal();
sleepAtLeastSeconds(5);
}
});
for (int i = 0; i < LOG_ENTRY_COUNT_TO_SNAPSHOT; i++) {
invocationManager.invoke(groupId, new RaftTestApplyOp("value" + i)).get();
}
RaftNodeImpl leaderRaftNode = (RaftNodeImpl) ((RaftService) getNodeEngineImpl(leader).getService(RaftService.SERVICE_NAME)).getRaftNode(groupId);
RaftNodeImpl followerRaftNode = (RaftNodeImpl) ((RaftService) getNodeEngineImpl(follower).getService(RaftService.SERVICE_NAME)).getRaftNode(groupId);
// the leader takes a snapshot
long[] leaderSnapshotIndex = new long[1];
assertTrueEventually(() -> {
long idx = getSnapshotEntry(leaderRaftNode).index();
assertTrue(idx > 0);
leaderSnapshotIndex[0] = idx;
});
// the follower doesn't have it since its raft log is still empty
assertTrueAllTheTime(() -> assertEquals(0, getSnapshotEntry(followerRaftNode).index()), 10);
resetPacketFiltersFrom(leader);
// the follower installs the snapshot after it hears from the leader
assertTrueEventually(() -> assertTrue(getSnapshotEntry(followerRaftNode).index() > 0));
assertTrueEventually(() -> {
RaftSessionService sessionService = getNodeEngineImpl(follower).getService(RaftSessionService.SERVICE_NAME);
RaftSessionRegistry registry = sessionService.getSessionRegistryOrNull(groupId);
assertNotNull(registry.getSession(response.getSessionId()));
});
// the follower disconnects from the leader again
dropOperationsBetween(leader, follower, RaftServiceDataSerializerHook.F_ID, asList(RaftServiceDataSerializerHook.APPEND_REQUEST_OP, RaftServiceDataSerializerHook.INSTALL_SNAPSHOT_OP));
for (int i = 0; i < LOG_ENTRY_COUNT_TO_SNAPSHOT; i++) {
invocationManager.invoke(groupId, new HeartbeatSessionOp(response.getSessionId())).get();
}
// the leader takes a new snapshot
assertTrueEventually(() -> assertTrue(getSnapshotEntry(leaderRaftNode).index() > leaderSnapshotIndex[0]));
resetPacketFiltersFrom(leader);
// the follower installs the new snapshot after it hears from the leader
assertTrueEventually(() -> {
CPSessionInfo leaderSession = getSession(leader, groupId, response.getSessionId());
CPSessionInfo followerSession = getSession(follower, groupId, response.getSessionId());
assertNotNull(leaderSession);
assertNotNull(followerSession);
assertEquals(leaderSession.version(), followerSession.version());
});
}
use of com.hazelcast.cp.internal.raft.impl.RaftNodeImpl in project hazelcast by hazelcast.
the class LocalRaftGroup method destroy.
public void destroy() {
for (int i = 0; i < nodes.length; i++) {
RaftNodeImpl node = nodes[i];
LocalRaftIntegration integration = integrations[i];
if (integration.isShutdown()) {
continue;
}
node.forceSetTerminatedStatus().joinInternal();
integration.shutdown();
}
}
use of com.hazelcast.cp.internal.raft.impl.RaftNodeImpl in project hazelcast by hazelcast.
the class LocalRaftGroup method waitUntilLeaderElected.
public RaftNodeImpl waitUntilLeaderElected() {
RaftNodeImpl[] leaderRef = new RaftNodeImpl[1];
assertTrueEventually(() -> {
RaftNodeImpl leaderNode = getLeaderNode();
assertNotNull(leaderNode);
int leaderTerm = getTerm(leaderNode);
for (RaftNodeImpl raftNode : nodes) {
if (integrations[getIndexOf(raftNode.getLocalMember())].isShutdown()) {
continue;
}
assertEquals(leaderNode.getLocalMember(), getLeaderMember(raftNode));
assertEquals(leaderTerm, getTerm(raftNode));
}
leaderRef[0] = leaderNode;
});
return leaderRef[0];
}
use of com.hazelcast.cp.internal.raft.impl.RaftNodeImpl in project hazelcast by hazelcast.
the class LocalRaftGroup method createNewRaftNode.
public RaftNodeImpl createNewRaftNode() {
int oldSize = this.integrations.length;
int newSize = oldSize + 1;
RaftEndpoint[] endpoints = new RaftEndpoint[newSize];
LocalRaftIntegration[] integrations = new LocalRaftIntegration[newSize];
RaftNodeImpl[] nodes = new RaftNodeImpl[newSize];
System.arraycopy(this.members, 0, endpoints, 0, oldSize);
System.arraycopy(this.integrations, 0, integrations, 0, oldSize);
System.arraycopy(this.nodes, 0, nodes, 0, oldSize);
LocalRaftIntegration integration = createNewLocalRaftIntegration();
createdNodeCount++;
integrations[oldSize] = integration;
RaftEndpoint endpoint = integration.getLocalEndpoint();
endpoints[oldSize] = endpoint;
RaftStateStore raftStateStore = raftStateStoreFactory.apply(endpoint, raftAlgorithmConfig);
RaftNodeImpl node = newRaftNode(groupId, endpoint, asList(initialMembers), raftAlgorithmConfig, integration, raftStateStore);
nodes[oldSize] = node;
this.members = endpoints;
this.integrations = integrations;
this.nodes = nodes;
node.start();
initDiscovery();
return node;
}
Aggregations