From ec3982c0ff2ea1e0f20a8aba939ac2c631513c95 Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Fri, 2 Nov 2018 16:10:39 -0500 Subject: [PATCH] pull out advertise URI changes --- ctl/server.go | 1 - gossip/gossip.go | 28 ++++------------------------ server.go | 16 ++++------------ server/config.go | 6 ------ server/server.go | 6 ------ server/server_test.go | 1 + uri.go | 17 ++++------------- 7 files changed, 13 insertions(+), 62 deletions(-) diff --git a/ctl/server.go b/ctl/server.go index 90766c498..7f384ec7b 100644 --- a/ctl/server.go +++ b/ctl/server.go @@ -26,7 +26,6 @@ func BuildServerFlags(cmd *cobra.Command, srv *server.Command) { flags := cmd.Flags() flags.StringVarP(&srv.Config.DataDir, "data-dir", "d", srv.Config.DataDir, "Directory to store pilosa data files.") flags.StringVarP(&srv.Config.Bind, "bind", "b", srv.Config.Bind, "Default URI on which pilosa should listen.") - flags.StringVarP(&srv.Config.Advertise, "advertise", "a", "", "Address to broadcast to other hosts and clients to be contacted on.") flags.IntVarP(&srv.Config.MaxWritesPerRequest, "max-writes-per-request", "", srv.Config.MaxWritesPerRequest, "Number of write commands per request.") flags.StringVar(&srv.Config.LogPath, "log-path", srv.Config.LogPath, "Log path") flags.BoolVar(&srv.Config.Verbose, "verbose", srv.Config.Verbose, "Enable verbose logging") diff --git a/gossip/gossip.go b/gossip/gossip.go index d03016792..789ed50b0 100644 --- a/gossip/gossip.go +++ b/gossip/gossip.go @@ -205,18 +205,8 @@ func NewMemberSet(cfg Config, api *pilosa.API, options ...memberSetOption) (*mem conf.Name = api.Node().ID conf.BindAddr = api.Node().URI.Host conf.BindPort = port - if cfg.AdvertisePort != "" { - port, err = strconv.Atoi(cfg.Port) - if err != nil { - return nil, fmt.Errorf("convert advertise port: %s", err) - } - } conf.AdvertisePort = port - if cfg.AdvertiseHost != "" { - conf.AdvertiseAddr = cfg.AdvertiseHost - } else { - conf.AdvertiseAddr = hostToIP(api.Node().URI.Host) - } + conf.AdvertiseAddr = hostToIP(api.Node().URI.Host) // conf.TCPTimeout = time.Duration(cfg.StreamTimeout) conf.SuspicionMult = cfg.SuspicionMult @@ -457,20 +447,10 @@ func newTransport(conf *memberlist.Config) (*memberlist.NetTransport, error) { // Config holds toml-friendly memberlist configuration. type Config struct { - // Host is the host gossip will bind to. If left blank it will be set to the - // host from Pilosa. - Host string `toml:"host"` // Port indicates the port to which pilosa should bind for internal state sharing. - Port string `toml:"port"` - // AdvertiseHost is the hostname or IP other nodes should use to connect to - // this host. If left blank, the value for Host will be used. This is useful - // in some proxy and NAT scenarios. - AdvertiseHost string `toml:"advertise-host` - // AdvertisePort is the port other nodes will use to connect to this one. - // Behaves like AdvertiseHost. - AdvertisePort string `toml:"advertise-port"` - Seeds []string `toml:"seeds"` - Key string `toml:"key"` + Port string `toml:"port"` + Seeds []string `toml:"seeds"` + Key string `toml:"key"` // StreamTimeout is the timeout for establishing a stream connection with // a remote node for a full state sync, and for stream read and write // operations. Maps to memberlist TCPTimeout. diff --git a/server.go b/server.go index 36190e315..a4cb8fc8b 100644 --- a/server.go +++ b/server.go @@ -62,7 +62,6 @@ type Server struct { // nolint: maligned nodeID string uri URI - advertiseURI URI antiEntropyInterval time.Duration metricInterval time.Duration diagnosticInterval time.Duration @@ -74,7 +73,7 @@ type Server struct { // nolint: maligned dataDir string } -// TODO (2.0): have this return an interface for Holder instead of concrete object? +// TODO: have this return an interface for Holder instead of concrete object? func (s *Server) Holder() *Holder { return s.holder } @@ -161,13 +160,6 @@ func OptServerInternalClient(c InternalClient) ServerOption { } } -func OptServerAdvertiseURI(u *URI) ServerOption { - return func(s *Server) error { - s.advertiseURI = *u - return nil - } -} - // DEPRECATED func OptServerPrimaryTranslateStore(store TranslateStore) ServerOption { return func(s *Server) error { @@ -304,7 +296,7 @@ func NewServer(opts ...ServerOption) (*Server, error) { // Set Cluster Node. node := &Node{ ID: s.nodeID, - URI: s.advertiseURI, + URI: s.uri, IsCoordinator: s.cluster.Coordinator == s.nodeID, } s.cluster.Node = node @@ -589,7 +581,7 @@ func (s *Server) SendSync(m Message) error { node := node s.logger.Printf("SendSync to: %s", node.URI) // Don't forward the message to ourselves. - if s.advertiseURI == node.URI { + if s.uri == node.URI { continue } @@ -684,7 +676,7 @@ func (s *Server) monitorDiagnostics() { s.diagnostics.Logger = s.logger s.diagnostics.SetVersion(Version) - s.diagnostics.Set("Host", s.advertiseURI.Host) + s.diagnostics.Set("Host", s.uri.Host) s.diagnostics.Set("Cluster", strings.Join(s.cluster.nodeIDs(), ",")) s.diagnostics.Set("NumNodes", len(s.cluster.nodes)) s.diagnostics.Set("NumCPU", runtime.NumCPU()) diff --git a/server/config.go b/server/config.go index 210a2e298..d255e4bb6 100644 --- a/server/config.go +++ b/server/config.go @@ -36,15 +36,9 @@ type Config struct { // DataDir is the directory where Pilosa stores both indexed data and // running state such as cluster topology information. DataDir string `toml:"data-dir"` - // Bind is the host:port on which Pilosa will listen. Bind string `toml:"bind"` - // Advertise is the host:port that this node will report as its address to - // others. If left blank (the default), this will be set to the bind address - // once it is listening. - Advertise string `toml:"advertise"` - // MaxWritesPerRequest limits the number of mutating commands that can be in // a single request to the server. This includes Set, Clear, // SetRowAttrs & SetColumnAttrs. diff --git a/server/server.go b/server/server.go index 8521abdec..010eb2f8a 100644 --- a/server/server.go +++ b/server/server.go @@ -248,11 +248,6 @@ func (m *Command) SetupServer() error { uri.SetPort(uint16(m.ln.Addr().(*net.TCPAddr).Port)) } - advertURI, err := pilosa.NewURIFromAddressWithDefault(m.Config.Advertise, uri) - if err != nil { - return errors.Wrapf(err, "processing avertise address '%s'", m.Config.Advertise) - } - c := http.GetHTTPClient(TLSConfig) // Primary store configuration is handled automatically now. @@ -281,7 +276,6 @@ func (m *Command) SetupServer() error { pilosa.OptServerGCNotifier(gcnotify.NewActiveGCNotifier()), pilosa.OptServerStatsClient(statsClient), pilosa.OptServerURI(uri), - pilosa.OptServerAdvertiseURI(advertURI), pilosa.OptServerInternalClient(http.NewInternalClientFromURI(uri, c)), pilosa.OptServerPrimaryTranslateStoreFunc(http.NewTranslateStore), pilosa.OptServerClusterDisabled(m.Config.Cluster.Disabled, m.Config.Cluster.Hosts), diff --git a/server/server_test.go b/server/server_test.go index d62605ce0..aa202a54c 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -405,6 +405,7 @@ func TestClusteringNodesReplica1(t *testing.T) { // Create new main with the same config. config := cluster[2].Command.Config config.Translation.MapSize = 100000 + // config.Bind = cluster[2].API.Node().URI.HostPort() // this isn't necessary, but makes the test run way faster config.Gossip.Port = strconv.Itoa(int(cluster[2].Command.GossipTransport().URI.Port)) diff --git a/uri.go b/uri.go index 7cf985f0b..231457691 100644 --- a/uri.go +++ b/uri.go @@ -82,10 +82,6 @@ func NewURIFromAddress(address string) (*URI, error) { return parseAddress(address) } -func NewURIFromAddressWithDefault(address string, base *URI) (*URI, error) { - return parseAddressWithDefault(address, base) -} - // setScheme sets the scheme of this URI. func (u *URI) setScheme(scheme string) error { m := schemeRegexp.FindStringSubmatch(scheme) @@ -158,20 +154,20 @@ func (u URI) Type() string { return "URI" } -func parseAddressWithDefault(address string, def *URI) (uri *URI, err error) { +func parseAddress(address string) (uri *URI, err error) { m := addressRegexp.FindStringSubmatch(address) if m == nil { return nil, errors.New("invalid address") } - scheme := def.Scheme + scheme := "http" if m[2] != "" { scheme = m[2] } - host := def.Host + host := "localhost" if m[3] != "" { host = m[3] } - var port = int(def.Port) + var port = 10101 if m[5] != "" { port, err = strconv.Atoi(m[5]) if err != nil { @@ -189,11 +185,6 @@ func parseAddressWithDefault(address string, def *URI) (uri *URI, err error) { return uri, nil } -func parseAddress(address string) (uri *URI, err error) { - u, err := parseAddressWithDefault(address, defaultURI()) - return u, err -} - // MarshalJSON marshals URI into a JSON-encoded byte slice. func (u *URI) MarshalJSON() ([]byte, error) { var output struct {