mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
Added support for v2 raft APIs and -raft-protocol option
This commit is contained in:
committed by
Preetha Appan
parent
721b23d262
commit
de90db139a
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/hashicorp/nomad/nomad"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
"github.com/hashicorp/nomad/nomad/structs/config"
|
||||
"github.com/hashicorp/raft"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -141,6 +142,9 @@ func convertServerConfig(agentConfig *Config, logOutput io.Writer) (*nomad.Confi
|
||||
if agentConfig.Server.ProtocolVersion != 0 {
|
||||
conf.ProtocolVersion = uint8(agentConfig.Server.ProtocolVersion)
|
||||
}
|
||||
if agentConfig.Server.RaftProtocol != 0 {
|
||||
conf.RaftConfig.ProtocolVersion = raft.ProtocolVersion(agentConfig.Server.RaftProtocol)
|
||||
}
|
||||
if agentConfig.Server.NumSchedulers != 0 {
|
||||
conf.NumSchedulers = agentConfig.Server.NumSchedulers
|
||||
}
|
||||
|
||||
@@ -83,6 +83,7 @@ func (c *Command) readConfig() *Config {
|
||||
flags.IntVar(&cmdConfig.Server.RetryMaxAttempts, "retry-max", 0, "")
|
||||
flags.StringVar(&cmdConfig.Server.RetryInterval, "retry-interval", "", "")
|
||||
flags.StringVar(&cmdConfig.Server.EncryptKey, "encrypt", "", "gossip encryption key")
|
||||
flags.IntVar(&cmdConfig.Server.RaftProtocol, "raft-protocol", 0, "")
|
||||
|
||||
// Client-only options
|
||||
flags.StringVar(&cmdConfig.Client.StateDir, "state-dir", "", "")
|
||||
@@ -876,6 +877,10 @@ Server Options:
|
||||
Address of an agent to join at start time. Can be specified
|
||||
multiple times.
|
||||
|
||||
-raft-protocol=<num>
|
||||
The Raft protocol version to use. Used for enabling certain Autopilot
|
||||
features. Defaults to 2.
|
||||
|
||||
-retry-join=<address>
|
||||
Address of an agent to join at start time with retries enabled.
|
||||
Can be specified multiple times.
|
||||
|
||||
@@ -256,6 +256,9 @@ type ServerConfig struct {
|
||||
// ProtocolVersionMin and ProtocolVersionMax.
|
||||
ProtocolVersion int `mapstructure:"protocol_version"`
|
||||
|
||||
// RaftProtocol is the Raft protocol version to speak. This must be from [1-3].
|
||||
RaftProtocol int `mapstructure:"raft_protocol"`
|
||||
|
||||
// NumSchedulers is the number of scheduler thread that are run.
|
||||
// This can be as many as one per core, or zero to disable this server
|
||||
// from doing any scheduling work.
|
||||
@@ -976,6 +979,9 @@ func (a *ServerConfig) Merge(b *ServerConfig) *ServerConfig {
|
||||
if b.ProtocolVersion != 0 {
|
||||
result.ProtocolVersion = b.ProtocolVersion
|
||||
}
|
||||
if b.RaftProtocol != 0 {
|
||||
result.RaftProtocol = b.RaftProtocol
|
||||
}
|
||||
if b.NumSchedulers != 0 {
|
||||
result.NumSchedulers = b.NumSchedulers
|
||||
}
|
||||
|
||||
@@ -234,6 +234,7 @@ func TestConfig_Merge(t *testing.T) {
|
||||
BootstrapExpect: 2,
|
||||
DataDir: "/tmp/data2",
|
||||
ProtocolVersion: 2,
|
||||
RaftProtocol: 2,
|
||||
NumSchedulers: 2,
|
||||
EnabledSchedulers: []string{structs.JobTypeBatch},
|
||||
NodeGCThreshold: "12h",
|
||||
|
||||
@@ -79,14 +79,14 @@ func (c *OperatorRaftListCommand) Run(args []string) int {
|
||||
}
|
||||
|
||||
// Format it as a nice table.
|
||||
result := []string{"Node|ID|Address|State|Voter"}
|
||||
result := []string{"Node|ID|Address|State|Voter|RaftProtocol"}
|
||||
for _, s := range reply.Servers {
|
||||
state := "follower"
|
||||
if s.Leader {
|
||||
state = "leader"
|
||||
}
|
||||
result = append(result, fmt.Sprintf("%s|%s|%s|%s|%v",
|
||||
s.Node, s.ID, s.Address, state, s.Voter))
|
||||
result = append(result, fmt.Sprintf("%s|%s|%s|%s|%v|%s",
|
||||
s.Node, s.ID, s.Address, state, s.Voter, s.RaftProtocol))
|
||||
}
|
||||
c.Ui.Output(columnize.SimpleFormat(result))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user