use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint in project hazelcast by hazelcast.
the class LocalRaftGroup method getLeaderEndpoint.
public RaftEndpoint getLeaderEndpoint() {
RaftEndpoint leader = null;
for (int i = 0; i < size(); i++) {
if (integrations[i].isShutdown()) {
continue;
}
RaftNodeImpl node = nodes[i];
RaftEndpoint endpoint = getLeaderMember(node);
if (leader == null) {
leader = endpoint;
} else if (!leader.equals(endpoint)) {
throw new AssertionError("Group doesn't have a single leader endpoint yet!");
}
}
return leader;
}
use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint in project hazelcast by hazelcast.
the class CandidateStateTest method test_grantVote_withMajority.
@Test
public void test_grantVote_withMajority() {
for (int i = 0; i < majority; i++) {
RaftEndpoint endpoint = newRaftMember(1000 + i);
assertTrue(state.grantVote(endpoint));
}
assertEquals(majority, state.voteCount());
assertTrue(state.isMajorityGranted());
}
use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint in project hazelcast by hazelcast.
the class CandidateStateTest method test_grantVote_withoutMajority.
@Test
public void test_grantVote_withoutMajority() {
RaftEndpoint endpoint = newRaftMember(1000);
assertTrue(state.grantVote(endpoint));
assertFalse(state.grantVote(endpoint));
assertEquals(1, state.voteCount());
assertFalse(state.isMajorityGranted());
}
use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint in project hazelcast by hazelcast.
the class RaftService method createRaftNode.
void createRaftNode(CPGroupId groupId, Collection<RaftEndpoint> members, RaftEndpoint localCPMember) {
assert !(Thread.currentThread() instanceof PartitionOperationThread) : "Cannot create RaftNode of " + groupId + " in a partition thread!";
if (nodes.containsKey(groupId) || !isStartCompleted() || !hasSameSeed(groupId)) {
return;
}
if (getLocalCPMember() == null) {
logger.warning("Not creating Raft node for " + groupId + " because local CP member is not initialized yet.");
return;
}
nodeLock.readLock().lock();
try {
if (destroyedGroupIds.contains(groupId)) {
logger.warning("Not creating RaftNode[" + groupId + "] since the CP group is already destroyed.");
return;
} else if (terminatedRaftNodeGroupIds.contains(groupId)) {
if (!nodeEngine.isRunning()) {
logger.fine("Not creating RaftNode[" + groupId + "] since the local CP member is already terminated.");
return;
}
}
int partitionId = getCPGroupPartitionId(groupId);
RaftIntegration integration = new NodeEngineRaftIntegration(nodeEngine, groupId, localCPMember, partitionId);
RaftAlgorithmConfig raftAlgorithmConfig = config.getRaftAlgorithmConfig();
CPPersistenceService persistenceService = getCPPersistenceService();
RaftStateStore stateStore = persistenceService.createRaftStateStore((RaftGroupId) groupId, null);
RaftNodeImpl node = newRaftNode(groupId, localCPMember, members, raftAlgorithmConfig, integration, stateStore);
if (nodes.putIfAbsent(groupId, node) == null) {
if (destroyedGroupIds.contains(groupId)) {
nodes.remove(groupId, node);
removeNodeMetrics(groupId);
logger.warning("Not creating RaftNode[" + groupId + "] since the CP group is already destroyed.");
return;
}
node.start();
logger.info("RaftNode[" + groupId + "] is created with " + members);
}
} finally {
nodeLock.readLock().unlock();
}
}
use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint in project hazelcast by hazelcast.
the class CPGroupSummary method readData.
@Override
public void readData(ObjectDataInput in) throws IOException {
id = in.readObject();
int initialMemberCount = in.readInt();
Set<RaftEndpoint> initialMembers = new LinkedHashSet<RaftEndpoint>();
for (int i = 0; i < initialMemberCount; i++) {
RaftEndpoint member = in.readObject();
initialMembers.add(member);
}
this.initialMembers = unmodifiableSet(initialMembers);
int memberCount = in.readInt();
members = new LinkedHashSet<CPMember>(memberCount);
for (int i = 0; i < memberCount; i++) {
CPMember member = in.readObject();
members.add(member);
}
members = unmodifiableSet(members);
status = CPGroupStatus.valueOf(in.readString());
}
Aggregations