Search in sources :

Example 1 with PartitionManagementService

use of io.atomix.primitive.partition.PartitionManagementService in project atomix by atomix.

the class PrimaryBackupPartitionGroup method open.

@Override
public CompletableFuture<ManagedPartitionGroup> open(PartitionManagementService managementService) {
    threadFactory = new ThreadPoolContextFactory("atomix-" + name() + "-%d", Runtime.getRuntime().availableProcessors() * 2, LOGGER);
    List<CompletableFuture<Partition>> futures = partitions.values().stream().map(p -> p.open(managementService, threadFactory)).collect(Collectors.toList());
    return CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()])).thenApply(v -> {
        LOGGER.info("Started");
        return this;
    });
}
Also used : Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) MemberGroupStrategy(io.atomix.primitive.partition.MemberGroupStrategy) PartitionId(io.atomix.primitive.partition.PartitionId) ArrayList(java.util.ArrayList) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Lists(com.google.common.collect.Lists) Partition(io.atomix.primitive.partition.Partition) PrimitiveProtocol(io.atomix.primitive.PrimitiveProtocol) Map(java.util.Map) MemberGroupProvider(io.atomix.primitive.partition.MemberGroupProvider) ManagedPartitionGroup(io.atomix.primitive.partition.ManagedPartitionGroup) Logger(org.slf4j.Logger) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Recovery(io.atomix.primitive.Recovery) Maps(com.google.common.collect.Maps) PartitionGroup(io.atomix.primitive.partition.PartitionGroup) Collectors(java.util.stream.Collectors) ThreadContextFactory(io.atomix.utils.concurrent.ThreadContextFactory) ThreadPoolContextFactory(io.atomix.utils.concurrent.ThreadPoolContextFactory) List(java.util.List) MemberGroup(io.atomix.primitive.partition.MemberGroup) PartitionManagementService(io.atomix.primitive.partition.PartitionManagementService) Replication(io.atomix.primitive.Replication) Type(io.atomix.primitive.PrimitiveProtocol.Type) MultiPrimaryProtocol(io.atomix.protocols.backup.MultiPrimaryProtocol) Collections(java.util.Collections) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) CompletableFuture(java.util.concurrent.CompletableFuture) ThreadPoolContextFactory(io.atomix.utils.concurrent.ThreadPoolContextFactory)

Example 2 with PartitionManagementService

use of io.atomix.primitive.partition.PartitionManagementService in project atomix by atomix.

the class Atomix method start.

/**
 * Starts the Atomix instance.
 * <p>
 * The returned future will be completed once this instance completes startup. Note that in order to complete startup,
 * all partitions must be able to form. For Raft partitions, that requires that a majority of the nodes in each
 * partition be started concurrently.
 *
 * @return a future to be completed once the instance has completed startup
 */
