From d10d8d94e1ee57b1555478c17f1d71f5f8567443 Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Tue, 18 Apr 2017 11:31:17 -0500 Subject: [PATCH] simplify config structure - remove gossip sub-struct --- cmd/server.go | 4 ++-- config.go | 16 ++++++---------- server/server.go | 20 ++++++++++---------- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/cmd/server.go b/cmd/server.go index 2dd662bbe..51d92824a 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -84,8 +84,8 @@ on the configured port.`, flags.StringVarP(&Server.CPUProfile, "profile.cpu", "", "", "Where to store CPU profile.") flags.DurationVarP(&Server.CPUTime, "profile.cpu-time", "", 30*time.Second, "CPU profile duration.") flags.StringVarP(&Server.Config.Cluster.Type, "cluster.type", "", "static", "Determine how the cluster handles membership and state sharing. Choose from [static, http, gossip]") - flags.StringVarP(&Server.Config.Cluster.Gossip.Seed, "cluster.gossip.seed", "", "", "Host with which to seed the gossip membership.") - flags.IntVarP(&Server.Config.Cluster.Gossip.Port, "cluster.gossip.port", "", 0, "Port to which pilosa should bind for gossip.") + flags.StringVarP(&Server.Config.Cluster.GossipSeed, "cluster.gossip-seed", "", "", "Host with which to seed the gossip membership.") + flags.StringVarP(&Server.Config.Cluster.InternalPort, "cluster.internal-port", "", "", "Port to which pilosa should bind for internal state sharing.") return serveCmd } diff --git a/config.go b/config.go index 094bb9d65..22750d72d 100644 --- a/config.go +++ b/config.go @@ -16,11 +16,12 @@ type Config struct { Host string `toml:"host"` Cluster struct { - ReplicaN int `toml:"replicas"` - Type string `toml:"type"` - Nodes []string `toml:"hosts"` - PollingInterval Duration `toml:"polling-interval"` - Gossip ConfigGossip `toml:"gossip"` + ReplicaN int `toml:"replicas"` + Type string `toml:"type"` + Nodes []string `toml:"hosts"` + PollingInterval Duration `toml:"polling-interval"` + InternalPort string `toml:"internal-port"` + GossipSeed string `toml:"gossip-seed"` } `toml:"cluster"` Plugins struct { @@ -34,11 +35,6 @@ type Config struct { LogPath string `toml:"log-path"` } -type ConfigGossip struct { - Port int `toml:"port"` - Seed string `toml:"seed"` -} - // NewConfig returns an instance of Config with default options. func NewConfig() *Config { c := &Config{ diff --git a/server/server.go b/server/server.go index 16d17407f..a627daade 100644 --- a/server/server.go +++ b/server/server.go @@ -122,25 +122,25 @@ func (m *Command) SetupServer() error { switch m.Config.Cluster.Type { // TODO change name to something that encompasses broadcasting, receiving broadcasts, and tracking cluster membership case "http": - port := strconv.Itoa(m.Config.Cluster.Gossip.Port) - m.Server.Broadcaster = httpbroadcast.NewHTTPBroadcaster(m.Server, port) - m.Server.BroadcastReceiver = httpbroadcast.NewHTTPBroadcastReceiver(port, m.Stderr) + m.Server.Broadcaster = httpbroadcast.NewHTTPBroadcaster(m.Server, m.Config.Cluster.InternalPort) + m.Server.BroadcastReceiver = httpbroadcast.NewHTTPBroadcastReceiver(m.Config.Cluster.InternalPort, m.Stderr) m.Server.Cluster.NodeSet = httpbroadcast.NewHTTPNodeSet() err := m.Server.Cluster.NodeSet.(*httpbroadcast.HTTPNodeSet).Join(m.Server.Cluster.Nodes) if err != nil { return err } case "gossip": - gossipPort, err := strconv.Atoi(pilosa.DefaultGossipPort) + gossipPortStr := pilosa.DefaultGossipPort + if m.Config.Cluster.InternalPort != "" { + gossipPortStr = m.Config.Cluster.InternalPort + } + gossipPort, err := strconv.Atoi(gossipPortStr) if err != nil { - panic(err) // Atoi on a compile-time constant should never fail. + return err } gossipSeed := pilosa.DefaultHost - if m.Config.Cluster.Gossip.Port != 0 { - gossipPort = m.Config.Cluster.Gossip.Port - } - if m.Config.Cluster.Gossip.Seed != "" { - gossipSeed = m.Config.Cluster.Gossip.Seed + if m.Config.Cluster.GossipSeed != "" { + gossipSeed = m.Config.Cluster.GossipSeed } // get the host portion of addr to use for binding gossipHost, _, err := net.SplitHostPort(m.Config.Host)