|
@@ -797,6 +797,7 @@ func (bp *brokerProducer) handleResponse(response *brokerProducerResponse) {
|
|
|
func (bp *brokerProducer) handleSuccess(sent *produceSet, response *ProduceResponse) {
|
|
|
|
|
|
|
|
|
+ var retryTopics []string
|
|
|
sent.eachPartition(func(topic string, partition int32, pSet *partitionSet) {
|
|
|
if response == nil {
|
|
|
|
|
@@ -828,21 +829,41 @@ func (bp *brokerProducer) handleSuccess(sent *produceSet, response *ProduceRespo
|
|
|
|
|
|
case ErrInvalidMessage, ErrUnknownTopicOrPartition, ErrLeaderNotAvailable, ErrNotLeaderForPartition,
|
|
|
ErrRequestTimedOut, ErrNotEnoughReplicas, ErrNotEnoughReplicasAfterAppend:
|
|
|
- Logger.Printf("producer/broker/%d state change to [retrying] on %s/%d because %v\n",
|
|
|
- bp.broker.ID(), topic, partition, block.Err)
|
|
|
- if bp.currentRetries[topic] == nil {
|
|
|
- bp.currentRetries[topic] = make(map[int32]error)
|
|
|
- }
|
|
|
- bp.currentRetries[topic][partition] = block.Err
|
|
|
-
|
|
|
- bp.parent.retryMessages(bp.buffer.dropPartition(topic, partition), block.Err)
|
|
|
- bp.parent.retryBatch(topic, partition, pSet, block.Err)
|
|
|
-
|
|
|
+ retryTopics = append(retryTopics, topic)
|
|
|
|
|
|
default:
|
|
|
bp.parent.returnErrors(pSet.msgs, block.Err)
|
|
|
}
|
|
|
})
|
|
|
+
|
|
|
+ if len(retryTopics) > 0 {
|
|
|
+ err := bp.parent.client.RefreshMetadata(retryTopics...)
|
|
|
+ if err != nil {
|
|
|
+ Logger.Printf("Failed refreshing metadata because of %v\n", err)
|
|
|
+ }
|
|
|
+
|
|
|
+ sent.eachPartition(func(topic string, partition int32, pSet *partitionSet) {
|
|
|
+ block := response.GetBlock(topic, partition)
|
|
|
+ if block == nil {
|
|
|
+
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ switch block.Err {
|
|
|
+ case ErrInvalidMessage, ErrUnknownTopicOrPartition, ErrLeaderNotAvailable, ErrNotLeaderForPartition,
|
|
|
+ ErrRequestTimedOut, ErrNotEnoughReplicas, ErrNotEnoughReplicasAfterAppend:
|
|
|
+ Logger.Printf("producer/broker/%d state change to [retrying] on %s/%d because %v\n",
|
|
|
+ bp.broker.ID(), topic, partition, block.Err)
|
|
|
+ if bp.currentRetries[topic] == nil {
|
|
|
+ bp.currentRetries[topic] = make(map[int32]error)
|
|
|
+ }
|
|
|
+ bp.currentRetries[topic][partition] = block.Err
|
|
|
+
|
|
|
+ bp.parent.retryMessages(bp.buffer.dropPartition(topic, partition), block.Err)
|
|
|
+ bp.parent.retryBatch(topic, partition, pSet, block.Err)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
func (p *asyncProducer) retryBatch(topic string, partition int32, pSet *partitionSet, kerr KError) {
|
|
@@ -859,15 +880,8 @@ func (p *asyncProducer) retryBatch(topic string, partition int32, pSet *partitio
|
|
|
}
|
|
|
msg.retries++
|
|
|
}
|
|
|
-
|
|
|
- err := p.client.RefreshMetadata(topic)
|
|
|
- if err != nil {
|
|
|
- Logger.Printf("Failed retrying batch for %v-%d because of %v while refreshing metadata\n", topic, partition, err)
|
|
|
- for _, msg := range pSet.msgs {
|
|
|
- p.returnError(msg, kerr)
|
|
|
- }
|
|
|
- return
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
leader, err := p.client.Leader(topic, partition)
|
|
|
if err != nil {
|
|
|
Logger.Printf("Failed retrying batch for %v-%d because of %v while looking up for new leader\n", topic, partition, err)
|