This is an automated email from the ASF dual-hosted git repository.
caogaofei pushed a commit to branch dev/1.3
in repository https://gitbox.apache.org/repos/asf/iotdb-client-go.git
The following commit(s) were added to refs/heads/dev/1.3 by this push:
new b4e7151 [To dev/1.3] Remove global endPointList to avoid cluster init
error
b4e7151 is described below
commit b4e7151e22c449af727f36df32cb3d5c65842c27
Author: shuwenwei <[email protected]>
AuthorDate: Fri Mar 21 18:39:04 2025 +0800
[To dev/1.3] Remove global endPointList to avoid cluster init error
---
client/session.go | 36 ++++++++++++++++++++----------------
test/e2e/e2e_test.go | 10 ++++++++++
2 files changed, 30 insertions(+), 16 deletions(-)
diff --git a/client/session.go b/client/session.go
index e5f2184..aa778fb 100644
--- a/client/session.go
+++ b/client/session.go
@@ -21,7 +21,6 @@ package client
import (
"bytes"
- "container/list"
"context"
"encoding/binary"
"errors"
@@ -63,6 +62,7 @@ type Session struct {
trans thrift.TTransport
requestStatementId int64
protocolFactory thrift.TProtocolFactory
+ endPointList []endPoint
}
type endPoint struct {
@@ -70,8 +70,6 @@ type endPoint struct {
Port string
}
-var endPointList = list.New()
-
func (s *Session) Open(enableRPCCompression bool, connectionTimeoutInMs int)
error {
if s.config.FetchSize <= 0 {
s.config.FetchSize = DefaultFetchSize
@@ -1078,24 +1076,29 @@ func (s *Session) GetSessionId() int64 {
}
func NewSession(config *Config) Session {
- endPoint := endPoint{}
- endPoint.Host = config.Host
- endPoint.Port = config.Port
- endPointList.PushBack(endPoint)
- return Session{config: config}
+ endPointList := []endPoint{{
+ Host: config.Host,
+ Port: config.Port,
+ }}
+ return Session{
+ config: config,
+ endPointList: endPointList,
+ }
}
func NewClusterSession(clusterConfig *ClusterConfig) (Session, error) {
session := Session{}
- node := endPoint{}
+ session.endPointList = make([]endPoint, len(clusterConfig.NodeUrls))
for i := 0; i < len(clusterConfig.NodeUrls); i++ {
+ node := endPoint{}
node.Host = strings.Split(clusterConfig.NodeUrls[i], ":")[0]
node.Port = strings.Split(clusterConfig.NodeUrls[i], ":")[1]
- endPointList.PushBack(node)
+ session.endPointList[i] = node
}
var err error
- for e := endPointList.Front(); e != nil; e = e.Next() {
- session.trans =
thrift.NewTSocketConf(net.JoinHostPort(e.Value.(endPoint).Host,
e.Value.(endPoint).Port), &thrift.TConfiguration{
+ for i := range session.endPointList {
+ ep := session.endPointList[i]
+ session.trans = thrift.NewTSocketConf(net.JoinHostPort(ep.Host,
ep.Port), &thrift.TConfiguration{
ConnectTimeout: time.Duration(0), // Use 0 for no
timeout
})
// session.trans = thrift.NewTFramedTransport(session.trans)
// deprecated
@@ -1106,7 +1109,7 @@ func NewClusterSession(clusterConfig *ClusterConfig)
(Session, error) {
if err != nil {
log.Println(err)
} else {
- session.config =
getConfig(e.Value.(endPoint).Host, e.Value.(endPoint).Port,
+ session.config = getConfig(ep.Host, ep.Port,
clusterConfig.UserName,
clusterConfig.Password, clusterConfig.FetchSize, clusterConfig.TimeZone,
clusterConfig.ConnectRetryMax)
break
}
@@ -1181,13 +1184,14 @@ func (s *Session) reconnect() bool {
var connectedSuccess = false
for i := 0; i < s.config.ConnectRetryMax; i++ {
- for e := endPointList.Front(); e != nil; e = e.Next() {
- err = s.initClusterConn(e.Value.(endPoint))
+ for i := range s.endPointList {
+ ep := s.endPointList[i]
+ err = s.initClusterConn(ep)
if err == nil {
connectedSuccess = true
break
} else {
- log.Println("Connection refused:",
e.Value.(endPoint))
+ log.Println("Connection refused:", ep)
}
}
if connectedSuccess {
diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go
index e4b91ea..3ad5c2e 100644
--- a/test/e2e/e2e_test.go
+++ b/test/e2e/e2e_test.go
@@ -75,6 +75,16 @@ func (s *e2eTestSuite) checkError(status *common.TSStatus,
err error) {
}
}
+func (s *e2eTestSuite) Test_WrongURL() {
+ clusterConfig := client.ClusterConfig{
+ NodeUrls: strings.Split("iotdb1:6667", ","),
+ UserName: "root",
+ Password: "root",
+ }
+ _, err := client.NewClusterSession(&clusterConfig)
+ s.Require().Error(err)
+}
+
func (s *e2eTestSuite) Test_CreateTimeseries() {
var (
path = "root.tsg1.dev1.status"