/** * Sets the system management partition group. * <p> * The system management group must be configured for stateful instances. This group will be used to store primitive * and transaction metadata and coordinate primary elections for replication protocols. * <pre> * {@code * Atomix atomix = Atomix.builder() * .withManagementGroup(RaftPartitionGroup.builder("system") * .withNumPartitions(1) * .build()) * .build(); * } * </pre> * <p> * The configured partition group is replicated on whichever nodes define them in this configuration. That is, * this node will participate in whichever partition group is provided to this method. * <p> * The management group can also be configured in {@code atomix.conf} under the {@code management-group} key. * * @param systemManagementGroup the system management partition group * @return the Atomix builder */ public AtomixBuilder withManagementGroup(ManagedPartitionGroup systemManagementGroup) { config.setManagementGroup(systemManagementGroup.config()); return this; }
@Override @SuppressWarnings("unchecked") public CompletableFuture<Void> stop() { groupMembershipService.removeListener(groupMembershipEventListener); Stream<CompletableFuture<Void>> systemStream = Stream.of(systemGroup != null ? systemGroup.close() : CompletableFuture.completedFuture(null)); Stream<CompletableFuture<Void>> groupStream = groups.values().stream().map(ManagedPartitionGroup::close); List<CompletableFuture<Void>> futures = Stream.concat(systemStream, groupStream).collect(Collectors.toList()); return CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()])).exceptionally(throwable -> { LOGGER.error("Failed closing partition group(s)", throwable); return null; }).thenCompose(v -> electionService != null ? electionService.stop() : CompletableFuture.completedFuture(null)).exceptionally(throwable -> { LOGGER.error("Failed stopping election service", throwable); return null; }).thenCompose(v -> groupMembershipService.stop()).exceptionally(throwable -> { LOGGER.error("Failed stopping group membership service", throwable); return null; }).thenRun(() -> { LOGGER.info("Stopped"); started.set(false); }); } }
@Override @SuppressWarnings("unchecked") public PartitionGroup getPartitionGroup(String name) { ManagedPartitionGroup group = groups.get(name); if (group != null) { return group; } if (systemGroup != null && systemGroup.name().equals(name)) { return systemGroup; } return null; }
this.systemGroup = systemGroup != null ? new PartitionGroupMembership( systemGroup.name(), systemGroup.config(), ImmutableSet.of(membershipService.getLocalMember().id()), true) : null; groups.forEach(group -> { this.groups.put(group.name(), new PartitionGroupMembership( group.name(), group.config(), ImmutableSet.of(membershipService.getLocalMember().id()), false)); });
new DefaultSessionIdService()); if (systemGroupMembership.members().contains(clusterMembershipService.getLocalMember().id())) { return systemGroup.join(managementService); } else { return systemGroup.connect(managementService); group = ((PartitionGroup.Type) membership.config().getType()) .newPartitionGroup(membership.config()); groups.put(group.name(), group); return group.join(partitionManagementService); } else { return group.connect(partitionManagementService);
@SuppressWarnings("unchecked") private void handleMembershipChange(PartitionGroupMembershipEvent event) { if (partitionManagementService == null) { return; } if (!event.membership().system()) { synchronized (groups) { ManagedPartitionGroup group = groups.get(event.membership().group()); if (group == null) { group = ((PartitionGroup.Type) event.membership().config().getType()) .newPartitionGroup(event.membership().config()); groups.put(event.membership().group(), group); if (event.membership().members().contains(clusterMembershipService.getLocalMember().id())) { group.join(partitionManagementService); } else { group.connect(partitionManagementService); } } } } }
/** * Sets the primitive partition groups. * <p> * The primitive partition groups represent partitions that are directly accessible to distributed primitives. To use * partitioned primitives, at least one node must be configured with at least one data partition group. * <pre> * {@code * Atomix atomix = Atomix.builder() * .withPartitionGroups(PrimaryBackupPartitionGroup.builder("data") * .withNumPartitions(32) * .build()) * .build(); * } * </pre> * The partition group name is used to uniquely identify the group when constructing primitive instances. Partitioned * primitives will reference a specific protocol and partition group within which to replicate the primitive. * <p> * The configured partition groups are replicated on whichever nodes define them in this configuration. That is, * this node will participate in whichever partition groups are provided to this method. * <p> * The partition groups can also be configured in {@code atomix.conf} under the {@code partition-groups} key. * * @param partitionGroups the partition groups * @return the Atomix builder * @throws NullPointerException if the partition groups are null */ public AtomixBuilder withPartitionGroups(Collection<ManagedPartitionGroup> partitionGroups) { partitionGroups.forEach(group -> config.addPartitionGroup(group.config())); return this; }
@SuppressWarnings("unchecked") public DefaultPartitionService( ClusterMembershipService membershipService, ClusterCommunicationService messagingService, PrimitiveTypeRegistry primitiveTypeRegistry, ManagedPartitionGroup systemGroup, Collection<ManagedPartitionGroup> groups, PartitionGroupTypeRegistry groupTypeRegistry) { this.clusterMembershipService = membershipService; this.communicationService = messagingService; this.primitiveTypeRegistry = primitiveTypeRegistry; this.groupMembershipService = new DefaultPartitionGroupMembershipService( membershipService, messagingService, systemGroup, groups, groupTypeRegistry); this.systemGroup = systemGroup; groups.forEach(group -> this.groups.put(group.name(), group)); }
config.addPartitionGroup(partitionGroup.config()); return this;
/** * Sets the system management partition group. * <p> * The system management group must be configured for stateful instances. This group will be used to store primitive * and transaction metadata and coordinate primary elections for replication protocols. * <pre> * {@code * Atomix atomix = Atomix.builder() * .withManagementGroup(RaftPartitionGroup.builder("system") * .withNumPartitions(1) * .build()) * .build(); * } * </pre> * <p> * The configured partition group is replicated on whichever nodes define them in this configuration. That is, * this node will participate in whichever partition group is provided to this method. * <p> * The management group can also be configured in {@code atomix.conf} under the {@code management-group} key. * * @param systemManagementGroup the system management partition group * @return the Atomix builder */ public AtomixBuilder withManagementGroup(ManagedPartitionGroup systemManagementGroup) { config.setManagementGroup(systemManagementGroup.config()); return this; }
config.addPartitionGroup(partitionGroup.config()); return this;
/** * Sets the primitive partition groups. * <p> * The primitive partition groups represent partitions that are directly accessible to distributed primitives. To use * partitioned primitives, at least one node must be configured with at least one data partition group. * <pre> * {@code * Atomix atomix = Atomix.builder() * .withPartitionGroups(PrimaryBackupPartitionGroup.builder("data") * .withNumPartitions(32) * .build()) * .build(); * } * </pre> * The partition group name is used to uniquely identify the group when constructing primitive instances. Partitioned * primitives will reference a specific protocol and partition group within which to replicate the primitive. * <p> * The configured partition groups are replicated on whichever nodes define them in this configuration. That is, * this node will participate in whichever partition groups are provided to this method. * <p> * The partition groups can also be configured in {@code atomix.conf} under the {@code partition-groups} key. * * @param partitionGroups the partition groups * @return the Atomix builder * @throws NullPointerException if the partition groups are null */ public AtomixBuilder withPartitionGroups(Collection<ManagedPartitionGroup> partitionGroups) { partitionGroups.forEach(group -> config.addPartitionGroup(group.config())); return this; }