use of com.hazelcast.cp.internal.raftop.metadata.CreateRaftGroupOp in project hazelcast by hazelcast.
the class RaftInvocationManager method invokeCreateRaftGroup.
private void invokeCreateRaftGroup(String groupName, int groupSize, long groupIndex, List<RaftEndpoint> members, InternalCompletableFuture<RaftGroupId> resultFuture) {
InternalCompletableFuture<CPGroupSummary> f = invoke(raftService.getMetadataGroupId(), new CreateRaftGroupOp(groupName, members, groupIndex));
f.whenCompleteAsync((group, t) -> {
if (t == null) {
resultFuture.complete((RaftGroupId) group.id());
triggerRaftNodeCreation(group);
} else {
if (t instanceof CannotCreateRaftGroupException) {
logger.fine("Could not create CP group: " + groupName + " with members: " + members + " and group index: " + groupIndex, t.getCause());
invokeGetMembersToCreateRaftGroup(groupName, groupSize, resultFuture);
return;
}
resultFuture.completeExceptionally(t);
}
});
}
use of com.hazelcast.cp.internal.raftop.metadata.CreateRaftGroupOp in project hazelcast by hazelcast.
the class MetadataRaftGroupTest method when_raftGroupIsCreated_onNonMetadataMembers_thenLeaderShouldBeElected.
@Test
public void when_raftGroupIsCreated_onNonMetadataMembers_thenLeaderShouldBeElected() throws ExecutionException, InterruptedException {
int metadataGroupSize = 3;
int otherRaftGroupSize = 2;
instances = newInstances(metadataGroupSize + otherRaftGroupSize, metadataGroupSize, 0);
HazelcastInstance leaderInstance = getLeaderInstance(instances, getMetadataGroupId(instances[0]));
RaftService raftService = getRaftService(leaderInstance);
Collection<CPMemberInfo> allEndpoints = raftService.getMetadataGroupManager().getActiveMembers();
assertTrueEventually(() -> assertNotNull(raftService.getMetadataGroupManager().getGroup(getMetadataGroupId(leaderInstance))));
CPGroup metadataGroup = raftService.getMetadataGroupManager().getGroup(getMetadataGroupId(leaderInstance));
Collection<CPMemberInfo> endpoints = new HashSet<>(otherRaftGroupSize);
for (CPMemberInfo endpoint : allEndpoints) {
if (!metadataGroup.members().contains(endpoint)) {
endpoints.add(endpoint);
}
}
assertEquals(otherRaftGroupSize, endpoints.size());
List<RaftEndpoint> groupEndpoints = new ArrayList<>();
for (CPMemberInfo member : endpoints) {
groupEndpoints.add(member.toRaftEndpoint());
}
RaftOp op = new CreateRaftGroupOp("test", groupEndpoints, RandomPicker.getInt(Integer.MAX_VALUE));
InternalCompletableFuture<CPGroupSummary> f = raftService.getInvocationManager().invoke(getMetadataGroupId(leaderInstance), op);
f.whenCompleteAsync((group, t) -> {
if (t == null) {
raftService.getInvocationManager().triggerRaftNodeCreation(group);
}
});
CPGroupId groupId = f.get().id();
for (HazelcastInstance instance : instances) {
if (endpoints.contains(instance.getCPSubsystem().getLocalCPMember())) {
assertTrueEventually(() -> {
RaftNodeImpl raftNode = getRaftNode(instance, groupId);
assertNotNull(raftNode);
assertNotNull("Leader is null on " + raftNode, getLeaderMember(raftNode));
});
}
}
}
Aggregations