Browse Source

Add option to ignore cassandras reported address

Add IgnorePeerAddr to cluster config which when enabled will use the
supplied host address instead of the one which the driver discovers from
cassandra.
Chris Bannister 10 years ago
parent
commit
8c70accded
2 changed files with 18 additions and 0 deletions
  1. 9 0
      cluster.go
  2. 9 0
      events.go

+ 9 - 0
cluster.go

@@ -126,6 +126,15 @@ type ClusterConfig struct {
 	// via Discovery
 	// via Discovery
 	HostFilter HostFilter
 	HostFilter HostFilter
 
 
+	// If IgnorePeerAddr is true and the address in system.peers does not match
+	// the supplied host by either initial hosts or discovered via events then the
+	// host will be replaced with the supplied address.
+	//
+	// For example if an event comes in with host=10.0.0.1 but when looking up that
+	// address in system.local or system.peers returns 127.0.0.1, the peer will be
+	// set to 10.0.0.1 which is what will be used to connect to.
+	IgnorePeerAddr bool
+
 	// internal config for testing
 	// internal config for testing
 	disableControlConn bool
 	disableControlConn bool
 }
 }

+ 9 - 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}
 		hostInfo = &HostInfo{peer: host.String(), port: port, state: NodeUp}
 	}
 	}
 
 
+	addr := host.String()
+	if s.cfg.IgnorePeerAddr && hostInfo.Peer() != addr {
+		hostInfo.setPeer(addr)
+	}
+
 	if s.cfg.HostFilter != nil {
 	if s.cfg.HostFilter != nil {
 		if !s.cfg.HostFilter.Accept(hostInfo) {
 		if !s.cfg.HostFilter.Accept(hostInfo) {
 			return
 			return
@@ -216,6 +221,10 @@ func (s *Session) handleNodeUp(ip net.IP, port int, waitForBinary bool) {
 	addr := ip.String()
 	addr := ip.String()
 	host := s.ring.getHost(addr)
 	host := s.ring.getHost(addr)
 	if host != nil {
 	if host != nil {
+		if s.cfg.IgnorePeerAddr && host.Peer() != addr {
+			host.setPeer(addr)
+		}
+
 		if s.cfg.HostFilter != nil {
 		if s.cfg.HostFilter != nil {
 			if !s.cfg.HostFilter.Accept(host) {
 			if !s.cfg.HostFilter.Accept(host) {
 				return
 				return