This is a continuation of my previous question
I was experimenting kafka's min.insync.replicas
and here's the summary:
- Setup 3 brokers in local, created a topic
insync
withmin.insync.replicas=2
. - Messages were produced by kafka-console-producer with
acks=all
and read by kafka-console-consumer - Bought down 2 brokers leaving just 1
insync.replicas
and was expecting an exception in producer as mentioned here and here
But it never happened and producer was producing messages and consumer was reading them from console without any errors.(more details in previous question)
Then, Instead of producing messages from console-producer , I wrote a java producer with same configurations as console producer and finally got the following exception.
ERROR [Replica Manager on Broker 0]: Error processing append operation on partition insync-0 (kafka.server.ReplicaManager) org.apache.kafka.common.errors.NotEnoughReplicasException: Number of insync replicas for partition [insync,0] is [ 1 ], below required minimum [ 2 ]
Although I expected it from the producer(java code), it showed up in the kafka broker.
Console producer command
./kafka-console-producer.sh --broker-list localhost:9092 --topic insync --producer.config ../config/producer.properties
kafka-console-producer properties:
bootstrap.servers=localhost:9092,localhost:9093,localhost:9094
compression.type=none
batch.size=20
acks=all
Java producer code:
public static void main(String[] args) {
KafkaProducer<String, String> kafkaProducer = new KafkaProducer<String, String>(producerConfigs());
try {
int count = 0;
while (true) {
ProducerRecord<String, String> record = new ProducerRecord<String, String>("insync",
"test message: " + count);
kafkaProducer.send(record);
Thread.sleep(3000);
count++;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
kafkaProducer.close();
}
}
private static Properties producerConfigs() {
Properties properties = new Properties();
properties.put("bootstrap.servers", "localhost:9092,localhost:9093,localhost:9094");
properties.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
properties.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
properties.put("acks", "all");
return properties;
}
This brings me more questions.
- Why does it happen while running java producer and not in console-producer.?
- Why does the exception occur in broker and not in producer(java code)?
the documentation for
min.insync.replicas
saysIf this minimum cannot be met, then the producer will raise an exception (either NotEnoughReplicas or NotEnoughReplicasAfterAppend)
How does kafka guarantee reliability in this case?
request-required-acks
on the console producer, not justacks
. And do you have unclean leader election enabled? – OneCricketeerrequest-required-acks
is deprecated fromkafka 0.8
. Im usingkafka 0.10.0
. cwiki.apache.org/confluence/display/KAFKA/… – Arun Gowdakafka 0.10
in production. So sticking to the same version :) – Arun Gowda