Search in sources :

Example 21 with RaftPartition

use of io.atomix.raft.partition.RaftPartition in project zeebe by camunda-cloud.

the class ClusteringRule method stepDown.

public void stepDown(final Broker broker, final int partitionId) {
    final var atomix = broker.getBrokerContext().getClusterServices();
    final MemberId nodeId = atomix.getMembershipService().getLocalMember().id();
    final var raftPartition = broker.getBrokerContext().getPartitionManager().getPartitionGroup().getPartitions().stream().filter(partition -> partition.members().contains(nodeId)).filter(partition -> partition.id().id() == partitionId).map(RaftPartition.class::cast).findFirst().orElseThrow();
    raftPartition.getServer().stepDown().join();
}
Also used : DEBUG_EXPORTER(io.camunda.zeebe.broker.test.EmbeddedBrokerConfigurator.DEBUG_EXPORTER) START_PARTITION_ID(io.camunda.zeebe.protocol.Protocol.START_PARTITION_ID) Address(io.atomix.utils.net.Address) AutoCloseableRule(io.camunda.zeebe.test.util.AutoCloseableRule) EmbeddedBrokerRule.assignSocketAddresses(io.camunda.zeebe.broker.test.EmbeddedBrokerRule.assignSocketAddresses) TimeoutException(java.util.concurrent.TimeoutException) Gateway(io.camunda.zeebe.gateway.Gateway) UncheckedExecutionException(io.camunda.zeebe.util.exception.UncheckedExecutionException) Duration(java.time.Duration) Map(java.util.Map) ClusterCfg(io.camunda.zeebe.gateway.impl.configuration.ClusterCfg) LangUtil(org.agrona.LangUtil) SocketBindingCfg(io.camunda.zeebe.broker.system.configuration.SocketBindingCfg) NettyMessagingService(io.atomix.cluster.messaging.impl.NettyMessagingService) Path(java.nio.file.Path) EmbeddedBrokerConfigurator.setCluster(io.camunda.zeebe.broker.test.EmbeddedBrokerConfigurator.setCluster) ControlledActorClock(io.camunda.zeebe.util.sched.clock.ControlledActorClock) ProcessInstanceCreationRecord(io.camunda.zeebe.protocol.impl.record.value.processinstance.ProcessInstanceCreationRecord) BrokerAdminService(io.camunda.zeebe.broker.system.management.BrokerAdminService) PartitionManagerImpl(io.camunda.zeebe.broker.partitioning.PartitionManagerImpl) Predicate(java.util.function.Predicate) SystemContext(io.camunda.zeebe.broker.system.SystemContext) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BrokerInfo(io.camunda.zeebe.client.api.response.BrokerInfo) Set(java.util.Set) Description(org.junit.runner.Description) DISABLE_EMBEDDED_GATEWAY(io.camunda.zeebe.broker.test.EmbeddedBrokerConfigurator.DISABLE_EMBEDDED_GATEWAY) RecordingExporterTestWatcher(io.camunda.zeebe.test.util.record.RecordingExporterTestWatcher) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) SwimMembershipProtocol(io.atomix.cluster.protocol.SwimMembershipProtocol) UncheckedIOException(java.io.UncheckedIOException) Objects(java.util.Objects) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) ExternalResource(org.junit.rules.ExternalResource) NetworkCfg(io.camunda.zeebe.broker.system.configuration.NetworkCfg) SnapshotId(io.camunda.zeebe.snapshots.SnapshotId) BootstrapDiscoveryProvider(io.atomix.cluster.discovery.BootstrapDiscoveryProvider) Broker(io.camunda.zeebe.broker.Broker) ZeebeClient(io.camunda.zeebe.client.ZeebeClient) Optional(java.util.Optional) Awaitility(org.awaitility.Awaitility) IntStream(java.util.stream.IntStream) Statement(org.junit.runners.model.Statement) AtomixClusterBuilder(io.atomix.cluster.AtomixClusterBuilder) PartitionStatus(io.camunda.zeebe.broker.system.management.PartitionStatus) EmbeddedBrokerConfigurator.setInitialContactPoints(io.camunda.zeebe.broker.test.EmbeddedBrokerConfigurator.setInitialContactPoints) ActorFuture(io.camunda.zeebe.util.sched.future.ActorFuture) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) SpringBrokerBridge(io.camunda.zeebe.broker.SpringBrokerBridge) FileBasedSnapshotMetadata(io.camunda.zeebe.snapshots.impl.FileBasedSnapshotMetadata) PartitionInfo(io.camunda.zeebe.client.api.response.PartitionInfo) RaftPartition(io.atomix.raft.partition.RaftPartition) MemberId(io.atomix.cluster.MemberId) BrokerResponse(io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse) BrokerContext(io.camunda.zeebe.broker.bootstrap.BrokerContext) SocketUtil(io.camunda.zeebe.test.util.socket.SocketUtil) LOG(io.camunda.zeebe.broker.Broker.LOG) Topology(io.camunda.zeebe.client.api.response.Topology) ExporterDirectorContext(io.camunda.zeebe.broker.exporter.stream.ExporterDirectorContext) ClusterConfig(io.atomix.cluster.ClusterConfig) BrokerCfg(io.camunda.zeebe.broker.system.configuration.BrokerCfg) BrokerCreateProcessInstanceRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerCreateProcessInstanceRequest) Files(java.nio.file.Files) AtomixCluster(io.atomix.cluster.AtomixCluster) NetUtil(io.netty.util.NetUtil) IOException(java.io.IOException) ZeebeClientBuilder(io.camunda.zeebe.client.ZeebeClientBuilder) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) PartitionListener(io.camunda.zeebe.broker.PartitionListener) LogStream(io.camunda.zeebe.logstreams.log.LogStream) Paths(java.nio.file.Paths) QueryService(io.camunda.zeebe.engine.state.QueryService) GatewayCfg(io.camunda.zeebe.gateway.impl.configuration.GatewayCfg) CompletableActorFuture(io.camunda.zeebe.util.sched.future.CompletableActorFuture) NettyUnicastService(io.atomix.cluster.messaging.impl.NettyUnicastService) TEST_RECORDER(io.camunda.zeebe.broker.test.EmbeddedBrokerConfigurator.TEST_RECORDER) Assert(org.junit.Assert) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) ActorScheduler(io.camunda.zeebe.util.sched.ActorScheduler) MemberId(io.atomix.cluster.MemberId) RaftPartition(io.atomix.raft.partition.RaftPartition)

