pull out advertise URI changes

This commit is contained in:
Matt Jaffee 2018-11-02 16:10:39 -05:00
parent 02aee931a1
commit ec3982c0ff
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF
7 changed files with 13 additions and 62 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

17
uri.go
View file

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