diff --git a/go/config/config.go b/go/config/config.go index 5d65da4b9..3e8f27e59 100644 --- a/go/config/config.go +++ b/go/config/config.go @@ -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 diff --git a/go/raft/fsm.go b/go/raft/fsm.go index a1cd0387a..b82fcfd90 100644 --- a/go/raft/fsm.go +++ b/go/raft/fsm.go @@ -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) } diff --git a/go/raft/raft.go b/go/raft/raft.go index dcb8cca2d..6e8942a45 100644 --- a/go/raft/raft.go +++ b/go/raft/raft.go @@ -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 } @@ -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 @@ -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 } @@ -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 } @@ -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 } diff --git a/go/raft/store.go b/go/raft/store.go index fb0257771..1721ecbbb 100644 --- a/go/raft/store.go +++ b/go/raft/store.go @@ -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 @@ -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, }