-
Notifications
You must be signed in to change notification settings - Fork 781
/
broadcast.go
64 lines (53 loc) · 1.72 KB
/
broadcast.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
package memberlist
import (
"fmt"
"github.com/go-kit/kit/log/level"
"github.com/hashicorp/memberlist"
"github.com/cortexproject/cortex/pkg/util"
)
// ringBroadcast implements memberlist.Broadcast interface, which is used by memberlist.TransmitLimitedQueue.
type ringBroadcast struct {
key string
content []string // Description of what is stored in this value. Used for invalidation.
version uint // local version of the value, generated by merging this change
msg []byte // encoded key and value
finished func(b ringBroadcast)
}
func (r ringBroadcast) Invalidates(old memberlist.Broadcast) bool {
if oldb, ok := old.(ringBroadcast); ok {
if r.key != oldb.key {
return false
}
// if 'content' (result of Mergeable.MergeContent) of this broadcast is a superset of content of old value,
// and this broadcast has resulted in a newer ring update, we can invalidate the old value
for _, oldName := range oldb.content {
found := false
for _, newName := range r.content {
if oldName == newName {
found = true
break
}
}
if !found {
return false
}
}
// only do this check if this ringBroadcast covers same ingesters as 'b'
// otherwise, we may be invalidating some older messages, which however covered different
// ingesters
if r.version >= oldb.version {
level.Debug(util.Logger).Log("msg", "Invalidating forwarded broadcast", "key", r.key, "version", r.version, "oldVersion", oldb.version, "content", fmt.Sprintf("%v", r.content), "oldContent", fmt.Sprintf("%v", oldb.content))
return true
}
}
return false
}
func (r ringBroadcast) Message() []byte {
return r.msg
}
func (r ringBroadcast) Finished() {
if r.finished != nil {
r.finished(r)
}
r.msg = nil
}