Search in sources :

Example 11 with PartitionChangeRecord

use of org.apache.kafka.common.metadata.PartitionChangeRecord in project kafka by apache.

the class ReplicationControlManagerTest method testElectPreferredLeaders.

@Test
public void testElectPreferredLeaders() throws Exception {
    ReplicationControlTestContext ctx = new ReplicationControlTestContext();
    ReplicationControlManager replication = ctx.replicationControl;
    ctx.registerBrokers(0, 1, 2, 3, 4);
    ctx.unfenceBrokers(2, 3, 4);
    Uuid fooId = ctx.createTestTopic("foo", new int[][] { new int[] { 1, 2, 3 }, new int[] { 2, 3, 4 }, new int[] { 0, 2, 1 } }).topicId();
    ElectLeadersRequestData request1 = new ElectLeadersRequestData().setElectionType(ElectionType.PREFERRED.value).setTopicPartitions(new TopicPartitionsCollection(asList(new TopicPartitions().setTopic("foo").setPartitions(asList(0, 1)), new TopicPartitions().setTopic("bar").setPartitions(asList(0, 1))).iterator()));
    ControllerResult<ElectLeadersResponseData> election1Result = replication.electLeaders(request1);
    ElectLeadersResponseData expectedResponse1 = buildElectLeadersResponse(NONE, false, Utils.mkMap(Utils.mkEntry(new TopicPartition("foo", 0), new ApiError(PREFERRED_LEADER_NOT_AVAILABLE)), Utils.mkEntry(new TopicPartition("foo", 1), new ApiError(ELECTION_NOT_NEEDED)), Utils.mkEntry(new TopicPartition("bar", 0), new ApiError(UNKNOWN_TOPIC_OR_PARTITION, "No such topic as bar")), Utils.mkEntry(new TopicPartition("bar", 1), new ApiError(UNKNOWN_TOPIC_OR_PARTITION, "No such topic as bar"))));
    assertElectLeadersResponse(expectedResponse1, election1Result.response());
    assertEquals(Collections.emptyList(), election1Result.records());
    ctx.unfenceBrokers(0, 1);
    ControllerResult<AlterIsrResponseData> alterIsrResult = replication.alterIsr(new AlterIsrRequestData().setBrokerId(2).setBrokerEpoch(102).setTopics(asList(new AlterIsrRequestData.TopicData().setName("foo").setPartitions(asList(new AlterIsrRequestData.PartitionData().setPartitionIndex(0).setCurrentIsrVersion(0).setLeaderEpoch(0).setNewIsr(asList(1, 2, 3)))))));
    assertEquals(new AlterIsrResponseData().setTopics(asList(new AlterIsrResponseData.TopicData().setName("foo").setPartitions(asList(new AlterIsrResponseData.PartitionData().setPartitionIndex(0).setLeaderId(2).setLeaderEpoch(0).setIsr(asList(1, 2, 3)).setCurrentIsrVersion(1).setErrorCode(NONE.code()))))), alterIsrResult.response());
    ElectLeadersResponseData expectedResponse2 = buildElectLeadersResponse(NONE, false, Utils.mkMap(Utils.mkEntry(new TopicPartition("foo", 0), ApiError.NONE), Utils.mkEntry(new TopicPartition("foo", 1), new ApiError(ELECTION_NOT_NEEDED)), Utils.mkEntry(new TopicPartition("bar", 0), new ApiError(UNKNOWN_TOPIC_OR_PARTITION, "No such topic as bar")), Utils.mkEntry(new TopicPartition("bar", 1), new ApiError(UNKNOWN_TOPIC_OR_PARTITION, "No such topic as bar"))));
    ctx.replay(alterIsrResult.records());
    ControllerResult<ElectLeadersResponseData> election2Result = replication.electLeaders(request1);
    assertElectLeadersResponse(expectedResponse2, election2Result.response());
    assertEquals(asList(new ApiMessageAndVersion(new PartitionChangeRecord().setPartitionId(0).setTopicId(fooId).setLeader(1), (short) 0)), election2Result.records());
}
Also used : PartitionChangeRecord(org.apache.kafka.common.metadata.PartitionChangeRecord) PartitionData(org.apache.kafka.common.message.AlterIsrRequestData.PartitionData) ElectLeadersResponseData(org.apache.kafka.common.message.ElectLeadersResponseData) AlterIsrRequestData(org.apache.kafka.common.message.AlterIsrRequestData) ElectLeadersRequestData(org.apache.kafka.common.message.ElectLeadersRequestData) Uuid(org.apache.kafka.common.Uuid) TopicPartition(org.apache.kafka.common.TopicPartition) TopicData(org.apache.kafka.common.message.AlterIsrRequestData.TopicData) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) AlterIsrResponseData(org.apache.kafka.common.message.AlterIsrResponseData) ApiError(org.apache.kafka.common.requests.ApiError) TopicPartitionsCollection(org.apache.kafka.common.message.ElectLeadersRequestData.TopicPartitionsCollection) TopicPartitions(org.apache.kafka.common.message.ElectLeadersRequestData.TopicPartitions) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 12 with PartitionChangeRecord

