"Original" Kafka admin source code Analysis

Source: Internet
Author: User

The admin package defines some implementations of the command line

First, Adminoperationexception.scalaAn exception class that represents the exception thrown when executing the admin command Second, Adminutils.scalaAdmin Some common tools methods: 1. Assignreplicastobrokers: Responsible for assigning replicas to different broker. There are two main goals: ① to distribute copies on different brokers as evenly as possible; ② for partitions that are assigned to the same broker, their other replicas are assigned to different brokers as much as possible. If you want to achieve these goals, you need to ① allocate the I one copy of each partition from a random location in the broker list to be allocated in round-bin manner; ② uses an incremental offset to allocate the remaining replica allocations. It is important to note that the replica factor cannot be larger than the broker number 2. Addpartitions: Used to increase partition 3 for an existing topic. Deletetopic: To delete topic, create a child node 4 under Create a/admin/delete_topics node on zookeeper. Topicexists: Determine if a topic exists 5. Createtopic: Assign the copy first, and then create the TOPIC6 on the corresponding path on the zookeeper. Changetopicconfig: Update an existing topic configuration information and create a change message notification so that the change can be passed to the other broker7. Fetchtopicconfig: Read the configuration information of topic from zookeeper, the specific path is/config/topics/[topic] Third, Preferredreplicaleaderelectioncommand.scalaThis class moves the leader of each partition to the preferred replica, primarily for re-balancing leadership on each broker. Can be used either directly as a command, or automatically by Kafka when a property auto.leader.rebalance.enable=true is specified. The default is 300 seconds for automatic checking. Preferredreplicaleaderelectioncommand The Parsepreferredreplicaelectiondata and Writepreferredreplicaelectiondata methods of object are respectively parsed and constructed under zookeeper path/admin/ The JSON data string for the Preferred_replica_election node.the Preferredreplicaleaderelectioncommaind class defines two methods:1. Validatepartition: Verify partition legitimacy, mainly check whether the partition exists. 2. Moveleadertopreferredreplica: Transfer leadership to the preferred copy. The specific logic is as follows:
    • Filter out those partitions that don't exist.
    • Constructs a specific JSON string to be updated in the/admin/preferred_replica_election node of the zookeeper
    • If automatic balance is enabled, a background thread will periodically listen for changes in the data of that node
Iv. Reassignpartitionscommand.scalaAdding a new server to the Kafka cluster is easy, specifying a unique broker ID and starting up, but these new servers are not automatically allocated new data partitions, so you need to manually move some of the data to the new server. This class is intended to achieve this. The core method is Reassignpartitions, the logic is to create the corresponding data record under the zookeeper/admin_reassign_partitions, The controller registers a zookeeper listener to listen for data changes on that node. Wu, Topiccommand.scalaAn object that can be run to create, delete, describe, or change topic:1. Createtopic: To create a topic, it is worth noting that by configuring Replica-assignment you can manually assign which partitions fall on which broker. If you don't specify it, Kafka automatically helps you do the assignment, and then creates the Topic2. Altertopic: Modify TOPIC3. Listtopic: Lists all topic4 in the current cluster. Deletetopic: Deletes a topic. It is actually marked that the topic can already be deleted 5. Describetopic: The main is to get the topic partition information, copy information, leader copy, and ISR

"Original" Kafka admin source code Analysis

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.