This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #472 from raintank/partitionedNotifyKafka
Make kafka-cluster chunk save messages partition aware.
- Loading branch information
Showing
12 changed files
with
211 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package kafka | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/Shopify/sarama" | ||
) | ||
|
||
// returns elements that are in a but not in b | ||
func DiffPartitions(a []int32, b []int32) []int32 { | ||
var diff []int32 | ||
Iter: | ||
for _, eA := range a { | ||
for _, eB := range b { | ||
if eA == eB { | ||
continue Iter | ||
} | ||
} | ||
diff = append(diff, eA) | ||
} | ||
return diff | ||
} | ||
|
||
func GetPartitions(client sarama.Client, topics []string) ([]int32, error) { | ||
partitionCount := 0 | ||
partitions := make([]int32, 0) | ||
var err error | ||
for i, topic := range topics { | ||
partitions, err = client.Partitions(topic) | ||
if err != nil { | ||
return nil, fmt.Errorf("Failed to get partitions for topic %s. %s", topic, err) | ||
} | ||
if len(partitions) == 0 { | ||
return nil, fmt.Errorf("No partitions returned for topic %s", topic) | ||
} | ||
if i > 0 { | ||
if len(partitions) != partitionCount { | ||
return nil, fmt.Errorf("Configured topics have different partition counts, this is not supported") | ||
} | ||
continue | ||
} | ||
partitionCount = len(partitions) | ||
} | ||
return partitions, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.