use of org.apache.kafka.common.metadata.PartitionChangeRecord in project kafka by apache.

the class ReplicationControlManagerTest method testCancelReassignPartitions.

@Test
public void testCancelReassignPartitions() throws Exception {
    ReplicationControlTestContext ctx = new ReplicationControlTestContext();
    ReplicationControlManager replication = ctx.replicationControl;
    ctx.registerBrokers(0, 1, 2, 3, 4);
    ctx.unfenceBrokers(0, 1, 2, 3, 4);
    Uuid fooId = ctx.createTestTopic("foo", new int[][] { new int[] { 1, 2, 3, 4 }, new int[] { 0, 1, 2, 3 }, new int[] { 4, 3, 1, 0 }, new int[] { 2, 3, 4, 1 } }).topicId();
    Uuid barId = ctx.createTestTopic("bar", new int[][] { new int[] { 4, 3, 2 } }).topicId();
    assertEquals(NONE_REASSIGNING, replication.listPartitionReassignments(null));
    List<ApiMessageAndVersion> fenceRecords = new ArrayList<>();
    replication.handleBrokerFenced(3, fenceRecords);
    ctx.replay(fenceRecords);
    assertEquals(new PartitionRegistration(new int[] { 1, 2, 3, 4 }, new int[] { 1, 2, 4 }, new int[] {}, new int[] {}, 1, 1, 1), replication.getPartition(fooId, 0));
    ControllerResult<AlterPartitionReassignmentsResponseData> alterResult = replication.alterPartitionReassignments(new AlterPartitionReassignmentsRequestData().setTopics(asList(new ReassignableTopic().setName("foo").setPartitions(asList(new ReassignablePartition().setPartitionIndex(0).setReplicas(asList(1, 2, 3)), new ReassignablePartition().setPartitionIndex(1).setReplicas(asList(1, 2, 3, 0)), new ReassignablePartition().setPartitionIndex(2).setReplicas(asList(5, 6, 7)), new ReassignablePartition().setPartitionIndex(3).setReplicas(asList()))), new ReassignableTopic().setName("bar").setPartitions(asList(new ReassignablePartition().setPartitionIndex(0).setReplicas(asList(1, 2, 3, 4, 0)))))));
    assertEquals(new AlterPartitionReassignmentsResponseData().setErrorMessage(null).setResponses(asList(new ReassignableTopicResponse().setName("foo").setPartitions(asList(new ReassignablePartitionResponse().setPartitionIndex(0).setErrorMessage(null), new ReassignablePartitionResponse().setPartitionIndex(1).setErrorMessage(null), new ReassignablePartitionResponse().setPartitionIndex(2).setErrorCode(INVALID_REPLICA_ASSIGNMENT.code()).setErrorMessage("The manual partition assignment includes broker 5, " + "but no such broker is registered."), new ReassignablePartitionResponse().setPartitionIndex(3).setErrorCode(INVALID_REPLICA_ASSIGNMENT.code()).setErrorMessage("The manual partition assignment includes an empty " + "replica list."))), new ReassignableTopicResponse().setName("bar").setPartitions(asList(new ReassignablePartitionResponse().setPartitionIndex(0).setErrorMessage(null))))), alterResult.response());
    ctx.replay(alterResult.records());
    assertEquals(new PartitionRegistration(new int[] { 1, 2, 3 }, new int[] { 1, 2 }, new int[] {}, new int[] {}, 1, 2, 2), replication.getPartition(fooId, 0));
    assertEquals(new PartitionRegistration(new int[] { 1, 2, 3, 0 }, new int[] { 0, 1, 2 }, new int[] {}, new int[] {}, 0, 1, 2), replication.getPartition(fooId, 1));
    assertEquals(new PartitionRegistration(new int[] { 1, 2, 3, 4, 0 }, new int[] { 4, 2 }, new int[] {}, new int[] { 0, 1 }, 4, 1, 2), replication.getPartition(barId, 0));
    ListPartitionReassignmentsResponseData currentReassigning = new ListPartitionReassignmentsResponseData().setErrorMessage(null).setTopics(asList(new OngoingTopicReassignment().setName("bar").setPartitions(asList(new OngoingPartitionReassignment().setPartitionIndex(0).setRemovingReplicas(Collections.emptyList()).setAddingReplicas(asList(0, 1)).setReplicas(asList(1, 2, 3, 4, 0))))));
    assertEquals(currentReassigning, replication.listPartitionReassignments(null));
    assertEquals(NONE_REASSIGNING, replication.listPartitionReassignments(asList(new ListPartitionReassignmentsTopics().setName("foo").setPartitionIndexes(asList(0, 1, 2)))));
    assertEquals(currentReassigning, replication.listPartitionReassignments(asList(new ListPartitionReassignmentsTopics().setName("bar").setPartitionIndexes(asList(0, 1, 2)))));
    ControllerResult<AlterIsrResponseData> alterIsrResult = replication.alterIsr(new AlterIsrRequestData().setBrokerId(4).setBrokerEpoch(104).setTopics(asList(new TopicData().setName("bar").setPartitions(asList(new PartitionData().setPartitionIndex(0).setCurrentIsrVersion(2).setLeaderEpoch(1).setNewIsr(asList(4, 1, 2, 3, 0)))))));
    assertEquals(new AlterIsrResponseData().setTopics(asList(new AlterIsrResponseData.TopicData().setName("bar").setPartitions(asList(new AlterIsrResponseData.PartitionData().setPartitionIndex(0).setLeaderId(4).setLeaderEpoch(1).setIsr(asList(4, 1, 2, 3, 0)).setCurrentIsrVersion(3).setErrorCode(NONE.code()))))), alterIsrResult.response());
    ControllerResult<AlterPartitionReassignmentsResponseData> cancelResult = replication.alterPartitionReassignments(new AlterPartitionReassignmentsRequestData().setTopics(asList(new ReassignableTopic().setName("foo").setPartitions(asList(new ReassignablePartition().setPartitionIndex(0).setReplicas(null))), new ReassignableTopic().setName("bar").setPartitions(asList(new ReassignablePartition().setPartitionIndex(0).setReplicas(null))))));
    assertEquals(ControllerResult.atomicOf(Collections.singletonList(new ApiMessageAndVersion(new PartitionChangeRecord().setTopicId(barId).setPartitionId(0).setLeader(4).setReplicas(asList(2, 3, 4)).setRemovingReplicas(null).setAddingReplicas(Collections.emptyList()), (short) 0)), new AlterPartitionReassignmentsResponseData().setErrorMessage(null).setResponses(asList(new ReassignableTopicResponse().setName("foo").setPartitions(asList(new ReassignablePartitionResponse().setPartitionIndex(0).setErrorCode(NO_REASSIGNMENT_IN_PROGRESS.code()).setErrorMessage(null))), new ReassignableTopicResponse().setName("bar").setPartitions(asList(new ReassignablePartitionResponse().setPartitionIndex(0).setErrorMessage(null)))))), cancelResult);
    ctx.replay(cancelResult.records());
    assertEquals(NONE_REASSIGNING, replication.listPartitionReassignments(null));
    assertEquals(new PartitionRegistration(new int[] { 2, 3, 4 }, new int[] { 4, 2 }, new int[] {}, new int[] {}, 4, 2, 3), replication.getPartition(barId, 0));
}
Also used : PartitionRegistration(org.apache.kafka.metadata.PartitionRegistration) ReassignablePartition(org.apache.kafka.common.message.AlterPartitionReassignmentsRequestData.ReassignablePartition) PartitionChangeRecord(org.apache.kafka.common.metadata.PartitionChangeRecord) ReassignableTopic(org.apache.kafka.common.message.AlterPartitionReassignmentsRequestData.ReassignableTopic) ArrayList(java.util.ArrayList) TopicData(org.apache.kafka.common.message.AlterIsrRequestData.TopicData) ListPartitionReassignmentsResponseData(org.apache.kafka.common.message.ListPartitionReassignmentsResponseData) ReassignableTopicResponse(org.apache.kafka.common.message.AlterPartitionReassignmentsResponseData.ReassignableTopicResponse) PartitionData(org.apache.kafka.common.message.AlterIsrRequestData.PartitionData) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) ListPartitionReassignmentsTopics(org.apache.kafka.common.message.ListPartitionReassignmentsRequestData.ListPartitionReassignmentsTopics) ReassignablePartitionResponse(org.apache.kafka.common.message.AlterPartitionReassignmentsResponseData.ReassignablePartitionResponse) AlterPartitionReassignmentsRequestData(org.apache.kafka.common.message.AlterPartitionReassignmentsRequestData) AlterIsrRequestData(org.apache.kafka.common.message.AlterIsrRequestData) OngoingTopicReassignment(org.apache.kafka.common.message.ListPartitionReassignmentsResponseData.OngoingTopicReassignment) Uuid(org.apache.kafka.common.Uuid) AlterPartitionReassignmentsResponseData(org.apache.kafka.common.message.AlterPartitionReassignmentsResponseData) OngoingPartitionReassignment(org.apache.kafka.common.message.ListPartitionReassignmentsResponseData.OngoingPartitionReassignment) AlterIsrResponseData(org.apache.kafka.common.message.AlterIsrResponseData) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 13 with PartitionChangeRecord

