-
Notifications
You must be signed in to change notification settings - Fork 4
/
request.go
40 lines (33 loc) · 924 Bytes
/
request.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
package linhybster
import (
"github.com/ibalajiarun/go-consensus/pkg/command/commandpb"
pb "github.com/ibalajiarun/go-consensus/protocols/linhybster/linhybsterpb"
)
func (s *linhybster) onRequest(cmd *commandpb.Command) *instance {
if !s.isPrimaryAtView(s.id, s.view) {
s.logger.Panicf("Fix your client config. I am not the leader: %v", s.id)
}
s.logger.Debugf("Replica %v received command ID %v\n", s.id, cmd.Timestamp)
index := s.index.GetAndIncrement()
inst := &instance{
s: s,
is: pb.InstanceState{
View: s.view,
Index: index,
Status: pb.InstanceState_Prepared,
Command: cmd,
},
cCert: newQuorum(s),
}
s.log[index] = inst
s.logger.Debugf("onRequest inst %v", index)
pm := &pb.NormalMessage{
View: s.view,
Index: index,
Type: pb.NormalMessage_Prepare,
Command: cmd,
}
mBytes := s.marshall(pm)
s.broadcast(mBytes, true /* sendToSelf */, nil)
return inst
}