Skip to content

Commit

Permalink
Improve sleep logic around ErrConsumerCoordinatorNotAvailable
Browse files Browse the repository at this point in the history
  • Loading branch information
wvanbergen committed Apr 9, 2015
1 parent c7bcd38 commit 5720591
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ func (client *client) refreshCoordinator(consumerGroup string, attemptsRemaining

case ErrConsumerCoordinatorNotAvailable:
Logger.Printf("client/coordinator Coordinator for consumer group %s not yet available, trying again in %dms...\n", consumerGroup, client.conf.Metadata.Retry.Backoff/time.Millisecond)
time.Sleep(client.conf.Metadata.Retry.Backoff)
time.Sleep(2 * time.Second)
continue

default:
Expand All @@ -674,6 +674,7 @@ func (client *client) refreshCoordinator(consumerGroup string, attemptsRemaining
if attemptsRemaining > 0 {
Logger.Printf("client/coordinator Trying again to find coordinator for consumer group %s... (%d attempts remaining)\n", consumerGroup, attemptsRemaining)

time.Sleep(client.conf.Metadata.Retry.Backoff)
client.resurrectDeadBrokers()
return client.refreshCoordinator(consumerGroup, attemptsRemaining-1)
}
Expand Down
20 changes: 10 additions & 10 deletions functional_client_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sarama

import (
"fmt"
"testing"
"time"
)
Expand Down Expand Up @@ -61,21 +62,20 @@ func TestFuncClientCoordinator(t *testing.T) {
checkKafkaVersion(t, "0.8.2")
checkKafkaAvailability(t)

config := NewConfig()
config.Metadata.Retry.Max = 10
config.Metadata.Retry.Backoff = 1 * time.Second
client, err := NewClient(kafkaBrokers, config)
client, err := NewClient(kafkaBrokers, nil)
if err != nil {
t.Fatal(err)
}

broker, err := client.Coordinator("new_consumer_group")
if err != nil {
t.Error(err)
}
for i := 0; i < 10; i++ {
broker, err := client.Coordinator(fmt.Sprintf("another_new_consumer_group_%d", i))
if err != nil {
t.Error(err)
}

if connected, err := broker.Connected(); !connected || err != nil {
t.Errorf("Expected to coordinator %s broker to be properly connected.", broker.Addr())
if connected, err := broker.Connected(); !connected || err != nil {
t.Errorf("Expected to coordinator %s broker to be properly connected.", broker.Addr())
}
}

safeClose(t, client)
Expand Down

0 comments on commit 5720591

Please sign in to comment.