-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
65 lines (54 loc) · 1.56 KB
/
main.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
package main
import (
"github.com/vadiminshakov/committer/config"
"github.com/vadiminshakov/committer/core/cohort"
"github.com/vadiminshakov/committer/core/cohort/commitalgo"
"github.com/vadiminshakov/committer/core/cohort/commitalgo/hooks"
"github.com/vadiminshakov/committer/core/coordinator"
"github.com/vadiminshakov/committer/io/db"
"github.com/vadiminshakov/committer/io/gateway/grpc/server"
"github.com/vadiminshakov/gowal"
"os"
"os/signal"
"syscall"
)
const (
walDir string = "wal"
walSegmentPrefix string = "msgs_"
walSegmentThreshold int = 10000
walMaxSegments int = 100
walIsInSyncDiskMode bool = true
)
func main() {
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
conf := config.Get()
database, err := db.New(conf.DBPath)
if err != nil {
panic(err)
}
walConfig := gowal.Config{
Dir: walDir,
Prefix: walSegmentPrefix,
SegmentThreshold: walSegmentThreshold,
MaxSegments: walMaxSegments,
IsInSyncDiskMode: walIsInSyncDiskMode,
}
wal, err := gowal.NewWAL(walConfig)
if err != nil {
panic(err)
}
coordImpl, err := coordinator.New(conf, wal, database)
if err != nil {
panic(err)
}
committer := commitalgo.NewCommitter(database, conf.CommitType, wal, hooks.Propose, hooks.Commit, conf.Timeout)
cohortImpl := cohort.NewCohort(committer, cohort.Mode(conf.CommitType))
s, err := server.New(conf, cohortImpl, coordImpl, database)
if err != nil {
panic(err)
}
s.Run(server.WhiteListChecker)
<-ch
s.Stop()
}