simplify config structure - remove gossip sub-struct

This commit is contained in:
Matt Jaffee 2017-04-18 11:31:17 -05:00 • committed by Travis
parent 0da580d0e9
commit d10d8d94e1
3 changed files with 18 additions and 22 deletions

View file

@ -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
}

View file

@ -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{

View file

@ -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)