forked from VKCOM/kittenhouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conf.go
66 lines (53 loc) · 1.23 KB
/
conf.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 inmem
import (
"sync"
"github.com/vkcom/kittenhouse/core/destination"
)
const (
debug = false
)
var flusherMap = struct {
sync.Mutex
v map[destination.ServersStr]*flusher
}{
v: make(map[destination.ServersStr]*flusher),
}
// UpdateDestinationsConfig accepts destination.Map and starts new flushers if neccessary
func UpdateDestinationsConfig(m destination.Map) {
flusherMap.Lock()
defer flusherMap.Unlock()
for _, fl := range flusherMap.v {
select {
case fl.stopCh <- struct{}{}:
default:
}
}
var defaultFlusher *flusher
flusherMap.v = make(map[destination.ServersStr]*flusher, len(m))
allTables := make(map[string]struct{})
for dst, settings := range m {
fl := &flusher{
isDefault: settings.Default,
dst: settings,
stopCh: make(chan struct{}, 1),
}
if settings.Default {
defaultFlusher = fl
} else {
fl.includeTables = make(map[string]struct{}, len(settings.Tables))
}
for _, table := range settings.Tables {
allTables[table] = struct{}{}
if !settings.Default {
fl.includeTables[table] = struct{}{}
}
}
flusherMap.v[dst] = fl
}
if defaultFlusher != nil {
defaultFlusher.excludeTables = allTables
}
for _, fl := range flusherMap.v {
go fl.loop()
}
}