Reassigning Kafka Partitions

Partition reassignment is to reassign replicas of a partition to different brokers to solve the problem of unbalanced broker load.

Partition reassignment is required in the following scenarios:

The DMS for Kafka console provides automatic and manual reassignment. Automatic reassignment is recommended because it ensures that leaders are evenly distributed.

This function is unavailable for single-node instances.

Operation Impact

Preparing for Partition Reassignment

Auto Reassignment

  1. Log in to the console.
  2. Click in the upper left corner to select a region.

    Select the region where your Kafka instance is located.

  3. Click Service List and choose Application > Distributed Message Service. The Kafka instance list is displayed.
  4. Click the desired Kafka instance to view the instance details.
  5. In the navigation pane, choose Topics.
  6. Reassign partitions using either of the following methods:

    • Select one or more topics and choose Reassign > Auto above the topic list.
    • In the row that contains the desired topic, choose More > Reassign > Auto.

  7. Set automatic reassignment parameters.

    • In the Brokers area, select the brokers to assign the topic's partition replicas to.
    • In the Topics area, enter the number of replicas to be automatically reassigned. The number of replicas must be less than or equal to the number of brokers.
    • Specify throttle. The default value is -1, indicating that there is no throttle If the instance has low workload (for example, only 30/300 MB/s is used), you are not advised to limit the bandwidth. If a throttle is required, you are advised to set it to a value greater than or equal to the total production bandwidth of the to-be-reassigned topic multiplied by the maximum number of replicas of the to-be-reassigned topic. For details, see Calculating a Throttle.
    • For Execute, specify when to execute the reassignment. Now means to execute it immediately. As scheduled means to execute it at the scheduled time.
    Figure 1 Setting automatic reassignment parameters

  8. (Optional) Click Calculate. Time Required indicates how long automatic balancing will take.
  9. Click OK.

    The following table lists how to check whether reassignment is complete (scheduled and non-scheduled tasks):

    Table 1 Checking the reassignment result

    Task Type

    Reassignment Result

    Background tasks

    In the upper left corner of the topic list, click View details and the Background Tasks > Background tasks page is displayed. The reassignment task is complete when it is in the Successful state.

    Scheduled tasks

    1. The Background Tasks > Scheduled tasks page is displayed. This page only shows whether scheduled tasks start to execute instead of whether they are successful.
      • When the task status is Pending, reassignment has not been executed.
      • When the task status is Successful, reassignment has started.
      • When the task status is Cancel, reassignment has been canceled.
    2. Click Background tasks tab page. When the task status is Successful, reassignment has completed.
    Figure 2 Background Tasks page
    • You cannot delete topics whose reassignment tasks have started. Otherwise, the tasks will never complete.
    • You cannot modify the partition quantity of topics whose reassignment tasks have started.
    • Reassignment tasks cannot be manually stopped. Please wait until they complete.
    • If partition reassignment has been scheduled, reassignment cannot be scheduled again for any topic in this instance until this reassignment is executed.

Manual Reassignment

  1. Log in to the console.
  2. Click in the upper left corner to select a region.

    Select the region where your Kafka instance is located.

  3. Click Service List and choose Application > Distributed Message Service. The Kafka instance list is displayed.
  4. Click the desired Kafka instance to view the instance details.
  5. In the navigation pane, choose Topics.
  6. Reassign partitions using either of the following methods:

    • Select a topic and choose Reassign > Manual above the topic list. Manual reassignment does not support batch operations.
    • In the row that contains the desired topic, choose More > Reassign > Manual.

  7. Set manual reassignment parameters.

    • In the upper right corner of the Manual dialog box, click Delete Replica or Add Replica to reduce or increase the number of replicas for each partition of the topic.
    • Under the name of the replica to be reassigned, click the broker name or and select the target broker to migrate the replica to. Assign replicas of the same partition to different brokers.
    • Specify throttle. The default value is -1, indicating that there is no throttle If the instance has low workload (for example, only 30/300 MB/s is used), you are not advised to limit the bandwidth. If a throttle is required, you are advised to set it to a value greater than or equal to the total production bandwidth of the to-be-reassigned topic multiplied by the maximum number of replicas of the to-be-reassigned topic. For details, see Calculating a Throttle.
    • For Execute, specify when to execute the reassignment. Now means to execute it immediately. As scheduled means to execute it at the scheduled time.
    Figure 3 Setting manual reassignment parameters

  8. (Optional) Click Calculate. Time Required indicates how long manual balancing will take.
  9. Click OK.

    The following table lists how to check whether reassignment is complete (scheduled and non-scheduled tasks):

    Table 2 Checking the reassignment result

    Task Type

    Reassignment Result

    Background tasks

    In the upper left corner of the topic list, click View details and the Background Tasks > Background tasks page is displayed. The reassignment task is complete when it is in the Successful state.

    Scheduled tasks

    1. The Background Tasks > Scheduled tasks page is displayed. This page only shows whether scheduled tasks start to execute instead of whether they are successful.
      • When the task status is Pending, reassignment has not been executed.
      • When the task status is Successful, reassignment has started.
      • When the task status is Cancel, reassignment has been canceled.
    2. Click Background tasks tab page. When the task status is Successful, reassignment has completed.
    Figure 4 Background Tasks page
    • You cannot delete topics whose reassignment tasks have started. Otherwise, the tasks will never complete.
    • You cannot modify the partition quantity of topics whose reassignment tasks have started.
    • Reassignment tasks cannot be manually stopped. Please wait until they complete.
    • If partition reassignment has been scheduled, reassignment cannot be scheduled again for any topic in this instance until this reassignment is executed.

