-
Notifications
You must be signed in to change notification settings - Fork 3
/
msg.go
executable file
·100 lines (81 loc) · 1.99 KB
/
msg.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package batchedpaxos
import (
"encoding/gob"
"fmt"
"github.com/acharapko/pbench/db"
"github.com/acharapko/pbench/idservice"
)
func init() {
gob.Register(P1a{})
gob.Register(P1b{})
gob.Register(P2a{})
gob.Register(P2b{})
gob.Register(P3{})
}
// P1a prepare message
type P1a struct {
Ballot idservice.Ballot
}
func (m P1a) String() string {
return fmt.Sprintf("P1a {b=%v}", m.Ballot)
}
// CommandBallot combines each command with its ballot number
type CommandBallot struct {
Commands []db.Command
Ballot idservice.Ballot
}
func (cb CommandBallot) String() string {
return fmt.Sprintf("cmd=%v b=%v", cb.Commands, cb.Ballot)
}
// P1b promise message
type P1b struct {
Ballot idservice.Ballot
ID idservice.ID // from node id
Log map[int]CommandBallot // uncommitted logs
}
func (m P1b) String() string {
return fmt.Sprintf("P1b {b=%v id=%s log=%v}", m.Ballot, m.ID, m.Log)
}
// P2a accept message
type P2a struct {
Ballot idservice.Ballot
Slot int
Command []db.Command
P3msg P3
}
func (m P2a) String() string {
return fmt.Sprintf("P2a {b=%v s=%d cmd=%v, P3={%v}}", m.Ballot, m.Slot, m.Command, m.P3msg)
}
// P2b accepted message
type P2b struct {
Ballot idservice.Ballot
ID idservice.ID // from node id
Slot int
}
func (m P2b) String() string {
return fmt.Sprintf("P2b {b=%v id=%s s=%d}", m.Ballot, m.ID, m.Slot)
}
// P3 commit message
type P3 struct {
Ballot idservice.Ballot
Slot []int
}
func (m P3) String() string {
return fmt.Sprintf("P3 {b=%v s=%d cmd=%v}", m.Ballot, m.Slot)
}
type P3RecoverRequest struct {
Ballot idservice.Ballot
Slot int
nodeId idservice.ID
}
func (m *P3RecoverRequest) String() string {
return fmt.Sprintf("P3RecoverRequest {b=%v slots=%d, nodeToRecover=%v}", m.Ballot, m.Slot, m.nodeId)
}
type P3RecoverReply struct {
Ballot idservice.Ballot
Slot int
Commands []db.Command
}
func (m *P3RecoverReply) String() string {
return fmt.Sprintf("P3Recoverreply {b=%v slots=%d, cmd=%v}", m.Ballot, m.Slot, m.Commands)
}