Skip to content

Commit 61d9cf4

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 e9b9ba1 commit 61d9cf4

14 files changed

+117
-101
lines changed

CHANGELOG.md

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

2626
### Changed
2727

28+
- Breaking change: rename `Call` to `Call16` and `Call17` to `Call` (#125)
2829
- Handle everything with `go test` (#115)
2930
- Use plain package instead of module for UUID submodule (#134)
3031
- 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

connection_pool/connection_pool.go

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -255,27 +255,29 @@ func (connPool *ConnectionPool) Upsert(space interface{}, tuple, ops interface{}
255255
return conn.Upsert(space, tuple, ops)
256256
}
257257

258-
// Call calls registered Tarantool function.
258+
// Call16 calls registered Tarantool function.
259259
// It uses request code for Tarantool 1.6, so result is converted to array of arrays.
260-
func (connPool *ConnectionPool) Call(functionName string, args interface{}, userMode Mode) (resp *tarantool.Response, err error) {
260+
// Deprecated since 1.7.4. This breaking change was needed to extend call() and eval()
261+
// API with per-requests options.
262+
func (connPool *ConnectionPool) Call16(functionName string, args interface{}, userMode Mode) (resp *tarantool.Response, err error) {
261263
conn, err := connPool.getNextConnection(userMode)
262264
if err != nil {
263265
return nil, err
264266
}
265267

266-
return conn.Call(functionName, args)
268+
return conn.Call16(functionName, args)
267269
}
268270

269-
// Call17 calls registered Tarantool function.
270-
// It uses request code for Tarantool 1.7, so result is not converted
271+
// Call calls registered Tarantool function.
272+
// It uses request code for Tarantool >= 1.7, so result is not converted
271273
// (though, keep in mind, result is always array).
272-
func (connPool *ConnectionPool) Call17(functionName string, args interface{}, userMode Mode) (resp *tarantool.Response, err error) {
274+
func (connPool *ConnectionPool) Call(functionName string, args interface{}, userMode Mode) (resp *tarantool.Response, err error) {
273275
conn, err := connPool.getNextConnection(userMode)
274276
if err != nil {
275277
return nil, err
276278
}
277279

278-
return conn.Call17(functionName, args)
280+
return conn.Call(functionName, args)
279281
}
280282

281283
// Eval passes lua expression for evaluation.
@@ -351,27 +353,29 @@ func (connPool *ConnectionPool) UpdateTyped(space, index interface{}, key, ops i
351353
return conn.UpdateTyped(space, index, key, ops, result)
352354
}
353355

354-
// CallTyped calls registered function.
356+
// Call16Typed calls registered function.
355357
// It uses request code for Tarantool 1.6, so result is converted to array of arrays.
356-
func (connPool *ConnectionPool) CallTyped(functionName string, args interface{}, result interface{}, userMode Mode) (err error) {
358+
// Deprecated since 1.7.4. This breaking change was needed to extend call() and eval()
359+
// API with per-requests options.
360+
func (connPool *ConnectionPool) Call16Typed(functionName string, args interface{}, result interface{}, userMode Mode) (err error) {
357361
conn, err := connPool.getNextConnection(userMode)
358362
if err != nil {
359363
return err
360364
}
361365

362-
return conn.CallTyped(functionName, args, result)
366+
return conn.Call16Typed(functionName, args, result)
363367
}
364368

365-
// Call17Typed calls registered function.
366-
// It uses request code for Tarantool 1.7, so result is not converted
369+
// CallTyped calls registered function.
370+
// It uses request code for Tarantool >= 1.7, so result is not converted
367371
// (though, keep in mind, result is always array).
368-
func (connPool *ConnectionPool) Call17Typed(functionName string, args interface{}, result interface{}, userMode Mode) (err error) {
372+
func (connPool *ConnectionPool) CallTyped(functionName string, args interface{}, result interface{}, userMode Mode) (err error) {
369373
conn, err := connPool.getNextConnection(userMode)
370374
if err != nil {
371375
return err
372376
}
373377

374-
return conn.Call17Typed(functionName, args, result)
378+
return conn.CallTyped(functionName, args, result)
375379
}
376380

377381
// EvalTyped passes lua expression for evaluation.
@@ -449,27 +453,29 @@ func (connPool *ConnectionPool) UpsertAsync(space interface{}, tuple interface{}
449453
return conn.UpsertAsync(space, tuple, ops)
450454
}
451455

452-
// CallAsync sends a call to registered Tarantool function and returns Future.
456+
// Call16Async sends a call to registered Tarantool function and returns Future.
453457
// It uses request code for Tarantool 1.6, so future's result is always array of arrays.
454-
func (connPool *ConnectionPool) CallAsync(functionName string, args interface{}, userMode Mode) *tarantool.Future {
458+
// Deprecated since 1.7.4. This breaking change was needed to extend call() and eval()
459+
// API with per-requests options.
460+
func (connPool *ConnectionPool) Call16Async(functionName string, args interface{}, userMode Mode) *tarantool.Future {
455461
conn, err := connPool.getNextConnection(userMode)
456462
if err != nil {
457463
return tarantool.NewErrorFuture(err)
458464
}
459465

460-
return conn.CallAsync(functionName, args)
466+
return conn.Call16Async(functionName, args)
461467
}
462468

463-
// Call17Async sends a call to registered Tarantool function and returns Future.
464-
// It uses request code for Tarantool 1.7, so future's result will not be converted
469+
// CallAsync sends a call to registered Tarantool function and returns Future.
470+
// It uses request code for Tarantool >= 1.7, so future's result will not be converted
465471
// (though, keep in mind, result is always array).
466-
func (connPool *ConnectionPool) Call17Async(functionName string, args interface{}, userMode Mode) *tarantool.Future {
472+
func (connPool *ConnectionPool) CallAsync(functionName string, args interface{}, userMode Mode) *tarantool.Future {
467473
conn, err := connPool.getNextConnection(userMode)
468474
if err != nil {
469475
return tarantool.NewErrorFuture(err)
470476
}
471477

472-
return conn.Call17Async(functionName, args)
478+
return conn.CallAsync(functionName, args)
473479
}
474480

475481
// EvalAsync sends a lua expression for evaluation and returns Future.
@@ -487,7 +493,7 @@ func (connPool *ConnectionPool) EvalAsync(expr string, args interface{}, userMod
487493
//
488494

489495
func (connPool *ConnectionPool) getConnectionRole(conn *tarantool.Connection) (Role, error) {
490-
resp, err := conn.Call17("box.info", []interface{}{})
496+
resp, err := conn.Call("box.info", []interface{}{})
491497
if err != nil {
492498
return unknown, err
493499
}
@@ -506,7 +512,7 @@ func (connPool *ConnectionPool) getConnectionRole(conn *tarantool.Connection) (R
506512
return unknown, ErrIncorrectStatus
507513
}
508514

509-
resp, err = conn.Call17("box.info", []interface{}{})
515+
resp, err = conn.Call("box.info", []interface{}{})
510516
if err != nil {
511517
return unknown, err
512518
}

connection_pool/connection_pool_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func TestCall(t *testing.T) {
219219
defer connPool.Close()
220220

221221
// PreferRO
222-
resp, err := connPool.Call17("box.info", []interface{}{}, connection_pool.PreferRO)
222+
resp, err := connPool.Call("box.info", []interface{}{}, connection_pool.PreferRO)
223223
require.Nilf(t, err, "failed to Call")
224224
require.NotNilf(t, resp, "response is nil after Call")
225225
require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call")
@@ -230,7 +230,7 @@ func TestCall(t *testing.T) {
230230
require.Truef(t, ro, "expected `true` with mode `PreferRO`")
231231

232232
// PreferRW
233-
resp, err = connPool.Call17("box.info", []interface{}{}, connection_pool.PreferRW)
233+
resp, err = connPool.Call("box.info", []interface{}{}, connection_pool.PreferRW)
234234
require.Nilf(t, err, "failed to Call")
235235
require.NotNilf(t, resp, "response is nil after Call")
236236
require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call")
@@ -241,7 +241,7 @@ func TestCall(t *testing.T) {
241241
require.Falsef(t, ro, "expected `false` with mode `PreferRW`")
242242

243243
// RO
244-
resp, err = connPool.Call17("box.info", []interface{}{}, connection_pool.RO)
244+
resp, err = connPool.Call("box.info", []interface{}{}, connection_pool.RO)
245245
require.Nilf(t, err, "failed to Call")
246246
require.NotNilf(t, resp, "response is nil after Call")
247247
require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call")
@@ -252,7 +252,7 @@ func TestCall(t *testing.T) {
252252
require.Truef(t, ro, "expected `true` with mode `RO`")
253253

254254
// RW
255-
resp, err = connPool.Call17("box.info", []interface{}{}, connection_pool.RW)
255+
resp, err = connPool.Call("box.info", []interface{}{}, connection_pool.RW)
256256
require.Nilf(t, err, "failed to Call")
257257
require.NotNilf(t, resp, "response is nil after Call")
258258
require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call")

connection_pool/example_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,15 +490,15 @@ func ExampleConnectionPool_Update() {
490490
// Data [[key1 new_value]]
491491
}
492492

493-
func ExampleConnectionPool_Call17() {
493+
func ExampleConnectionPool_Call() {
494494
pool, err := examplePool(testRoles)
495495
if err != nil {
496496
fmt.Println(err)
497497
}
498498
defer pool.Close()
499499

500500
// Call a function 'simple_incr' with arguments.
501-
resp, err := pool.Call17("simple_incr", []interface{}{1}, connection_pool.PreferRW)
501+
resp, err := pool.Call("simple_incr", []interface{}{1}, connection_pool.PreferRW)
502502
fmt.Println("Call simple_incr()")
503503
fmt.Println("Error", err)
504504
fmt.Println("Code", resp.Code)

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: 28 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,20 @@ 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+
// Deprecated since 1.7.4. This breaking change was needed to extend call() and eval()
328+
// API with per-requests options.
329+
func (connMulti *ConnectionMulti) Call16(functionName string, args interface{}) (resp *tarantool.Response, err error) {
330+
return connMulti.getCurrentConnection().Call16(functionName, args)
329331
}
330332

331-
// Call17 calls registered Tarantool function.
332-
// It uses request code for Tarantool 1.7, so result is not converted
333+
// Call calls registered Tarantool function.
334+
// It uses request code for Tarantool >= 1.7, so result is not converted
333335
// (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)
336+
func (connMulti *ConnectionMulti) Call(functionName string, args interface{}) (resp *tarantool.Response, err error) {
337+
return connMulti.getCurrentConnection().Call(functionName, args)
336338
}
337339

338340
// Eval passes Lua expression for evaluation.
@@ -375,18 +377,20 @@ func (connMulti *ConnectionMulti) UpdateTyped(space, index interface{}, key, ops
375377
return connMulti.getCurrentConnection().UpdateTyped(space, index, key, ops, result)
376378
}
377379

378-
// CallTyped calls registered function.
380+
// Call16Typed calls registered function.
379381
// It uses request code for Tarantool 1.6, so result is converted to array of
380382
// arrays.
381-
func (connMulti *ConnectionMulti) CallTyped(functionName string, args interface{}, result interface{}) (err error) {
382-
return connMulti.getCurrentConnection().CallTyped(functionName, args, result)
383+
// Deprecated since 1.7.4. This breaking change was needed to extend call() and eval()
384+
// API with per-requests options.
385+
func (connMulti *ConnectionMulti) Call16Typed(functionName string, args interface{}, result interface{}) (err error) {
386+
return connMulti.getCurrentConnection().Call16Typed(functionName, args, result)
383387
}
384388

385-
// Call17Typed calls registered function.
386-
// It uses request code for Tarantool 1.7, so result is not converted (though,
389+
// CallTyped calls registered function.
390+
// It uses request code for Tarantool >= 1.7, so result is not converted (though,
387391
// 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)
392+
func (connMulti *ConnectionMulti) CallTyped(functionName string, args interface{}, result interface{}) (err error) {
393+
return connMulti.getCurrentConnection().CallTyped(functionName, args, result)
390394
}
391395

392396
// EvalTyped passes Lua expression for evaluation.
@@ -429,18 +433,20 @@ func (connMulti *ConnectionMulti) UpsertAsync(space interface{}, tuple interface
429433
return connMulti.getCurrentConnection().UpsertAsync(space, tuple, ops)
430434
}
431435

432-
// CallAsync sends a call to registered Tarantool function and returns Future.
436+
// Call16Async sends a call to registered Tarantool function and returns Future.
433437
// It uses request code for Tarantool 1.6, so future's result is always array
434438
// of arrays.
435-
func (connMulti *ConnectionMulti) CallAsync(functionName string, args interface{}) *tarantool.Future {
436-
return connMulti.getCurrentConnection().CallAsync(functionName, args)
439+
// Deprecated since 1.7.4. This breaking change was needed to extend call() and eval()
440+
// API with per-requests options.
441+
func (connMulti *ConnectionMulti) Call16Async(functionName string, args interface{}) *tarantool.Future {
442+
return connMulti.getCurrentConnection().Call16Async(functionName, args)
437443
}
438444

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
445+
// CallAsync sends a call to registered Tarantool function and returns Future.
446+
// It uses request code for Tarantool >= 1.7, so future's result will not be converted
441447
// (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)
448+
func (connMulti *ConnectionMulti) CallAsync(functionName string, args interface{}) *tarantool.Future {
449+
return connMulti.getCurrentConnection().CallAsync(functionName, args)
444450
}
445451

446452
// 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

0 commit comments

Comments
 (0)