...
As described in KIP-500, the controller will store its data in the internal @metadata topic__cluster_metadata topic. This topic will contain a single partition which is managed by Raft, as described in KIP-595: A Raft Protocol for the Metadata Quorum.
...
Metadata changes need to be persisted to the @metadata __cluster_metadata log before we apply them on the other nodes in the cluster. This means waiting for the metadata log's last stable offset to advance to the offset of the change. After that point, we are guaranteed not to lose the change as long as we uphold the Raft invariants.
...
However, this "future state" may never be committed. For example, the active controller might fail, truncating some of its future state. Therefore, the active controller must not make this future state "visible" to the rest of the cluster until it has been made persistent – that is, until it becomes current state. In the case of the @metadata topic__cluster_metadata topic, the replication protocol itself neatly takes care of this for us. In the case of controller RPCs like AlterIsr, the controller handles this by not sending back a response until the designated change has been persisted.
...
The active controller makes changes to the metadata by appending records to the log. Each record has a null key, and this format for its value:
- an unsigned varint specifying the frame type (currently 0)
- an unsigned varint specifying the record type.
- an unsigned varint specifying the record version
- the payload in Kafka RPC format
For example, if we wanted to encode a TopicRecord, we might have 0 encoded as a varint, 1 encoded as a varint, followed by 0 as the record version, followed by the serialized topic data.
The frame type, record type, and version will typically only take one byte each, for a total header size overhead of two three bytes.
Record Format Versions
...
The main change in the broker state machine is that the RECOVERING_FROM_UNCLEAN_SHUTDOWN state has been renamed to RECOVERY. Also, unlike previously, the broker will always pass through RECOVERY (although it may only stay in this state for a very short amount of time).
Public Interfaces
meta.properties
When a storage directory is in use by a cluster running in kip-500 mode, it will have a new version of the meta.properties file. Since the current version is 0, the new version will be 1. Just as in version 0, meta.properties will continue to be a Java Properties file. This essentially means that it is a plain text file where each line has the format key=value.
In version 0 of meta.properties, the cluster.id field is optional. In contrast, in version 1 it is mandatory.
In version 0 of meta.properties, the cluster.id field is serialized in hexadecimal. In contrast, in version 1 it is serialized in base64.
Version 1 of meta.properties replaces the broker.id field with node.id.
For servers running in kip-500 mode, the `meta.properties` file must be present in every log directory. The process will raise an error during startup if if either the meta.properties file does not exist or if the node.id found does not match what the value from the configuration file.
Here is an example of a version 1 meta.properties file:
Code Block |
---|
$ cat /tmp/kafka-logs/meta.properties
#
#Tue Dec 01 10:08:08 PST 2020
cluster.id=3Db5QLSqSZieL3rJBUUegA
version=1
node.id=0 |
kafka-storage.sh
There will be a new command-line tool, kafka-storage.sh.
Partition Reassignment
Just like the ZooKeeper-based controller, the quorum controller will implement the KIP-455 partition reassignment API. This API specifies both alter and list operations.
The alter operation specifies a partition, plus a target replica list. If the target replica list is a subset of the partition's current replica list, and the new replica list contains at least one member of the current ISR, then the reassignment can be completed immediately. In this case, the controller issues a PartitionChangeRecord changing the replica set and ISR (if appropriate).
On the other hand, if the new replica list has additional replicas, or specifies a subset of replicas that doesn't intersect with the current ISR, then we add the additional replicas to the replica list, and wait for the ISR to catch up.
So, for example, if the old replica list was [1, 2, 3], and the new list was [3, 4, 5], we would proceed as follows:
- change the replica list to [1, 2, 3, 4, 5], and set addingReplicas to [4, 5]
- Wait for an alterIsr which adds both broker 4 and 5
- Change the replica list to [3, 4, 5 ] and prune the ISR accordingly. Remove addingReplicas.
Just like with the ZooKeeper-based controller, the new controller stores reassignments as "hard state." Reassignments will continue even after a controller failover or broker shutdown and restart. Reassignment state appears in controller snapshots, as addingReplicas and removingReplicas.
Unlike the old controller, the quorum controller does not prevent topics that are undergoing reassignment from being deleted. If a topic is deleted, then any partition reassignments that it had are terminated.
Typically, reassignments which require ISR changes are completed by a leader adding some new replicas, via the alterIsr RPC. (Note that another possible way for a reassignment to be completed is via a broker being added to a partition ISR during unfencing).
When a broker makes an alterIsr change that completes a reassignment, the resulting ISR will be different than requested. For example, if the leader is 1, and the current ISR is 1, 2, 3, and the target replica set is 1, 2, 4, when the leader tries to change the ISR to 1, 2, 3, 4, the controller will change it to 1, 2, 4 instead, completing the reassignment. Since the alterIsr response returns the actual ISR which was actually applied, the leader will apply this new ISR instead.
If the new ISR would does not contain the leader which made the alterIsr call, the controller returns FENCED_LEADER_EPOCH. This will notify the broker that it should wait until it can replay the latest partition change from the log. That partition change record will make this broker a follower rather than a leader.
Public Interfaces
meta.properties
When a storage directory is in use by a cluster running in kip-500 mode, it will have a new version of the meta.properties file. Since the current version is 0, the new version will be 1. Just as in version 0, meta.properties will continue to be a Java Properties file. This essentially means that it is a plain text file where each line has the format key=value.
In version 0 of meta.properties, the cluster.id field is optional. In contrast, in version 1 it is mandatory.
In version 0 of meta.properties, the cluster.id field is serialized in hexadecimal. In contrast, in version 1 it is serialized in base64.
Version 1 of meta.properties replaces the broker.id field with node.id.
For servers running in kip-500 mode, the `meta.properties` file must be present in every log directory. The process will raise an error during startup if if either the meta.properties file does not exist or if the node.id found does not match what the value from the configuration file.
Here is an example of a version 1 meta.properties file:
Code Block |
---|
$ cat /tmp/kafka-logs/meta.properties
#
#Tue Dec 01 10:08:08 PST 2020
cluster.id=3Db5QLSqSZieL3rJBUUegA
version=1
node.id=0 |
kafka-storage.sh
There will be a new command-line tool, kafka-storage.sh.
Code Block |
---|
$ ./bin/kafka-storage.sh -h
usage: kafka-storage [-h] {info,format,random-uuid} ...
The Kafka storage tool.
positional arguments:
{info,format,random-uuid}
info Get information about the Kafka log directories on this node.
format Format the Kafka log directories on this node.
random-uuid Print a random UUID.
optional arguments:
-h, --help show this help message and exit |
kafka-storage.sh will have three subcommands: info, format, and random-uuid.
info
Code Block |
---|
$ ./bin/kafka-storage.sh info -h
usage: kafka-storage info [-h] --config CONFIG
optional arguments:
-h, --help show this help message and exit
--config CONFIG, -c CONFIG
The Kafka configuration file to use. |
The info command will give information about the configured storage directories. Example output:
Code Block |
---|
Found log directory:
/tmp/kafka-logs
Found metadata: MetaProperties(clusterId=51380268-1036-410d-a8fc-fb3b55f48033) |
format
Code Block |
---|
$ ./bin/kafka-storage.sh format -h
usage: kafka-storage format [-h] --config CONFIG --cluster-id CLUSTER_ID [--ignore-formatted]
optional arguments:
-h, --help show this help message and exit
--config CONFIG, -c CONFIG
The Kafka configuration file to use.
--cluster-id CLUSTER_ID, -t CLUSTER_ID
The cluster ID to use.
--ignore-formatted, -g |
When running kip-500 mode, the storage directories must be formatted using this command prior to starting up the brokers and controllers.
If any of the storage directories are formatted, the command will normally fail. This behavior can be changed by passing the --ignore-formatted option. When this option is passed, the format command will skip over already formatted directories rather than failing.
random-uuid
Code Block |
---|
$ ./bin/kafka-storage.sh random-uuid -h
usage: kafka-storage random-uuid [-h]
optional arguments:
-h, --help show this help message and exit |
The random-uuid command prints out a random UUID to stdout.
Code Block |
---|
$ ./bin/kafka-storage.sh random-uuid
8XUwXa9qSyi9tSOquGtauQ |
kafka-cluster.sh
There will also be new command-line tool named kafka-cluster.sh.
Code Block |
---|
$ ./bin/kafka-cluster.sh -h
usage: kafka-cluster [-h] {id,unregister} ...
The Kafka cluster tool.
positional arguments:
{cluster-id,unregister}
cluster-id Get information about the ID of a cluster.
unregister Unregister a broker ID.
optional arguments:
-h, --help show this help message and exit |
kafka-storage.sh will have two subcommands: id and unregister.
cluster-id
Code Block |
---|
$ ./bin/kafka-cluster.sh cluster-id -h
usage: kafka-cluster cluster-id [-b,-c,-h]
optional arguments:
-b, --bootstrap-server a list of host/port pairs to use for establishing the connection to the kafka cluster.
-c, --config a property file containing configs to be passed to Admin Client.
-h, --help show this help message and exit |
The ID command prints out the cluster id
unregister
Code Block |
---|
$ ./bin/kafka-cluster.sh unregister -h
usage: kafka-cluster unregister [-h] [--bootstrap-server BOOTSTRAP_SERVER] [--config CONFIG] [--id ID]
optional arguments:
-h, --help show this help message and exit
--bootstrap-server BOOTSTRAP_SERVER, -b BOOTSTRAP_SERVER
A list of host/port pairs to use for establishing the connection to the kafka cluster.
--config CONFIG, -c CONFIG
A property file containing configs to passed to AdminClient.
--id ID, -i ID The ID of the broker to unregister. |
The decommission command removes the registration of a specific broker ID. It will use make an UnregisterBrokerRequest in order to do this.
Changes to kafka-dump-log-segments.sh
kafka-dump-log-seguments.sh will have two new flags: --cluster-metadata-decoder, and --skip-record-metadata.
The --cluster-metadata-decoder flag will tell the DumpLogSegments tool to decode the records as KIP-500 metadata. Each record will be output in the following JSON format:
Code Block |
---|
payload: {"type":<record type enum name>, "version":<record version number>, "data":<record JSON>} |
Example output:
Code Block |
---|
payload: {"type":"TOPIC_RECORD","version":0,"data":{"name":"bar","topicId":"GU_rXds2FGppL1JqXYpx2g"}}
payload: {"type":"PARTITION_RECORD","version":0,"data":{"partitionId":0,"topicId":"GU_rXds2FGppL1JqXYpx2g","replicas":[1],"isr":[1],"removingReplicas":null,"addingReplicas":null,"leader":1,"leaderEpoch":0,"partitionEpoch":0}}
payload: {"type":"PARTITION_CHANGE_RECORD","version":0,"data":{"partitionId":0,"topicId":"GU_rXds2FGppL1JqXYpx2g","leader":-1}}
payload: {"type":"PARTITION_CHANGE_RECORD","version":0,"data":{"partitionId":0,"topicId":"WCnrza5uWKeerYa7HCNpOg","leader":-1}}
payload: {"type":"PARTITION_CHANGE_RECORD","version":0,"data":{"partitionId":0,"topicId":"GU_rXds2FGppL1JqXYpx2g","leader":-1}}
payload: {"type":"PARTITION_CHANGE_RECORD","version":0,"data":{"partitionId":0,"topicId":"WCnrza5uWKeerYa7HCNpOg","leader":-1}}
payload: {"type":"FENCE_BROKER_RECORD","version":0,"data":{"id":1,"epoch":0}} |
The --skip-record-metadata flag will skip printing metadata for each record. However, metadata for each record batch will still be printed when this flag is present.
kafka-metadata-shell.sh
The Kafka Metadata shell is a new command which allows users to interactively examine the metadata stored in a KIP-500 cluster.
It can read the metadata from the controllers directly, by connecting to them, or from a metadata snapshot on disk. In the former case, the quorum voters must be specified by passing the --controllers flag; in the latter case, the snapshot file should be specified via --snapshot.
Code Block |
---|
$ ./bin/kafka-metadata-shell.sh -h
usage: metadata-tool [-h] [--controllers CONTROLLERS] [--config CONFIG] [--snapshot SNAPSHOT] [command [command ...]]
The Apache Kafka metadata tool
positional arguments:
command |
Code Block |
$ ./bin/kafka-storage.sh -h usage: kafka-storage [-h] {info,format,random-uuid} ... The Kafka storage tool. positional arguments: {info,format,random-uuid} info Get information about the Kafka log directories on this node. format Format the Kafka log directories on this node. random-uuid PrintThe acommand randomto UUIDrun. optional arguments: -h, --help show this help message and exit |
kafka-storage.sh will have three subcommands: info, format, and random-uuid.
info
Code Block |
---|
$ ./bin/kafka-storage.sh info -h usage: kafka-storage info [-h] --config CONFIG optional arguments: -h, --help --controllers CONTROLLERS, -C CONTROLLERS The showquorum thisvoter helpconnection messagestring andto exituse. --config CONFIG, -c CONFIG The Kafka configuration file to use. |
The info command will give information about the configured storage directories. Example output:
Code Block |
---|
Found log directory:
/tmp/kafka-logs
Found metadata: MetaProperties(clusterId=51380268-1036-410d-a8fc-fb3b55f48033) |
format
--snapshot SNAPSHOT, -s SNAPSHOT
The snapshot file to read. |
The metadata tool works by replaying the log and storing the state into in-memory nodes. These nodes are presented in a fashion similar to filesystem directories. For browsing the nodes, several commands are supported:
Code Block |
---|
>> help
Welcome to the Apache Kafka metadata shell.
usage: {cat,cd,exit,find,help,history,ls,man,pwd} ...
positional arguments:
{cat,cd,exit,find,help,history,ls,man,pwd}
cat |
Code Block |
$ ./bin/kafka-storage.sh format -h usage: kafka-storage format [-h] --config CONFIG --cluster-id CLUSTER_ID [--ignore-formatted] optional arguments: -h, --help show this help message and exit --config CONFIG, -c CONFIG Show the contents of metadata nodes. Thecd Kafka configuration file to use. --cluster-id CLUSTER_ID, -t CLUSTER_ID Set the current working directory. exit The cluster ID to use. --ignore-formatted, -g |
When running kip-500 mode, the storage directories must be formatted using this command prior to starting up the brokers and controllers.
If any of the storage directories are formatted, the command will normally fail. This behavior can be changed by passing the --ignore-formatted option. When this option is passed, the format command will skip over already formatted directories rather than failing.
random-uuid
Code Block |
---|
$ ./bin/kafka-storage.sh random-uuid -h usage: kafka-storage random-uuid [-h] optional arguments: -h, --help Exit the metadata shell. find Search for nodes in show thisthe directory hierarchy. help message and exit |
The random-uuid command prints out a random UUID to stdout.
Code Block |
---|
$ ./bin/kafka-storage.sh random-uuid 8XUwXa9qSyi9tSOquGtauQ |
kafka-cluster.sh
There will also be new command-line tool named kafka-cluster.sh.
Code Block |
---|
$ ./bin/kafka-cluster.sh -h usage: kafka-cluster [-h] {id,unregister} ... The Kafka cluster tool. positional arguments: {cluster-id,unregister} cluster-id Display this help message. history Print command history. ls Get information about the ID ofList ametadata clusternodes. man unregister Show the Unregisterhelp text for a brokerspecific IDcommand. optional arguments: -h, --help pwd showPrint thisthe helpcurrent message and exit |
kafka-storage.sh will have two subcommands: id and unregister.
cluster-id
Code Block |
---|
$ ./bin/kafka-cluster.sh cluster-id -h
usage: kafka-cluster cluster-id [-b,-c,-h]
optional arguments:
-b, --bootstrap-server a list of host/port pairs to use for establishing the connection to the kafka cluster.
-c, --config a property file containing configs to be passed to Admin Client.
-h, --help show this help message and exit |
The ID command prints out the cluster id
unregister
Code Block |
---|
$ ./bin/kafka-cluster.sh unregister -h
usage: kafka-cluster unregister [-h] [--bootstrap-server BOOTSTRAP_SERVER] [--config CONFIG] [--id ID]
optional arguments:
-h, --help show this help message and exit
--bootstrap-server BOOTSTRAP_SERVER, -b BOOTSTRAP_SERVER
A list of host/port pairs to use for establishing the connection to the kafka cluster.
--config CONFIG, -c CONFIG
A property file containing configs to passed to AdminClient.
--id ID, -i ID The ID of the broker to unregister. |
The decommission command removes the registration of a specific broker ID. It will use make an UnregisterBrokerRequest in order to do this.
Configurations
...
null
broker
controller
broker,controller
...
If this is null (absent) then we are in legacy mode.
Otherwise, we are in KIP-500 mode and this configuration determines what roles this process should play: broker, controller, or both.
...
If non-null, this must be a comma-separated list of listener names.
When communicating with the controller quorum, the broker will always use the first listener in this list.
...
A comma-separated list of the names of the listeners used by the KIP-500 controller. This configuration is required if this process is a KIP-500 controller. The legacy controller will not use this configuration
Despite the similar name, note that this is different from the "control plane listener" introduced by KIP-291.
...
A comma-separated list of the configured listeners. For example,
INTERNAL://192.1.1.8:9092, EXTERNAL://10.1.1.5:9093, CONTROLLER://192.1.1.8:9094
...
If non-null, this must be a comma-separated list of all the controller voters, in the format:
{controller-id}@{controller-host):{controller-port}
...
When in KIP-500 mode, each node must have this configuration, in order to find out how to communicate with the controller quorum.
Note that this replaces the "quorum.voters" config described in KIP-595.
This configuration is required for both brokers and controllers.
...
This configuration replaces `broker.id` for zk-based Kafka processes in order to reflect its more general usage. It serves as the ID associated with each role that the process is acting as.
For example, a configuration with `node.id=0` and `process.roles=broker,controller` defines two nodes: `broker-0` and `controller-0`.
...
controller.quorum.election.timeout.ms
...
working directory. |
The interface of the metadata tool is currently considered unstable and may change when KIP-500 becomes production-ready.
Configurations
Configuration Name | Possible Values | Notes |
---|---|---|
process.roles | null broker controller broker,controller | If this is null (absent) then we are in legacy mode. Otherwise, we are in KIP-500 mode and this configuration determines what roles this process should play: broker, controller, or both. |
controller.listener.names | If non-null, this must be a comma-separated list of listener names. When communicating with the controller quorum, the broker will always use the first listener in this list. | A comma-separated list of the names of the listeners used by the KIP-500 controller. This configuration is required if this process is a KIP-500 controller. The legacy controller will not use this configuration Despite the similar name, note that this is different from the "control plane listener" introduced by KIP-291. |
listeners | A comma-separated list of the configured listeners. For example, INTERNAL://192.1.1.8:9092, EXTERNAL://10.1.1.5:9093, CONTROLLER://192.1.1.8:9094 | This configuration is now required. |
sasl.mechanism.controller.protocol | SASL mechanism used for communication with controllers. Default is GSSAPI. | This is analogous to sasl.mechanism.inter.broker.protocol, but for communication with the controllers. |
controller.quorum.voters | If non-null, this must be a comma-separated list of all the controller voters, in the format: {controller-id}@{controller-host):{controller-port} | When in KIP-500 mode, each node must have this configuration, in order to find out how to communicate with the controller quorum. Note that this replaces the "quorum.voters" config described in KIP-595. This configuration is required for both brokers and controllers. |
node.id | a 32-bit ID | This configuration replaces `broker.id` for zk-based Kafka processes in order to reflect its more general usage. It serves as the ID associated with each role that the process is acting as. For example, a configuration with `node.id=0` and `process.roles=broker,controller` defines two nodes: `broker-0` and `controller-0`. |
initial.broker.registration.timeout.ms | 60000 | When initially registering with the controller quorum, the number of milliseconds to wait before declaring failure and exiting the broker process. |
broker.heartbeat.interval.ms | 3000 | The length of time between broker heartbeats. |
broker.session.timeout.ms | 18000 | The length of time that a broker lease lasts if no heartbeats are made. |
metadata.log.dir | If set, this must be a path to a log directory. | This configuration determines where we put the metadata log. if it is not set, the metadata log is placed in the first log directory from log.dirs. |
controller.quorum.fetch.timeout.ms | Maximum time without a successful fetch from the current leader before a new election is started. | New name for quorum.fetch.timeout.ms |
controller.quorum.election.timeout.ms | Maximum time without collected a majority of votes during the candidate state before a new election is retried | New name for quorum.election.timeout.ms |
controller.quorum.election.backoff.max.ms | Maximum exponential backoff time (based on the number if retries) after an election timeout, before a new election is triggered. | New name for quorum.election.backoff.max.ms |
controller.quorum.request.timeout.ms | Maximum time before a pending request is considered failed and the connection is dropped | New name for quorum.request.timeout.ms |
controller.quorum.retry.backoff.ms | Initial delay between request retries. This config and the one below is used for retriable request errors or lost connectivity and are different from the election.backoff configs above | New name for quorum.retry.backoff.ms |
controller.quorum.retry.backoff.max.ms | Max delay between requests. Backoff will increase exponentially beginning from quorum.retry.backoff.ms | New name for quorum.retry.backoff.max.ms |
Deprecated Configurations
Configuration Name | Reason |
---|---|
control.plane.listener.name | We no longer need to maintain a separate listener for messages from the controller, since the controller does not send messages out any more (it receives them). |
broker.id.generation.enable | Automatic broker ID generation is no longer supported. |
zookeeper.* | We no longer need configurations for ZooKeeper. |
New Error Codes
DUPLICATE_BROKER_REGISTRATION
There will be a new error code, DUPLICATE_BROKER_REGISTRATION, that the active controller will return when a broker tries to register with an ID that is currently in use.
INVALID_CLUSTER_ID
There will be a new error code, INVALID_CLUSTER_ID, that the controller will return if the broker tries to register with the wrong cluster ID.
AdminClient
There will be a new AdminClient RPC, unregisterBroker.
Code Block | ||
---|---|---|
| ||
UnregisterBrokerResult unregisterBroker(int brokerId, UnregisterBrokerOptions options)
public class UnregisterBrokerResult {
public KafkaFuture<Void> all();
}
public class UnregisterBrokerOptions extends AbstractOptions<UnregisterBrokerOptions> {
} |
RPCs
Obsoleting the Metadata Propagation RPCs
As discussed earlier, the new controller will use FetchRequest to fetch metadata from the active controller. The details of how Raft fetching will work are spelled out in KIP-595: A Raft Protocol for the Metadata Quorum.
Since we propagate the metadata via Raft, we will no longer need to send out LeaderAndIsrRequest, UpdateMetadataRequest, and StopReplicaRequest. These requests will be sent out only when we're in legacy mode, not when we're in KIP-500 mode. Eventually we will add some support for these requests to the new controller, in order to support rolling upgrade from a pre-KIP-500 release. However, for the purpose of this KIP, the new controller will not use these requests.
Obsoleting the Controlled Shutdown RPC
The broker heartbeat mechanism replaces the controlled shutdown RPC. Therefore, we will not need to support the this RPC any more in the controller-- except for compatibility during upgrades, which will be described further in a follow-on KIP.
Topic Identifiers
This KIP builds on top of the work done in KIP-516 to improve how partitions are tracked.
Because each topic is identified by a unique topic UUID, we can implement topic deletion with a single record, RemoveTopicRecord. Upon replaying this record, each broker will delete the associated topic if it is present.
Of course, some brokers may be down when the topic is deleted. In fact, some brokers may never see the RemoveTopicRecord. This record may get collapsed into one of the periodic metadata snapshots. If this happens, the record will be reflected in the snapshot through the absence of a broker record, not its presence. Therefore, during the startup process, brokers must compare the log directories that they have with the ones contained in the latest metadata. The appropriate time to do this is at the start of the RECOVERY phase. At this point, the broker has the latest metadata.
BrokerRegistration
Required ACLs: CLUSTERACTION on CLUSTER
Code Block | ||
---|---|---|
| ||
{
"apiKey": 57,
"type": "request",
"name": "BrokerRegistrationRequest",
"validVersions": "0",
"flexibleVersions": "0+",
"fields": [
{ "name": "BrokerId", "type": "int32", "versions": "0+",
"about": "The broker ID." },
{ "name": "ClusterId", "type": "string", "versions": "0+",
"about": "The cluster id of the broker process." },
{ "name": "IncarnationId", "type": "uuid", "versions": "0+",
"about": "The incarnation id of the broker process." },
{ "name": "CurrentMetadataOffset", "type": "int64", "versions": "0+",
"about": "The highest metadata offset which the broker has reached." },
{ "name": "Listeners", "type": "[]Listener",
"about": "The listeners of this broker", "versions": "0+", "fields": [
{ "name": "Name", "type": "string", "versions": "0+", "mapKey": true,
"about": "The name of the endpoint." },
{ "name": "Host", "type": "string", "versions |
Deprecated Configurations
...
New Error Codes
DUPLICATE_BROKER_REGISTRATION
There will be a new error code, DUPLICATE_BROKER_REGISTRATION, that the active controller will return when a broker tries to register with an ID that is currently in use.
INVALID_CLUSTER_ID
There will be a new error code, INVALID_CLUSTER_ID, that the controller will return if the broker tries to register with the wrong cluster ID.
AdminClient
There will be a new AdminClient RPC, unregisterBroker.
Code Block | ||
---|---|---|
| ||
UnregisterBrokerResult unregisterBroker(int brokerId, UnregisterBrokerOptions options)
public class UnregisterBrokerResult {
public KafkaFuture<Void> all();
}
public class UnregisterBrokerOptions extends AbstractOptions<UnregisterBrokerOptions> {
} |
RPCs
Obsoleting the Metadata Propagation RPCs
As discussed earlier, the new controller will use FetchRequest to fetch metadata from the active controller. The details of how Raft fetching will work are spelled out in KIP-595: A Raft Protocol for the Metadata Quorum.
Since we propagate the metadata via Raft, we will no longer need to send out LeaderAndIsrRequest, UpdateMetadataRequest, and StopReplicaRequest. These requests will be sent out only when we're in legacy mode, not when we're in KIP-500 mode. Eventually we will add some support for these requests to the new controller, in order to support rolling upgrade from a pre-KIP-500 release. However, for the purpose of this KIP, the new controller will not use these requests.
Obsoleting the Controlled Shutdown RPC
The broker heartbeat mechanism replaces the controlled shutdown RPC. Therefore, we will not need to support the this RPC any more in the controller-- except for compatibility during upgrades, which will be described further in a follow-on KIP.
Topic Identifiers
This KIP builds on top of the work done in KIP-516 to improve how partitions are tracked.
Because each topic is identified by a unique topic UUID, we can implement topic deletion with a single record, RemoveTopicRecord. Upon replaying this record, each broker will delete the associated topic if it is present.
Of course, some brokers may be down when the topic is deleted. In fact, some brokers may never see the RemoveTopicRecord. This record may get collapsed into one of the periodic metadata snapshots. If this happens, the record will be reflected in the snapshot through the absence of a broker record, not its presence. Therefore, during the startup process, brokers must compare the log directories that they have with the ones contained in the latest metadata. The appropriate time to do this is at the start of the RECOVERY phase. At this point, the broker has the latest metadata.
BrokerRegistration
Required ACLs: CLUSTERACTION on CLUSTER
Code Block | ||
---|---|---|
| ||
{ "apiKey": 57, "type": "request", "name": "BrokerRegistrationRequest", "validVersions": "0", "flexibleVersions": "0+", "fields "about": [ "The hostname." }, { "name": "BrokerIdPort", "type": "int32uint16", "versions": "0+", "about": "The broker IDport." }, { "name": "ClusterIdSecurityProtocol", "type": "uuidint16", "versions": "0+", "about": "The cluster id of the broker process." }, , "about": "The security protocol." } ] { "name": "IncarnationIdFeatures", "type": "uuid[]Feature", "versions": "0+", "about": "The incarnationfeatures idon of thethis broker", process."versions": },"0+", "fields": [ { "name": "CurrentMetadataOffsetName", "type": "int64string", "versions": "0+", "mapKey": true, "about": "The highestfeature metadata offset which the broker has reached." }, name." } { "name": "ListenersMinSupportedVersion", "type": "[]Listenerint16", "versions": "0+", "about": "The listeners of this broker", "versionsabout": "0+", "fields": [The minimum supported feature level." }, { "name": "NameMaxSupportedVersion", "type": "stringint16", "versions": "0+", "mapKey": true, "about": "The namemaximum ofsupported thefeature endpointlevel." }, ] }, { "name": "HostRack", "type": "string", "versions": "0+", "nullableVersions": "0+", "about": "The hostnamerack which this broker is in." }, ] } { {"apiKey": 57, "nametype": "Portresponse", "typename": "uint16BrokerRegistrationResponse", "versionsvalidVersions": "0+", "about"flexibleVersions": "The port." }0+", "fields": [ { "name": "SecurityProtocolThrottleTimeMs", "type": "int16int32", "versions": "0+", "about": "TheDuration securityin protocol." } ] { "name": "Features", "type": "[]Feature", "about": "The features on this broker", "versions": "0+", "fields": [ milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota." }, { "name": "NameErrorCode", "type": "stringint16", "versions": "0+", "mapKey": true, "about": "The error code, or 0 if "about": "The feature namethere was no error." }, { "name": "MinSupportedVersionBrokerEpoch", "type": "int16int64", "versions": "0+", "default": "-1", "about": "The minimumbroker's supportedassigned feature level." }, { "name": "MaxSupportedVersion", epoch, or -1 if none was assigned." } ] } |
BrokerHeartbeat
Required ACLs: CLUSTERACTION on CLUSTER
As described earlier, the broker periodically sends out a heartbeat request to the active controller.
Code Block | ||
---|---|---|
| ||
{ "apiKey": 58, "type": "int16request", "versionsname": "0+BrokerHeartbeatRequest", "aboutvalidVersions": "The maximum supported feature level." }0", ]"flexibleVersions": "0+", },"fields": [ { "name": "RackBrokerId", "type": "stringint32", "versions": "0+", "nullableVersions": "0+", "about": "The rack which this broker is inID." }, ] } { "apiKeyname": 57"BrokerEpoch", "type": "responseint64", "nameversions": "BrokerRegistrationResponse0+", "validVersionsdefault": "0-1", "flexibleVersionsabout": "0+", The broker "fieldsepoch.": [}, { "name": "ThrottleTimeMsCurrentMetadataOffset", "type": "int32int64", "versions": "0+", "about": "Duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota "about": "One more than the highest metadata offset which the broker has reached." }, { "name": "ErrorCodeWantFence", "type": "int16bool", "versions": "0+", "about": "TheTrue errorif code,the orbroker 0wants ifto therebe wasfenced, nofalse errorotherwise." }, { "name": "BrokerEpochWantShutDown", "type": "int64bool", "versions": "0+", "default": "-1", "about": "TheTrue broker'sif assignedthe epoch,broker orwants -1to ifinitiate nonecontrolled was assignedshutdown." } ] } |
BrokerHeartbeat
Required ACLs: CLUSTERACTION on CLUSTER
As described earlier, the broker periodically sends out a heartbeat request to the active controller.
Code Block | ||
---|---|---|
| ||
{ "apiKey": 58, "type": "requestresponse", "name": "BrokerHeartbeatRequestBrokerHeartbeatResponse", "validVersions": "0", "flexibleVersions": "0+", "fields": [ { "name": "BrokerIdThrottleTimeMs", "type": "int32", "versions": "0+", "about": "The broker IDDuration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota." }, { "name": "BrokerEpochErrorCode", "type": "int64int16", "versions": "0+", "default": "-1", "about": "The broker epoch error code, or 0 if there was no error." }, { "name": "CurrentMetadataOffsetIsCaughtUp", "type": "int64bool", "versions": "0+", "about": "OneTrue if morethe thanbroker thehas highestapproximately metadatacaught offsetup whichwith the brokerlatest has reachedmetadata." }, { "name": "WantFenceIsFenced", "type": "bool", "versions": "0+", "about": "True if the broker wants to beis fenced, false otherwise." }, { "name": "WantShutDownShouldShutDown", "type": "bool", "versions": "0+", "about": "True if the broker wantsshould toproceed initiatewith controlledits shutdown." } ] } } |
The controller will wait to unfence a broker until it sends a heartbeat where ShouldFence is false and CurrentMetadataOffset is caught up.
If the heartbeat request has ShouldShutDown set, the controller will try to move all the leaders off of the broker.
The controller will set ControlledShutdownOk if the broker is cleared to execute a controlled shutdown. In other words, if it has no leaderships.
The controller will return NOT_CONTROLLER if it is not active. Brokers will always return NOT_CONTROLLER for these RPCs.
UnregisterBroker
Required ACLs: ALTER on CLUSTER
The UnregisterBrokerRequest asks the controller to unregister a broker from the cluster.
Code Block | ||
---|---|---|
| ||
{ "apiKey": 5859, "type": "response", "name": "BrokerHeartbeatResponse", "validVersions": "0", "flexibleVersions": "0+", "fields": [ { "name": "ThrottleTimeMs", "type": "int32", "versions": "0+", "about": "Duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota." },request", "name": "UnregisterBrokerRequest", "validVersions": "0", "flexibleVersions": "0+", "fields": [ { "name": "ErrorCodeBrokerId", "type": "int16int32", "versions": "0+", "about": "The errorbroker code,ID orto 0 if there was no error." }, { "nameunregister." } ] } { "apiKey": 59, "type": "IsCaughtUpresponse", "typename": "boolUnregisterBrokerResponse", "versionsvalidVersions": "0+", "aboutflexibleVersions": "True if the broker has approximately caught up with the latest metadata." },"0+", "fields": [ { "name": "IsFencedThrottleTimeMs", "type": "boolint32", "versions": "0+", "about": "TrueDuration in milliseconds for which the request was throttled due to a quota violation, or zero if the broker is fenced request did not violate any quota." }, { "name": "ShouldShutDownErrorCode", "type": "boolint16", "versions": "0+", "about": "TrueThe iferror thecode, brokeror should0 proceedif with its shutdown." } ] } |
The controller will wait to unfence a broker until it sends a heartbeat where ShouldFence is false and CurrentMetadataOffset is caught up.
If the heartbeat request has ShouldShutDown set, the controller will try to move all the leaders off of the broker.
The controller will set ControlledShutdownOk if the broker is cleared to execute a controlled shutdown. In other words, if it has no leaderships.
The controller will return NOT_CONTROLLER if it is not active. Brokers will always return NOT_CONTROLLER for these RPCs.
UnregisterBroker
Required ACLs: ALTER on CLUSTER
The UnregisterBrokerRequest asks the controller to unregister a broker from the cluster.
there was no error." },
]
} |
The valid response codes are:
- NONE if the unregistration succeeded or if the broker was already unregistered.
- NOT_CONTROLLER if the node that the request was sent to is not the controller
- UNSUPPORTED_VERSION if KIP-500 mode is not enabled
Record Formats
RegisterBrokerRecord
Code Block | ||
---|---|---|
Code Block | ||
| ||
{ "apiKey": 590, "type": "request", "name": "UnregisterBrokerRequestmetadata", "validVersionsname": "0RegisterBrokerRecord" , "flexibleVersionsvalidVersions": "0+", "fields": [ { "name": "BrokerId", "type": "int32", "versions": "0+", "about": "The broker ID to unregisterid." } ] } { "apiKey, { "name": 59, "type": "response"IncarnationId", "nametype": "UnregisterBrokerResponseuuid", "validVersionsversions": "0+", "flexibleVersionsabout": "0+", The incarnation "fields": [ id of the broker process." }, { "name": "ThrottleTimeMsBrokerEpoch", "type": "int32int64", "versions": "0+", "about": "Duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota "about": "The broker epoch assigned by the controller." }, { "name": "ErrorCodeEndPoints", "type": "int16[]BrokerEndpoint", "versions": "0+", "nullableVersions": "0+", "about": "The errorendpoints code,that orcan 0be ifused thereto was no error." }, ] } |
The valid response codes are:
- NONE if the unregistration succeeded or if the broker was already unregistered.
- NOT_CONTROLLER if the node that the request was sent to is not the controller
- UNSUPPORTED_VERSION if KIP-500 mode is not enabled
Record Formats
RegisterBrokerRecord
Code Block |
---|
{ "apiKey": 0, "type": "metadata", "name": "RegisterBrokerRecord" , "validVersionscommunicate with this broker.", "fields": [ { "name": "Name", "type": "string", "versions": "0+", "mapKey": true, "fieldsabout": [ "The name of the endpoint." }, { "name": "BrokerIdHost", "type": "int32string", "versions": "0+", "about": "The broker idhostname." }, { "name": "IncarnationIdPort", "type": "uuiduint16", "versions": "0+", "about": "The incarnation id of the broker processport." }, { "name": "BrokerEpochSecurityProtocol", "type": "int64int16", "versions": "0+", "about": "The broker epoch assigned by the controllersecurity protocol." } ]}, { "name": "EndPointsFeatures", "type": "[]BrokerEndpointBrokerFeature", "versions": "0+", "nullableVersions": "0+", "about": "The endpointsfeatures that canthis be used to communicate with this brokerbroker supports.", "fields": [ { "name": "Name", "type": "string", "versions": "0+", "mapKey": true, "about": "The name of the endpointfeature." }, { "name": "HostMinVersion", "type": "stringint16", "versions": "0+", "about": "The hostname minimum feature level that this broker supports." }, { "name": "PortMaxVersion", "type": "uint16int16", "versions": "0+", "about": "The port maximum feature level that this broker supports." } ]}, { "name": "Rack", "type": "string", "versions": "0+", "nullableVersions": "0+", "about": "The broker rack." } ] } |
UnregisterBrokerRecord
Code Block |
---|
{ "nameapiKey": 1, "type": "SecurityProtocolmetadata",, "typename": "int16UnregisterBrokerRecord", "versionsvalidVersions": "0+", "aboutfields": "The security protocol." }[ ]}, { "name": "FeaturesBrokerId", "type": "[]BrokerFeatureint32", "versions": "0+", "nullableVersions": "0+", "about": "The features that this broker supportsid.", "fields": [ }, { "name": "NameBrokerEpoch", "type": "stringint64", "versions": "0+", "mapKey": true, "about": "The name of the feature." }, broker epoch." } ] } |
TopicRecord
Code Block |
---|
{ "apiKey": 2, "type { "name": "MinVersionmetadata", "typename": "int16TopicRecord", "versionsvalidVersions": "0+", "aboutfields": "The[ minimum feature level that this broker supports." }, { "name": "MaxVersionTopicName", "type": "int16string", "versions": "0+", "about": "The maximum feature level that this broker supports." } ]}, topic name." }, { "name": "RackTopicId", "type": "stringuuid", "versions": "0+", "nullableVersions": "0+", "about": "The broker rackunique ID of this topic." } ] } |
...
PartitionRecord
Code Block |
---|
{ "apiKey": 13, "type": "metadata", "name": "UnregisterBrokerRecordPartitionRecord", "validVersions": "0", "fields": [ { "name": "BrokerId", "type": "int32", "versions": "0+", "about": "The broker id." }, { "name": "BrokerEpochPartitionId", "type": "int64int32", "versions": "0+", "default": "-1", "about": "The brokerpartition epochid." }, ] } |
TopicRecord
Code Block |
---|
{ { "apiKeyname": 2"TopicId", "type": "metadatauuid", "nameversions": "TopicRecord0+", "validVersionsabout": "0", The unique "fields": [ ID of this topic." }, { "name": "TopicNameReplicas", "type": "string[]int32", "versions": "0+", "about": "The topic namereplicas of this partition, sorted by preferred order." }, { "name": "TopicIdIsr", "type": "uuid[]int32", "versions": "0+", "about": "The uniquein-sync IDreplicas of this topic.partition" }, ] } |
PartitionRecord
Code Block |
---|
{ "apiKeyname": 3"RemovingReplicas", "type": "metadata[]int32", "nameversions": "PartitionRecord0+", "validVersionsabout": "0", "fields": [The replicas that we are in the process of removing." }, { "name": "PartitionIdAddingReplicas", "type": "[]int32", "versions": "0+", "default": "-1", "about": "The partition idreplicas that we are in the process of adding." }, { "name": "TopicIdLeader", "type": "uuidint32", "versions": "0++", "default": "-1", "about": "The unique ID of this topiclead replica, or -1 if there is no leader." }, { "name": "ReplicasLeaderEpoch", "type": "[]int32", "versions": "0+", "default": "-1", "about": "The replicas of this partition, sorted by preferred orderAn epoch that gets incremented each time we change the leader." }, { "name] } |
ConfigRecord
Code Block |
---|
{ "apiKey": "Isr"4, "type": "[]int32metadata", "versionsname": "0+ConfigRecord", "aboutvalidVersions": "0"The, in-sync replicas of this partition" }, "fields": [ { "name": "RemovingReplicasResourceType", "type": "[]int32int8", "versions": "0+", "about": "The replicastype thatof weresource arethis inconfiguration the process of removingapplies to." }, { "name": "AddingReplicasResourceName", "type": "[]int32string", "versions": "0+", "about": "The replicasname thatof wethe areresource inthis theconfiguration processapplies of addingto." }, { "name": "LeaderName", "type": "int32string", "versions": "0+", "defaultabout": "-1", The name of the configuration key." }, "about": "The lead replica, or -1 if there is no leader." }, { "name": "LeaderEpochValue", "type": "int32string", "versions": "0+", "default": "-1", "about": "An epoch that gets incremented each time we changeThe value of the leaderconfiguration." } ] } |
ConfigRecord
Code Block |
---|
{ } |
PartitionChangeRecord
Code Block |
---|
{ "apiKey": 45, "type": "metadata", "name": "ConfigRecordPartitionChangeRecord", "validVersions": "0", "fields": [ { "name": "ResourceTypePartitionId", "type": "int8int32", "versions": "0+", "default": "-1", "about": "The type of resource this configuration applies topartition id." }, { "name": "ResourceNameTopicId", "type": "stringuuid", "versions": "0+", "about": "The unique nameID of the resource this configuration applies totopic." }, { "name": "NameIsr", "type": "string "[]int32", "default": "null", "versionsentityType": "0+brokerId", "aboutversions": "The name of the configuration key." },0+", "nullableVersions": "0+", "taggedVersions": "0+", "tag": 0, "about": "null if the ISR didn't change; the new in-sync replicas otherwise." }, { "name": "ValueLeader", "type": "stringint32", "versionsdefault": "0+-2", "entityType": "brokerId", "aboutversions": "The value of the configuration." }0+", "taggedVersions": "0+", "tag": 1, ] "about": "-1 if there is now no } |
IsrChangeRecord
Code Block |
---|
{ "apiKey": 5, "type": "metadata", "name": "IsrChangeRecord", "validVersions": "0", "fields": [leader; -2 if the leader didn't change; the new leader otherwise." }, { "name": "PartitionIdReplicas", "type": "[]int32", "versionsdefault": "0+null", "defaultentityType": "-1brokerId", "aboutversions": "The partition id." }, { "name0+", "nullableVersions": "TopicId0+", "typetaggedVersions": "uuid0+", "versionstag": "0+"2, "about": "The unique ID of this topicnull if the replicas didn't change; the new replicas otherwise." }, { "name": "IsrRemovingReplicas", "type": "[]int32", "versionsdefault": "0+null", "aboutentityType": "The in-sync replicas of this partition" }brokerId", { "nameversions": "Leader0+", "typenullableVersions": "int320+", "versionstaggedVersions": "0+", "defaulttag": "-1"3, "about": "The lead replica, or -1 if there is no leadernull if the removing replicas didn't change; the new removing replicas otherwise." }, { "name": "LeaderEpochAddingReplicas", "type": "[]int32", "default": "null", "entityType": "brokerId", "versions": "0+", "nullableVersions": "0+", "defaulttaggedVersions": "0+", "-1tag": 4, "about": "Annull if epochthe thatadding getsreplicas incremented each time we change the leaderdidn't change; the new adding replicas otherwise." } ] } |
AccessControlRecord
...