use of org.apache.kafka.common.metadata.PartitionChangeRecord in project kafka by apache.

the class TopicsImageTest method testDeleteAfterChanges.

@Test
public void testDeleteAfterChanges() {
    int localId = 3;
    Uuid zooId = Uuid.fromString("0hHJ3X5ZQ-CFfQ5xgpj90w");
    List<TopicImage> topics = new ArrayList<>();
    topics.add(newTopicImage("zoo", zooId, newPartition(new int[] { localId, 1, 2 })));
    TopicsImage image = new TopicsImage(newTopicsByIdMap(topics), newTopicsByNameMap(topics));
    List<ApiMessageAndVersion> topicRecords = new ArrayList<>();
    // leader to follower
    topicRecords.add(new ApiMessageAndVersion(new PartitionChangeRecord().setTopicId(zooId).setPartitionId(0).setLeader(1), PARTITION_CHANGE_RECORD.highestSupportedVersion()));
    // remove zoo topic
    topicRecords.add(new ApiMessageAndVersion(new RemoveTopicRecord().setTopicId(zooId), REMOVE_TOPIC_RECORD.highestSupportedVersion()));
    TopicsDelta delta = new TopicsDelta(image);
    RecordTestUtils.replayAll(delta, topicRecords);
    LocalReplicaChanges changes = delta.localChanges(localId);
    assertEquals(new HashSet<>(Arrays.asList(new TopicPartition("zoo", 0))), changes.deletes());
    assertEquals(Collections.emptyMap(), changes.leaders());
    assertEquals(Collections.emptyMap(), changes.followers());
}
Also used : PartitionChangeRecord(org.apache.kafka.common.metadata.PartitionChangeRecord) ArrayList(java.util.ArrayList) Uuid(org.apache.kafka.common.Uuid) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) RemoveTopicRecord(org.apache.kafka.common.metadata.RemoveTopicRecord) TopicPartition(org.apache.kafka.common.TopicPartition) Test(org.junit.jupiter.api.Test)

