@@ -15,8 +15,6 @@ import (
15
15
"github.com/hashicorp/raft"
16
16
raftboltdb "github.com/hashicorp/raft-boltdb"
17
17
"github.com/rs/zerolog"
18
-
19
- "github.com/evstack/ev-node/block"
20
18
)
21
19
22
20
type clusterClient interface {
@@ -47,8 +45,8 @@ type Config struct {
47
45
// FSM implements raft.FSM for block state
48
46
type FSM struct {
49
47
logger zerolog.Logger
50
- state * block. RaftBlockState
51
- applyCh chan <- block. RaftApplyMsg
48
+ state * RaftBlockState
49
+ applyCh chan <- RaftApplyMsg
52
50
}
53
51
54
52
// NewNode creates a new raft node
@@ -63,7 +61,7 @@ func NewNode(cfg *Config, clusterClient clusterClient, logger zerolog.Logger) (*
63
61
64
62
fsm := & FSM {
65
63
logger : logger .With ().Str ("component" , "raft-fsm" ).Logger (),
66
- state : & block. RaftBlockState {},
64
+ state : & RaftBlockState {},
67
65
}
68
66
69
67
logStore , err := raftboltdb .NewBoltStore (filepath .Join (cfg .RaftDir , "raft-log.db" ))
@@ -165,7 +163,7 @@ func (n *Node) NodeID() string {
165
163
}
166
164
167
165
// ProposeBlock proposes a block state to be replicated via raft
168
- func (n * Node ) Broadcast (ctx context.Context , state * block. RaftBlockState ) error {
166
+ func (n * Node ) Broadcast (ctx context.Context , state * RaftBlockState ) error {
169
167
if ! n .IsLeader () {
170
168
return fmt .Errorf ("not leader" )
171
169
}
@@ -184,7 +182,7 @@ func (n *Node) Broadcast(ctx context.Context, state *block.RaftBlockState) error
184
182
}
185
183
186
184
// GetState returns the current replicated state
187
- func (n * Node ) GetState () * block. RaftBlockState {
185
+ func (n * Node ) GetState () * RaftBlockState {
188
186
return n .fsm .state
189
187
}
190
188
@@ -231,13 +229,13 @@ func (n *Node) Shutdown() error {
231
229
}
232
230
233
231
// SetApplyCallback sets a callback to be called when log entries are applied
234
- func (n * Node ) SetApplyCallback (ch chan <- block. RaftApplyMsg ) {
232
+ func (n * Node ) SetApplyCallback (ch chan <- RaftApplyMsg ) {
235
233
n .fsm .applyCh = ch
236
234
}
237
235
238
236
// Apply implements raft.FSM
239
237
func (f * FSM ) Apply (log * raft.Log ) interface {} {
240
- var state block. RaftBlockState
238
+ var state RaftBlockState
241
239
if err := json .Unmarshal (log .Data , & state ); err != nil {
242
240
f .logger .Error ().Err (err ).Msg ("unmarshal block state" )
243
241
return err
@@ -248,7 +246,7 @@ func (f *FSM) Apply(log *raft.Log) interface{} {
248
246
249
247
if f .applyCh != nil {
250
248
select {
251
- case f .applyCh <- block. RaftApplyMsg {Index : log .Index , State : & state }:
249
+ case f .applyCh <- RaftApplyMsg {Index : log .Index , State : & state }:
252
250
default :
253
251
f .logger .Warn ().Msg ("apply channel full, dropping message" )
254
252
}
@@ -266,7 +264,7 @@ func (f *FSM) Snapshot() (raft.FSMSnapshot, error) {
266
264
func (f * FSM ) Restore (rc io.ReadCloser ) error {
267
265
defer rc .Close ()
268
266
269
- var state block. RaftBlockState
267
+ var state RaftBlockState
270
268
if err := json .NewDecoder (rc ).Decode (& state ); err != nil {
271
269
return fmt .Errorf ("decode snapshot: %w" , err )
272
270
}
@@ -277,7 +275,7 @@ func (f *FSM) Restore(rc io.ReadCloser) error {
277
275
}
278
276
279
277
type fsmSnapshot struct {
280
- state * block. RaftBlockState
278
+ state * RaftBlockState
281
279
}
282
280
283
281
func (s * fsmSnapshot ) Persist (sink raft.SnapshotSink ) error {
0 commit comments