-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathraft_info.go
49 lines (37 loc) · 920 Bytes
/
raft_info.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
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
)
type RaftInfoCommand struct {
}
func (a *RaftInfoCommand) Help() string {
helpText := `
Usage: nomad-debug info logs <path_to_nomad_dir>
Emits some info about the raft logs.
`
return strings.TrimSpace(helpText)
}
func (c *RaftInfoCommand) Name() string { return "raft info" }
func (c *RaftInfoCommand) Synopsis() string {
return "output info of raft log"
}
func (c *RaftInfoCommand) Run(args []string) int {
if len(args) != 1 {
return 1
}
p := filepath.Join(args[0], "server", "raft", "raft.db")
store, firstIdx, lastIdx, err := raftState(p)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to open raft logs: %v\n", err)
return 1
}
defer store.Close()
fmt.Println("path: ", p)
fmt.Println("length: ", lastIdx-firstIdx+1)
fmt.Println("first index: ", firstIdx)
fmt.Println("last index: ", lastIdx)
return 0
}