Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opt go client #110

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions client/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ const (
var errLength = errors.New("deviceIds, times, measurementsList and valuesList's size should be equal")

type Config struct {
Host string
Port string
UserName string
Password string
FetchSize int32
TimeZone string
ConnectRetryMax int
Host string
Port string
UserName string
Password string
FetchSize int32
TimeZone string
ConnectRetryMax int
enableRPCCompression bool
}

type Session struct {
Expand Down Expand Up @@ -99,11 +100,8 @@ func (s *Session) Open(enableRPCCompression bool, connectionTimeoutInMs int) err
return err
}
}
if enableRPCCompression {
protocolFactory = thrift.NewTCompactProtocolFactory()
} else {
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
}
s.config.enableRPCCompression = enableRPCCompression
protocolFactory = getProtocolFactory(enableRPCCompression)
iprot := protocolFactory.GetProtocol(s.trans)
oprot := protocolFactory.GetProtocol(s.trans)
s.client = rpc.NewIClientRPCServiceClient(thrift.NewTStandardClient(iprot, oprot))
Expand Down Expand Up @@ -150,11 +148,8 @@ func (s *Session) OpenCluster(enableRPCCompression bool) error {
var protocolFactory thrift.TProtocolFactory
var err error

if enableRPCCompression {
protocolFactory = thrift.NewTCompactProtocolFactory()
} else {
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
}
s.config.enableRPCCompression = enableRPCCompression
protocolFactory = getProtocolFactory(enableRPCCompression)
iprot := protocolFactory.GetProtocol(s.trans)
oprot := protocolFactory.GetProtocol(s.trans)
s.client = rpc.NewIClientRPCServiceClient(thrift.NewTStandardClient(iprot, oprot))
Expand All @@ -170,6 +165,14 @@ func (s *Session) OpenCluster(enableRPCCompression bool) error {
return err
}

func getProtocolFactory(enableRPCCompression bool) thrift.TProtocolFactory {
if enableRPCCompression {
return thrift.NewTCompactProtocolFactoryConf(&thrift.TConfiguration{})
} else {
return thrift.NewTBinaryProtocolFactoryConf(&thrift.TConfiguration{})
}
}

func (s *Session) Close() (r *common.TSStatus, err error) {
req := rpc.NewTSCloseSessionReq()
req.SessionId = s.sessionId
Expand Down Expand Up @@ -1149,7 +1152,7 @@ func (s *Session) initClusterConn(node endPoint) error {
}

var protocolFactory thrift.TProtocolFactory
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
protocolFactory = getProtocolFactory(s.config.enableRPCCompression)
iprot := protocolFactory.GetProtocol(s.trans)
oprot := protocolFactory.GetProtocol(s.trans)
s.client = rpc.NewIClientRPCServiceClient(thrift.NewTStandardClient(iprot, oprot))
Expand Down
Loading
Loading