Browse Source

sesssion now creates a single connconfig

Chris Bannister 10 years ago
parent
commit
a65110e114
3 changed files with 18 additions and 23 deletions
  1. 3 14
      connectionpool.go
  2. 4 8
      control.go
  3. 11 1
      session.go

+ 3 - 14
connectionpool.go

@@ -62,7 +62,6 @@ type policyConnPool struct {
 
 	port     int
 	numConns int
-	connCfg  *ConnConfig
 	keyspace string
 
 	mu            sync.RWMutex
@@ -101,19 +100,13 @@ func connConfig(session *Session) (*ConnConfig, error) {
 }
 
 func newPolicyConnPool(session *Session, hostPolicy HostSelectionPolicy,
-	connPolicy func() ConnSelectionPolicy) (*policyConnPool, error) {
-
-	connCfg, err := connConfig(session)
-	if err != nil {
-		return nil, err
-	}
+	connPolicy func() ConnSelectionPolicy) *policyConnPool {
 
 	// create the pool
 	pool := &policyConnPool{
 		session:       session,
 		port:          session.cfg.Port,
 		numConns:      session.cfg.NumConns,
-		connCfg:       connCfg,
 		keyspace:      session.cfg.Keyspace,
 		hostPolicy:    hostPolicy,
 		connPolicy:    connPolicy,
@@ -123,7 +116,7 @@ func newPolicyConnPool(session *Session, hostPolicy HostSelectionPolicy,
 	pool.endpoints = make([]string, len(session.cfg.Hosts))
 	copy(pool.endpoints, session.cfg.Hosts)
 
-	return pool, nil
+	return pool
 }
 
 func (p *policyConnPool) SetHosts(hosts []*HostInfo) {
@@ -146,7 +139,6 @@ func (p *policyConnPool) SetHosts(hosts []*HostInfo) {
 				host.Peer(),
 				p.port,
 				p.numConns,
-				p.connCfg,
 				p.keyspace,
 				p.connPolicy(),
 			)
@@ -238,7 +230,6 @@ func (p *policyConnPool) addHost(host *HostInfo) {
 		host.Peer(),
 		p.port,
 		p.numConns,
-		p.connCfg,
 		p.keyspace,
 		p.connPolicy(),
 	)
@@ -282,7 +273,6 @@ type hostConnPool struct {
 	port     int
 	addr     string
 	size     int
-	connCfg  *ConnConfig
 	keyspace string
 	policy   ConnSelectionPolicy
 	// protection for conns, closed, filling
@@ -292,7 +282,7 @@ type hostConnPool struct {
 	filling bool
 }
 
-func newHostConnPool(session *Session, host string, port, size int, connCfg *ConnConfig,
+func newHostConnPool(session *Session, host *HostInfo, port, size int,
 	keyspace string, policy ConnSelectionPolicy) *hostConnPool {
 
 	pool := &hostConnPool{
@@ -301,7 +291,6 @@ func newHostConnPool(session *Session, host string, port, size int, connCfg *Con
 		port:     port,
 		addr:     JoinHostPort(host, port),
 		size:     size,
-		connCfg:  connCfg,
 		keyspace: keyspace,
 		policy:   policy,
 		conns:    make([]*Conn, 0, size),

+ 4 - 8
control.go

@@ -20,8 +20,10 @@ type controlConn struct {
 
 	conn atomic.Value
 
-	retry   RetryPolicy
-	connCfg *ConnConfig
+	session *Session
+	conn    atomic.Value
+
+	retry RetryPolicy
 
 	closeWg sync.WaitGroup
 	quit    chan struct{}
@@ -84,12 +86,6 @@ func (c *controlConn) connect(endpoints []string) error {
 		shuffled[perm[i]] = endpoint
 	}
 
-	connCfg, err := connConfig(c.session)
-	if err != nil {
-		return err
-	}
-	c.connCfg = connCfg
-
 	// store that we are not connected so that reconnect wont happen if we error
 	atomic.StoreInt64(&c.connecting, -1)
 

+ 11 - 1
session.go

@@ -37,7 +37,10 @@ type Session struct {
 	trace               Tracer
 	hostSource          *ringDescriber
 	ring                ring
-	mu                  sync.RWMutex
+
+	connCfg *ConnConfig
+
+	mu sync.RWMutex
 
 	hostFilter HostFilter
 
@@ -74,6 +77,13 @@ func NewSession(cfg ClusterConfig) (*Session, error) {
 		pageSize: cfg.PageSize,
 	}
 
+	connCfg, err := connConfig(s)
+	if err != nil {
+		s.Close()
+		return nil, fmt.Errorf("gocql: unable to create session: %v", err)
+	}
+	s.connCfg = connCfg
+
 	s.nodeEvents = newEventDeouncer("NodeEvents", s.handleNodeEvent)
 
 	s.routingKeyInfoCache.lru = lru.New(cfg.MaxRoutingKeyInfo)