Skip to content

Commit bb812b8

Browse files
authored
Fix ClusterSessionInit
1 parent bf6a3e3 commit bb812b8

File tree

4 files changed

+51
-51
lines changed

4 files changed

+51
-51
lines changed

client/session.go

+12-14
Original file line numberDiff line numberDiff line change
@@ -1137,23 +1137,21 @@ func NewClusterSession(clusterConfig *ClusterConfig) Session {
11371137
session.trans = thrift.NewTSocketConf(net.JoinHostPort(e.Value.(endPoint).Host, e.Value.(endPoint).Port), &thrift.TConfiguration{
11381138
ConnectTimeout: time.Duration(0), // Use 0 for no timeout
11391139
})
1140-
if err == nil {
1141-
// session.trans = thrift.NewTFramedTransport(session.trans) // deprecated
1142-
var tmp_conf = thrift.TConfiguration{MaxFrameSize: thrift.DEFAULT_MAX_FRAME_SIZE}
1143-
session.trans = thrift.NewTFramedTransportConf(session.trans, &tmp_conf)
1144-
if !session.trans.IsOpen() {
1145-
err = session.trans.Open()
1146-
if err != nil {
1147-
log.Println(err)
1148-
} else {
1149-
session.config = getConfig(e.Value.(endPoint).Host, e.Value.(endPoint).Port,
1150-
clusterConfig.UserName, clusterConfig.Password, clusterConfig.FetchSize, clusterConfig.TimeZone, clusterConfig.ConnectRetryMax)
1151-
break
1152-
}
1140+
// session.trans = thrift.NewTFramedTransport(session.trans) // deprecated
1141+
var tmp_conf = thrift.TConfiguration{MaxFrameSize: thrift.DEFAULT_MAX_FRAME_SIZE}
1142+
session.trans = thrift.NewTFramedTransportConf(session.trans, &tmp_conf)
1143+
if !session.trans.IsOpen() {
1144+
err = session.trans.Open()
1145+
if err != nil {
1146+
log.Println(err)
1147+
} else {
1148+
session.config = getConfig(e.Value.(endPoint).Host, e.Value.(endPoint).Port,
1149+
clusterConfig.UserName, clusterConfig.Password, clusterConfig.FetchSize, clusterConfig.TimeZone, clusterConfig.ConnectRetryMax)
1150+
break
11531151
}
11541152
}
11551153
}
1156-
if err != nil {
1154+
if !session.trans.IsOpen() {
11571155
log.Fatal("No Server Can Connect")
11581156
}
11591157
return session

example/session_example.go

+15-13
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ func main() {
5757
}
5858
defer session.Close()
5959

60+
//connectCluster()
61+
6062
setStorageGroup("root.ln1")
6163
deleteStorageGroup("root.ln1")
6264

@@ -143,6 +145,19 @@ func main() {
143145
deleteTimeseries("root.ln.device1.*")
144146
}
145147

148+
// If your IotDB is a cluster version, you can use the following code for multi node connection
149+
func connectCluster() {
150+
config := &client.ClusterConfig{
151+
NodeUrls: strings.Split("127.0.0.1:6667,127.0.0.1:6668,127.0.0.1:6669", ","),
152+
UserName: "root",
153+
Password: "root",
154+
}
155+
session = client.NewClusterSession(config)
156+
if err := session.OpenCluster(false); err != nil {
157+
log.Fatal(err)
158+
}
159+
}
160+
146161
func printDevice1(sds *client.SessionDataSet) {
147162
showTimestamp := !sds.IsIgnoreTimeStamp()
148163
if showTimestamp {
@@ -667,16 +682,3 @@ func checkError(status *common.TSStatus, err error) {
667682
}
668683
}
669684
}
670-
671-
// If your IotDB is a cluster version, you can use the following code for multi node connection
672-
func connectCluster() {
673-
config := &client.ClusterConfig{
674-
NodeUrls: strings.Split("127.0.0.1:6667,127.0.0.1:6668,127.0.0.1:6669", ","),
675-
UserName: "root",
676-
Password: "root",
677-
}
678-
session = client.NewClusterSession(config)
679-
if err := session.OpenCluster(false); err != nil {
680-
log.Fatal(err)
681-
}
682-
}

example/session_pool/session_pool_example.go

+20-19
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func main() {
6767
}()
6868

6969
}
70+
//useNodeUrls()
7071
setStorageGroup("root.ln1")
7172
setStorageGroup("root.ln2")
7273
deleteStorageGroups("root.ln1", "root.ln2")
@@ -139,6 +140,25 @@ func main() {
139140

140141
}
141142

143+
// If your IoTDB is a cluster version, you can use the following code for session pool connection
144+
func useNodeUrls() {
145+
146+
config := &client.PoolConfig{
147+
UserName: user,
148+
Password: password,
149+
NodeUrls: strings.Split("127.0.0.1:6667,127.0.0.1:6668", ","),
150+
}
151+
sessionPool = client.NewSessionPool(config, 3, 60000, 60000, false)
152+
defer sessionPool.Close()
153+
session, err := sessionPool.GetSession()
154+
defer sessionPool.PutBack(session)
155+
if err != nil {
156+
log.Print(err)
157+
return
158+
}
159+
160+
}
161+
142162
func setStorageGroup(sg string) {
143163
session, err := sessionPool.GetSession()
144164
defer sessionPool.PutBack(session)
@@ -762,22 +782,3 @@ func checkError(status *common.TSStatus, err error) {
762782
}
763783
}
764784
}
765-
766-
// If your IotDB is a cluster version or doubleLive, you can use the following code for session pool connection
767-
func useSessionPool() {
768-
769-
config := &client.PoolConfig{
770-
UserName: user,
771-
Password: password,
772-
NodeUrls: strings.Split("127.0.0.1:6667,127.0.0.1:6668", ","),
773-
}
774-
sessionPool = client.NewSessionPool(config, 3, 60000, 60000, false)
775-
defer sessionPool.Close()
776-
session, err := sessionPool.GetSession()
777-
defer sessionPool.PutBack(session)
778-
if err != nil {
779-
log.Print(err)
780-
return
781-
}
782-
783-
}

test/e2e/e2e_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/apache/iotdb-client-go/common"
2525
"log"
2626
"math/rand"
27+
"strings"
2728
"testing"
2829
"time"
2930

@@ -41,14 +42,12 @@ func TestE2ETestSuite(t *testing.T) {
4142
}
4243

4344
func (s *e2eTestSuite) SetupSuite() {
44-
config := &client.Config{
45-
Host: "iotdb",
46-
Port: "6667",
45+
clusterConfig := client.ClusterConfig{
46+
NodeUrls: strings.Split("iotdb:6668,iotdb:6667,iotdb:6669", ","),
4747
UserName: "root",
4848
Password: "root",
4949
}
50-
51-
s.session = client.NewSession(config)
50+
s.session = client.NewClusterSession(&clusterConfig)
5251
err := s.session.Open(false, 0)
5352
s.Require().NoError(err)
5453
}

0 commit comments

Comments
 (0)