The scenario
I have started all the components for a multi-broker configuration in a single machine using the shell scripts found in https://archive.apache.org/dist/kafka/2.0.0/kafka_2.11-2.0.0.tgz
- Started zookeeper with the zookeeper-properties
- Started 3 brokers with 3 different server properties. They differentiate only on these config values
broker.id
log.dirs
port
I have also tried to change offsets.topic.replication.factor
and transaction.state.log.replication.factor
, but I don't believe they are relevant.
Note: the order how I started the brokers is 0 , 1 , 2
- Create a topic with replication factor 3 and one partition
bin/kafka-topics.sh --create --topic repl_topic --zookeeper localhost:2181 --replication-factor 3 --partitions 1
- Started console producer and consumer
bin/kafka-console-producer.sh --topic repl_topic --broker-list localhost:9092,localhost:9093,localhost:9094
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092,localhost:9093,localhost:9094 -topic repl_topic --from-beginning
Producer and consumer appear to work correctly. However if I shutdown by Ctrl-C the broker 0 (even if it is not leader), the consumer receives a warning but it doesn't receive anymore message from the producer. Only when broker 0 will be up again, the consumer will receive all the messages.
My conclusion
The consumer is dependent on broker 0 only. It doesn't interact with the others.
My question
Why?
I have finally figured out the problem and I have fixed that. Checking the __consumer_offsets, I have noticed it is not replicated.
Indeed, the first time I have started a consumer it was for a topic with a replication_factor equal to 1. In that time, the consumer created only one replica. That topic was not anymore updated and then the other brokers were not able to see it if broker 0 was going down.
Solution
It is possible to establish a new replication level per partition by the command
bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file new_reassignment.json --execute
The new_reassignment.json json file used there has the following content
At this point, it is possible to manage the failure of any broker with sucess.
__consumer_offsets -- extra info
The number of partitions in this particular topic is set per default to 50. The consumer triggers its creation. The topic is mainly used by the consumer to commit the received message for each topic:partion. If this __consumer_offsets topic is not visible to the other brokers, the brokers will not have a way to inform the consumer to consume new messages.