Przeglądaj źródła

add the simple discovery filter back in for now

Chris Bannister 10 lat temu
rodzic
commit
f683ea9a83
2 zmienionych plików z 33 dodań i 2 usunięć
  1. 23 2
      cluster.go
  2. 10 0
      events.go

+ 23 - 2
cluster.go

@@ -67,6 +67,27 @@ func (p PoolConfig) buildPool(session *Session) *policyConnPool {
 	return newPolicyConnPool(session, hostSelection, connSelection)
 }
 
+type DiscoveryConfig struct {
+	// If not empty will filter all discoverred hosts to a single Data Centre (default: "")
+	DcFilter string
+	// If not empty will filter all discoverred hosts to a single Rack (default: "")
+	RackFilter string
+	// ignored
+	Sleep time.Duration
+}
+
+func (d DiscoveryConfig) matchFilter(host *HostInfo) bool {
+	if d.DcFilter != "" && d.DcFilter != host.DataCenter() {
+		return false
+	}
+
+	if d.RackFilter != "" && d.RackFilter != host.Rack() {
+		return false
+	}
+
+	return true
+}
+
 // ClusterConfig is a struct to configure the default cluster implementation
 // of gocoql. It has a varity of attributes that can be used to modify the
 // behavior to fit the most common use cases. Applications that requre a
@@ -94,12 +115,12 @@ type ClusterConfig struct {
 	// configuration of host selection and connection selection policies.
 	PoolConfig PoolConfig
 
+	Discovery DiscoveryConfig
+
 	// The maximum amount of time to wait for schema agreement in a cluster after
 	// receiving a schema change frame. (deault: 60s)
 	MaxWaitSchemaAgreement time.Duration
 
-	HostFilter
-
 	// internal config for testing
 	disableControlConn bool
 }

+ 10 - 0
events.go

@@ -167,6 +167,11 @@ func (s *Session) handleNewNode(host net.IP, port int, waitForBinary bool) {
 		hostInfo = &HostInfo{peer: host.String(), port: port, state: NodeUp}
 	}
 
+	// TODO: remove this when the host selection policy is more sophisticated
+	if !s.cfg.Discovery.matchFilter(hostInfo) {
+		return
+	}
+
 	if t := hostInfo.Version().nodeUpDelay(); t > 0 && waitForBinary {
 		time.Sleep(t)
 	}
@@ -197,6 +202,11 @@ func (s *Session) handleNodeUp(ip net.IP, port int, waitForBinary bool) {
 	addr := ip.String()
 	host := s.ring.getHost(addr)
 	if host != nil {
+		// TODO: remove this when the host selection policy is more sophisticated
+		if !s.cfg.Discovery.matchFilter(host) {
+			return
+		}
+
 		if t := host.Version().nodeUpDelay(); t > 0 && waitForBinary {
 			time.Sleep(t)
 		}