-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathrebuilding.go
53 lines (46 loc) · 1.3 KB
/
rebuilding.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
package quamina
// This file contains some experimental rebuildWhileLocked policies that are not
// currently used anywhere. Here just for examples and possible
// future use.
// liveRatioTrigger's rebuild function returns true when there are at
// least MinLive live patterns and the ratio of removed to live
// patterns is greater than 1.
//
// This type is not used anywhere; just here as an example and maybe
// for future consideration.
type liveRatioTrigger struct {
Ratio float64
MinLive int
}
func newLiveRatioTrigger(ratio float64, minimum int) *liveRatioTrigger {
return &liveRatioTrigger{
Ratio: ratio,
MinLive: minimum,
}
}
func (t *liveRatioTrigger) rebuild(added bool, s *prunerStats) bool {
if added {
return false
}
live := s.Live - s.Deleted
if live == 0 {
return false
}
if live < t.MinLive {
return false
}
return t.Ratio <= float64(s.Deleted)/float64(live)
}
// neverTrigger is a rebuildTrigger that will never trigger a rebuild.
//
// Setting prunerMatcher.rebuildTrigger to nil will have the same effect.
//
// This type is not used anywhere; just here as an example and maybe
// for future consideration.
type neverTrigger struct{}
func newNeverTrigger() *neverTrigger {
return &neverTrigger{}
}
func (t *neverTrigger) rebuild(added bool, s *prunerStats) bool {
return false
}