mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-07 19:37:51 +00:00
move the StateHandler interface from the Gossip package back to Pilosa and us this interface for the Handler to access the LocalState
This commit is contained in:
parent
989e0273be
commit
940b62335c
3 changed files with 14 additions and 27 deletions
|
|
@ -14,14 +14,6 @@ import (
|
|||
"github.com/pilosa/pilosa/internal"
|
||||
)
|
||||
|
||||
// StateHandler specifies two methods which an object must implement to share
|
||||
// state in the cluster. These are used by the GossipNodeSet to implement the
|
||||
// LocalState and MergeRemoteState methods of memberlist.Delegate
|
||||
type StateHandler interface {
|
||||
LocalState() (proto.Message, error)
|
||||
HandleRemoteState(proto.Message) error
|
||||
}
|
||||
|
||||
// GossipNodeSet represents a gossip implementation of NodeSet using memberlist
|
||||
// GossipNodeSet also represents a gossip implementation of pilosa.Broadcaster
|
||||
// GossipNodeSet also represents an implementation of memberlist.Delegate
|
||||
|
|
@ -31,7 +23,7 @@ type GossipNodeSet struct {
|
|||
|
||||
broadcasts *memberlist.TransmitLimitedQueue
|
||||
|
||||
stateHandler StateHandler
|
||||
stateHandler pilosa.StateHandler
|
||||
config *GossipConfig
|
||||
|
||||
// The writer for any logging.
|
||||
|
|
@ -89,7 +81,7 @@ type GossipConfig struct {
|
|||
}
|
||||
|
||||
// NewGossipNodeSet returns a new instance of GossipNodeSet.
|
||||
func NewGossipNodeSet(name string, gossipHost string, gossipPort int, gossipSeed string, sh StateHandler) *GossipNodeSet {
|
||||
func NewGossipNodeSet(name string, gossipHost string, gossipPort int, gossipSeed string, sh pilosa.StateHandler) *GossipNodeSet {
|
||||
g := &GossipNodeSet{
|
||||
LogOutput: os.Stderr,
|
||||
}
|
||||
|
|
|
|||
11
handler.go
11
handler.go
|
|
@ -23,18 +23,11 @@ import (
|
|||
"github.com/pilosa/pilosa/pql"
|
||||
)
|
||||
|
||||
// ServerHandler a method to update the local node's state information
|
||||
// this is used to handle the cluster status request and append the
|
||||
// local node's state with the cluster state gathered via Gossip
|
||||
type ServerHandler interface {
|
||||
HandleStateRequest() error
|
||||
}
|
||||
|
||||
// Handler represents an HTTP handler.
|
||||
type Handler struct {
|
||||
Index *Index
|
||||
Broadcaster Broadcaster
|
||||
ServerHandler ServerHandler
|
||||
ServerHandler StateHandler
|
||||
|
||||
// Local hostname & cluster configuration.
|
||||
Host string
|
||||
|
|
@ -124,7 +117,7 @@ func (h *Handler) handleGetSchema(w http.ResponseWriter, r *http.Request) {
|
|||
func (h *Handler) handleGetStatus(w http.ResponseWriter, r *http.Request) {
|
||||
// Compute my local state
|
||||
fmt.Println("Call interface")
|
||||
h.ServerHandler.HandleStateRequest()
|
||||
h.ServerHandler.LocalState()
|
||||
|
||||
if err := json.NewEncoder(w).Encode(getStatusResponse{
|
||||
Health: h.Cluster.NodeState,
|
||||
|
|
|
|||
18
server.go
18
server.go
|
|
@ -26,6 +26,14 @@ const (
|
|||
DefaultPollingInterval = 60 * time.Second
|
||||
)
|
||||
|
||||
// StateHandler specifies two methods which an object must implement to share
|
||||
// state in the cluster. These are used by the GossipNodeSet to implement the
|
||||
// LocalState and MergeRemoteState methods of memberlist.Delegate
|
||||
type StateHandler interface {
|
||||
LocalState() (proto.Message, error)
|
||||
HandleRemoteState(proto.Message) error
|
||||
}
|
||||
|
||||
// Server represents an index wrapped by a running HTTP server.
|
||||
type Server struct {
|
||||
ln net.Listener
|
||||
|
|
@ -242,11 +250,6 @@ func (s *Server) monitorMaxSlices() {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *Server) HandleStateRequest() error {
|
||||
_, err := s.LocalState()
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *Server) ReceiveMessage(pb proto.Message) error {
|
||||
switch obj := pb.(type) {
|
||||
case *internal.CreateSliceMessage:
|
||||
|
|
@ -281,13 +284,13 @@ func (s *Server) ReceiveMessage(pb proto.Message) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Server implements gossip.StateHandler.
|
||||
// LocalState returns the state of the local node as well as the
|
||||
// index (dbs/frames) according to the local node.
|
||||
// Server implements gossip.StateHandler.
|
||||
// In a gossip implementation, memberlist.Delegate.LocalState() uses this.
|
||||
func (s *Server) LocalState() (proto.Message, error) {
|
||||
if s.Index == nil {
|
||||
return nil, errors.New("Server.Index is nil.")
|
||||
return nil, errors.New("Server.Index is nil")
|
||||
}
|
||||
|
||||
// Get Node DB Slices
|
||||
|
|
@ -406,7 +409,6 @@ func (s *Server) monitorRuntime() {
|
|||
case <-gcn.AfterGC():
|
||||
// GC just ran
|
||||
s.Index.Stats.Count("garbage_collection", 1)
|
||||
s.logger().Printf("garbage collection complete")
|
||||
case <-ticker.C:
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue