MINOR: Add comment to onPartitionsLost override (#14121)

This adds comments to the ConsumerRebalanceListener overrides, in order to briefly explain why we are overriding these methods, when they are called, and what you can or can't do. Especially onPartitionsLost can create some confusion given the default implementation.

Reviewers: Luke Chen <showuon@gmail.com>, David Jacot <djacot@confluent.io>
This commit is contained in:
Federico Valeri 2023-08-11 04:34:55 +02:00 committed by GitHub
parent 594156e01b
commit 111df859f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -151,15 +151,20 @@ public class Consumer extends Thread implements ConsumerRebalanceListener {
@Override @Override
public void onPartitionsRevoked(Collection<TopicPartition> partitions) { public void onPartitionsRevoked(Collection<TopicPartition> partitions) {
Utils.printOut("Revoked partitions: %s", partitions); Utils.printOut("Revoked partitions: %s", partitions);
// this can be used to commit pending offsets when using manual commit and EOS is disabled
} }
@Override @Override
public void onPartitionsAssigned(Collection<TopicPartition> partitions) { public void onPartitionsAssigned(Collection<TopicPartition> partitions) {
Utils.printOut("Assigned partitions: %s", partitions); Utils.printOut("Assigned partitions: %s", partitions);
// this can be used to read the offsets from an external store or some other initialization
} }
@Override @Override
public void onPartitionsLost(Collection<TopicPartition> partitions) { public void onPartitionsLost(Collection<TopicPartition> partitions) {
Utils.printOut("Lost partitions: %s", partitions); Utils.printOut("Lost partitions: %s", partitions);
// this is called when partitions are reassigned before we had a chance to revoke them gracefully
// we can't commit pending offsets because these partitions are probably owned by other consumers already
// nevertheless, we may need to do some other cleanup
} }
} }