2020-08-21 21:16:42 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/helper/raftutil"
|
|
|
|
"github.com/posener/complete"
|
|
|
|
)
|
|
|
|
|
|
|
|
type OperatorRaftInfoCommand struct {
|
|
|
|
Meta
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *OperatorRaftInfoCommand) Help() string {
|
|
|
|
helpText := `
|
2021-12-16 15:32:11 +00:00
|
|
|
Usage: nomad operator raft info <path to nomad data dir>
|
2020-08-21 21:16:42 +00:00
|
|
|
|
2021-12-16 15:32:11 +00:00
|
|
|
Displays summary information about the raft logs in the data directory.
|
|
|
|
|
|
|
|
This command requires file system permissions to access the data directory on
|
|
|
|
disk. The Nomad server locks access to the data directory, so this command
|
|
|
|
cannot be run on a data directory that is being used by a running Nomad server.
|
2020-11-19 21:38:08 +00:00
|
|
|
|
2020-08-31 11:47:16 +00:00
|
|
|
This is a low-level debugging tool and not subject to Nomad's usual backward
|
|
|
|
compatibility guarantees.
|
2020-08-21 21:16:42 +00:00
|
|
|
`
|
|
|
|
return strings.TrimSpace(helpText)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *OperatorRaftInfoCommand) AutocompleteFlags() complete.Flags {
|
|
|
|
return complete.Flags{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *OperatorRaftInfoCommand) AutocompleteArgs() complete.Predictor {
|
|
|
|
return complete.PredictNothing
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *OperatorRaftInfoCommand) Synopsis() string {
|
|
|
|
return "Display info of the raft log"
|
|
|
|
}
|
|
|
|
|
2021-12-16 15:32:11 +00:00
|
|
|
func (c *OperatorRaftInfoCommand) Name() string { return "operator raft info" }
|
2020-08-21 21:16:42 +00:00
|
|
|
|
|
|
|
func (c *OperatorRaftInfoCommand) Run(args []string) int {
|
|
|
|
if len(args) != 1 {
|
|
|
|
c.Ui.Error("This command takes one argument: <path>")
|
|
|
|
c.Ui.Error(commandErrorText(c))
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2020-09-18 01:35:17 +00:00
|
|
|
// Find raft.db
|
2020-09-24 23:00:53 +00:00
|
|
|
raftPath, err := raftutil.FindRaftFile(args[0])
|
2020-09-18 01:35:17 +00:00
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(err.Error())
|
|
|
|
return 1
|
2020-08-21 21:16:42 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 01:35:17 +00:00
|
|
|
store, firstIdx, lastIdx, err := raftutil.RaftStateInfo(raftPath)
|
2020-08-21 21:16:42 +00:00
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("failed to open raft logs: %v", err))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
defer store.Close()
|
|
|
|
|
2020-09-18 01:35:17 +00:00
|
|
|
c.Ui.Output(fmt.Sprintf("path: %v", raftPath))
|
2020-08-21 21:16:42 +00:00
|
|
|
c.Ui.Output(fmt.Sprintf("length: %v", lastIdx-firstIdx+1))
|
|
|
|
c.Ui.Output(fmt.Sprintf("first index: %v", firstIdx))
|
|
|
|
c.Ui.Output(fmt.Sprintf("last index: %v", lastIdx))
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|