Example 14 with PartitionChangeRecord

use of org.apache.kafka.common.metadata.PartitionChangeRecord in project kafka by apache.

the class ReplicationControlManager method generateLeaderAndIsrUpdates.

/**
 * Iterate over a sequence of partitions and generate ISR changes and/or leader
 * changes if necessary.
 *
 * @param context           A human-readable context string used in log4j logging.
 * @param brokerToRemove    NO_LEADER if no broker is being removed; the ID of the
 *                          broker to remove from the ISR and leadership, otherwise.
 * @param brokerToAdd       NO_LEADER if no broker is being added; the ID of the
 *                          broker which is now eligible to be a leader, otherwise.
 * @param records           A list of records which we will append to.
 * @param iterator          The iterator containing the partitions to examine.
 */
void generateLeaderAndIsrUpdates(String context, int brokerToRemove, int brokerToAdd, List<ApiMessageAndVersion> records, Iterator<TopicIdPartition> iterator) {
    int oldSize = records.size();
    // If the caller passed a valid broker ID for brokerToAdd, rather than passing
    // NO_LEADER, that node will be considered an acceptable leader even if it is
    // currently fenced. This is useful when handling unfencing. The reason is that
    // while we're generating the records to handle unfencing, the ClusterControlManager
    // still shows the node as fenced.
    // 
    // Similarly, if the caller passed a valid broker ID for brokerToRemove, rather
    // than passing NO_LEADER, that node will never be considered an acceptable leader.
    // This is useful when handling a newly fenced node. We also exclude brokerToRemove
    // from the target ISR, but we need to exclude it here too, to handle the case
    // where there is an unclean leader election which chooses a leader from outside
    // the ISR.
    Function<Integer, Boolean> isAcceptableLeader = r -> (r != brokerToRemove) && (r == brokerToAdd || clusterControl.unfenced(r));
    while (iterator.hasNext()) {
        TopicIdPartition topicIdPart = iterator.next();
        TopicControlInfo topic = topics.get(topicIdPart.topicId());
        if (topic == null) {
            throw new RuntimeException("Topic ID " + topicIdPart.topicId() + " existed in isrMembers, but not in the topics map.");
        }
        PartitionRegistration partition = topic.parts.get(topicIdPart.partitionId());
        if (partition == null) {
            throw new RuntimeException("Partition " + topicIdPart + " existed in isrMembers, but not in the partitions map.");
        }
        PartitionChangeBuilder builder = new PartitionChangeBuilder(partition, topicIdPart.topicId(), topicIdPart.partitionId(), isAcceptableLeader, () -> configurationControl.uncleanLeaderElectionEnabledForTopic(topic.name));
        // Note: if brokerToRemove was passed as NO_LEADER, this is a no-op (the new
        // target ISR will be the same as the old one).
        builder.setTargetIsr(Replicas.toList(Replicas.copyWithout(partition.isr, brokerToRemove)));
        builder.build().ifPresent(records::add);
    }
    if (records.size() != oldSize) {
        if (log.isDebugEnabled()) {
            StringBuilder bld = new StringBuilder();
            String prefix = "";
            for (ListIterator<ApiMessageAndVersion> iter = records.listIterator(oldSize); iter.hasNext(); ) {
                ApiMessageAndVersion apiMessageAndVersion = iter.next();
                PartitionChangeRecord record = (PartitionChangeRecord) apiMessageAndVersion.message();
                bld.append(prefix).append(topics.get(record.topicId()).name).append("-").append(record.partitionId());
                prefix = ", ";
            }
            log.debug("{}: changing partition(s): {}", context, bld.toString());
        } else if (log.isInfoEnabled()) {
            log.info("{}: changing {} partition(s)", context, records.size() - oldSize);
        }
    }
}
Also used : ListPartitionReassignmentsTopics(org.apache.kafka.common.message.ListPartitionReassignmentsRequestData.ListPartitionReassignmentsTopics) OpType(org.apache.kafka.clients.admin.AlterConfigOp.OpType) InvalidReplicationFactorException(org.apache.kafka.common.errors.InvalidReplicationFactorException) ElectLeadersRequestData(org.apache.kafka.common.message.ElectLeadersRequestData) CreatePartitionsTopic(org.apache.kafka.common.message.CreatePartitionsRequestData.CreatePartitionsTopic) PartitionResult(org.apache.kafka.common.message.ElectLeadersResponseData.PartitionResult) LogContext(org.apache.kafka.common.utils.LogContext) Map(java.util.Map) TimelineInteger(org.apache.kafka.timeline.TimelineInteger) SET(org.apache.kafka.clients.admin.AlterConfigOp.OpType.SET) AlterIsrResponseData(org.apache.kafka.common.message.AlterIsrResponseData) NoReassignmentInProgressException(org.apache.kafka.common.errors.NoReassignmentInProgressException) INVALID_REQUEST(org.apache.kafka.common.protocol.Errors.INVALID_REQUEST) InvalidTopicException(org.apache.kafka.common.errors.InvalidTopicException) UNREGISTER_BROKER_RECORD(org.apache.kafka.common.metadata.MetadataRecordType.UNREGISTER_BROKER_RECORD) SnapshotRegistry(org.apache.kafka.timeline.SnapshotRegistry) NO_LEADER(org.apache.kafka.metadata.LeaderConstants.NO_LEADER) InvalidPartitionsException(org.apache.kafka.common.errors.InvalidPartitionsException) UNKNOWN_TOPIC_ID(org.apache.kafka.common.protocol.Errors.UNKNOWN_TOPIC_ID) PartitionChangeRecord(org.apache.kafka.common.metadata.PartitionChangeRecord) Errors(org.apache.kafka.common.protocol.Errors) UnknownTopicOrPartitionException(org.apache.kafka.common.errors.UnknownTopicOrPartitionException) CreatableTopicResult(org.apache.kafka.common.message.CreateTopicsResponseData.CreatableTopicResult) RemoveTopicRecord(org.apache.kafka.common.metadata.RemoveTopicRecord) TimelineHashMap(org.apache.kafka.timeline.TimelineHashMap) NO_REASSIGNMENT_IN_PROGRESS(org.apache.kafka.common.protocol.Errors.NO_REASSIGNMENT_IN_PROGRESS) BrokerRegistration(org.apache.kafka.metadata.BrokerRegistration) Supplier(java.util.function.Supplier) TOPIC(org.apache.kafka.common.config.ConfigResource.Type.TOPIC) ArrayList(java.util.ArrayList) FENCED_LEADER_EPOCH(org.apache.kafka.common.protocol.Errors.FENCED_LEADER_EPOCH) UnfenceBrokerRecord(org.apache.kafka.common.metadata.UnfenceBrokerRecord) ElectionType(org.apache.kafka.common.ElectionType) BrokerHeartbeatReply(org.apache.kafka.metadata.BrokerHeartbeatReply) AlterPartitionReassignmentsRequestData(org.apache.kafka.common.message.AlterPartitionReassignmentsRequestData) UnknownTopicIdException(org.apache.kafka.common.errors.UnknownTopicIdException) Topic(org.apache.kafka.common.internals.Topic) CreatableReplicaAssignment(org.apache.kafka.common.message.CreateTopicsRequestData.CreatableReplicaAssignment) FENCE_BROKER_RECORD(org.apache.kafka.common.metadata.MetadataRecordType.FENCE_BROKER_RECORD) ElectLeadersResponseData(org.apache.kafka.common.message.ElectLeadersResponseData) ReassignablePartition(org.apache.kafka.common.message.AlterPartitionReassignmentsRequestData.ReassignablePartition) BrokerHeartbeatRequestData(org.apache.kafka.common.message.BrokerHeartbeatRequestData) CreatableTopicCollection(org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopicCollection) CreateTopicsRequestData(org.apache.kafka.common.message.CreateTopicsRequestData) ReassignableTopic(org.apache.kafka.common.message.AlterPartitionReassignmentsRequestData.ReassignableTopic) PartitionRecord(org.apache.kafka.common.metadata.PartitionRecord) CreatePartitionsAssignment(org.apache.kafka.common.message.CreatePartitionsRequestData.CreatePartitionsAssignment) UNFENCE_BROKER_RECORD(org.apache.kafka.common.metadata.MetadataRecordType.UNFENCE_BROKER_RECORD) PARTITION_RECORD(org.apache.kafka.common.metadata.MetadataRecordType.PARTITION_RECORD) BrokerIdNotRegisteredException(org.apache.kafka.common.errors.BrokerIdNotRegisteredException) ListIterator(java.util.ListIterator) CreatePartitionsTopicResult(org.apache.kafka.common.message.CreatePartitionsResponseData.CreatePartitionsTopicResult) ReassignableTopicResponse(org.apache.kafka.common.message.AlterPartitionReassignmentsResponseData.ReassignableTopicResponse) ReplicaElectionResult(org.apache.kafka.common.message.ElectLeadersResponseData.ReplicaElectionResult) TOPIC_RECORD(org.apache.kafka.common.metadata.MetadataRecordType.TOPIC_RECORD) FenceBrokerRecord(org.apache.kafka.common.metadata.FenceBrokerRecord) TopicRecord(org.apache.kafka.common.metadata.TopicRecord) Collection(java.util.Collection) UnregisterBrokerRecord(org.apache.kafka.common.metadata.UnregisterBrokerRecord) TopicPartitions(org.apache.kafka.common.message.ElectLeadersRequestData.TopicPartitions) PartitionRegistration(org.apache.kafka.metadata.PartitionRegistration) Collectors(java.util.stream.Collectors) Replicas(org.apache.kafka.metadata.Replicas) INVALID_UPDATE_VERSION(org.apache.kafka.common.protocol.Errors.INVALID_UPDATE_VERSION) TopicIdPartition(org.apache.kafka.controller.BrokersToIsrs.TopicIdPartition) List(java.util.List) NO_LEADER_CHANGE(org.apache.kafka.metadata.LeaderConstants.NO_LEADER_CHANGE) Entry(java.util.Map.Entry) Optional(java.util.Optional) CreateTopicsResponseData(org.apache.kafka.common.message.CreateTopicsResponseData) Uuid(org.apache.kafka.common.Uuid) ReassignablePartitionResponse(org.apache.kafka.common.message.AlterPartitionReassignmentsResponseData.ReassignablePartitionResponse) ListPartitionReassignmentsResponseData(org.apache.kafka.common.message.ListPartitionReassignmentsResponseData) HashMap(java.util.HashMap) REMOVE_TOPIC_RECORD(org.apache.kafka.common.metadata.MetadataRecordType.REMOVE_TOPIC_RECORD) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) CreatableTopic(org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopic) Function(java.util.function.Function) OptionalInt(java.util.OptionalInt) ApiError(org.apache.kafka.common.requests.ApiError) UnknownServerException(org.apache.kafka.common.errors.UnknownServerException) ConfigResource(org.apache.kafka.common.config.ConfigResource) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) PolicyViolationException(org.apache.kafka.common.errors.PolicyViolationException) OngoingPartitionReassignment(org.apache.kafka.common.message.ListPartitionReassignmentsResponseData.OngoingPartitionReassignment) OngoingTopicReassignment(org.apache.kafka.common.message.ListPartitionReassignmentsResponseData.OngoingTopicReassignment) NoSuchElementException(java.util.NoSuchElementException) UNKNOWN_TOPIC_OR_PARTITION(org.apache.kafka.common.protocol.Errors.UNKNOWN_TOPIC_OR_PARTITION) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) InvalidReplicaAssignmentException(org.apache.kafka.common.errors.InvalidReplicaAssignmentException) NO_OP_EXISTENCE_CHECKER(org.apache.kafka.controller.ConfigurationControlManager.NO_OP_EXISTENCE_CHECKER) AlterPartitionReassignmentsResponseData(org.apache.kafka.common.message.AlterPartitionReassignmentsResponseData) CreateTopicPolicy(org.apache.kafka.server.policy.CreateTopicPolicy) AlterIsrRequestData(org.apache.kafka.common.message.AlterIsrRequestData) InvalidRequestException(org.apache.kafka.common.errors.InvalidRequestException) Collections(java.util.Collections) ApiException(org.apache.kafka.common.errors.ApiException) PartitionRegistration(org.apache.kafka.metadata.PartitionRegistration) PartitionChangeRecord(org.apache.kafka.common.metadata.PartitionChangeRecord) TopicIdPartition(org.apache.kafka.controller.BrokersToIsrs.TopicIdPartition) TimelineInteger(org.apache.kafka.timeline.TimelineInteger) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion)