Re-scheduling Partition Reassignment

  1. On the Scheduled tasks tab page on the Background Tasks page, click the drop-down box in the upper left corner, select a time period, enter the desired topic name in the search box, and press Enter.

    Figure 5 Querying reassignment schedules

  2. In the row that contains the desired task, click Modify.
  3. In the Change Schedule dialog box, change the schedule or cancel the scheduled task.

    • To change the schedule, select a time and click OK.
    • To cancel the task, select Cancel (as shown in Figure 6) and click OK.
      Figure 6 Canceling a scheduled reassignment task

Calculating a Throttle

Throttles are affected by the execution duration of the reassignment, leader/follower distribution of partition replicas, and message production rate.

Assume that the partition reassignment task needs to be completed within 200s and each replica has 100 MB data. Calculate the throttle in the following scenarios:

Scenario 1: Topic 1 has two partitions and two replicas, and Topic 2 has one partition and one replica. All leader replicas are on the same broker. One replica needs to be added for Topic 1 and Topic 2 respectively.

Table 3 Replica distribution before reassignment

Topic Name

Partition Name

Broker of Leader Replica

Broker of Follower Replica

Topic 1

0

0

0, 1

Topic 1

1

0

0, 2

Topic 2

0

0

0

Table 4 Replica distribution after reassignment

Topic Name

Partition Name

Broker of Leader Replica

Broker of Follower Replica

Topic 1

0

0

0, 1, 2

Topic 1

1

0

0, 1, 2

Topic 2

0

0

0, 2

Figure 7 Reassignment scenario 1

As shown in Figure 7, three replicas fetch data from Broker 0. Each replica on Broker 0 has 100 MB data. Broker 0 has only leader replicas, and Broker 1 and Broker 2 have only follower replicas.

In conclusion, to complete the partition reassignment task within 200s, set the throttle to a value greater than or equal to 1.5 MB/s. The bandwidth should be set to be greater than or equal to 2 MB/s because the limit on it on the console must be an integer.

Scenario 2: Topic 1 has two partitions and one replica, and Topic 2 has two partitions and one replica. Leader replicas are on different brokers. One replica needs to be added for Topic 1 and Topic 2 respectively.

Table 5 Replica distribution before reassignment

Topic Name

Partition Name

Broker of Leader Replica

Broker of Follower Replica

Topic 1

0

0

0

Topic 1

1

1

1

Topic 2

0

1

1

Topic 2

1

2

2

Table 6 Replica distribution after reassignment

Topic Name

Partition Name

Broker of Leader Replica

Broker of Follower Replica

Topic 1

0

0

0, 2

Topic 1

1

1

1, 2

Topic 2

0

1

1, 2

Topic 2

1

2

2, 0

Figure 8 Reassignment scenario 2

As shown in Figure 8, Broker 1 has only leader replicas, and Broker 0 and Broker 2 have both leader and follower replicas. Leader and follower replicas on Broker 0 and Broker 2 are throttled separately.

In conclusion, to complete the partition reassignment task within 200s, set the throttle to a value greater than or equal to 1.5 MB/s. The bandwidth should be set to be greater than or equal to 2 MB/s because the limit on it on the console must be an integer.

Scenario 3: Both Topic 1 and Topic 2 have one partition and two replicas. All leader replicas are on the same broker. One replica needs to be added to Topic 1. Messages are produced on Topic 1, causing replication.

Table 7 Replica distribution before reassignment

Topic Name

Partition Name

Broker of Leader Replica

Broker of Follower Replica

Topic 1

0

0

0, 1

Topic 2

0

0

0, 1

Table 8 Replica distribution after reassignment

Topic Name

Partition Name

Broker of Leader Replica

Broker of Follower Replica

Topic 1

0

0

0, 1, 2

Topic 2

0

0

0, 1

Figure 9 Reassignment scenario 3

As shown in Figure 9, one replica needs to fetch data from Broker 0 for partition reassignment, and the other replica needs to fetch data from Broker 0 for message production. Since the throttle does not distinguish between message production and partition reassignment, the traffic caused by both is limited and counted.

In conclusion, to complete the partition reassignment task within 200s, set the throttle to a value greater than or equal to 1.9 MB/s. The bandwidth should be set to be greater than or equal to 2 MB/s because the limit on it on the console must be an integer.