use of io.atomix.raft.partition.RaftPartition in project zeebe by camunda.
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();
}
use of io.atomix.raft.partition.RaftPartition in project zeebe by camunda.
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);
}
use of io.atomix.raft.partition.RaftPartition in project zeebe by camunda.
the class ClusteringRule method forceClusterToHaveNewLeader.
public void forceClusterToHaveNewLeader(final int expectedLeader) {
final var previousLeader = getCurrentLeaderForPartition(1);
if (previousLeader.getNodeId() == expectedLeader) {
return;
}
final var broker = brokers.get(expectedLeader);
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() == START_PARTITION_ID).map(RaftPartition.class::cast).findFirst().orElseThrow();
raftPartition.getServer().promote().join();
awaitOtherLeader(START_PARTITION_ID, previousLeader.getNodeId());
}
use of io.atomix.raft.partition.RaftPartition in project zeebe by camunda.
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();
});
}
use of io.atomix.raft.partition.RaftPartition in project zeebe by camunda-cloud.
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;
}
Aggregations