Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ type Configuration struct {
RaftBind string
RaftAdvertise string
RaftDataDir string
RaftDisableDNSLookup bool
DefaultRaftPort int // if a RaftNodes entry does not specify port, use this one
RaftNodes []string // Raft nodes to make initial connection with
ExpectFailureAnalysisConcensus bool
Expand Down
2 changes: 1 addition & 1 deletion go/raft/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (f *fsm) Apply(l *raft.Log) interface{} {
}

if c.Op == YieldCommand {
toPeer, err := normalizeRaftNode(string(c.Value))
toPeer, err := normalizeRaftNode(string(c.Value), f.raftDisableDNSLookup)
if err != nil {
return log.Errore(err)
}
Expand Down
26 changes: 15 additions & 11 deletions go/raft/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,19 @@ func computeLeaderURI() (uri string, err error) {
func Setup(applier CommandApplier, snapshotCreatorApplier SnapshotCreatorApplier, thisHostname string) error {
log.Debugf("Setting up raft")
ThisHostname = thisHostname
raftBind, err := normalizeRaftNode(config.Config.RaftBind)
raftDisableDNSLookup := config.Config.RaftDisableDNSLookup
raftBind, err := normalizeRaftNode(config.Config.RaftBind, raftDisableDNSLookup)
if err != nil {
return err
}
raftAdvertise, err := normalizeRaftNode(config.Config.RaftAdvertise)
raftAdvertise, err := normalizeRaftNode(config.Config.RaftAdvertise, raftDisableDNSLookup)
if err != nil {
return err
}
store = NewStore(config.Config.RaftDataDir, raftBind, raftAdvertise, applier, snapshotCreatorApplier)
store = NewStore(config.Config.RaftDataDir, raftBind, raftAdvertise, raftDisableDNSLookup, applier, snapshotCreatorApplier)
peerNodes := []string{}
for _, raftNode := range config.Config.RaftNodes {
peerNode, err := normalizeRaftNode(raftNode)
peerNode, err := normalizeRaftNode(raftNode, raftDisableDNSLookup)
if err != nil {
return err
}
Expand Down Expand Up @@ -195,11 +196,14 @@ func normalizeRaftHostnameIP(host string) (string, error) {

// normalizeRaftNode attempts to make sure there's a port to the given node.
// It consults the DefaultRaftPort when there isn't
func normalizeRaftNode(node string) (string, error) {
func normalizeRaftNode(node string, disableLookup bool) (string, error) {
hostPort := strings.Split(node, ":")
host, err := normalizeRaftHostnameIP(hostPort[0])
if err != nil {
return host, err
host := hostPort[0]
if !disableLookup {
host, err := normalizeRaftHostnameIP(hostPort[0])
if err != nil {
return host, err
}
}
if len(hostPort) > 1 {
return fmt.Sprintf("%s:%s", host, hostPort[1]), nil
Expand Down Expand Up @@ -319,7 +323,7 @@ func PublishCommand(op string, value interface{}) (response interface{}, err err
}

func AddPeer(addr string) (response interface{}, err error) {
addr, err = normalizeRaftNode(addr)
addr, err = normalizeRaftNode(addr, store.raftDisableDNSLookup)
if err != nil {
return "", err
}
Expand All @@ -328,7 +332,7 @@ func AddPeer(addr string) (response interface{}, err error) {
}

func RemovePeer(addr string) (response interface{}, err error) {
addr, err = normalizeRaftNode(addr)
addr, err = normalizeRaftNode(addr, store.raftDisableDNSLookup)
if err != nil {
return "", err
}
Expand All @@ -337,7 +341,7 @@ func RemovePeer(addr string) (response interface{}, err error) {
}

func PublishYield(toPeer string) (response interface{}, err error) {
toPeer, err = normalizeRaftNode(toPeer)
toPeer, err = normalizeRaftNode(toPeer, store.raftDisableDNSLookup)
if err != nil {
return "", err
}
Expand Down
10 changes: 6 additions & 4 deletions go/raft/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import (
)

type Store struct {
raftDir string
raftBind string
raftAdvertise string
raftDir string
raftBind string
raftAdvertise string
raftDisableDNSLookup bool

raft *raft.Raft // The consensus mechanism
peerStore raft.PeerStore
Expand All @@ -31,11 +32,12 @@ type storeCommand struct {
}

// NewStore inits and returns a new store
func NewStore(raftDir string, raftBind string, raftAdvertise string, applier CommandApplier, snapshotCreatorApplier SnapshotCreatorApplier) *Store {
func NewStore(raftDir string, raftBind string, raftAdvertise string, raftDisableDNSLookup bool, applier CommandApplier, snapshotCreatorApplier SnapshotCreatorApplier) *Store {
return &Store{
raftDir: raftDir,
raftBind: raftBind,
raftAdvertise: raftAdvertise,
raftDisableDNSLookup: raftDisableDNSLookup,
applier: applier,
snapshotCreatorApplier: snapshotCreatorApplier,
}
Expand Down