This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
forked from bsm/sarama-cluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster.go
66 lines (53 loc) · 1.45 KB
/
cluster.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package cluster
import "sort"
// Strategy for partition to consumer assignement
type Strategy string
const (
// StrategyRange is the default and assigns partition ranges to consumers.
// Example with six partitions and two consumers:
// C1: [0, 1, 2]
// C2: [3, 4, 5]
StrategyRange Strategy = "range"
// StrategyRoundRobin assigns partitions by alternating over consumers.
// Example with six partitions and two consumers:
// C1: [0, 2, 4]
// C2: [1, 3, 5]
StrategyRoundRobin Strategy = "roundrobin"
)
// Error instances are wrappers for internal errors with a context and
// may be returned through the consumer's Errors() channel
type Error struct {
Ctx string
error
}
// --------------------------------------------------------------------
type none struct{}
type topicPartition struct {
Topic string
Partition int32
}
type offsetInfo struct {
Offset int64
Metadata string
}
func (i offsetInfo) NextOffset(fallback int64) int64 {
if i.Offset > -1 {
return i.Offset
}
return fallback
}
type int32Slice []int32
func (p int32Slice) Len() int { return len(p) }
func (p int32Slice) Less(i, j int) bool { return p[i] < p[j] }
func (p int32Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
func (p int32Slice) Diff(o int32Slice) (res []int32) {
on := len(o)
for _, x := range p {
n := sort.Search(on, func(i int) bool { return o[i] >= x })
if n < on && o[n] == x {
continue
}
res = append(res, x)
}
return
}