@@ -21,7 +21,6 @@ package client
2121
2222import (
2323 "bytes"
24- "container/list"
2524 "context"
2625 "encoding/binary"
2726 "errors"
@@ -63,15 +62,14 @@ type Session struct {
6362 trans thrift.TTransport
6463 requestStatementId int64
6564 protocolFactory thrift.TProtocolFactory
65+ endPointList []endPoint
6666}
6767
6868type endPoint struct {
6969 Host string
7070 Port string
7171}
7272
73- var endPointList = list .New ()
74-
7573func (s * Session ) Open (enableRPCCompression bool , connectionTimeoutInMs int ) error {
7674 if s .config .FetchSize <= 0 {
7775 s .config .FetchSize = DefaultFetchSize
@@ -1078,24 +1076,29 @@ func (s *Session) GetSessionId() int64 {
10781076}
10791077
10801078func NewSession (config * Config ) Session {
1081- endPoint := endPoint {}
1082- endPoint .Host = config .Host
1083- endPoint .Port = config .Port
1084- endPointList .PushBack (endPoint )
1085- return Session {config : config }
1079+ endPointList := []endPoint {{
1080+ Host : config .Host ,
1081+ Port : config .Port ,
1082+ }}
1083+ return Session {
1084+ config : config ,
1085+ endPointList : endPointList ,
1086+ }
10861087}
10871088
10881089func NewClusterSession (clusterConfig * ClusterConfig ) (Session , error ) {
10891090 session := Session {}
1090- node := endPoint {}
1091+ session . endPointList = make ([] endPoint , len ( clusterConfig . NodeUrls ))
10911092 for i := 0 ; i < len (clusterConfig .NodeUrls ); i ++ {
1093+ node := endPoint {}
10921094 node .Host = strings .Split (clusterConfig .NodeUrls [i ], ":" )[0 ]
10931095 node .Port = strings .Split (clusterConfig .NodeUrls [i ], ":" )[1 ]
1094- endPointList . PushBack ( node )
1096+ session . endPointList [ i ] = node
10951097 }
10961098 var err error
1097- for e := endPointList .Front (); e != nil ; e = e .Next () {
1098- session .trans = thrift .NewTSocketConf (net .JoinHostPort (e .Value .(endPoint ).Host , e .Value .(endPoint ).Port ), & thrift.TConfiguration {
1099+ for i := range session .endPointList {
1100+ ep := session .endPointList [i ]
1101+ session .trans = thrift .NewTSocketConf (net .JoinHostPort (ep .Host , ep .Port ), & thrift.TConfiguration {
10991102 ConnectTimeout : time .Duration (0 ), // Use 0 for no timeout
11001103 })
11011104 // session.trans = thrift.NewTFramedTransport(session.trans) // deprecated
@@ -1106,7 +1109,7 @@ func NewClusterSession(clusterConfig *ClusterConfig) (Session, error) {
11061109 if err != nil {
11071110 log .Println (err )
11081111 } else {
1109- session .config = getConfig (e . Value .( endPoint ). Host , e . Value .( endPoint ) .Port ,
1112+ session .config = getConfig (ep . Host , ep .Port ,
11101113 clusterConfig .UserName , clusterConfig .Password , clusterConfig .FetchSize , clusterConfig .TimeZone , clusterConfig .ConnectRetryMax )
11111114 break
11121115 }
@@ -1181,13 +1184,14 @@ func (s *Session) reconnect() bool {
11811184 var connectedSuccess = false
11821185
11831186 for i := 0 ; i < s .config .ConnectRetryMax ; i ++ {
1184- for e := endPointList .Front (); e != nil ; e = e .Next () {
1185- err = s .initClusterConn (e .Value .(endPoint ))
1187+ for i := range s .endPointList {
1188+ ep := s .endPointList [i ]
1189+ err = s .initClusterConn (ep )
11861190 if err == nil {
11871191 connectedSuccess = true
11881192 break
11891193 } else {
1190- log .Println ("Connection refused:" , e . Value .( endPoint ) )
1194+ log .Println ("Connection refused:" , ep )
11911195 }
11921196 }
11931197 if connectedSuccess {
0 commit comments