-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.go
93 lines (72 loc) · 2.09 KB
/
log.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
package raft
import (
"fmt"
"net"
)
// LogType describes various types of log entries.
type LogType uint8
const (
// LogCommand is applied to a user FSM.
LogCommand LogType = iota
// LogNoop is used to assert leadership.
LogNoop
// LogAddPeer is used to add a new peer.
LogAddPeer
// LogRemovePeer is used to remove an existing peer.
LogRemovePeer
// LogBarrier is used to ensure all preceeding operations have been
// applied to the FSM. It is similar to LogNoop, but instead of returning
// once committed, it only returns once the FSM manager acks it. Otherwise
// it is possible there are operations committed but not yet applied to
// the FSM.
LogBarrier
)
var logTypeName = map[LogType]string{
LogCommand: "LogCmd",
LogNoop: "LogNoop",
LogAddPeer: "LogAddPeer",
LogRemovePeer: "LogRemovePeer",
LogBarrier: "LogBarrier",
}
func (t LogType) String() string {
if t > LogBarrier {
return fmt.Sprintf("Unknown LogType: %d", t)
}
return logTypeName[t]
}
// Log entries are replicated to all members of the Raft cluster
// and form the heart of the replicated state machine.
type Log struct {
Index uint64
Term uint64
Type LogType
Data []byte
// Peer is not exported since it is not transmitted, only used
// internally to construct the Data field.
peer net.Addr
}
// LogStore is used to provide an interface for storing
// and retrieving logs in a durable fashion
type LogStore interface {
// Returns the first index written. 0 for no entries.
FirstIndex() (uint64, error)
// Returns the last index written. 0 for no entries.
LastIndex() (uint64, error)
// Gets a log entry at a given index
GetLog(index uint64, log *Log) error
// Stores a log entry
StoreLog(log *Log) error
// Stores multiple log entries
StoreLogs(logs []*Log) error
// Deletes a range of log entries. The range is inclusive.
DeleteRange(min, max uint64) error
}
type Logger interface {
Enable()
Disable()
Printf(format string, v ...interface{})
Println(v ...interface{})
Errorf(format string, v ...interface{})
Infof(format string, v ...interface{})
Infoln(v ...interface{})
}