Sfoglia il codice sorgente

add more info to host info

Chris Bannister 10 anni fa
parent
commit
ee1e09bbda
3 ha cambiato i file con 31 aggiunte e 2 eliminazioni
  1. 2 0
      events.go
  2. 26 1
      host_source.go
  3. 3 1
      session.go

+ 2 - 0
events.go

@@ -6,6 +6,7 @@ import (
 )
 
 func (s *Session) handleEvent(framer *framer) {
+	// TODO(zariel): need to debounce events frames, and possible also events
 	defer framerPool.Put(framer)
 
 	frame, err := framer.parseFrame()
@@ -36,6 +37,7 @@ func (s *Session) handleEvent(framer *framer) {
 		case "UP":
 			s.handleNodeUp(f.host, f.port)
 		case "DOWN":
+			s.handleNodeDown(f.host, f.port)
 		}
 	default:
 		log.Printf("gocql: invalid event frame (%T): %v\n", f, f)

+ 26 - 1
host_source.go

@@ -8,16 +8,41 @@ import (
 	"time"
 )
 
+type nodeState int32
+
+func (n nodeState) String() {
+	if n == NodeUp {
+		return "UP"
+	} else if n == NodeDown {
+		return "DOWN"
+	}
+}
+
+const (
+	NodeUp nodeState = iota
+	NodeDown
+)
+
 type HostInfo struct {
 	Peer       string
 	DataCenter string
 	Rack       string
 	HostId     string
+	Version    cassVersion
+	State      nodeState
 	Tokens     []string
 }
 
+type cassVersion struct {
+	Major, Minor, Patch int
+}
+
+func (c cassVersion) String() string {
+	return fmt.Sprintf("v%d.%d.%d", c.Major, c.Minor, c.Patch)
+}
+
 func (h HostInfo) String() string {
-	return fmt.Sprintf("[hostinfo peer=%q data_centre=%q rack=%q host_id=%q num_tokens=%d]", h.Peer, h.DataCenter, h.Rack, h.HostId, len(h.Tokens))
+	return fmt.Sprintf("[hostinfo peer=%q data_centre=%q rack=%q host_id=%q version=%q state=%s num_tokens=%d]", h.Peer, h.DataCenter, h.Rack, h.HostId, h.Version, h.State, len(h.Tokens))
 }
 
 // Polls system.peers at a specific interval to find new hosts

+ 3 - 1
session.go

@@ -42,6 +42,9 @@ type Session struct {
 
 	control *controlConn
 
+	// ring metadata
+	hosts []HostInfo
+
 	cfg ClusterConfig
 
 	closeMu  sync.RWMutex
@@ -79,7 +82,6 @@ func NewSession(cfg ClusterConfig) (*Session, error) {
 	if !cfg.disableControlConn {
 		s.control = createControlConn(s)
 		if err := s.control.connect(cfg.Hosts); err != nil {
-			s.control.close()
 			return nil, err
 		}