-
Notifications
You must be signed in to change notification settings - Fork 0
/
group.go
81 lines (59 loc) · 1.55 KB
/
group.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package gopaxos
type group struct {
comm *communicate
conf *config
instance *instance
initRet error
ch chan struct{}
}
func newGroup(ls LogStorage, network Network, masterSM insideSM, groupIdx int, opt *Options) *group {
ret := &group{}
ret.conf = newConfig(ls, opt.Sync, opt.SyncInterval, opt.UseMembership, &opt.MyNode,
opt.NodeInfoList, opt.FollowerNodeInfoList, groupIdx, opt.GroupCount, opt.MembershipChangeCallback)
ret.comm = newCommunicate(ret.conf, opt.MyNode.GetNodeID(), opt.UDPMaxSize, network)
ret.instance = newInstance(ret.conf, ls, ret.comm, opt)
ret.initRet = nil
ret.conf.setMasterSM(masterSM)
return ret
}
func (g *group) startInit() {
g.ch = make(chan struct{}, 1)
go g.init()
}
func (g *group) init() {
g.initRet = g.conf.init()
if g.initRet != nil {
return
}
g.addStateMachine(g.conf.getSystemVSM())
g.addStateMachine(g.conf.getMasterSM())
g.initRet = g.instance.init()
g.ch <- struct{}{}
}
func (g *group) getInitRet() error {
<-g.ch
return g.initRet
}
func (g *group) start() {
g.instance.start()
}
func (g *group) getConfig() *config {
return g.conf
}
func (g *group) getInstance() *instance {
return g.instance
}
func (g *group) getCommitter() *committer {
return g.instance.getCommitter()
}
func (g *group) getCheckpointCleaner() *cleaner {
return g.instance.getCheckpointCleaner()
}
func (g *group) getCheckpointRePlayer() *rePlayer {
return g.instance.getCheckpointRePlayer()
}
func (g *group) addStateMachine(sm StateMachine) {
g.instance.addStateMachine(sm)
}
func (g *group) stop() {
}