@@ -21,7 +21,6 @@ package client
2121
2222import (
2323 "bytes"
24- "container/list"
2524 "context"
2625 "encoding/binary"
2726 "errors"
@@ -77,7 +76,7 @@ type Session struct {
7776 trans thrift.TTransport
7877 requestStatementId int64
7978 protocolFactory thrift.TProtocolFactory
80- endPointList * list. List
79+ endPointList [] endPoint
8180}
8281
8382type endPoint struct {
@@ -1139,11 +1138,10 @@ func NewSession(config *Config) Session {
11391138}
11401139
11411140func newSessionWithSpecifiedSqlDialect (config * Config ) Session {
1142- endPointList := list .New ()
1143- endPoint := endPoint {}
1144- endPoint .Host = config .Host
1145- endPoint .Port = config .Port
1146- endPointList .PushBack (endPoint )
1141+ endPointList := []endPoint {{
1142+ Host : config .Host ,
1143+ Port : config .Port ,
1144+ }}
11471145 return Session {
11481146 config : config ,
11491147 endPointList : endPointList ,
@@ -1157,16 +1155,17 @@ func NewClusterSession(clusterConfig *ClusterConfig) (Session, error) {
11571155
11581156func newClusterSessionWithSqlDialect (clusterConfig * ClusterConfig ) (Session , error ) {
11591157 session := Session {}
1160- node := endPoint {}
1161- session .endPointList = list .New ()
1158+ session .endPointList = make ([]endPoint , len (clusterConfig .NodeUrls ))
11621159 for i := 0 ; i < len (clusterConfig .NodeUrls ); i ++ {
1160+ node := endPoint {}
11631161 node .Host = strings .Split (clusterConfig .NodeUrls [i ], ":" )[0 ]
11641162 node .Port = strings .Split (clusterConfig .NodeUrls [i ], ":" )[1 ]
1165- session .endPointList . PushBack ( node )
1163+ session .endPointList [ i ] = node
11661164 }
11671165 var err error
1168- for e := session .endPointList .Front (); e != nil ; e = e .Next () {
1169- session .trans = thrift .NewTSocketConf (net .JoinHostPort (e .Value .(endPoint ).Host , e .Value .(endPoint ).Port ), & thrift.TConfiguration {
1166+ for i := range session .endPointList {
1167+ ep := session .endPointList [i ]
1168+ session .trans = thrift .NewTSocketConf (net .JoinHostPort (ep .Host , ep .Port ), & thrift.TConfiguration {
11701169 ConnectTimeout : time .Duration (0 ), // Use 0 for no timeout
11711170 })
11721171 // session.trans = thrift.NewTFramedTransport(session.trans) // deprecated
@@ -1177,7 +1176,7 @@ func newClusterSessionWithSqlDialect(clusterConfig *ClusterConfig) (Session, err
11771176 if err != nil {
11781177 log .Println (err )
11791178 } else {
1180- session .config = getConfig (e . Value .( endPoint ). Host , e . Value .( endPoint ) .Port ,
1179+ session .config = getConfig (ep . Host , ep .Port ,
11811180 clusterConfig .UserName , clusterConfig .Password , clusterConfig .FetchSize , clusterConfig .TimeZone , clusterConfig .ConnectRetryMax , clusterConfig .Database , clusterConfig .sqlDialect )
11821181 break
11831182 }
@@ -1254,13 +1253,14 @@ func (s *Session) reconnect() bool {
12541253 var connectedSuccess = false
12551254
12561255 for i := 0 ; i < s .config .ConnectRetryMax ; i ++ {
1257- for e := s .endPointList .Front (); e != nil ; e = e .Next () {
1258- err = s .initClusterConn (e .Value .(endPoint ))
1256+ for i := range s .endPointList {
1257+ ep := s .endPointList [i ]
1258+ err = s .initClusterConn (ep )
12591259 if err == nil {
12601260 connectedSuccess = true
12611261 break
12621262 } else {
1263- log .Println ("Connection refused:" , e . Value .( endPoint ) )
1263+ log .Println ("Connection refused:" , ep )
12641264 }
12651265 }
12661266 if connectedSuccess {
0 commit comments