mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: attempt first version of Interface
This commit is contained in:
committed by
Yicheng Qin
parent
8d7be33dd8
commit
50e0db4038
31
raft/node.go
Normal file
31
raft/node.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package raft
|
||||
|
||||
import "sync"
|
||||
|
||||
type Interface interface {
|
||||
Step(m Message)
|
||||
}
|
||||
|
||||
type Node struct {
|
||||
lk sync.Mutex
|
||||
sm *stateMachine
|
||||
}
|
||||
|
||||
func New(k, addr int, next Interface) Interface {
|
||||
n := &Node{
|
||||
sm: newStateMachine(k, addr, next),
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// Propose asynchronously proposes data be applied to the underlying state machine.
|
||||
func (n *Node) Propose(data []byte) {
|
||||
m := Message{Type: msgHup, Data: data}
|
||||
n.Step(m)
|
||||
}
|
||||
|
||||
func (n *Node) Step(m Message) {
|
||||
n.lk.Lock()
|
||||
defer n.lk.Unlock()
|
||||
n.sm.Step(m)
|
||||
}
|
||||
Reference in New Issue
Block a user