Search in sources :

Example 1 with Member

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;
}
Also used : IntIterator(io.zeebe.util.collection.IntIterator) Member(io.zeebe.broker.clustering.member.Member)

Example 2 with Member

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;
    }
}
Also used : Member(io.zeebe.broker.clustering.member.Member)

Example 3 with Member

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);
}
Also used : Member(io.zeebe.broker.clustering.member.Member) PartitionRequest(io.zeebe.broker.topic.TestPartitionManager.PartitionRequest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TopologyBroker(io.zeebe.broker.clustering.handler.TopologyBroker) IntIterator(io.zeebe.util.collection.IntIterator) SocketAddress(io.zeebe.transport.SocketAddress) Duration(java.time.Duration) TypedStreamProcessor(io.zeebe.broker.logstreams.processor.TypedStreamProcessor) Before(org.junit.Before) TopicEvent(io.zeebe.broker.system.log.TopicEvent) TransportHeaderDescriptor(io.zeebe.transport.impl.TransportHeaderDescriptor) TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) ResolvePendingPartitionsCommand(io.zeebe.broker.system.log.ResolvePendingPartitionsCommand) TopicsIndex(io.zeebe.broker.system.log.TopicsIndex) PendingPartitionsIndex(io.zeebe.broker.system.log.PendingPartitionsIndex) Test(org.junit.Test) SystemPartitionManager(io.zeebe.broker.system.log.SystemPartitionManager) Instant(java.time.Instant) TestUtil.doRepeatedly(io.zeebe.test.util.TestUtil.doRepeatedly) Collectors(java.util.stream.Collectors) TopicState(io.zeebe.broker.system.log.TopicState) PartitionState(io.zeebe.broker.system.log.PartitionState) List(java.util.List) TypedStreamEnvironment(io.zeebe.broker.logstreams.processor.TypedStreamEnvironment) Assertions.fail(org.assertj.core.api.Assertions.fail) Stream(java.util.stream.Stream) Rule(org.junit.Rule) Ignore(org.junit.Ignore) StreamProcessorRule(io.zeebe.broker.util.StreamProcessorRule) BufferUtil(io.zeebe.util.buffer.BufferUtil) Optional(java.util.Optional) TypedEvent(io.zeebe.broker.logstreams.processor.TypedEvent) PartitionEvent(io.zeebe.broker.system.log.PartitionEvent) RequestResponseHeaderDescriptor(io.zeebe.transport.impl.RequestResponseHeaderDescriptor) IntIterator(io.zeebe.util.collection.IntIterator) PartitionRequest(io.zeebe.broker.topic.TestPartitionManager.PartitionRequest) SocketAddress(io.zeebe.transport.SocketAddress) Member(io.zeebe.broker.clustering.member.Member) Test(org.junit.Test)

Example 4 with Member

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;
}
Also used : Member(io.zeebe.broker.clustering.member.Member)

Example 5 with Member

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());
            }
        }
    }
}
Also used : IntIterator(io.zeebe.util.collection.IntIterator) PendingPartition(io.zeebe.broker.system.log.PendingPartitionsIndex.PendingPartition) Member(io.zeebe.broker.clustering.member.Member)

Aggregations

Member (io.zeebe.broker.clustering.member.Member)5 IntIterator (io.zeebe.util.collection.IntIterator)3 TopologyBroker (io.zeebe.broker.clustering.handler.TopologyBroker)1 TypedEvent (io.zeebe.broker.logstreams.processor.TypedEvent)1 TypedStreamEnvironment (io.zeebe.broker.logstreams.processor.TypedStreamEnvironment)1 TypedStreamProcessor (io.zeebe.broker.logstreams.processor.TypedStreamProcessor)1 PartitionEvent (io.zeebe.broker.system.log.PartitionEvent)1 PartitionState (io.zeebe.broker.system.log.PartitionState)1 PendingPartitionsIndex (io.zeebe.broker.system.log.PendingPartitionsIndex)1 PendingPartition (io.zeebe.broker.system.log.PendingPartitionsIndex.PendingPartition)1 ResolvePendingPartitionsCommand (io.zeebe.broker.system.log.ResolvePendingPartitionsCommand)1 SystemPartitionManager (io.zeebe.broker.system.log.SystemPartitionManager)1 TopicEvent (io.zeebe.broker.system.log.TopicEvent)1 TopicState (io.zeebe.broker.system.log.TopicState)1 TopicsIndex (io.zeebe.broker.system.log.TopicsIndex)1 PartitionRequest (io.zeebe.broker.topic.TestPartitionManager.PartitionRequest)1 StreamProcessorRule (io.zeebe.broker.util.StreamProcessorRule)1 TestUtil.doRepeatedly (io.zeebe.test.util.TestUtil.doRepeatedly)1 TestUtil.waitUntil (io.zeebe.test.util.TestUtil.waitUntil)1 SocketAddress (io.zeebe.transport.SocketAddress)1