diff --git a/api.go b/api.go index 36af91b0f..ab4948588 100644 --- a/api.go +++ b/api.go @@ -22,7 +22,6 @@ import ( "fmt" "io" "io/ioutil" - "net/http" "strconv" "strings" "time" @@ -45,7 +44,6 @@ type API struct { BroadcastHandler BroadcastHandler StatusHandler StatusHandler Cluster *Cluster - RemoteClient *http.Client Logger Logger } diff --git a/cluster.go b/cluster.go index 28feb80a3..dccac02a1 100644 --- a/cluster.go +++ b/cluster.go @@ -21,7 +21,6 @@ import ( "hash/fnv" "io/ioutil" "math/rand" - "net/http" "os" "path/filepath" "sort" @@ -264,9 +263,6 @@ type Cluster struct { Logger Logger - // - RemoteClient *http.Client - InternalClient InternalClient } diff --git a/fragment.go b/fragment.go index 012c62503..ab50117fc 100644 --- a/fragment.go +++ b/fragment.go @@ -25,7 +25,6 @@ import ( "hash" "io" "io/ioutil" - "net/http" "os" "sort" "sync" @@ -1719,9 +1718,8 @@ func (h *blockHasher) WriteValue(v uint64) { type FragmentSyncer struct { Fragment *Fragment - Node *Node - Cluster *Cluster - RemoteClient *http.Client + Node *Node + Cluster *Cluster Closing <-chan struct{} } diff --git a/handler.go b/handler.go index f9c3435af..7c2b76a3f 100644 --- a/handler.go +++ b/handler.go @@ -2,7 +2,7 @@ package pilosa import ( "encoding/json" - "net/http" + "net" ) // QueryRequest represent a request to process a query. @@ -61,13 +61,13 @@ func (resp *QueryResponse) MarshalJSON() ([]byte, error) { } type Handler interface { - http.Handler + Serve(ln net.Listener, closing <-chan struct{}) GetAPI() *API } type NopHandler struct{} -func (n *NopHandler) ServeHTTP(_ http.ResponseWriter, _ *http.Request) {} +func (n *NopHandler) Serve(ln net.Listener, closing <-chan struct{}) {} func (n *NopHandler) GetAPI() *API { return nil diff --git a/holder.go b/holder.go index e7af65643..8dac3329b 100644 --- a/holder.go +++ b/holder.go @@ -18,7 +18,6 @@ import ( "context" "fmt" "io/ioutil" - "net/http" "os" "path" "path/filepath" @@ -563,9 +562,8 @@ func (h *Holder) logStartup() error { type HolderSyncer struct { Holder *Holder - Node *Node - Cluster *Cluster - RemoteClient *http.Client + Node *Node + Cluster *Cluster // Stats Stats StatsClient @@ -755,11 +753,10 @@ func (s *HolderSyncer) syncFragment(index, field, view string, slice uint64) err // Sync fragments together. fs := FragmentSyncer{ - Fragment: frag, - Node: s.Node, - Cluster: s.Cluster, - Closing: s.Closing, - RemoteClient: s.RemoteClient, + Fragment: frag, + Node: s.Node, + Cluster: s.Cluster, + Closing: s.Closing, } if err := fs.syncFragment(); err != nil { return errors.Wrap(err, "syncing fragment") diff --git a/holder_test.go b/holder_test.go index 31b50b900..72a10b815 100644 --- a/holder_test.go +++ b/holder_test.go @@ -362,7 +362,6 @@ func TestHolderSyncer_SyncHolder(t *testing.T) { client := http.GetHTTPClient(nil) httpClient := http.NewInternalClientFromURI(uri, client) cluster.InternalClient = httpClient - cluster.RemoteClient = client // Create a local holder. hldr0 := test.MustOpenHolder() @@ -419,11 +418,10 @@ func TestHolderSyncer_SyncHolder(t *testing.T) { // Set up syncer. syncer := pilosa.HolderSyncer{ - Holder: hldr0.Holder, - Node: cluster.Nodes[0], - Cluster: cluster, - RemoteClient: http.GetHTTPClient(nil), - Stats: pilosa.NopStatsClient, + Holder: hldr0.Holder, + Node: cluster.Nodes[0], + Cluster: cluster, + Stats: pilosa.NopStatsClient, } if err := syncer.SyncHolder(); err != nil { diff --git a/http/handler.go b/http/handler.go index df5108826..41a5faf55 100644 --- a/http/handler.go +++ b/http/handler.go @@ -117,6 +117,18 @@ func NewHandler(opts ...HandlerOption) (*Handler, error) { return handler, nil } +func (h *Handler) Serve(ln net.Listener, closing <-chan struct{}) { + server := &http.Server{Handler: h} + go func() { + <-closing + server.Close() + }() + err := server.Serve(ln) + if err != nil && err.Error() != "http: Server closed" { + h.Logger.Printf("HTTP handler terminated with error: %s\n", err) + } +} + func (h *Handler) populateValidators() { h.validators = map[string]*queryValidationSpec{} h.validators["GetFragmentNodes"] = queryValidationSpecRequired("slice", "index") diff --git a/server.go b/server.go index f330b6e6a..b1ce4bfaa 100644 --- a/server.go +++ b/server.go @@ -19,7 +19,6 @@ import ( "fmt" "log" "net" - "net/http" "os" "os/exec" "path/filepath" @@ -63,7 +62,6 @@ type Server struct { Broadcaster Broadcaster BroadcastReceiver BroadcastReceiver Gossiper Gossiper - remoteClient *http.Client systemInfo SystemInfo gcNotifier GCNotifier NewAttrStore func(string) AttrStore @@ -162,15 +160,6 @@ func OptServerGCNotifier(gcn GCNotifier) ServerOption { } } -// TODO: Remove RemoteClient -func OptServerRemoteClient(c *http.Client) ServerOption { - return func(s *Server) error { - s.remoteClient = c - s.Cluster.RemoteClient = c - return nil - } -} - func OptServerInternalClient(c InternalClient) ServerOption { return func(s *Server) error { s.executor = NewExecutor(OptExecutorInternalQueryClient(c)) @@ -313,18 +302,8 @@ func (s *Server) Open() error { // Initialize Holder. s.Holder.Broadcaster = s.Broadcaster - // Serve HTTP. - go func() { - server := &http.Server{Handler: s.handler} - go func() { - <-s.closing - server.Close() - }() - err := server.Serve(s.ln) - if err != nil && err.Error() != "http: Server closed" { - s.logger.Printf("HTTP handler terminated with error: %s\n", err) - } - }() + // Serve handler. + go s.handler.Serve(s.ln, s.closing) // Start the BroadcastReceiver. if err := s.BroadcastReceiver.Start(s); err != nil { @@ -424,7 +403,6 @@ func (s *Server) monitorAntiEntropy() { syncer.Node = s.Cluster.Node syncer.Cluster = s.Cluster syncer.Closing = s.closing - syncer.RemoteClient = s.remoteClient syncer.Stats = s.Holder.Stats.WithTags("HolderSyncer") // Sync holders. diff --git a/server/server.go b/server/server.go index 42b547d43..d034a4aa8 100644 --- a/server/server.go +++ b/server/server.go @@ -216,7 +216,6 @@ func (m *Command) SetupServer() error { } c := http.GetHTTPClient(TLSConfig) - api.RemoteClient = c m.Server, err = pilosa.NewServer( pilosa.OptServerAntiEntropyInterval(time.Duration(m.Config.AntiEntropy.Interval)), @@ -235,7 +234,6 @@ func (m *Command) SetupServer() error { pilosa.OptServerStatsClient(statsClient), pilosa.OptServerListener(ln), pilosa.OptServerURI(uri), - pilosa.OptServerRemoteClient(c), pilosa.OptServerInternalClient(http.NewInternalClientFromURI(uri, c)), )