Procházet zdrojové kódy

Cleaned up code to streamline the connection being added to the pool and removed code related to old keyspace behaviour.

Phillip Couto před 12 roky
rodič
revize
5cf7b6ee4c
2 změnil soubory, kde provedl 10 přidání a 43 odebrání
  1. 10 41
      cluster.go
  2. 0 2
      conn.go

+ 10 - 41
cluster.go

@@ -138,35 +138,26 @@ func (c *clusterImpl) connect(addr string) {
 				return
 				return
 			}
 			}
 		}
 		}
-		c.addConn(conn, "")
+		c.addConn(conn)
 		return
 		return
 	}
 	}
 }
 }
 
 
-func (c *clusterImpl) changeKeyspace(conn *Conn, keyspace string, connected bool) {
-	if err := conn.UseKeyspace(keyspace); err != nil {
-		conn.Close()
-		if connected {
-			c.removeConn(conn)
-		}
-		go c.connect(conn.Address())
-	}
-	if !connected {
-		c.addConn(conn, keyspace)
-	}
-}
-
-func (c *clusterImpl) addConn(conn *Conn, keyspace string) {
+func (c *clusterImpl) addConn(conn *Conn) {
 	c.mu.Lock()
 	c.mu.Lock()
 	defer c.mu.Unlock()
 	defer c.mu.Unlock()
 	if c.quit {
 	if c.quit {
 		conn.Close()
 		conn.Close()
 		return
 		return
 	}
 	}
-	if keyspace != c.keyspace && c.keyspace != "" {
-		// change the keyspace before adding the node to the pool
-		go c.changeKeyspace(conn, c.keyspace, false)
-		return
+	//Set the connection's keyspace if any before adding it to the pool
+	if c.keyspace != "" {
+		if err := conn.UseKeyspace(c.keyspace); err != nil {
+			log.Printf("error setting connection keyspace. %v", err)
+			conn.Close()
+			go c.connect(conn.Address())
+			return
+		}
 	}
 	}
 	connPool := c.connPool[conn.Address()]
 	connPool := c.connPool[conn.Address()]
 	if connPool == nil {
 	if connPool == nil {
@@ -214,28 +205,6 @@ func (c *clusterImpl) HandleError(conn *Conn, err error, closed bool) {
 	}
 	}
 }
 }
 
 
-func (c *clusterImpl) HandleKeyspace(conn *Conn, keyspace string) {
-	c.mu.Lock()
-	if c.keyspace == keyspace {
-		c.mu.Unlock()
-		return
-	}
-	c.keyspace = keyspace
-	conns := make([]*Conn, 0, len(c.conns))
-	for conn := range c.conns {
-		conns = append(conns, conn)
-	}
-	c.mu.Unlock()
-
-	// change the keyspace of all other connections too
-	for i := 0; i < len(conns); i++ {
-		if conns[i] == conn {
-			continue
-		}
-		c.changeKeyspace(conns[i], keyspace, true)
-	}
-}
-
 func (c *clusterImpl) Pick(qry *Query) *Conn {
 func (c *clusterImpl) Pick(qry *Query) *Conn {
 	return c.hostPool.Pick(qry)
 	return c.hostPool.Pick(qry)
 }
 }

+ 0 - 2
conn.go

@@ -23,7 +23,6 @@ const maskVersion = 0x7F
 
 
 type Cluster interface {
 type Cluster interface {
 	HandleError(conn *Conn, err error, closed bool)
 	HandleError(conn *Conn, err error, closed bool)
-	HandleKeyspace(conn *Conn, keyspace string)
 }
 }
 
 
 type Authenticator interface {
 type Authenticator interface {
@@ -426,7 +425,6 @@ func (c *Conn) executeQuery(qry *Query) *Iter {
 		}
 		}
 		return iter
 		return iter
 	case resultKeyspaceFrame:
 	case resultKeyspaceFrame:
-		c.cluster.HandleKeyspace(c, x.Keyspace)
 		return &Iter{}
 		return &Iter{}
 	case errorFrame:
 	case errorFrame:
 		if x.Code == errUnprepared && len(qry.values) > 0 {
 		if x.Code == errUnprepared && len(qry.values) > 0 {