Skip to content

Commit e269bad

Browse files
authored
Fix bugs for rc/1.3.3 (#113)
* Return error when constructing cluster session failed * fix bugs
1 parent a9ebffb commit e269bad

File tree

8 files changed

+51
-34
lines changed

8 files changed

+51
-34
lines changed

Diff for: client/bitmap.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ var UnmarkBitUtil = []byte{
3737
}
3838

3939
func NewBitMap(size int) *BitMap {
40+
// Need to maintain consistency with the calculation method on the IoTDB side.
4041
bitMap := &BitMap{
4142
size: size,
42-
bits: make([]byte, (size+7)/8),
43+
bits: make([]byte, size/8+1),
4344
}
4445
return bitMap
4546
}

Diff for: client/rpcdataset.go

+4
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ func (s *IoTDBRpcDataSet) getColumnType(columnName string) TSDataType {
8989
return s.columnTypeDeduplicatedList[s.getColumnIndex(columnName)]
9090
}
9191

92+
func (s *IoTDBRpcDataSet) isNullWithColumnName(columnName string) bool {
93+
return s.isNull(int(s.getColumnIndex(columnName)), s.rowsIndex-1)
94+
}
95+
9296
func (s *IoTDBRpcDataSet) isNull(columnIndex int, rowIndex int) bool {
9397
if s.closed {
9498
return true

Diff for: client/session.go

+25-27
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type Session struct {
6262
sessionId int64
6363
trans thrift.TTransport
6464
requestStatementId int64
65+
protocolFactory thrift.TProtocolFactory
6566
}
6667

6768
type endPoint struct {
@@ -83,7 +84,6 @@ func (s *Session) Open(enableRPCCompression bool, connectionTimeoutInMs int) err
8384
s.config.ConnectRetryMax = DefaultConnectRetryMax
8485
}
8586

86-
var protocolFactory thrift.TProtocolFactory
8787
var err error
8888

8989
// in thrift 0.14.1, this func returns two values; in thrift 0.15.0, it returns one.
@@ -99,13 +99,10 @@ func (s *Session) Open(enableRPCCompression bool, connectionTimeoutInMs int) err
9999
return err
100100
}
101101
}
102-
if enableRPCCompression {
103-
protocolFactory = thrift.NewTCompactProtocolFactory()
104-
} else {
105-
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
106-
}
107-
iprot := protocolFactory.GetProtocol(s.trans)
108-
oprot := protocolFactory.GetProtocol(s.trans)
102+
s.protocolFactory = getProtocolFactory(enableRPCCompression)
103+
iprot := s.protocolFactory.GetProtocol(s.trans)
104+
oprot := s.protocolFactory.GetProtocol(s.trans)
105+
109106
s.client = rpc.NewIClientRPCServiceClient(thrift.NewTStandardClient(iprot, oprot))
110107
req := rpc.TSOpenSessionReq{ClientProtocol: rpc.TSProtocolVersion_IOTDB_SERVICE_PROTOCOL_V3, ZoneId: s.config.TimeZone, Username: s.config.UserName,
111108
Password: &s.config.Password}
@@ -147,16 +144,11 @@ func (s *Session) OpenCluster(enableRPCCompression bool) error {
147144
s.config.ConnectRetryMax = DefaultConnectRetryMax
148145
}
149146

150-
var protocolFactory thrift.TProtocolFactory
151147
var err error
152148

153-
if enableRPCCompression {
154-
protocolFactory = thrift.NewTCompactProtocolFactory()
155-
} else {
156-
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
157-
}
158-
iprot := protocolFactory.GetProtocol(s.trans)
159-
oprot := protocolFactory.GetProtocol(s.trans)
149+
s.protocolFactory = getProtocolFactory(enableRPCCompression)
150+
iprot := s.protocolFactory.GetProtocol(s.trans)
151+
oprot := s.protocolFactory.GetProtocol(s.trans)
160152
s.client = rpc.NewIClientRPCServiceClient(thrift.NewTStandardClient(iprot, oprot))
161153
req := rpc.TSOpenSessionReq{ClientProtocol: rpc.TSProtocolVersion_IOTDB_SERVICE_PROTOCOL_V3, ZoneId: s.config.TimeZone, Username: s.config.UserName,
162154
Password: &s.config.Password}
@@ -170,14 +162,22 @@ func (s *Session) OpenCluster(enableRPCCompression bool) error {
170162
return err
171163
}
172164

173-
func (s *Session) Close() (r *common.TSStatus, err error) {
165+
func getProtocolFactory(enableRPCCompression bool) thrift.TProtocolFactory {
166+
if enableRPCCompression {
167+
return thrift.NewTCompactProtocolFactoryConf(&thrift.TConfiguration{})
168+
} else {
169+
return thrift.NewTBinaryProtocolFactoryConf(&thrift.TConfiguration{})
170+
}
171+
}
172+
173+
func (s *Session) Close() error {
174174
req := rpc.NewTSCloseSessionReq()
175175
req.SessionId = s.sessionId
176-
_, err = s.client.CloseSession(context.Background(), req)
176+
_, err := s.client.CloseSession(context.Background(), req)
177177
if err != nil {
178-
return nil, err
178+
return err
179179
}
180-
return nil, s.trans.Close()
180+
return s.trans.Close()
181181
}
182182

183183
/*
@@ -1085,7 +1085,7 @@ func NewSession(config *Config) Session {
10851085
return Session{config: config}
10861086
}
10871087

1088-
func NewClusterSession(clusterConfig *ClusterConfig) Session {
1088+
func NewClusterSession(clusterConfig *ClusterConfig) (Session, error) {
10891089
session := Session{}
10901090
node := endPoint{}
10911091
for i := 0; i < len(clusterConfig.NodeUrls); i++ {
@@ -1113,9 +1113,9 @@ func NewClusterSession(clusterConfig *ClusterConfig) Session {
11131113
}
11141114
}
11151115
if !session.trans.IsOpen() {
1116-
log.Fatal("No Server Can Connect")
1116+
return session, fmt.Errorf("no server can connect")
11171117
}
1118-
return session
1118+
return session, nil
11191119
}
11201120

11211121
func (s *Session) initClusterConn(node endPoint) error {
@@ -1148,10 +1148,8 @@ func (s *Session) initClusterConn(node endPoint) error {
11481148
s.config.ConnectRetryMax = DefaultConnectRetryMax
11491149
}
11501150

1151-
var protocolFactory thrift.TProtocolFactory
1152-
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
1153-
iprot := protocolFactory.GetProtocol(s.trans)
1154-
oprot := protocolFactory.GetProtocol(s.trans)
1151+
iprot := s.protocolFactory.GetProtocol(s.trans)
1152+
oprot := s.protocolFactory.GetProtocol(s.trans)
11551153
s.client = rpc.NewIClientRPCServiceClient(thrift.NewTStandardClient(iprot, oprot))
11561154
req := rpc.TSOpenSessionReq{ClientProtocol: rpc.TSProtocolVersion_IOTDB_SERVICE_PROTOCOL_V3, ZoneId: s.config.TimeZone, Username: s.config.UserName,
11571155
Password: &s.config.Password}

Diff for: client/sessiondataset.go

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ func (s *SessionDataSet) GetText(columnName string) string {
4646
return s.ioTDBRpcDataSet.getText(columnName)
4747
}
4848

49+
func (s *SessionDataSet) IsNull(columnName string) bool {
50+
return s.ioTDBRpcDataSet.isNullWithColumnName(columnName)
51+
}
52+
4953
func (s *SessionDataSet) GetBool(columnName string) bool {
5054
return s.ioTDBRpcDataSet.getBool(columnName)
5155
}

Diff for: client/sessionpool.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,11 @@ func (spool *SessionPool) GetSession() (session Session, err error) {
9595

9696
func (spool *SessionPool) ConstructSession(config *PoolConfig) (session Session, err error) {
9797
if len(config.NodeUrls) > 0 {
98-
session = NewClusterSession(getClusterSessionConfig(config))
99-
if err := session.OpenCluster(spool.enableCompression); err != nil {
98+
session, err = NewClusterSession(getClusterSessionConfig(config))
99+
if err != nil {
100+
return session, err
101+
}
102+
if err = session.OpenCluster(spool.enableCompression); err != nil {
100103
log.Print(err)
101104
return session, err
102105
}

Diff for: client/tablet.go

+2
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ func (t *Tablet) SetValueAt(value interface{}, columnIndex, rowIndex int) error
119119
}
120120
// Mark the nil value position
121121
t.bitMaps[columnIndex].Mark(rowIndex)
122+
return nil
122123
}
123124

124125
switch t.measurementSchemas[columnIndex].DataType {
@@ -296,6 +297,7 @@ func (t *Tablet) getValuesBytes() ([]byte, error) {
296297
columnHasNil := bitMap != nil && !bitMap.IsAllUnmarked()
297298
binary.Write(buff, binary.BigEndian, columnHasNil)
298299
if columnHasNil {
300+
// Need to maintain consistency with the calculation method on the IoTDB side.
299301
binary.Write(buff, binary.BigEndian, bitMap.GetBits()[0:t.RowSize/8+1])
300302
}
301303
}

Diff for: example/session_example.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,11 @@ func connectCluster() {
152152
UserName: "root",
153153
Password: "root",
154154
}
155-
session = client.NewClusterSession(config)
156-
if err := session.OpenCluster(false); err != nil {
155+
session, err := client.NewClusterSession(config)
156+
if err != nil {
157+
log.Fatal(err)
158+
}
159+
if err = session.OpenCluster(false); err != nil {
157160
log.Fatal(err)
158161
}
159162
}

Diff for: test/e2e/e2e_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ func (s *e2eTestSuite) SetupSuite() {
4747
UserName: "root",
4848
Password: "root",
4949
}
50-
s.session = client.NewClusterSession(&clusterConfig)
51-
err := s.session.Open(false, 0)
50+
session, err := client.NewClusterSession(&clusterConfig)
51+
s.Require().NoError(err)
52+
s.session = session
53+
err = s.session.Open(false, 0)
5254
s.Require().NoError(err)
5355
}
5456

0 commit comments

Comments
 (0)