Skip to content

Commit a82f715

Browse files
committed
code-health: update format for Call to 1.7
An incompatible change was introduced in Tarantool 1.7 which was released in 2016. This change is about a new binary protocol command for CALL, which no more restricts a function to returning an array of tuples and allows returning an arbitrary MsgPack/JSON result, including scalars, nil and void (nothing). We should be in-line with tarantool here and provide `Call17` as just `Call` and rename current `Call` to `Call16`. Closes #125
1 parent cb9f156 commit a82f715

11 files changed

+70
-72
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
2424

2525
### Changed
2626

27+
- Breaking change: rename `Call` to `Call16` and `Call17` to `Call` (#125)
2728
- Handle everything with `go test` (#115)
2829
- Use plain package instead of module for UUID submodule (#134)
2930
- Reset buffer if its average use size smaller than quater of capacity (#95)

connection.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ func (d defaultLogger) Report(event ConnLogKind, conn *Connection, v ...interfac
111111
//
112112
// ATTENTION: result argument for *Typed methods should deserialize from
113113
// msgpack array, cause Tarantool always returns result as an array.
114-
// For all space related methods and Call* (but not Call17*) methods Tarantool
114+
// For all space related methods and Call16* (but not Call*) methods Tarantool
115115
// always returns array of array (array of tuples for space related methods).
116-
// For Eval* and Call17* Tarantool always returns array, but does not forces
116+
// For Eval* and Call* Tarantool always returns array, but does not forces
117117
// array of arrays.
118118
type Connection struct {
119119
addr string

connector.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ type Connector interface {
1414
Delete(space, index interface{}, key interface{}) (resp *Response, err error)
1515
Update(space, index interface{}, key, ops interface{}) (resp *Response, err error)
1616
Upsert(space interface{}, tuple, ops interface{}) (resp *Response, err error)
17+
Call16(functionName string, args interface{}) (resp *Response, err error)
1718
Call(functionName string, args interface{}) (resp *Response, err error)
18-
Call17(functionName string, args interface{}) (resp *Response, err error)
1919
Eval(expr string, args interface{}) (resp *Response, err error)
2020

2121
GetTyped(space, index interface{}, key interface{}, result interface{}) (err error)
@@ -24,8 +24,8 @@ type Connector interface {
2424
ReplaceTyped(space interface{}, tuple interface{}, result interface{}) (err error)
2525
DeleteTyped(space, index interface{}, key interface{}, result interface{}) (err error)
2626
UpdateTyped(space, index interface{}, key, ops interface{}, result interface{}) (err error)
27+
Call16Typed(functionName string, args interface{}, result interface{}) (err error)
2728
CallTyped(functionName string, args interface{}, result interface{}) (err error)
28-
Call17Typed(functionName string, args interface{}, result interface{}) (err error)
2929
EvalTyped(expr string, args interface{}, result interface{}) (err error)
3030

3131
SelectAsync(space, index interface{}, offset, limit, iterator uint32, key interface{}) *Future
@@ -34,7 +34,7 @@ type Connector interface {
3434
DeleteAsync(space, index interface{}, key interface{}) *Future
3535
UpdateAsync(space, index interface{}, key, ops interface{}) *Future
3636
UpsertAsync(space interface{}, tuple interface{}, ops interface{}) *Future
37+
Call16Async(functionName string, args interface{}) *Future
3738
CallAsync(functionName string, args interface{}) *Future
38-
Call17Async(functionName string, args interface{}) *Future
3939
EvalAsync(expr string, args interface{}) *Future
4040
}

const.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ const (
66
ReplaceRequest = 3
77
UpdateRequest = 4
88
DeleteRequest = 5
9-
CallRequest = 6 /* call in 1.6 format */
9+
Call16Request = 6 /* call in 1.6 format */
1010
AuthRequest = 7
1111
EvalRequest = 8
1212
UpsertRequest = 9
13-
Call17Request = 10
13+
CallRequest = 10 /* call in >=1.7 format */
1414
PingRequest = 64
1515
SubscribeRequest = 66
1616

example_custom_unpacking_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func Example_customUnpacking() {
117117
fmt.Println("Tuples (tuples2):", tuples2)
118118

119119
// Call a function "func_name" returning a table of custom tuples.
120-
var tuples3 []Tuple3
120+
var tuples3 [][]Tuple3
121121
err = conn.CallTyped("func_name", []interface{}{}, &tuples3)
122122
if err != nil {
123123
log.Fatalf("Failed to CallTyped: %s", err.Error())
@@ -130,6 +130,6 @@ func Example_customUnpacking() {
130130
// Code 0
131131
// Tuples (tuples1) [{777 orig [{lol 1} {wut 3}]}]
132132
// Tuples (tuples2): [{{} 777 orig [{lol 1} {wut 3}]}]
133-
// Tuples (tuples3): [{{} 221 [{Moscow 34} {Minsk 23} {Kiev 31}]}]
133+
// Tuples (tuples3): [[{{} 221 [{Moscow 34} {Minsk 23} {Kiev 31}]}]]
134134

135135
}

example_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,12 @@ func ExampleConnection_Update() {
253253
// Data [[14 bye bla]]
254254
}
255255

256-
func ExampleConnection_Call17() {
256+
func ExampleConnection_Call() {
257257
conn := example_connect()
258258
defer conn.Close()
259259

260260
// Call a function 'simple_incr' with arguments.
261-
resp, err := conn.Call17("simple_incr", []interface{}{1})
261+
resp, err := conn.Call("simple_incr", []interface{}{1})
262262
fmt.Println("Call simple_incr()")
263263
fmt.Println("Error", err)
264264
fmt.Println("Code", resp.Code)

multi/multi.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func (connMulti *ConnectionMulti) checker() {
186186
continue
187187
}
188188
var resp [][]string
189-
err := connMulti.Call17Typed(connMulti.opts.NodesGetFunctionName, []interface{}{}, &resp)
189+
err := connMulti.CallTyped(connMulti.opts.NodesGetFunctionName, []interface{}{}, &resp)
190190
if err != nil {
191191
continue
192192
}
@@ -321,18 +321,18 @@ func (connMulti *ConnectionMulti) Upsert(space interface{}, tuple, ops interface
321321
return connMulti.getCurrentConnection().Upsert(space, tuple, ops)
322322
}
323323

324-
// Call calls registered Tarantool function.
324+
// Call16 calls registered Tarantool function.
325325
// It uses request code for Tarantool 1.6, so result is converted to array of
326326
// arrays.
327-
func (connMulti *ConnectionMulti) Call(functionName string, args interface{}) (resp *tarantool.Response, err error) {
328-
return connMulti.getCurrentConnection().Call(functionName, args)
327+
func (connMulti *ConnectionMulti) Call16(functionName string, args interface{}) (resp *tarantool.Response, err error) {
328+
return connMulti.getCurrentConnection().Call16(functionName, args)
329329
}
330330

331-
// Call17 calls registered Tarantool function.
332-
// It uses request code for Tarantool 1.7, so result is not converted
331+
// Call calls registered Tarantool function.
332+
// It uses request code for Tarantool >=1.7, so result is not converted
333333
// (though, keep in mind, result is always array).
334-
func (connMulti *ConnectionMulti) Call17(functionName string, args interface{}) (resp *tarantool.Response, err error) {
335-
return connMulti.getCurrentConnection().Call17(functionName, args)
334+
func (connMulti *ConnectionMulti) Call(functionName string, args interface{}) (resp *tarantool.Response, err error) {
335+
return connMulti.getCurrentConnection().Call(functionName, args)
336336
}
337337

338338
// Eval passes Lua expression for evaluation.
@@ -375,18 +375,18 @@ func (connMulti *ConnectionMulti) UpdateTyped(space, index interface{}, key, ops
375375
return connMulti.getCurrentConnection().UpdateTyped(space, index, key, ops, result)
376376
}
377377

378-
// CallTyped calls registered function.
378+
// Call16Typed calls registered function.
379379
// It uses request code for Tarantool 1.6, so result is converted to array of
380380
// arrays.
381-
func (connMulti *ConnectionMulti) CallTyped(functionName string, args interface{}, result interface{}) (err error) {
382-
return connMulti.getCurrentConnection().CallTyped(functionName, args, result)
381+
func (connMulti *ConnectionMulti) Call16Typed(functionName string, args interface{}, result interface{}) (err error) {
382+
return connMulti.getCurrentConnection().Call16Typed(functionName, args, result)
383383
}
384384

385-
// Call17Typed calls registered function.
386-
// It uses request code for Tarantool 1.7, so result is not converted (though,
385+
// CallTyped calls registered function.
386+
// It uses request code for Tarantool >=1.7, so result is not converted (though,
387387
// keep in mind, result is always array)
388-
func (connMulti *ConnectionMulti) Call17Typed(functionName string, args interface{}, result interface{}) (err error) {
389-
return connMulti.getCurrentConnection().Call17Typed(functionName, args, result)
388+
func (connMulti *ConnectionMulti) CallTyped(functionName string, args interface{}, result interface{}) (err error) {
389+
return connMulti.getCurrentConnection().CallTyped(functionName, args, result)
390390
}
391391

392392
// EvalTyped passes Lua expression for evaluation.
@@ -429,18 +429,18 @@ func (connMulti *ConnectionMulti) UpsertAsync(space interface{}, tuple interface
429429
return connMulti.getCurrentConnection().UpsertAsync(space, tuple, ops)
430430
}
431431

432-
// CallAsync sends a call to registered Tarantool function and returns Future.
432+
// Call16Async sends a call to registered Tarantool function and returns Future.
433433
// It uses request code for Tarantool 1.6, so future's result is always array
434434
// of arrays.
435-
func (connMulti *ConnectionMulti) CallAsync(functionName string, args interface{}) *tarantool.Future {
436-
return connMulti.getCurrentConnection().CallAsync(functionName, args)
435+
func (connMulti *ConnectionMulti) Call16Async(functionName string, args interface{}) *tarantool.Future {
436+
return connMulti.getCurrentConnection().Call16Async(functionName, args)
437437
}
438438

439-
// Call17Async sends a call to registered Tarantool function and returns Future.
440-
// It uses request code for Tarantool 1.7, so future's result will not be converted
439+
// CallAsync sends a call to registered Tarantool function and returns Future.
440+
// It uses request code for Tarantool >=1.7, so future's result will not be converted
441441
// (though, keep in mind, result is always array).
442-
func (connMulti *ConnectionMulti) Call17Async(functionName string, args interface{}) *tarantool.Future {
443-
return connMulti.getCurrentConnection().Call17Async(functionName, args)
442+
func (connMulti *ConnectionMulti) CallAsync(functionName string, args interface{}) *tarantool.Future {
443+
return connMulti.getCurrentConnection().CallAsync(functionName, args)
444444
}
445445

446446
// EvalAsync passes Lua expression for evaluation.

queue/queue.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ func (q *queue) Kick(count uint64) (uint64, error) {
289289
resp, err := q.conn.Call(q.cmds.kick, []interface{}{count})
290290
var id uint64
291291
if err == nil {
292-
id = resp.Data[0].([]interface{})[0].(uint64)
292+
id = resp.Data[0].(uint64)
293293
}
294294
return id, err
295295
}
@@ -309,10 +309,7 @@ func (q *queue) Statistic() (interface{}, error) {
309309
}
310310

311311
if len(resp.Data) != 0 {
312-
data, ok := resp.Data[0].([]interface{})
313-
if ok && len(data) != 0 {
314-
return data[0], nil
315-
}
312+
return resp.Data[0], nil
316313
}
317314

318315
return nil, nil

request.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,21 @@ func (conn *Connection) Upsert(space interface{}, tuple, ops interface{}) (resp
9696
return conn.UpsertAsync(space, tuple, ops).Get()
9797
}
9898

99-
// Call calls registered Tarantool function.
99+
// Call16 calls registered Tarantool function.
100100
// It uses request code for Tarantool 1.6, so result is converted to array of arrays
101101
//
102-
// It is equal to conn.CallAsync(functionName, args).Get().
103-
func (conn *Connection) Call(functionName string, args interface{}) (resp *Response, err error) {
104-
return conn.CallAsync(functionName, args).Get()
102+
// It is equal to conn.Call16Async(functionName, args).Get().
103+
func (conn *Connection) Call16(functionName string, args interface{}) (resp *Response, err error) {
104+
return conn.Call16Async(functionName, args).Get()
105105
}
106106

107-
// Call17 calls registered Tarantool function.
108-
// It uses request code for Tarantool 1.7, so result is not converted
107+
// Call calls registered Tarantool function.
108+
// It uses request code for Tarantool >=1.7, so result is not converted
109109
// (though, keep in mind, result is always array)
110110
//
111-
// It is equal to conn.Call17Async(functionName, args).Get().
112-
func (conn *Connection) Call17(functionName string, args interface{}) (resp *Response, err error) {
113-
return conn.Call17Async(functionName, args).Get()
111+
// It is equal to conn.CallAsync(functionName, args).Get().
112+
func (conn *Connection) Call(functionName string, args interface{}) (resp *Response, err error) {
113+
return conn.CallAsync(functionName, args).Get()
114114
}
115115

116116
// Eval passes Lua expression for evaluation.
@@ -188,21 +188,21 @@ func (conn *Connection) UpdateTyped(space, index interface{}, key, ops interface
188188
return conn.UpdateAsync(space, index, key, ops).GetTyped(result)
189189
}
190190

191-
// CallTyped calls registered function.
191+
// Call16Typed calls registered function.
192192
// It uses request code for Tarantool 1.6, so result is converted to array of arrays
193193
//
194-
// It is equal to conn.CallAsync(functionName, args).GetTyped(&result).
195-
func (conn *Connection) CallTyped(functionName string, args interface{}, result interface{}) (err error) {
196-
return conn.CallAsync(functionName, args).GetTyped(result)
194+
// It is equal to conn.Call16Async(functionName, args).GetTyped(&result).
195+
func (conn *Connection) Call16Typed(functionName string, args interface{}, result interface{}) (err error) {
196+
return conn.Call16Async(functionName, args).GetTyped(result)
197197
}
198198

199-
// Call17Typed calls registered function.
200-
// It uses request code for Tarantool 1.7, so result is not converted
199+
// CallTyped calls registered function.
200+
// It uses request code for Tarantool >=1.7, so result is not converted
201201
// (though, keep in mind, result is always array)
202202
//
203-
// It is equal to conn.Call17Async(functionName, args).GetTyped(&result).
204-
func (conn *Connection) Call17Typed(functionName string, args interface{}, result interface{}) (err error) {
205-
return conn.Call17Async(functionName, args).GetTyped(result)
203+
// It is equal to conn.CallAsync(functionName, args).GetTyped(&result).
204+
func (conn *Connection) CallTyped(functionName string, args interface{}, result interface{}) (err error) {
205+
return conn.CallAsync(functionName, args).GetTyped(result)
206206
}
207207

208208
// EvalTyped passes Lua expression for evaluation.
@@ -307,10 +307,10 @@ func (conn *Connection) UpsertAsync(space interface{}, tuple interface{}, ops in
307307
})
308308
}
309309

310-
// CallAsync sends a call to registered Tarantool function and returns Future.
310+
// Call16Async sends a call to registered Tarantool function and returns Future.
311311
// It uses request code for Tarantool 1.6, so future's result is always array of arrays
312-
func (conn *Connection) CallAsync(functionName string, args interface{}) *Future {
313-
future := conn.newFuture(CallRequest)
312+
func (conn *Connection) Call16Async(functionName string, args interface{}) *Future {
313+
future := conn.newFuture(Call16Request)
314314
return future.send(conn, func(enc *msgpack.Encoder) error {
315315
enc.EncodeMapLen(2)
316316
enc.EncodeUint64(KeyFunctionName)
@@ -320,11 +320,11 @@ func (conn *Connection) CallAsync(functionName string, args interface{}) *Future
320320
})
321321
}
322322

323-
// Call17Async sends a call to registered Tarantool function and returns Future.
324-
// It uses request code for Tarantool 1.7, so future's result will not be converted
323+
// CallAsync sends a call to registered Tarantool function and returns Future.
324+
// It uses request code for Tarantool >=1.7, so future's result will not be converted
325325
// (though, keep in mind, result is always array)
326-
func (conn *Connection) Call17Async(functionName string, args interface{}) *Future {
327-
future := conn.newFuture(Call17Request)
326+
func (conn *Connection) CallAsync(functionName string, args interface{}) *Future {
327+
future := conn.newFuture(CallRequest)
328328
return future.send(conn, func(enc *msgpack.Encoder) error {
329329
enc.EncodeMapLen(2)
330330
enc.EncodeUint64(KeyFunctionName)
@@ -426,7 +426,7 @@ func (fut *Future) Get() (*Response, error) {
426426
// GetTyped waits for Future and calls msgpack.Decoder.Decode(result) if no error happens.
427427
// It is could be much faster than Get() function.
428428
//
429-
// Note: Tarantool usually returns array of tuples (except for Eval and Call17 actions)
429+
// Note: Tarantool usually returns array of tuples (except for Eval and Call actions)
430430
func (fut *Future) GetTyped(result interface{}) error {
431431
fut.wait()
432432
if fut.err != nil {

response.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (resp *Response) String() (str string) {
147147
return fmt.Sprintf("<%d ERR 0x%x %s>", resp.RequestId, resp.Code, resp.Error)
148148
}
149149

150-
// Tuples converts result of Eval and Call17 to same format
150+
// Tuples converts result of Eval and Call to same format
151151
// as other actions returns (i.e. array of arrays).
152152
func (resp *Response) Tuples() (res [][]interface{}) {
153153
res = make([][]interface{}, len(resp.Data))

tarantool_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -620,25 +620,25 @@ func TestClient(t *testing.T) {
620620
t.Errorf("Result len of SelectTyped != 1")
621621
}
622622

623-
// Call
624-
resp, err = conn.Call("box.info", []interface{}{"box.schema.SPACE_ID"})
623+
// Call16
624+
resp, err = conn.Call16("box.info", []interface{}{"box.schema.SPACE_ID"})
625625
if err != nil {
626-
t.Errorf("Failed to Call: %s", err.Error())
626+
t.Errorf("Failed to Call16: %s", err.Error())
627627
}
628628
if resp == nil {
629-
t.Errorf("Response is nil after Call")
629+
t.Errorf("Response is nil after Call16")
630630
}
631631
if len(resp.Data) < 1 {
632632
t.Errorf("Response.Data is empty after Eval")
633633
}
634634

635-
// Call vs Call17
636-
resp, err = conn.Call("simple_incr", []interface{}{1})
635+
// Call16 vs Call
636+
resp, err = conn.Call16("simple_incr", []interface{}{1})
637637
if resp.Data[0].([]interface{})[0].(uint64) != 2 {
638638
t.Errorf("result is not {{1}} : %v", resp.Data)
639639
}
640640

641-
resp, err = conn.Call17("simple_incr", []interface{}{1})
641+
resp, err = conn.Call("simple_incr", []interface{}{1})
642642
if resp.Data[0].(uint64) != 2 {
643643
t.Errorf("result is not {{1}} : %v", resp.Data)
644644
}

0 commit comments

Comments
 (0)