Example 15 with PartitionChangeRecord

use of org.apache.kafka.common.metadata.PartitionChangeRecord in project kafka by apache.

the class MetadataNodeManagerTest method testPartitionChangeRecord.

@Test
public void testPartitionChangeRecord() {
    PartitionRecord oldPartitionRecord = new PartitionRecord().setTopicId(Uuid.fromString("GcaQDl2UTsCNs1p9s37XkQ")).setPartitionId(0).setPartitionEpoch(0).setLeader(0).setLeaderEpoch(0).setIsr(Arrays.asList(0, 1, 2)).setReplicas(Arrays.asList(0, 1, 2));
    PartitionChangeRecord partitionChangeRecord = new PartitionChangeRecord().setTopicId(Uuid.fromString("GcaQDl2UTsCNs1p9s37XkQ")).setPartitionId(0).setLeader(NO_LEADER_CHANGE).setReplicas(Arrays.asList(0, 1, 2));
    PartitionRecord newPartitionRecord = new PartitionRecord().setTopicId(Uuid.fromString("GcaQDl2UTsCNs1p9s37XkQ")).setPartitionId(0).setPartitionEpoch(1).setLeader(0).setLeaderEpoch(0).setIsr(Arrays.asList(0, 1, 2)).setReplicas(Arrays.asList(0, 1, 2));
    // Change nothing
    checkPartitionChangeRecord(oldPartitionRecord, partitionChangeRecord, newPartitionRecord);
    // Change isr
    checkPartitionChangeRecord(oldPartitionRecord, partitionChangeRecord.duplicate().setIsr(Arrays.asList(0, 2)), newPartitionRecord.duplicate().setIsr(Arrays.asList(0, 2)));
    // Change leader
    checkPartitionChangeRecord(oldPartitionRecord, partitionChangeRecord.duplicate().setLeader(1), newPartitionRecord.duplicate().setLeader(1).setLeaderEpoch(1));
}
Also used : PartitionChangeRecord(org.apache.kafka.common.metadata.PartitionChangeRecord) PartitionRecord(org.apache.kafka.common.metadata.PartitionRecord) Test(org.junit.jupiter.api.Test)

