// Module included in the following assemblies:
//
// assembly-scaling-clusters.adoc

[id='con-partition-reassignment-{context}']

= Partition reassignment

The Topic Operator does not currently support reassigning replicas to different brokers, so it is necessary to connect directly to broker pods to reassign replicas to brokers.

Within a broker pod, the `kafka-reassign-partitions.sh` utility allows you to reassign partitions to different brokers.

It has three different modes:

`--generate`::
Takes a set of topics and brokers and generates a _reassignment JSON file_ which will result in the partitions of those topics being assigned to those brokers.
Because this operates on whole topics, it cannot be used when you just need to reassign some of the partitions of some topics.

`--execute`::
Takes a _reassignment JSON file_ and applies it to the partitions and brokers in the cluster.
Brokers that gain partitions as a result become followers of the partition leader.
For a given partition, once the new broker has caught up and joined the ISR (in-sync replicas) the old broker will stop being a follower and will delete its replica.

`--verify`::
Using the same _reassignment JSON file_ as the `--execute` step, `--verify` checks whether all of the partitions in the file have been moved to their intended brokers.
If the reassignment is complete, --verify also removes any xref:con-reassignment-throttles-{context}[throttles] that are in effect.
Unless removed, throttles will continue to affect the cluster even after the reassignment has finished.

It is only possible to have one reassignment running in a cluster at any given time, and it is not possible to cancel a running reassignment.
If you need to cancel a reassignment, wait for it to complete and then perform another reassignment to revert the effects of the first reassignment.
The `kafka-reassign-partitions.sh` will print the reassignment JSON for this reversion as part of its output.
Very large reassignments should be broken down into a number of smaller reassignments in case there is a need to stop in-progress reassignment.

== Reassignment JSON file

The _reassignment JSON file_ has a specific structure:

[source,subs=+quotes]
----
{
  "version": 1,
  "partitions": [
    _<PartitionObjects>_
  ]
}
----

Where _<PartitionObjects>_ is a comma-separated list of objects like:

[source,subs=+quotes]
----
{
  "topic": _<TopicName>_,
  "partition": _<Partition>_,
  "replicas": [ _<AssignedBrokerIds>_ ]
}
----

NOTE: Although Kafka also supports a `"log_dirs"` property this should not be used in {ProductLongName}.

The following is an example reassignment JSON file that assigns topic `topic-a`, partition `4` to brokers `2`, `4` and `7`, and topic `topic-b` partition `2` to brokers `1`, `5` and `7`:

[source,json]
----
{
  "version": 1,
  "partitions": [
    {
      "topic": "topic-a",
      "partition": 4,
      "replicas": [2,4,7]
    },
    {
      "topic": "topic-b",
      "partition": 2,
      "replicas": [1,5,7]
    }
  ]
}
----

Partitions not included in the JSON are not changed.

