Skip to content

Commit ab4d8da

Browse files
author
Achille
authored
fix issue 971 (#973)
* fix issue 971 * fix int => int32 * fix TestMakeBrokersOneMissing * update documentation
1 parent fcb5875 commit ab4d8da

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

conn.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,11 +1017,17 @@ func (c *Conn) ReadPartitions(topics ...string) (partitions []Partition, err err
10171017
}
10181018

10191019
func makeBrokers(brokers map[int32]Broker, ids ...int32) []Broker {
1020-
b := make([]Broker, 0, len(ids))
1021-
for _, id := range ids {
1022-
if br, ok := brokers[id]; ok {
1023-
b = append(b, br)
1020+
b := make([]Broker, len(ids))
1021+
for i, id := range ids {
1022+
br, ok := brokers[id]
1023+
if !ok {
1024+
// When the broker id isn't found in the current list of known
1025+
// brokers, use a placeholder to report that the cluster has
1026+
// logical knowledge of the broker but no information about the
1027+
// physical host where it is running.
1028+
br.ID = int(id)
10241029
}
1030+
b[i] = br
10251031
}
10261032
return b
10271033
}

conn_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,16 +1353,19 @@ func TestMakeBrokersAllPresent(t *testing.T) {
13531353
func TestMakeBrokersOneMissing(t *testing.T) {
13541354
brokers := make(map[int32]Broker)
13551355
brokers[1] = Broker{ID: 1, Host: "203.0.113.101", Port: 9092}
1356-
brokers[3] = Broker{ID: 1, Host: "203.0.113.103", Port: 9092}
1356+
brokers[3] = Broker{ID: 3, Host: "203.0.113.103", Port: 9092}
13571357

13581358
b := makeBrokers(brokers, 1, 2, 3)
1359-
if len(b) != 2 {
1360-
t.Errorf("Expected 2 brokers, got %d", len(b))
1359+
if len(b) != 3 {
1360+
t.Errorf("Expected 3 brokers, got %d", len(b))
13611361
}
13621362
if b[0] != brokers[1] {
13631363
t.Errorf("Expected broker 1 at index 0, got %d", b[0].ID)
13641364
}
1365-
if b[1] != brokers[3] {
1366-
t.Errorf("Expected broker 3 at index 1, got %d", b[1].ID)
1365+
if b[1] != (Broker{ID: 2}) {
1366+
t.Errorf("Expected broker 2 at index 1, got %d", b[1].ID)
1367+
}
1368+
if b[2] != brokers[3] {
1369+
t.Errorf("Expected broker 3 at index 1, got %d", b[2].ID)
13671370
}
13681371
}

kafka.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ type Partition struct {
3838
ID int
3939

4040
// Leader, replicas, and ISR for the partition.
41+
//
42+
// When no physical host is known to be running a broker, the Host and Port
43+
// fields will be set to the zero values. The logical broker ID is always
44+
// set to the value known to the kafka cluster, even if the broker is not
45+
// currently backed by a physical host.
4146
Leader Broker
4247
Replicas []Broker
4348
Isr []Broker

0 commit comments

Comments
 (0)