Skip to content

Commit

Permalink
Split retry and timeout error (#357)
Browse files Browse the repository at this point in the history
* split retry times for session and error

* update errorcode

* feat: add int64 param (#348)

* feat: add int64 param

close: #288

* ci: use docker compose as ci runner dropped docker-compose

* fix: use test_client to test int64 param instead

* fix example for int64 test

- also hardcode the container name for test

* address Haris' comment

* update error log

* add test case for retry

* update

* update

---------

Co-authored-by: Wey Gu <[email protected]>
  • Loading branch information
HarrisChu and wey-gu authored Sep 24, 2024
1 parent ddc78ec commit fe239fa
Show file tree
Hide file tree
Showing 9 changed files with 725 additions and 72 deletions.
106 changes: 90 additions & 16 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1117,16 +1117,29 @@ func TestExecuteWithParameter(t *testing.T) {
// Load data
loadTestData(t, session)

// p1:true p2:3 p3:[true,3] p4:{"a":true,"b":"Bob"}
// Update the params map
params := make(map[string]interface{})
params["p1"] = true
params["p2"] = 3
params["p3"] = []interface{}{true, 3}
params["p4"] = map[string]interface{}{"a": true, "b": "Bob"}
params["p5"] = int64(9223372036854775807) // Max int64
params["p6"] = int64(-9223372036854775808) // Min int64
params["p7"] = int64(42) // Normal int64 value

// Simple result
{
resp, err := tryToExecuteWithParameter(session, "RETURN toBoolean($p1) and false, $p2+3, $p3[1]>3", params)
query := `RETURN
toBoolean($p1) and false,
$p2+3,
$p3[1]>3,
$p5,
$p6,
$p7,
$p5 + 1 AS overflow_add,
$p6 - 1 AS overflow_subtract,
$p7 * 2 AS normal_multiply`
resp, err := tryToExecuteWithParameter(session, query, params)
if err != nil {
t.Fatalf(err.Error())
return
Expand All @@ -1137,6 +1150,9 @@ func TestExecuteWithParameter(t *testing.T) {
t.Fatalf(err.Error())
return
}

// Test existing cases
// col0 toBoolean($p1) and false, p1 = true
valWrap, err := record.GetValueByIndex(0)
if err != nil {
t.Fatalf(err.Error())
Expand All @@ -1147,9 +1163,9 @@ func TestExecuteWithParameter(t *testing.T) {
t.Fatalf(err.Error())
return
}
assert.Equal(t,
false,
col1)
assert.Equal(t, false, col1)

// col1 $p2+3, p2 = 3
valWrap, err = record.GetValueByIndex(1)
if err != nil {
t.Fatalf(err.Error())
Expand All @@ -1160,9 +1176,9 @@ func TestExecuteWithParameter(t *testing.T) {
t.Fatalf(err.Error())
return
}
assert.Equal(t,
int64(6),
col2)
assert.Equal(t, int64(6), col2)

// col2 $p3[1]>3, p3 = [true,3]
valWrap, err = record.GetValueByIndex(2)
if err != nil {
t.Fatalf(err.Error())
Expand All @@ -1173,22 +1189,80 @@ func TestExecuteWithParameter(t *testing.T) {
t.Fatalf(err.Error())
return
}
assert.Equal(t,
false,
col3)
valWrap, err = record.GetValueByIndex(2)
assert.Equal(t, false, col3)

// Test int64 cases
// Max int64
valWrap, err = record.GetValueByIndex(3)
if err != nil {
t.Fatalf(err.Error())
return
}
col3, err = valWrap.AsBool()
assert.False(t, valWrap.IsNull())
maxInt64, err := valWrap.AsInt()
if err != nil {
t.Fatalf(err.Error())
return
}
assert.Equal(t,
false,
col3)
assert.Equal(t, int64(9223372036854775807), maxInt64)

// Min int64
valWrap, err = record.GetValueByIndex(4)
if err != nil {
t.Fatalf(err.Error())
return
}
assert.False(t, valWrap.IsNull())
minInt64, err := valWrap.AsInt()
if err != nil {
t.Fatalf(err.Error())
return
}
assert.Equal(t, int64(-9223372036854775808), minInt64)

// Normal int64
valWrap, err = record.GetValueByIndex(5)
if err != nil {
t.Fatalf(err.Error())
return
}
assert.False(t, valWrap.IsNull())
normalInt64, err := valWrap.AsInt()
if err != nil {
t.Fatalf(err.Error())
return
}
assert.Equal(t, int64(42), normalInt64)

// Overflow addition
valWrap, err = record.GetValueByIndex(6)
if err != nil {
t.Fatalf(err.Error())
return
}
assert.True(t, valWrap.IsNull(), "Overflow addition should result in null")

// Overflow subtraction
valWrap, err = record.GetValueByIndex(7)
if err != nil {
t.Fatalf(err.Error())
return
}
assert.True(t, valWrap.IsNull(), "Overflow subtraction should result in null")

// Normal multiplication
valWrap, err = record.GetValueByIndex(8)
if err != nil {
t.Fatalf(err.Error())
return
}
assert.False(t, valWrap.IsNull())
normalMultiply, err := valWrap.AsInt()
if err != nil {
t.Fatalf(err.Error())
return
}
assert.Equal(t, int64(84), normalMultiply)
}
// Complex result
{
Expand Down
16 changes: 14 additions & 2 deletions configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ type SessionPoolConf struct {
hostIndex int // index of the host in ServiceAddrs that the next new session will connect to
spaceName string // The space name that all sessions in the pool are bound to
sslConfig *tls.Config // Optional SSL config for the connection
retryGetSessionTimes int // The max times to retry get new session when executing a query
retryGetSessionTimes int // The max times to retry when execute a query and get invalid session
retryErrorTimes int // The max times to retry when execute a query and get a error

// Basic pool configs
// Socket timeout and Socket connection timeout, unit: seconds
Expand Down Expand Up @@ -159,6 +160,7 @@ func NewSessionPoolConf(
serviceAddrs: serviceAddrs,
spaceName: spaceName,
retryGetSessionTimes: 1,
retryErrorTimes: 1,
timeOut: 0 * time.Millisecond,
idleTime: 0 * time.Millisecond,
maxSize: 30,
Expand Down Expand Up @@ -224,7 +226,8 @@ func WithHandshakeKey(handshakeKey string) SessionPoolConfOption {
conf.handshakeKey = handshakeKey
}
}
func WithRetryTimes(retryTimes int) SessionPoolConfOption {

func WithSessionRetryTimes(retryTimes int) SessionPoolConfOption {
if retryTimes < 0 {
retryTimes = 0
}
Expand All @@ -233,6 +236,15 @@ func WithRetryTimes(retryTimes int) SessionPoolConfOption {
}
}

func WithErrorRetryTimes(retryTimes int) SessionPoolConfOption {
if retryTimes < 0 {
retryTimes = 0
}
return func(conf *SessionPoolConf) {
conf.retryErrorTimes = retryTimes
}
}

func (conf *SessionPoolConf) checkMandatoryFields() error {
// Check mandatory fields
if conf.username == "" {
Expand Down
16 changes: 15 additions & 1 deletion examples/parameter_example/parameter_example.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ func main() {
params["p2"] = 3
params["p3"] = []interface{}{true, 3}
params["p4"] = map[string]interface{}{"a": true, "b": 3}
params["p5"] = int64(9223372036854775807)

// Extract data from the resultSet
{
query := "RETURN abs($p2)+1 AS col1, toBoolean($p1) and false AS col2, $p3, $p4.a"
query := "RETURN abs($p2)+1 AS col1, toBoolean($p1) and false AS col2, $p3, $p4.a, $p5 AS col5"
// Send query
// resultSet, err := session.ExecuteWithParameter(query, params)
resultSet, err := session.ExecuteWithParameter(query, params)
Expand All @@ -90,6 +91,19 @@ func main() {
}
// Print whole row
fmt.Printf("The first row elements: %s\n", record.String())

// Specifically check the int64 value
valWrap, err := record.GetValueByIndex(4) // Column 'col5'
if err != nil {
log.Error(err.Error())
} else {
int64Val, err := valWrap.AsInt()
if err != nil {
log.Error(err.Error())
} else {
fmt.Printf("The int64 value (col5): %d\n", int64Val)
}
}
}
}(&wg)
wg.Wait()
Expand Down
1 change: 0 additions & 1 deletion nebula-docker-compose/docker-compose-ssl.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.4'
services:
metad0:
image: vesoft/nebula-metad:v3
Expand Down
4 changes: 3 additions & 1 deletion nebula-docker-compose/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.4'
services:
metad0:
image: vesoft/nebula-metad:nightly
Expand Down Expand Up @@ -266,6 +265,7 @@ services:

graphd0:
image: vesoft/nebula-graphd:nightly
container_name: nebula-docker-compose_graphd0_1
environment:
USER: root
TZ: "${TZ}"
Expand Down Expand Up @@ -314,6 +314,7 @@ services:

graphd1:
image: vesoft/nebula-graphd:nightly
container_name: nebula-docker-compose_graphd1_1
environment:
USER: root
TZ: "${TZ}"
Expand Down Expand Up @@ -362,6 +363,7 @@ services:

graphd2:
image: vesoft/nebula-graphd:nightly
container_name: nebula-docker-compose_graphd2_1
environment:
USER: root
TZ: "${TZ}"
Expand Down
Loading

0 comments on commit fe239fa

Please sign in to comment.