mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-12 15:51:01 +00:00
move static cluster setup logic into Server/Cluster
This commit is contained in:
parent
60eef02f31
commit
33b3a14b24
3 changed files with 39 additions and 15 deletions
17
cluster.go
17
cluster.go
|
|
@ -1801,3 +1801,20 @@ func (c *Cluster) mergeClusterStatus(cs *internal.ClusterStatus) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cluster) setStatic(hosts []string) error {
|
||||
if len(hosts) == 0 {
|
||||
return errors.New("must specify at least one host")
|
||||
}
|
||||
c.Static = true
|
||||
c.Coordinator = c.Node.ID
|
||||
for _, address := range hosts {
|
||||
uri, err := NewURIFromAddress(address)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "getting URI")
|
||||
}
|
||||
c.Nodes = append(c.Nodes, &Node{URI: *uri})
|
||||
}
|
||||
c.MemberSet = NewStaticMemberSet(c.Nodes)
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
19
server.go
19
server.go
|
|
@ -57,6 +57,7 @@ type Server struct {
|
|||
TranslateFile *TranslateFile
|
||||
diagnostics *DiagnosticsCollector
|
||||
executor *Executor
|
||||
hosts []string
|
||||
|
||||
// External
|
||||
handler Handler
|
||||
|
|
@ -207,6 +208,15 @@ func OptServerURI(uri *URI) ServerOption {
|
|||
}
|
||||
}
|
||||
|
||||
// OptClusterStatic tells the server to use a static cluster with the defined
|
||||
// hosts. Mostly used for testing.
|
||||
func OptServerClusterStatic(hosts []string) ServerOption {
|
||||
return func(s *Server) error {
|
||||
s.hosts = hosts
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// NewServer returns a new instance of Server.
|
||||
func NewServer(opts ...ServerOption) (*Server, error) {
|
||||
s := &Server{
|
||||
|
|
@ -272,6 +282,12 @@ func NewServer(opts ...ServerOption) (*Server, error) {
|
|||
IsCoordinator: s.Cluster.Coordinator == s.NodeID,
|
||||
}
|
||||
s.Cluster.Node = node
|
||||
if len(s.hosts) > 0 {
|
||||
err := s.Cluster.setStatic(s.hosts)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "setting cluster static")
|
||||
}
|
||||
}
|
||||
|
||||
// Append the NodeID tag to stats.
|
||||
s.Holder.Stats = s.Holder.Stats.WithTags(fmt.Sprintf("NodeID:%s", s.NodeID))
|
||||
|
|
@ -290,9 +306,8 @@ func NewServer(opts ...ServerOption) (*Server, error) {
|
|||
// Open opens and initializes the server.
|
||||
func (s *Server) Open() error {
|
||||
s.logger.Printf("open server")
|
||||
// s.ln can be configured prior to Open() via s.OpenListener().
|
||||
if s.ln == nil {
|
||||
return errors.New("Must pass a listener option to NewServer")
|
||||
return errors.New("must pass a listener option to NewServer")
|
||||
}
|
||||
|
||||
// Log startup
|
||||
|
|
|
|||
|
|
@ -209,6 +209,10 @@ func (m *Command) SetupServer() error {
|
|||
if err != nil {
|
||||
return errors.Wrap(err, "new stats client")
|
||||
}
|
||||
var hosts []string
|
||||
if m.Config.Cluster.Disabled {
|
||||
hosts = m.Config.Cluster.Hosts
|
||||
}
|
||||
|
||||
ln, err := getListener(*uri, TLSConfig)
|
||||
if err != nil {
|
||||
|
|
@ -242,6 +246,7 @@ func (m *Command) SetupServer() error {
|
|||
pilosa.OptServerURI(uri),
|
||||
pilosa.OptServerInternalClient(http.NewInternalClientFromURI(uri, c)),
|
||||
pilosa.OptServerPrimaryTranslateStore(primaryTranslateStore),
|
||||
pilosa.OptServerClusterStatic(hosts),
|
||||
)
|
||||
|
||||
return errors.Wrap(err, "new server")
|
||||
|
|
@ -250,19 +255,6 @@ func (m *Command) SetupServer() error {
|
|||
// SetupNetworking sets up internode communication based on the configuration.
|
||||
func (m *Command) SetupNetworking() error {
|
||||
if m.Config.Cluster.Disabled {
|
||||
m.Server.Cluster.Static = true
|
||||
m.Server.Cluster.Coordinator = m.Server.NodeID
|
||||
for _, address := range m.Config.Cluster.Hosts {
|
||||
uri, err := pilosa.NewURIFromAddress(address)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "getting URI")
|
||||
}
|
||||
m.Server.Cluster.Nodes = append(m.Server.Cluster.Nodes, &pilosa.Node{
|
||||
URI: *uri,
|
||||
})
|
||||
}
|
||||
|
||||
m.Server.Cluster.MemberSet = pilosa.NewStaticMemberSet(m.Server.Cluster.Nodes)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue