...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package v3compactor
16
17 import (
18 "context"
19 "fmt"
20 "time"
21
22 pb "go.etcd.io/etcd/api/v3/etcdserverpb"
23
24 "github.com/jonboulle/clockwork"
25 "go.uber.org/zap"
26 )
27
28 const (
29 ModePeriodic = "periodic"
30 ModeRevision = "revision"
31 )
32
33
34 type Compactor interface {
35
36
37 Run()
38
39 Stop()
40
41 Pause()
42
43 Resume()
44 }
45
46 type Compactable interface {
47 Compact(ctx context.Context, r *pb.CompactionRequest) (*pb.CompactionResponse, error)
48 }
49
50 type RevGetter interface {
51 Rev() int64
52 }
53
54
55 func New(
56 lg *zap.Logger,
57 mode string,
58 retention time.Duration,
59 rg RevGetter,
60 c Compactable,
61 ) (Compactor, error) {
62 if lg == nil {
63 lg = zap.NewNop()
64 }
65 switch mode {
66 case ModePeriodic:
67 return newPeriodic(lg, clockwork.NewRealClock(), retention, rg, c), nil
68 case ModeRevision:
69 return newRevision(lg, clockwork.NewRealClock(), int64(retention), rg, c), nil
70 default:
71 return nil, fmt.Errorf("unsupported compaction mode %s", mode)
72 }
73 }
74
View as plain text