question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[PIP-139] Support Broker send command to close producer/consumer.

See original GitHub issue

Relation pull request: #13337 Authors: @Technoboy- @mattisonchao

Motivation

  • When there are no user-created topics under a namespace, Namespace should be deleted. But currently, the system topic existed and the reader/producer could auto-create the system which may cause the namespace deletion to fail.
  • When enabling geo-replication under a namespace, inactive topics could not be deleted by GC, and if the broker enables auto-create topic, the topic will be created(replicator) even deleted with force=true.

For the above reasons, we need to close the topics readers/producers first, then delete the relative topics.

Following this way, we need to close consumers/producers(not disconnect, which means do not allow them to reconnect). So we write this PIP to discuss to resolve this problem.

Related email : https://lists.apache.org/thread/p4tmgk23l8j554bjr4h4ofk97bll5gp4

Goal

We can add a new field(reconnect) in command CommandCloseProducer/ CommandCloseConsumer to achieve this goal.

API Changes

  • Add reconnect to CommandCloseProducer;
**Before**

message CommandCloseProducer {
    required uint64 producer_id = 1;
    required uint64 request_id = 2;
}

**After**
message CommandCloseProducer {
    required uint64 producer_id = 1;
    required uint64 request_id = 2;
    optional bool reconnect = 3 [default = true];
}
  • Add reconnect to CommandCloseConsumer
**Before**

message CommandCloseConsumer {
    required uint64 consumer_id = 1;
    required uint64 request_id = 2;
}

**After**
message CommandCloseConsumer {
    required uint64 consumer_id = 1;
    required uint64 request_id = 2;
    optional bool reconnect = 3 [default = true];
}

Implementation

ClientCnx - Producer:

Before

@Override
protected void handleCloseProducer(CommandCloseProducer closeProducer) {
   log.info("[{}] Broker notification of Closed producer: {}", remoteAddress, closeProducer.getProducerId());
   final long producerId = closeProducer.getProducerId();
   ProducerImpl<?> producer = producers.get(producerId);
   if (producer != null) {
       producer.connectionClosed(this);
   } else {
       log.warn("Producer with id {} not found while closing producer ", producerId);
   }
}  

After:

@Override
protected void handleCloseProducer(CommandCloseProducer closeProducer) {
   log.info("[{}] Broker notification of Closed producer: {}", remoteAddress, closeProducer.getProducerId());
   final long producerId = closeProducer.getProducerId();
   ProducerImpl<?> producer = producers.get(producerId);
   if (producer != null) {
       if (closeProducer.isReconnect()) {
           producer.connectionClosed(this);
       } else {
           producer.closeAsync();
       }
   } else {
       log.warn("Producer with id {} not found while closing producer ", producerId);
   }
}

ClientCnx - Consumer:

Before

@Override
protected void handleCloseConsumer(CommandCloseConsumer closeConsumer) {
   log.info("[{}] Broker notification of Closed consumer: {}", remoteAddress, closeConsumer.getConsumerId());
   final long consumerId = closeConsumer.getConsumerId();
   ConsumerImpl<?> consumer = consumers.get(consumerId);
   if (consumer != null) {
       consumer.connectionClosed(this);
   } else {
       log.warn("Consumer with id {} not found while closing consumer ", consumerId);
   }
}    

After

@Override
protected void handleCloseConsumer(CommandCloseConsumer closeConsumer) {
   log.info("[{}] Broker notification of Closed consumer: {}", remoteAddress, closeConsumer.getConsumerId());
   final long consumerId = closeConsumer.getConsumerId();
   ConsumerImpl<?> consumer = consumers.get(consumerId);
   if (consumer != null) {
       if (closeConsumer.isReconnect()) {
           consumer.connectionClosed(this);
       } else {
           consumer.closeAsync();
       }
   } else {
       log.warn("Consumer with id {} not found while closing consumer ", consumerId);
   }
}   

Reject Alternatives

none.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Technoboy-commented, Feb 18, 2022

@merlimat @lhotari @eolivelli @codelipenghui @gaoran10 Could you help give some suggestions?

0reactions
Technoboy-commented, Mar 21, 2022

More details and discussions are in the email thread. and after diving into the code, we push #14730 to resolve the current problem. So now we decide to close this PIP.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Producer client — aiokafka 0.8.0 documentation
Under the hood, AIOKafkaProducer does quite some work on message delivery including batching, retries, etc. All of it can be configured, so let's...
Read more >
Kafka 3.3 Documentation
Stop the producer and consumer clients with Ctrl-C , if you haven't done so already. Stop the Kafka broker with Ctrl-C . Lastly,...
Read more >
Apache Pulsar Client Application Best Practices - StreamNative
When each message arrives you create a new Pulsar Message using the payload and use a Pulsar Producer to send that message over...
Read more >
Console Producer and Consumer Basics - Confluent Developer
Let's try to send some full key-value records now. If your previous console producer is still running close it with a CTRL+C and...
Read more >
Kafka Producer and Consumer Examples - DZone
Producer : Creates a record and publishes it to the broker. Consumer: Consumes records from the ... Execute this command to delete a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found