John Keeper
John Keeper

Reputation: 255

Kafka stops working after a restart: NotLeaderOrFollowerException

I just started learning Kafka and followed this quickstart. Everything runs fine until I restart my PC and I initiate a new zookeeper and kafka session using

./bin/zookeeper-server-start.sh ./config/zookeeper.properties

./bin/kafka-server-start.sh ./config/server.properties

After that, every time I start a Kafka consumer using, for example

/kafka-console-producer.sh --topic REPA1 --bootstrap-server localhost:9092

I get the following error:

WARN [Producer clientId=console-producer] Got error produce response with correlation id 5 on topic-partition REPA1-0, retrying (2 attempts left). Error: NOT_LEADER_OR_FOLLOWERS

(more attemps with the same error)

And finally

Received invalid metadata error in produce request on partition REPA1-0 due to org.apache.kafka.common.errors.NotLeaderOrFollowerException: For requests intended only for the leader, this error indicates that the broker is not the current leader. For requests intended for any replica, this error indicates that the broker is not a replica of the topic partition.. Going to request metadata update now

Which makes me think that every time I restart the kafka server and zookeeper, the information about the current leader of my topic is lost my producer tries to connect to the old leader, even tough I only have one broker and 1 partitions in my topic:

./kafka-topics.sh --bootstrap-server localhost:9092 --topic REPA1 --describe
Topic: REPA1    TopicId: r16Oy0BMQpmm-FNVBaGInA PartitionCount: 1   ReplicationFactor: 1    Configs: 
    Topic: REPA1    Partition: 0    Leader: 0   Replicas: 0 Isr: 0

How can I make sure that every time I restart zookeeper and kafka it still works?

Thank you for your time

Upvotes: 0

Views: 813

Answers (1)

OneCricketeer
OneCricketeer

Reputation: 191864

By default, Kafka and Zookeeper store data under /tmp

If you restart your computer, that directory is cleared, and you will lose all topic data, so will need to recreate all topics. Your consumers can't read from non existing topics.

Change Zookeeper dataDir and Kafka log.dirs to a more persistent location.

Upvotes: 1

Related Questions