use of io.zeebe.broker.clustering.member.Member in project zeebe by zeebe-io.
the class RemoteWorkflowsManager method forEachPartition.
private boolean forEachPartition(IntArrayList partitionIds, IntConsumer partitionIdConsumer, Predicate<SocketAddress> action) {
boolean success = true;
final Iterator<Member> members = partitionManager.getKnownMembers();
while (members.hasNext() && success) {
final Member member = members.next();
final IntIterator leadingPartitions = member.getLeadingPartitions();
while (leadingPartitions.hasNext() && success) {
final int partitionId = leadingPartitions.nextInt();
if (partitionIds.containsInt(partitionId)) {
partitionIdConsumer.accept(partitionId);
success = action.test(member.getManagementAddress());
}
}
}
return true;
}
use of io.zeebe.broker.clustering.member.Member in project zeebe by zeebe-io.
the class RoundRobinSelectionStrategy method selectBrokerForNewPartition.
@Override
public SocketAddress selectBrokerForNewPartition() {
final Iterator<Member> knownMembers = partitionManager.getKnownMembers();
moveToLastSelectedBroker(knownMembers);
final Member nextBroker = chooseNextBroker(knownMembers);
if (nextBroker != null) {
lastSelectedBroker.wrap(nextBroker.getManagementAddress());
return lastSelectedBroker;
} else {
lastSelectedBroker.reset();
return null;
}
}
use of io.zeebe.broker.clustering.member.Member in project zeebe by zeebe-io.
the class CreateTopicStreamProcessorTest method shouldSkipMembersWithoutManagmenetApiWhenDistributePartitionsRoundRobin.
@Test
public void shouldSkipMembersWithoutManagmenetApiWhenDistributePartitionsRoundRobin() {
// given
partitionManager.addMember(SOCKET_ADDRESS1);
partitionManager.addMember(SOCKET_ADDRESS2);
// last member has no management endpoint set yet
partitionManager.currentMembers.add(new Member() {
@Override
public SocketAddress getManagementAddress() {
return null;
}
@Override
public IntIterator getLeadingPartitions() {
return null;
}
});
rule.runStreamProcessor(this::buildStreamProcessor);
// when
rule.writeEvent(createTopic("foo", 4));
waitUntil(() -> partitionEventsInState(PartitionState.CREATING).count() == 4);
// then
final List<PartitionRequest> requests = partitionManager.getPartitionRequests();
assertThat(requests).extracting(r -> r.endpoint).containsOnly(SOCKET_ADDRESS1, SOCKET_ADDRESS2, SOCKET_ADDRESS1, SOCKET_ADDRESS2);
}
use of io.zeebe.broker.clustering.member.Member in project zeebe by zeebe-io.
the class RoundRobinSelectionStrategy method chooseNextBroker.
private Member chooseNextBroker(Iterator<Member> knownMembers) {
Member nextBroker = findNextMemberWithManagementAddress(knownMembers);
if (nextBroker == null) {
// reset iterator and try again to find a broker
knownMembers = partitionManager.getKnownMembers();
nextBroker = findNextMemberWithManagementAddress(knownMembers);
}
return nextBroker;
}
use of io.zeebe.broker.clustering.member.Member in project zeebe by zeebe-io.
the class ResolvePendingPartitionsCommand method checkCompletedCreation.
private void checkCompletedCreation() {
final Iterator<Member> currentMembers = partitionManager.getKnownMembers();
while (currentMembers.hasNext()) {
final Member currentMember = currentMembers.next();
final IntIterator partitionsLeadByMember = currentMember.getLeadingPartitions();
while (partitionsLeadByMember.hasNext()) {
final int currentPartition = partitionsLeadByMember.nextInt();
final PendingPartition partition = partitions.get(currentPartition);
if (partition != null) {
final TypedEvent<PartitionEvent> event = reader.readValue(partition.getPosition(), PartitionEvent.class);
event.getValue().setState(PartitionState.CREATE_COMPLETE);
// it is ok if writing fails,
// we will then try it again with the next command execution (there are no other side effects of completion)
writer.writeFollowupEvent(event.getKey(), event.getValue());
}
}
}
}
Aggregations