@Override
public synchronized CompletableFuture<Atomix> start() {
    if (closeFuture != null) {
        return Futures.exceptionalFuture(new IllegalStateException("Atomix instance " + (closeFuture.isDone() ? "shutdown" : "shutting down")));
    }
    if (openFuture != null) {
        return openFuture;
    }
    openFuture = messagingService.start().thenComposeAsync(v -> metadataService.start(), context).thenComposeAsync(v -> clusterService.start(), context).thenComposeAsync(v -> clusterMessagingService.start(), context).thenComposeAsync(v -> clusterEventingService.start(), context).thenComposeAsync(v -> systemPartitionGroup.open(new DefaultPartitionManagementService(metadataService, clusterService, clusterMessagingService, primitiveTypes, null, null)), context).thenComposeAsync(v -> {
        ManagedPrimaryElectionService electionService = new DefaultPrimaryElectionService(systemPartitionGroup, RaftProtocol.builder().withMinTimeout(Duration.ofMillis(250)).withMaxTimeout(Duration.ofSeconds(5)).withReadConsistency(ReadConsistency.LINEARIZABLE).withCommunicationStrategy(CommunicationStrategy.LEADER).withRecoveryStrategy(Recovery.RECOVER).withMaxRetries(5).build());
        ManagedSessionIdService sessionIdService = new IdGeneratorSessionIdService(systemPartitionGroup);
        return electionService.start().thenComposeAsync(v2 -> sessionIdService.start(), context).thenApply(v2 -> new DefaultPartitionManagementService(metadataService, clusterService, clusterMessagingService, primitiveTypes, electionService, sessionIdService));
    }, context).thenComposeAsync(partitionManagementService -> partitions.open((PartitionManagementService) partitionManagementService), context).thenComposeAsync(v -> primitives.start(), context).thenApplyAsync(v -> {
        metadataService.addNode(clusterService.getLocalNode());
        started.set(true);
        LOGGER.info("Started");
        return this;
    }, context);
    return openFuture;
}
Also used : ManagedClusterMetadataService(io.atomix.cluster.ManagedClusterMetadataService) Node(io.atomix.cluster.Node) Arrays(java.util.Arrays) ManagedPrimaryElectionService(io.atomix.primitive.partition.ManagedPrimaryElectionService) ClusterEventingService(io.atomix.cluster.messaging.ClusterEventingService) DistributedPrimitive(io.atomix.primitive.DistributedPrimitive) RaftProtocol(io.atomix.protocols.raft.RaftProtocol) LoggerFactory(org.slf4j.LoggerFactory) PrimitiveTypeRegistry(io.atomix.primitive.PrimitiveTypeRegistry) DistributedPrimitiveBuilder(io.atomix.primitive.DistributedPrimitiveBuilder) NettyMessagingService(io.atomix.messaging.impl.NettyMessagingService) TransactionBuilder(io.atomix.core.transaction.TransactionBuilder) Managed(io.atomix.utils.Managed) InetAddress(java.net.InetAddress) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) CorePrimitivesService(io.atomix.core.impl.CorePrimitivesService) Duration(java.time.Duration) ManagedPartitionGroup(io.atomix.primitive.partition.ManagedPartitionGroup) DefaultPrimaryElectionService(io.atomix.primitive.partition.impl.DefaultPrimaryElectionService) ManagedSessionIdService(io.atomix.primitive.session.ManagedSessionIdService) Collection(java.util.Collection) Set(java.util.Set) Endpoint(io.atomix.messaging.Endpoint) ManagedClusterEventingService(io.atomix.cluster.messaging.ManagedClusterEventingService) ReadConsistency(io.atomix.protocols.raft.ReadConsistency) RaftPartitionGroup(io.atomix.protocols.raft.partition.RaftPartitionGroup) SingleThreadContext(io.atomix.utils.concurrent.SingleThreadContext) ThreadContext(io.atomix.utils.concurrent.ThreadContext) ClusterMessagingService(io.atomix.cluster.messaging.ClusterMessagingService) CommunicationStrategy(io.atomix.protocols.raft.proxy.CommunicationStrategy) DefaultClusterMessagingService(io.atomix.cluster.messaging.impl.DefaultClusterMessagingService) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) DefaultPartitionService(io.atomix.primitive.partition.impl.DefaultPartitionService) IdGeneratorSessionIdService(io.atomix.core.generator.impl.IdGeneratorSessionIdService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ManagedPartitionService(io.atomix.primitive.partition.ManagedPartitionService) CompletableFuture(java.util.concurrent.CompletableFuture) ManagedClusterService(io.atomix.cluster.ManagedClusterService) DefaultClusterEventingService(io.atomix.cluster.messaging.impl.DefaultClusterEventingService) ArrayList(java.util.ArrayList) DefaultClusterService(io.atomix.cluster.impl.DefaultClusterService) Futures(io.atomix.utils.concurrent.Futures) PrimaryBackupPartitionGroup(io.atomix.protocols.backup.partition.PrimaryBackupPartitionGroup) ManagedMessagingService(io.atomix.messaging.ManagedMessagingService) ClusterMetadata(io.atomix.cluster.ClusterMetadata) Logger(org.slf4j.Logger) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) ClusterMetadataService(io.atomix.cluster.ClusterMetadataService) Recovery(io.atomix.primitive.Recovery) UnknownHostException(java.net.UnknownHostException) File(java.io.File) DefaultClusterMetadataService(io.atomix.cluster.impl.DefaultClusterMetadataService) ManagedClusterMessagingService(io.atomix.cluster.messaging.ManagedClusterMessagingService) MessagingService(io.atomix.messaging.MessagingService) PartitionManagementService(io.atomix.primitive.partition.PartitionManagementService) PrimitiveType(io.atomix.primitive.PrimitiveType) PartitionService(io.atomix.primitive.partition.PartitionService) DefaultPartitionManagementService(io.atomix.primitive.partition.impl.DefaultPartitionManagementService) ClusterService(io.atomix.cluster.ClusterService) Collections(java.util.Collections) ManagedPrimaryElectionService(io.atomix.primitive.partition.ManagedPrimaryElectionService) DefaultPrimaryElectionService(io.atomix.primitive.partition.impl.DefaultPrimaryElectionService) DefaultPartitionManagementService(io.atomix.primitive.partition.impl.DefaultPartitionManagementService) IdGeneratorSessionIdService(io.atomix.core.generator.impl.IdGeneratorSessionIdService) ManagedSessionIdService(io.atomix.primitive.session.ManagedSessionIdService)

