RobertIndie commented on code in PR #1422:
URL: https://github.com/apache/pulsar-client-go/pull/1422#discussion_r2340365386


##########
pulsar/producer_partition.go:
##########
@@ -385,31 +391,18 @@ func (p *partitionProducer) grabCnx(assignedBrokerURL 
string) error {
                "epoch": atomic.LoadUint64(&p.epoch),
        }).Info("Connected producer")
 
-       pendingItems := p.pendingQueue.ReadableSlice()
-       viewSize := len(pendingItems)
-       if viewSize > 0 {
-               p.log.Infof("Resending %d pending batches", viewSize)
-               lastViewItem := pendingItems[viewSize-1].(*pendingItem)
-
-               // iterate at most pending items
-               for i := 0; i < viewSize; i++ {
-                       item := p.pendingQueue.Poll()
-                       if item == nil {
-                               continue
-                       }
-                       pi := item.(*pendingItem)
-                       // when resending pending batches, we update the sendAt 
timestamp to record the metric.
-                       pi.Lock()
-                       pi.sentAt = time.Now()
-                       pi.Unlock()
-                       pi.buffer.Retain() // Retain for writing to the 
connection
-                       p.pendingQueue.Put(pi)
-                       p._getConn().WriteData(pi.ctx, pi.buffer)
+       p.pendingQueue.Iterate(func(item any) {
+               pi := item.(*pendingItem)
+               // when resending pending batches, we update the sendAt 
timestamp to record the metric.
+               pi.Lock()
+               pi.sentAt = time.Now()
+               pi.Unlock()
+               pi.buffer.Retain() // Retain for writing to the connection
+               p._getConn().WriteData(pi.ctx, pi.buffer)

Review Comment:
   The original logic is OK.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to