Example 22 with RaftPartition

use of io.atomix.raft.partition.RaftPartition in project zeebe by camunda-cloud.

the class BrokerSnapshotTest method setup.

@Before
public void setup() {
    final RaftPartition raftPartition = (RaftPartition) brokerRule.getBroker().getBrokerContext().getPartitionManager().getPartitionGroup().getPartition(PartitionId.from(PartitionManagerImpl.GROUP_NAME, PARTITION_ID));
    journalReader = raftPartition.getServer().openReader();
    brokerAdminService = brokerRule.getBroker().getBrokerContext().getBrokerAdminService();
    final String contactPoint = NetUtil.toSocketAddressString(brokerRule.getGatewayAddress());
    final ZeebeClientBuilder zeebeClientBuilder = ZeebeClient.newClientBuilder().usePlaintext().gatewayAddress(contactPoint);
    client = zeebeClientBuilder.build();
}
Also used : RaftPartition(io.atomix.raft.partition.RaftPartition) ZeebeClientBuilder(io.camunda.zeebe.client.ZeebeClientBuilder) Before(org.junit.Before)

Example 23 with RaftPartition

use of io.atomix.raft.partition.RaftPartition in project zeebe by camunda.

the class PartitionFactory method constructPartitions.

List<ZeebePartition> constructPartitions(final RaftPartitionGroup partitionGroup, final List<PartitionListener> partitionListeners, final TopologyManager topologyManager) {
    final var partitions = new ArrayList<ZeebePartition>();
    final var communicationService = clusterServices.getCommunicationService();
    final var eventService = clusterServices.getEventService();
    final var membershipService = clusterServices.getMembershipService();
    final MemberId nodeId = membershipService.getLocalMember().id();
    final List<RaftPartition> owningPartitions = partitionGroup.getPartitionsWithMember(nodeId).stream().map(RaftPartition.class::cast).collect(Collectors.toList());
    final var typedRecordProcessorsFactory = createFactory(topologyManager, localBroker, communicationService, eventService, deploymentRequestHandler);
    for (final RaftPartition owningPartition : owningPartitions) {
        final var partitionId = owningPartition.id().id();
        final ConstructableSnapshotStore constructableSnapshotStore = snapshotStoreFactory.getConstructableSnapshotStore(partitionId);
        final StateController stateController = createStateController(owningPartition, constructableSnapshotStore, snapshotStoreFactory.getSnapshotStoreConcurrencyControl(partitionId));
        final PartitionStartupAndTransitionContextImpl partitionStartupAndTransitionContext = new PartitionStartupAndTransitionContextImpl(localBroker.getNodeId(), owningPartition, partitionListeners, new AtomixPartitionMessagingService(communicationService, membershipService, owningPartition.members()), actorSchedulingService, brokerCfg, commandApiService::newCommandResponseWriter, () -> commandApiService.getOnProcessedListener(partitionId), constructableSnapshotStore, snapshotStoreFactory.getReceivableSnapshotStore(partitionId), stateController, typedRecordProcessorsFactory, exporterRepository, new PartitionProcessingState(owningPartition));
        final PartitionTransition newTransitionBehavior = new PartitionTransitionImpl(TRANSITION_STEPS);
        final ZeebePartition zeebePartition = new ZeebePartition(partitionStartupAndTransitionContext, newTransitionBehavior, STARTUP_STEPS);
        healthCheckService.registerMonitoredPartition(zeebePartition.getPartitionId(), zeebePartition);
        partitions.add(zeebePartition);
    }
    return partitions;
}
Also used : ArrayList(java.util.ArrayList) PartitionTransition(io.camunda.zeebe.broker.system.partitions.PartitionTransition) MemberId(io.atomix.cluster.MemberId) AtomixPartitionMessagingService(io.camunda.zeebe.broker.system.partitions.impl.AtomixPartitionMessagingService) PartitionProcessingState(io.camunda.zeebe.broker.system.partitions.impl.PartitionProcessingState) RaftPartition(io.atomix.raft.partition.RaftPartition) PartitionStartupAndTransitionContextImpl(io.camunda.zeebe.broker.system.partitions.PartitionStartupAndTransitionContextImpl) ConstructableSnapshotStore(io.camunda.zeebe.snapshots.ConstructableSnapshotStore) StateController(io.camunda.zeebe.broker.system.partitions.StateController) ZeebePartition(io.camunda.zeebe.broker.system.partitions.ZeebePartition) PartitionTransitionImpl(io.camunda.zeebe.broker.system.partitions.impl.PartitionTransitionImpl)

