use of com.hazelcast.cp.internal.exception.CannotCreateRaftGroupException in project hazelcast by hazelcast.
the class MetadataRaftGroupManager method createRaftGroup.
public CPGroupSummary createRaftGroup(String groupName, Collection<RaftEndpoint> groupEndpoints, long groupId) {
checkFalse(equalsIgnoreCase(METADATA_CP_GROUP_NAME, groupName), groupName + " is reserved for internal usage!");
checkMetadataGroupInitSuccessful();
// keep configuration on every metadata node
CPGroupInfo group = getRaftGroupByName(groupName);
if (group != null) {
if (group.memberCount() == groupEndpoints.size()) {
if (logger.isFineEnabled()) {
logger.fine("CP group " + groupName + " already exists.");
}
return group.toSummary(activeMembers);
}
String msg = group.id() + " already exists with a different size: " + group.memberCount();
logger.severe(msg);
throw new IllegalStateException(msg);
}
group = getRaftGroupById(groupId);
if (group != null) {
throw new CannotCreateRaftGroupException("Cannot create CP group: " + groupName + " with members: " + groupEndpoints + " because group index: " + groupId + " already belongs to " + group.name());
}
Map<UUID, CPMemberInfo> activeMembersMap = getActiveMembersMap();
CPMemberInfo leavingMember = membershipChangeSchedule != null ? membershipChangeSchedule.getLeavingMember() : null;
for (RaftEndpoint groupEndpoint : groupEndpoints) {
if ((leavingMember != null && groupEndpoint.getUuid().equals(leavingMember.getUuid())) || !activeMembersMap.containsKey(groupEndpoint.getUuid())) {
String msg = "Cannot create CP group: " + groupName + " since " + groupEndpoint + " is not active";
if (logger.isFineEnabled()) {
logger.fine(msg);
}
throw new CannotCreateRaftGroupException(msg);
}
}
return createRaftGroup(new CPGroupInfo(new RaftGroupId(groupName, getGroupIdSeed(), groupId), groupEndpoints));
}
use of com.hazelcast.cp.internal.exception.CannotCreateRaftGroupException 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);
}
});
}
Aggregations