Kafka0.8.2 Deleting topic logic

Source: Internet
Author: User

original link: Kafka0.8.2.1 Delete topic logicPrerequisites: When you start the broker, the switch to delete topic is turned on, which is added in Server.properties: Delete.topic.enable=truecommand: bin/kafka-topics.sh--zookeeper zk_host:port/chroot --delete--topic my_topic_name Note: chroot If it's not set, empty it .
This command actually creates a temporary node under the/admin/delete_topics of zookeeper (assuming your chroot is/), and the name is the topic name, such as if the command is executed:bin/kafka-topics.sh--zookeeper zk_host:port/chroot--delete--topic test-topicthen, after the command returns, a temporary node is created under Zookeeper's/admin/delete_topics directory Test-topic This command returns the message printed on the console as well, stating this:Topic test-topic is marked for deletion.Note:this would have no impact if delete.topic.enable are not set to true.This means that the command does not actually perform the delete action, but simply marks the topic to be deleted on the zookeeper, and also reminds the user Be sure to open the delete.topic.enable switch in advance (added in server.properties), otherwise the delete action will not be performed. If the previous runtime is not set, then the settings need to be rerun before they can be deleted .  So, how did Kafka perform the delete operation after we tagged the test-topic to be deleted? The overall process is as follows:1. The Kafka controller registers the child node change listener for the Zookeeper node/admin/delete_topics at startup--The above analysis has told us that The delete command is actually to create a temporary node under the node, the name is to be deleted topic name, mark the topic is to be deleted2. Kafka controller creates a separate thread at startup, performing the topic delete operation (implemented by the Deletetopicsthread class)3. When a thread starts to see if there is a need to delete the topic--hypothesis that we are executing the topic Delete command after the controller is started, then the topic collection to be deleted when the thread is just started should be empty4. Once the topic collection is found to be deleted is empty, topic delete thread will be suspended5. At this point, we perform the delete operation and delete the Topic:test-topic,delete command to create a child node under/admin/delete_topics test-topic6. The listener captures the change and immediately triggers the delete logic6.1 Query Whether Test-topic exists, does not exist to delete the/admin/delete_topics/test-topic node directly--delete a nonexistent topic, delete command is just create/admin/delete_ Topics/[topicname] node, it is not responsible for the existence of the checksum6.2 Check if Test-topic is currently performing preferred copy election or partition redistribution, if so, it is definitely not suitable for deletion. The Controller locally caches the topic collection that is currently unable to be deleted, and processes the topic in the collection after the partition is redistributed or preferred the copy election
6.3 How the two are not the same if the delete operation can now be performed, then the delete thread will resume the pending deletion
 The real logic for deleting a thread to perform a delete operation is:1. It first sends a request to all current brokers to update metadata information, telling them that the topic is going to be deleted, and that you can delete the information from the cache .2. Start deleting all partitions of this topic2.1 Send requests to all brokers to tell them that the partitions are to be deleted. When the broker receives it, it no longer accepts any client requests on those partitions.2.2 All replicas under each partition are placed in the Offlinereplica state so that the ISR is shrinking and leader information is updated to 1 when the leader copy is finally placed in the Offlinereplica state2.3 Place all replicas in the replicadeletionstarted state
2.4 The replica state machine captures the state change and then initiates Stopreplicarequest to Broker,broker to stop all fetcher threads, remove the cache, and then delete the underlying log file after the request is received
2.5 Close all idle Fetcher threads
3. Delete Zookeeper under/brokers/topics/test-topic node4. Delete Zookeeper under/config/topics/test-topic node5. Delete Zookeeper under/admin/delete_topics/test-topic node6. Update various caches to remove test-topic related information

Kafka0.8.2 Delete topic logic (GO)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.