Search in sources :

Example 61 with ApiMessageAndVersion

use of org.apache.kafka.server.common.ApiMessageAndVersion in project kafka by apache.

the class PartitionRegistrationTest method testRecordRoundTrip.

@Test
public void testRecordRoundTrip() {
    PartitionRegistration registrationA = new PartitionRegistration(new int[] { 1, 2, 3 }, new int[] { 1, 2 }, new int[] { 1 }, Replicas.NONE, 1, 0, 0);
    Uuid topicId = Uuid.fromString("OGdAI5nxT_m-ds3rJMqPLA");
    int partitionId = 4;
    ApiMessageAndVersion record = registrationA.toRecord(topicId, partitionId);
    PartitionRegistration registrationB = new PartitionRegistration((PartitionRecord) record.message());
    assertEquals(registrationA, registrationB);
}
Also used : Uuid(org.apache.kafka.common.Uuid) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) Test(org.junit.jupiter.api.Test)

Example 62 with ApiMessageAndVersion

use of org.apache.kafka.server.common.ApiMessageAndVersion 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 63 with ApiMessageAndVersion

use of org.apache.kafka.server.common.ApiMessageAndVersion in project kafka by apache.

the class RecordTestUtils method replayAll.

/**
 * Replay a list of records to the metadata delta.
 *
 * @param delta the metadata delta on which to replay the records
 * @param highestOffset highest offset from the list of records
 * @param highestEpoch highest epoch from the list of records
 * @param recordsAndVersions list of records
 */
public static void replayAll(MetadataDelta delta, long highestOffset, int highestEpoch, List<ApiMessageAndVersion> recordsAndVersions) {
    for (ApiMessageAndVersion recordAndVersion : recordsAndVersions) {
        ApiMessage record = recordAndVersion.message();
        delta.replay(highestOffset, highestEpoch, record);
    }
}
Also used : ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) ApiMessage(org.apache.kafka.common.protocol.ApiMessage)

Example 64 with ApiMessageAndVersion

use of org.apache.kafka.server.common.ApiMessageAndVersion in project kafka by apache.

the class RecordTestUtils method replayAll.

/**
 * Replay a list of records.
 *
 * @param target                The object to invoke the replay function on.
 * @param recordsAndVersions    A list of records.
 */
public static void replayAll(Object target, List<ApiMessageAndVersion> recordsAndVersions) {
    for (ApiMessageAndVersion recordAndVersion : recordsAndVersions) {
        ApiMessage record = recordAndVersion.message();
        try {
            Method method = target.getClass().getMethod("replay", record.getClass());
            method.invoke(target, record);
        } catch (NoSuchMethodException e) {
            try {
                Method method = target.getClass().getMethod("replay", record.getClass(), Optional.class);
                method.invoke(target, record, Optional.empty());
            } catch (NoSuchMethodException t) {
            // ignore
            } catch (InvocationTargetException t) {
                throw new RuntimeException(t);
            } catch (IllegalAccessException t) {
                throw new RuntimeException(t);
            }
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : Optional(java.util.Optional) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) ApiMessage(org.apache.kafka.common.protocol.ApiMessage) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 65 with ApiMessageAndVersion

use of org.apache.kafka.server.common.ApiMessageAndVersion in project kafka by apache.

the class ReplicationControlManager method handleBrokerUnregistered.

/**
 * Generate the appropriate records to handle a broker being unregistered.
 *
 * First, we remove this broker from any non-singleton ISR. Then we generate an
 * UnregisterBrokerRecord.
 *
 * @param brokerId      The broker id.
 * @param brokerEpoch   The broker epoch.
 * @param records       The record list to append to.
 */
void handleBrokerUnregistered(int brokerId, long brokerEpoch, List<ApiMessageAndVersion> records) {
    generateLeaderAndIsrUpdates("handleBrokerUnregistered", brokerId, NO_LEADER, records, brokersToIsrs.partitionsWithBrokerInIsr(brokerId));
    records.add(new ApiMessageAndVersion(new UnregisterBrokerRecord().setBrokerId(brokerId).setBrokerEpoch(brokerEpoch), UNREGISTER_BROKER_RECORD.highestSupportedVersion()));
}
Also used : UnregisterBrokerRecord(org.apache.kafka.common.metadata.UnregisterBrokerRecord) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion)

Aggregations

ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)84 ArrayList (java.util.ArrayList)38 Test (org.junit.jupiter.api.Test)35 Uuid (org.apache.kafka.common.Uuid)23 ApiError (org.apache.kafka.common.requests.ApiError)20 LogContext (org.apache.kafka.common.utils.LogContext)17 HashMap (java.util.HashMap)16 SnapshotRegistry (org.apache.kafka.timeline.SnapshotRegistry)15 List (java.util.List)12 Map (java.util.Map)12 PartitionChangeRecord (org.apache.kafka.common.metadata.PartitionChangeRecord)12 PartitionRegistration (org.apache.kafka.metadata.PartitionRegistration)11 TopicRecord (org.apache.kafka.common.metadata.TopicRecord)8 UnknownTopicOrPartitionException (org.apache.kafka.common.errors.UnknownTopicOrPartitionException)7 AlterIsrRequestData (org.apache.kafka.common.message.AlterIsrRequestData)7 Collections (java.util.Collections)6 Iterator (java.util.Iterator)6 Entry (java.util.Map.Entry)6 NoSuchElementException (java.util.NoSuchElementException)6 Optional (java.util.Optional)6