Aggregations

PartitionChangeRecord (org.apache.kafka.common.metadata.PartitionChangeRecord)15 ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)11 Test (org.junit.jupiter.api.Test)11 Uuid (org.apache.kafka.common.Uuid)8 ArrayList (java.util.ArrayList)5 AlterIsrRequestData (org.apache.kafka.common.message.AlterIsrRequestData)5 AlterIsrResponseData (org.apache.kafka.common.message.AlterIsrResponseData)5 TopicPartition (org.apache.kafka.common.TopicPartition)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 PartitionData (org.apache.kafka.common.message.AlterIsrRequestData.PartitionData)3 TopicData (org.apache.kafka.common.message.AlterIsrRequestData.TopicData)3 AlterPartitionReassignmentsRequestData (org.apache.kafka.common.message.AlterPartitionReassignmentsRequestData)3 ReassignablePartition (org.apache.kafka.common.message.AlterPartitionReassignmentsRequestData.ReassignablePartition)3 ReassignableTopic (org.apache.kafka.common.message.AlterPartitionReassignmentsRequestData.ReassignableTopic)3 AlterPartitionReassignmentsResponseData (org.apache.kafka.common.message.AlterPartitionReassignmentsResponseData)3 ReassignablePartitionResponse (org.apache.kafka.common.message.AlterPartitionReassignmentsResponseData.ReassignablePartitionResponse)3 ReassignableTopicResponse (org.apache.kafka.common.message.AlterPartitionReassignmentsResponseData.ReassignableTopicResponse)3 ElectLeadersRequestData (org.apache.kafka.common.message.ElectLeadersRequestData)3 ElectLeadersResponseData (org.apache.kafka.common.message.ElectLeadersResponseData)3 ListPartitionReassignmentsTopics (org.apache.kafka.common.message.ListPartitionReassignmentsRequestData.ListPartitionReassignmentsTopics)3