Search in sources :

Example 1 with RemoveTopicRecord

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

the class ReplicationControlManager method deleteTopic.

void deleteTopic(Uuid id, List<ApiMessageAndVersion> records) {
    TopicControlInfo topic = topics.get(id);
    if (topic == null) {
        throw new UnknownTopicIdException(UNKNOWN_TOPIC_ID.message());
    }
    records.add(new ApiMessageAndVersion(new RemoveTopicRecord().setTopicId(id), REMOVE_TOPIC_RECORD.highestSupportedVersion()));
}
Also used : ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) RemoveTopicRecord(org.apache.kafka.common.metadata.RemoveTopicRecord) UnknownTopicIdException(org.apache.kafka.common.errors.UnknownTopicIdException)

Example 2 with RemoveTopicRecord

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

the class MetadataNodeManagerTest method testTopicRecordAndRemoveTopicRecord.

@Test
public void testTopicRecordAndRemoveTopicRecord() {
    // Add topic
    TopicRecord topicRecord = new TopicRecord().setName("topicName").setTopicId(Uuid.fromString("GcaQDl2UTsCNs1p9s37XkQ"));
    metadataNodeManager.handleMessage(topicRecord);
    assertEquals("topicName", metadataNodeManager.getData().root().directory("topics", "topicName").file("name").contents());
    assertEquals("GcaQDl2UTsCNs1p9s37XkQ", metadataNodeManager.getData().root().directory("topics", "topicName").file("id").contents());
    assertEquals("topicName", metadataNodeManager.getData().root().directory("topicIds", "GcaQDl2UTsCNs1p9s37XkQ").file("name").contents());
    assertEquals("GcaQDl2UTsCNs1p9s37XkQ", metadataNodeManager.getData().root().directory("topicIds", "GcaQDl2UTsCNs1p9s37XkQ").file("id").contents());
    // Remove topic
    RemoveTopicRecord removeTopicRecord = new RemoveTopicRecord().setTopicId(Uuid.fromString("GcaQDl2UTsCNs1p9s37XkQ"));
    metadataNodeManager.handleMessage(removeTopicRecord);
    assertFalse(metadataNodeManager.getData().root().directory("topicIds").children().containsKey("GcaQDl2UTsCNs1p9s37XkQ"));
    assertFalse(metadataNodeManager.getData().root().directory("topics").children().containsKey("topicName"));
}
Also used : TopicRecord(org.apache.kafka.common.metadata.TopicRecord) RemoveTopicRecord(org.apache.kafka.common.metadata.RemoveTopicRecord) RemoveTopicRecord(org.apache.kafka.common.metadata.RemoveTopicRecord) Test(org.junit.jupiter.api.Test)

Example 3 with RemoveTopicRecord

use of org.apache.kafka.common.metadata.RemoveTopicRecord 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)

Aggregations

RemoveTopicRecord (org.apache.kafka.common.metadata.RemoveTopicRecord)3 ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)2 Test (org.junit.jupiter.api.Test)2 ArrayList (java.util.ArrayList)1 TopicPartition (org.apache.kafka.common.TopicPartition)1 Uuid (org.apache.kafka.common.Uuid)1 UnknownTopicIdException (org.apache.kafka.common.errors.UnknownTopicIdException)1 PartitionChangeRecord (org.apache.kafka.common.metadata.PartitionChangeRecord)1 TopicRecord (org.apache.kafka.common.metadata.TopicRecord)1