fix(client): re-send session configuration on reconnect (#178) Session.initClusterConn() built its TSOpenSessionReq without a Configuration map, while Open() and OpenCluster() populate Configuration["sql_dialect"], ["version"], and ["db"]. Because reconnect() routes exclusively through initClusterConn() and is the sole transparent-reconnect path, any session that reconnects after a server restart silently reverted to the server-default dialect with no database bound. For table-model sessions this poisons the session: every subsequent statement fails with a SqlParseError (700), and because that is a valid server response rather than a transport error, TableSessionPool keeps the session in the pool. Extract the Configuration-building block into a single helper and call it from all three open paths so the reconnect path sends what open sends and the three cannot drift again. Add a table-driven test for the helper. Verified against apache/iotdb:2.0.3-standalone: a table-model insert on a pooled session that reconnects after `docker restart` fails on the current code and succeeds with this change. Fixes #177 Co-authored-by: Claude <noreply@anthropic.com>
Apache IoTDB (Database for Internet of Things) is an IoT native database with high performance for data management and analysis, deployable on the edge and the cloud. Due to its light-weight architecture, high performance and rich feature set together with its deep integration with Apache Hadoop, Spark and Flink, Apache IoTDB can meet the requirements of massive data storage, high-speed data ingestion and complex data analysis in the IoT industrial fields.
This is the GoLang client of Apache IoTDB.
Apache IoTDB website: https://iotdb.apache.org Apache IoTDB GitHub: https://github.com/apache/iotdb
golang >= 1.25
With go mod
export GO111MODULE=on export GOPROXY=https://goproxy.io mkdir session_example && cd session_example curl -o session_example.go -L https://github.com/apache/iotdb-client-go/raw/main/example/session_example.go go mod init session_example go run session_example.go
Without go mod
# get thrift 0.23.0 go get github.com/apache/thrift cd $GOPATH/src/github.com/apache/thrift git checkout 0.23.0 mkdir -p $GOPATH/src/iotdb-client-go-example/session_example cd $GOPATH/src/iotdb-client-go-example/session_example curl -o session_example.go -L https://github.com/apache/iotdb-client-go/raw/main/example/session_example.go go run session_example.go
Set TLSConfig on client.Config, client.ClusterConfig, or client.PoolConfig to enable TLS. Add CertFile and KeyFile when the server requires mTLS client authentication.
config := &client.Config{ Host: host, Port: port, UserName: user, Password: password, TLSConfig: &client.TLSConfig{ CAFile: "/path/to/ca.pem", CertFile: "/path/to/client.pem", KeyFile: "/path/to/client-key.pem", }, } session := client.NewSession(config) if err := session.Open(false, 0); err != nil { log.Fatal(err) } defer session.Close()
SessionPool is a wrapper of a Session Set. Using SessionPool, the user do not need to consider how to reuse a session connection. If there is no available connections and the pool reaches its max size, the all methods will hang until there is a available connection. The PutBack method must be called after use
standalone
config := &client.PoolConfig{ Host: host, Port: port, UserName: user, Password: password, } sessionPool = client.NewSessionPool(config, 3, 60000, 60000, false)
cluster or doubleLive
config := &client.PoolConfig{ UserName: user, Password: password, NodeUrls: strings.Split("127.0.0.1:6667,127.0.0.1:6668", ","), } sessionPool = client.NewSessionPool(config, 3, 60000, 60000, false)
set storage group
session, err := sessionPool.GetSession() defer sessionPool.PutBack(session) if err == nil { session.SetStorageGroup(sg) }
query statement
var timeout int64 = 1000 session, err := sessionPool.GetSession() defer sessionPool.PutBack(session) if err != nil { log.Print(err) return } sessionDataSet, err := session.ExecuteQueryStatement(sql, &timeout) if err == nil { defer sessionDataSet.Close() printDataSet1(sessionDataSet) } else { log.Println(err) }
In the branch rel/0.13 and earlier versions, the version of apache/thrift is v0.14.1. In the latest version, apache/thrift has been upgraded to v0.23.0.
The two versions are not compatible on some interfaces. Using mismatched version will cause compilation errors.
The interfaces changed in the two versions are as follows:
NewTSocketConf. This function returns two values in the version v0.14.1 and only one value in newer versions.NewTFramedTransport has been deprecated, use NewTFramedTransportConf instead.For more details, please take a look at this PR: thrift compatibility update for IoTDB 0.13.0
The implementation of the function client/session.go/Open() is mismatched with the description. The parameter connectionTimeoutInMs represents connection timeout in milliseconds. However, in the older version, this function did not implement correctly, regarding it as nanosecond instead. The bug is now fixed. Positive value of this parameter means connection timeout in milliseconds. Set 0 for no timeout.