sijie commented on a change in pull request #5571: Add epoch for connection 
handler to handle create producer timeout.
URL: https://github.com/apache/pulsar/pull/5571#discussion_r343711137
 
 

 ##########
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/nonpersistent/NonPersistentTopic.java
 ##########
 @@ -207,9 +207,20 @@ public void addProducer(Producer producer) throws 
BrokerServiceException {
                 log.debug("[{}] {} Got request to create producer ", topic, 
producer.getProducerName());
             }
 
-            if (!producers.add(producer)) {
-                throw new NamingException(
-                        "Producer with name '" + producer.getProducerName() + 
"' is already connected to topic");
+            Producer existProducer = 
producers.putIfAbsent(producer.getProducerName(), producer);
+            if (existProducer != null) {
+                boolean canOverwrite = false;
+                if (existProducer.equals(producer) && 
!existProducer.isUserProvidedProducerName()
+                        && !producer.isUserProvidedProducerName() && 
producer.getEpoch() > existProducer.getEpoch()) {
+                    existProducer.close();
+                    canOverwrite = true;
+                }
+                if (canOverwrite) {
+                    producers.put(producer.getProducerName(), producer);
 
 Review comment:
   use `producers.replace(producer.getProducerName(), existingProducer, 
producer)` to make sure one can successfully add the producer.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to