Skip to content

Commit

Permalink
enhance session pool
Browse files Browse the repository at this point in the history
  • Loading branch information
HarrisChu committed Aug 24, 2023
1 parent 8fca693 commit 9eb1fa0
Show file tree
Hide file tree
Showing 8 changed files with 428 additions and 150 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ down:

ssl-test:
ssl_test=true go test -v --tags=integration -run TestSslConnection;
ssl_test=true go test -v --tags=integration -run TestSslSessionPool;

ssl-test-self-signed:
self_signed=true go test -v --tags=integration -run TestSslConnection;
Expand Down
13 changes: 2 additions & 11 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,10 @@ func (cn *connection) executeWithParameter(sessionID int64, stmt string,
params map[string]*nebula.Value) (*graph.ExecutionResponse, error) {
resp, err := cn.graph.ExecuteWithParameter(sessionID, []byte(stmt), params)
if err != nil {
// reopen the connection if timeout
if _, ok := err.(thrift.TransportException); ok {
if err.(thrift.TransportException).TypeID() == thrift.TIMED_OUT {
reopenErr := cn.reopen()
if reopenErr != nil {
return nil, reopenErr
}
return cn.graph.ExecuteWithParameter(sessionID, []byte(stmt), params)
}
}
return nil, err
}

return resp, err
return resp, nil
}

func (cn *connection) executeJson(sessionID int64, stmt string) ([]byte, error) {
Expand Down
1 change: 0 additions & 1 deletion connection_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ func (pool *ConnectionPool) GetSession(username, password string) (*Session, err
sessionID: sessID,
connection: conn,
connPool: pool,
sessPool: nil,
log: pool.log,
timezoneInfo: timezoneInfo{timezoneOffset, timezoneName},
}
Expand Down
8 changes: 8 additions & 0 deletions nebula-docker-compose/docker-compose-ssl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,14 @@ services:
-e 'ADD HOSTS "storaged0":44500,"storaged1":44500,"storaged2":44500'`;
if [[ $$? == 0 ]];then
echo "Hosts added successfully"
sleep 2;
nebula-console -addr graphd0 -port 3699 -u root -p nebula \
-enable_ssl=true \
-ssl_root_ca_path /secrets/root.crt \
-ssl_cert_path /secrets/client.crt \
-ssl_private_key_path /secrets/client.key \
--ssl_insecure_skip_verify=true \
-e 'CREATE SPACE session_pool(partition_num=4, replica_factor=1, vid_type = FIXED_STRING(30))'
break;
fi;
sleep 1;
Expand Down
11 changes: 4 additions & 7 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ package nebula_go
import (
"fmt"
"sync"
"time"

"github.com/vesoft-inc/nebula-go/v3/nebula"
graph "github.com/vesoft-inc/nebula-go/v3/nebula/graph"
Expand All @@ -26,9 +25,7 @@ type Session struct {
sessionID int64
connection *connection
connPool *ConnectionPool // the connection pool which the session belongs to. could be nil if the Session is store in the SessionPool
sessPool *SessionPool // the session pool which the session belongs to. could be nil if the Session is store in the ConnectionPool
log Logger
returnedAt time.Time // the timestamp that the session was created or returned.
mu sync.Mutex
timezoneInfo
}
Expand Down Expand Up @@ -228,6 +225,10 @@ func (session *Session) GetSessionID() int64 {
return session.sessionID
}

func IsError(resp *graph.ExecutionResponse) bool {
return resp.GetErrorCode() != nebula.ErrorCode_SUCCEEDED
}

// Ping checks if the session is valid
func (session *Session) Ping() error {
if session.connection == nil {
Expand All @@ -246,10 +247,6 @@ func (session *Session) Ping() error {
return nil
}

func IsError(resp *graph.ExecutionResponse) bool {
return resp.GetErrorCode() != nebula.ErrorCode_SUCCEEDED
}

// construct Slice to nebula.NList
func slice2Nlist(list []interface{}) (*nebula.NList, error) {
sv := []*nebula.Value{}
Expand Down
Loading

0 comments on commit 9eb1fa0

Please sign in to comment.