Search in sources :

Example 11 with RaftPartition

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

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 12 with RaftPartition

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

the class HealthMonitoringTest method shouldReportUnhealthyWhenRaftInactive.

@Test
public void shouldReportUnhealthyWhenRaftInactive() {
    // given
    final Broker leader = embeddedBrokerRule.getBroker();
    /* timeouts are selected generously as at the time of this implementation there is a
     * 1 minute cycle to update the state
     */
    await("Broker is healthy").atMost(Duration.ofMinutes(2)).until(() -> {
        embeddedBrokerRule.getClock().addTime(Duration.ofMinutes(1));
        return isBrokerHealthy();
    });
    // when
    final var raftPartition = (RaftPartition) leader.getBrokerContext().getPartitionManager().getPartitionGroup().getPartition(PartitionId.from(PartitionManagerImpl.GROUP_NAME, START_PARTITION_ID));
    raftPartition.getServer().stop();
    // then
    /* timeouts are selected generously as at the time of this implementation there is a
     * 1 minute cycle to update the state
     */
    waitAtMost(Duration.ofMinutes(2)).until(() -> {
        embeddedBrokerRule.getClock().addTime(Duration.ofMinutes(1));
        return !isBrokerHealthy();
    });
}
Also used : Broker(io.camunda.zeebe.broker.Broker) RaftPartition(io.atomix.raft.partition.RaftPartition) Test(org.junit.Test)

Example 13 with RaftPartition

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

the class RaftRolesTest method testStepDownInRoleChangedListener.

@Test
public void testStepDownInRoleChangedListener() throws Exception {
    // given
    final CompletableFuture<Void> roleChanged = new CompletableFuture<>();
    final CountDownLatch followerLatch = new CountDownLatch(2);
    final List<Role> roles = new ArrayList<>();
    startSingleNodeSinglePartitionWithPartitionConsumer(partition -> {
        final RaftPartition raftPartition = (RaftPartition) partition;
        raftPartition.addRoleChangeListener((role, term) -> {
            roles.add(role);
            if (!roleChanged.isDone() && role == Role.LEADER) {
                roleChanged.complete(null);
                // when
                raftPartition.stepDown();
            } else if (role == Role.FOLLOWER) {
                followerLatch.countDown();
            }
        });
    }).join();
    // then
    roleChanged.get(60, TimeUnit.SECONDS);
    followerLatch.await(10, TimeUnit.SECONDS);
    // single node becomes directly leader again
    assertThat(roles).containsSequence(Role.INACTIVE, Role.LEADER, Role.LEADER);
}
Also used : Role(io.atomix.raft.RaftServer.Role) AtomixClusterBuilder(io.atomix.cluster.AtomixClusterBuilder) AtomixClusterRule(io.atomix.cluster.AtomixClusterRule) Role(io.atomix.raft.RaftServer.Role) DefaultPartitionService(io.atomix.primitive.partition.impl.DefaultPartitionService) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomixCluster(io.atomix.cluster.AtomixCluster) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.Test) Collectors(java.util.stream.Collectors) File(java.io.File) ArrayList(java.util.ArrayList) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Rule(org.junit.Rule) Partition(io.atomix.primitive.partition.Partition) RaftPartition(io.atomix.raft.partition.RaftPartition) LangUtil(org.agrona.LangUtil) RaftPartitionGroup(io.atomix.raft.partition.RaftPartitionGroup) NoopSnapshotStoreFactory(io.atomix.cluster.NoopSnapshotStoreFactory) Collections(java.util.Collections) CompletableFuture(java.util.concurrent.CompletableFuture) RaftPartition(io.atomix.raft.partition.RaftPartition) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 14 with RaftPartition

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

the class RaftRolesTest method testRoleChangedListener.

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

Example 15 with RaftPartition

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

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)

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