Example 24 with RaftPartition

use of io.atomix.raft.partition.RaftPartition in project zeebe by camunda.

the class ClusteringRule method stepDown.

public void stepDown(final Broker broker, final int partitionId) {
    final var atomix = broker.getBrokerContext().getClusterServices();
    final MemberId nodeId = atomix.getMembershipService().getLocalMember().id();
    final var raftPartition = broker.getBrokerContext().getPartitionManager().getPartitionGroup().getPartitions().stream().filter(partition -> partition.members().contains(nodeId)).filter(partition -> partition.id().id() == partitionId).map(RaftPartition.class::cast).findFirst().orElseThrow();
    raftPartition.getServer().stepDown().join();
}
Also used : DEBUG_EXPORTER(io.camunda.zeebe.broker.test.EmbeddedBrokerConfigurator.DEBUG_EXPORTER) START_PARTITION_ID(io.camunda.zeebe.protocol.Protocol.START_PARTITION_ID) Address(io.atomix.utils.net.Address) AutoCloseableRule(io.camunda.zeebe.test.util.AutoCloseableRule) EmbeddedBrokerRule.assignSocketAddresses(io.camunda.zeebe.broker.test.EmbeddedBrokerRule.assignSocketAddresses) TimeoutException(java.util.concurrent.TimeoutException) Gateway(io.camunda.zeebe.gateway.Gateway) UncheckedExecutionException(io.camunda.zeebe.util.exception.UncheckedExecutionException) Duration(java.time.Duration) Map(java.util.Map) ClusterCfg(io.camunda.zeebe.gateway.impl.configuration.ClusterCfg) LangUtil(org.agrona.LangUtil) SocketBindingCfg(io.camunda.zeebe.broker.system.configuration.SocketBindingCfg) NettyMessagingService(io.atomix.cluster.messaging.impl.NettyMessagingService) Path(java.nio.file.Path) EmbeddedBrokerConfigurator.setCluster(io.camunda.zeebe.broker.test.EmbeddedBrokerConfigurator.setCluster) ControlledActorClock(io.camunda.zeebe.util.sched.clock.ControlledActorClock) ProcessInstanceCreationRecord(io.camunda.zeebe.protocol.impl.record.value.processinstance.ProcessInstanceCreationRecord) BrokerAdminService(io.camunda.zeebe.broker.system.management.BrokerAdminService) PartitionManagerImpl(io.camunda.zeebe.broker.partitioning.PartitionManagerImpl) Predicate(java.util.function.Predicate) SystemContext(io.camunda.zeebe.broker.system.SystemContext) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BrokerInfo(io.camunda.zeebe.client.api.response.BrokerInfo) Set(java.util.Set) Description(org.junit.runner.Description) DISABLE_EMBEDDED_GATEWAY(io.camunda.zeebe.broker.test.EmbeddedBrokerConfigurator.DISABLE_EMBEDDED_GATEWAY) RecordingExporterTestWatcher(io.camunda.zeebe.test.util.record.RecordingExporterTestWatcher) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) SwimMembershipProtocol(io.atomix.cluster.protocol.SwimMembershipProtocol) UncheckedIOException(java.io.UncheckedIOException) Objects(java.util.Objects) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) ExternalResource(org.junit.rules.ExternalResource) NetworkCfg(io.camunda.zeebe.broker.system.configuration.NetworkCfg) SnapshotId(io.camunda.zeebe.snapshots.SnapshotId) BootstrapDiscoveryProvider(io.atomix.cluster.discovery.BootstrapDiscoveryProvider) Broker(io.camunda.zeebe.broker.Broker) ZeebeClient(io.camunda.zeebe.client.ZeebeClient) Optional(java.util.Optional) Awaitility(org.awaitility.Awaitility) IntStream(java.util.stream.IntStream) Statement(org.junit.runners.model.Statement) AtomixClusterBuilder(io.atomix.cluster.AtomixClusterBuilder) PartitionStatus(io.camunda.zeebe.broker.system.management.PartitionStatus) EmbeddedBrokerConfigurator.setInitialContactPoints(io.camunda.zeebe.broker.test.EmbeddedBrokerConfigurator.setInitialContactPoints) ActorFuture(io.camunda.zeebe.util.sched.future.ActorFuture) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) SpringBrokerBridge(io.camunda.zeebe.broker.SpringBrokerBridge) FileBasedSnapshotMetadata(io.camunda.zeebe.snapshots.impl.FileBasedSnapshotMetadata) PartitionInfo(io.camunda.zeebe.client.api.response.PartitionInfo) RaftPartition(io.atomix.raft.partition.RaftPartition) MemberId(io.atomix.cluster.MemberId) BrokerResponse(io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse) BrokerContext(io.camunda.zeebe.broker.bootstrap.BrokerContext) SocketUtil(io.camunda.zeebe.test.util.socket.SocketUtil) LOG(io.camunda.zeebe.broker.Broker.LOG) Topology(io.camunda.zeebe.client.api.response.Topology) ExporterDirectorContext(io.camunda.zeebe.broker.exporter.stream.ExporterDirectorContext) ClusterConfig(io.atomix.cluster.ClusterConfig) BrokerCfg(io.camunda.zeebe.broker.system.configuration.BrokerCfg) BrokerCreateProcessInstanceRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerCreateProcessInstanceRequest) Files(java.nio.file.Files) AtomixCluster(io.atomix.cluster.AtomixCluster) NetUtil(io.netty.util.NetUtil) IOException(java.io.IOException) ZeebeClientBuilder(io.camunda.zeebe.client.ZeebeClientBuilder) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) PartitionListener(io.camunda.zeebe.broker.PartitionListener) LogStream(io.camunda.zeebe.logstreams.log.LogStream) Paths(java.nio.file.Paths) QueryService(io.camunda.zeebe.engine.state.QueryService) GatewayCfg(io.camunda.zeebe.gateway.impl.configuration.GatewayCfg) CompletableActorFuture(io.camunda.zeebe.util.sched.future.CompletableActorFuture) NettyUnicastService(io.atomix.cluster.messaging.impl.NettyUnicastService) TEST_RECORDER(io.camunda.zeebe.broker.test.EmbeddedBrokerConfigurator.TEST_RECORDER) Assert(org.junit.Assert) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) ActorScheduler(io.camunda.zeebe.util.sched.ActorScheduler) MemberId(io.atomix.cluster.MemberId) RaftPartition(io.atomix.raft.partition.RaftPartition)

