Pārlūkot izejas kodu

host source should only add hosts if it is not known to the ring

Chris Bannister 10 gadi atpakaļ
vecāks
revīzija
ba1fc9f374
1 mainītis faili ar 11 papildinājumiem un 17 dzēšanām
  1. 11 17
      host_source.go

+ 11 - 17
host_source.go

@@ -5,7 +5,6 @@ import (
 	"log"
 	"log"
 	"net"
 	"net"
 	"sync"
 	"sync"
-	"time"
 )
 )
 
 
 type nodeState int32
 type nodeState int32
@@ -147,6 +146,10 @@ func (h *HostInfo) setTokens(tokens []string) *HostInfo {
 	return h
 	return h
 }
 }
 
 
+func (h *HostInfo) IsUp() bool {
+	return h.State() == NodeUp
+}
+
 func (h HostInfo) String() string {
 func (h HostInfo) String() string {
 	h.mu.RLock()
 	h.mu.RLock()
 	defer h.mu.RUnlock()
 	defer h.mu.RUnlock()
@@ -278,22 +281,13 @@ func (r *ringDescriber) refreshRing() {
 		return
 		return
 	}
 	}
 
 
-	r.session.pool.SetHosts(hosts)
-	r.session.pool.SetPartitioner(partitioner)
-}
-
-func (r *ringDescriber) run(sleep time.Duration) {
-	if sleep == 0 {
-		sleep = 30 * time.Second
-	}
-
-	for {
-		r.refreshRing()
-
-		select {
-		case <-time.After(sleep):
-		case <-r.closeChan:
-			return
+	// TODO: move this to session
+	for _, h := range hosts {
+		if r.session.ring.addHostIfMissing(h) {
+			r.session.pool.addHost(h)
+			// TODO: trigger OnUp/OnAdd
 		}
 		}
 	}
 	}
+
+	r.session.pool.SetPartitioner(partitioner)
 }
 }