Example 3 with PartitionManagementService

use of io.atomix.primitive.partition.PartitionManagementService in project atomix by atomix.

the class PrimaryBackupPartition method open.

/**
 * Opens the primary-backup partition.
 */
CompletableFuture<Partition> open(PartitionManagementService managementService, ThreadContextFactory threadFactory) {
    election = managementService.getElectionService().getElectionFor(partitionId);
    server = new PrimaryBackupPartitionServer(this, managementService, memberGroupProvider, threadFactory);
    client = new PrimaryBackupPartitionClient(this, managementService, threadFactory);
    return server.start().thenCompose(v -> client.start()).thenApply(v -> this);
}
Also used : NodeId(io.atomix.cluster.NodeId) Collection(java.util.Collection) CompletableFuture(java.util.concurrent.CompletableFuture) PrimaryBackupPartitionClient(io.atomix.protocols.backup.partition.impl.PrimaryBackupPartitionClient) Collectors(java.util.stream.Collectors) Member(io.atomix.primitive.partition.Member) PartitionId(io.atomix.primitive.partition.PartitionId) ThreadContextFactory(io.atomix.utils.concurrent.ThreadContextFactory) PrimaryBackupPartitionServer(io.atomix.protocols.backup.partition.impl.PrimaryBackupPartitionServer) Partition(io.atomix.primitive.partition.Partition) PartitionManagementService(io.atomix.primitive.partition.PartitionManagementService) PrimaryElection(io.atomix.primitive.partition.PrimaryElection) MemberGroupProvider(io.atomix.primitive.partition.MemberGroupProvider) MultiPrimaryProtocol(io.atomix.protocols.backup.MultiPrimaryProtocol) PrimitiveClient(io.atomix.primitive.PrimitiveClient) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) PrimaryBackupPartitionClient(io.atomix.protocols.backup.partition.impl.PrimaryBackupPartitionClient) PrimaryBackupPartitionServer(io.atomix.protocols.backup.partition.impl.PrimaryBackupPartitionServer)

Aggregations

MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)3 PartitionManagementService (io.atomix.primitive.partition.PartitionManagementService)3 Collection (java.util.Collection)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 Recovery (io.atomix.primitive.Recovery)2 ManagedPartitionGroup (io.atomix.primitive.partition.ManagedPartitionGroup)2 MemberGroupProvider (io.atomix.primitive.partition.MemberGroupProvider)2 Partition (io.atomix.primitive.partition.Partition)2 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 ClusterMetadata (io.atomix.cluster.ClusterMetadata)1 ClusterMetadataService (io.atomix.cluster.ClusterMetadataService)1 ClusterService (io.atomix.cluster.ClusterService)1 ManagedClusterMetadataService (io.atomix.cluster.ManagedClusterMetadataService)1 ManagedClusterService (io.atomix.cluster.ManagedClusterService)1 Node (io.atomix.cluster.Node)1 NodeId (io.atomix.cluster.NodeId)1 DefaultClusterMetadataService (io.atomix.cluster.impl.DefaultClusterMetadataService)1