Example 25 with RaftPartition

use of io.atomix.raft.partition.RaftPartition in project zeebe by camunda.

the class RaftRolesTest method testExceptionInRoleChangedListener.

@Test
public void testExceptionInRoleChangedListener() throws Exception {
    // given
    final CompletableFuture<Void> roleChanged = new CompletableFuture<>();
    final CompletableFuture<Void> joinFuture = startSingleNodeSinglePartitionWithPartitionConsumer(partition -> {
        final RaftPartition raftPartition = (RaftPartition) partition;
        raftPartition.addRoleChangeListener((role, term) -> {
            roleChanged.complete(null);
            // when
            throw new RuntimeException("expected");
        });
    });
    // then
    joinFuture.join();
    roleChanged.get(60, TimeUnit.SECONDS);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RaftPartition(io.atomix.raft.partition.RaftPartition) Test(org.junit.Test)

Aggregations

RaftPartition (io.atomix.raft.partition.RaftPartition)26 CompletableFuture (java.util.concurrent.CompletableFuture)15 Test (org.junit.Test)12 MemberId (io.atomix.cluster.MemberId)11 AtomixCluster (io.atomix.cluster.AtomixCluster)9 AtomixClusterBuilder (io.atomix.cluster.AtomixClusterBuilder)9 Broker (io.camunda.zeebe.broker.Broker)9 ZeebeClientBuilder (io.camunda.zeebe.client.ZeebeClientBuilder)9 File (java.io.File)9 Collections (java.util.Collections)9 List (java.util.List)9 CountDownLatch (java.util.concurrent.CountDownLatch)9 ExecutionException (java.util.concurrent.ExecutionException)9 TimeUnit (java.util.concurrent.TimeUnit)9 Consumer (java.util.function.Consumer)9 Collectors (java.util.stream.Collectors)9 LangUtil (org.agrona.LangUtil)9 ClusterConfig (io.atomix.cluster.ClusterConfig)6 BootstrapDiscoveryProvider (io.atomix.cluster.discovery.BootstrapDiscoveryProvider)6 NettyMessagingService (io.atomix.cluster.messaging.impl.NettyMessagingService)6