forked from hashicorp/raft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fsm.go
37 lines (31 loc) · 1.24 KB
/
fsm.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
package raft
import (
"io"
)
// FSM provides an interface that can be implemented by
// clients to make use of the replicated log
type FSM interface {
// Apply log is invoked once a log entry is commited
Apply(*Log) interface{}
// Snapshot is used to support log compaction. This call should
// return an FSMSnapshot which can be used to save a point-in-time
// snapshot of the FSM. Apply and Snapshot are not called in multiple
// threads, but Apply will be called concurrently with Persist. This means
// the FSM should be implemented in a fashion that allows for concurrent
// updates while a snapshot is happening.
Snapshot() (FSMSnapshot, error)
// Restore is used to restore an FSM from a snapshot. It is not called
// concurrently with any other command. The FSM must discard all previous
// state.
Restore(io.ReadCloser) error
}
// FSMSnapshot is returned by an FSM in response to a Snapshot
// It must be safe to invoke FSMSnapshot methods with concurrent
// calls to Apply
type FSMSnapshot interface {
// Persist should dump all necessary state to the WriteCloser,
// and invoke close when finished or call Cancel on error.
Persist(sink SnapshotSink) error
// Release is invoked when we are finished with the snapshot
Release()
}