Skip to content

Commit ec19618

Browse files
committed
add support of a new binary protocol command for "call"
Added support for a new binary protocol command for "call" (used since 1.7.2). The old version of "call" has been moved to "call_16". Closes #101
1 parent 6c098be commit ec19618

8 files changed

+122
-22
lines changed

README.md

+34-4
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ Place it into project library path in your IDE.
8686
4. [Database queries](#database-queries)
8787
* [Tarantool::select](tarantool#select)
8888
* [Tarantool::insert, replace](#tarantoolinsert-tarantoolreplace)
89+
* [Tarantool::call_16](#tarantoolcall_16)
8990
* [Tarantool::call](#tarantoolcall)
9091
* [Tarantool::evaluate](#tarantoolevaluate)
9192
* [Tarantool::delete](#tarantooldelete)
@@ -122,6 +123,7 @@ Tarantool {
122123
public array Tarantool::select (mixed $space [, mixed $key = array() [, mixed $index = 0 [, int $limit = PHP_INT_MAX [, int $offset = 0 [, $iterator = Tarantool::ITERATOR_EQ ] ] ] ] ] )
123124
public array Tarantool::insert (mixed $space, array $tuple)
124125
public array Tarantool::replace (mixed $space, array $tuple)
126+
public array Tarantool::call_16 (string $procedure [, mixed args] )
125127
public array Tarantool::call (string $procedure [, mixed args] )
126128
public array Tarantool::evaluate (string $expression [, mixed args] )
127129
public array Tarantool::delete (mixed $space, mixed $key [, mixed $index] )
@@ -296,17 +298,18 @@ $tnt->insert("test", array(1, 3, "smth completely different"));
296298
$tnt->replace("test", array(1, 3, "smth completely different"));
297299
```
298300

299-
### Tarantool::call
301+
### Tarantool::call_16
300302

301303
``` php
302-
public array Tarantool::call(string $procedure [, mixed args])
304+
public array Tarantool::call_16(string $procedure [, mixed args])
303305
```
304306

305-
_**Description**_: Call stored procedure
307+
_**Description**_: Call stored procedure.
308+
Deprecated. For tarantool >= 1.7.2 use "call" instead.
306309

307310
_**Parameters**_
308311
* `procedure`: String, procedure to call (mandatory)
309-
* `args`: Any value to pass to procdure as arguments (empty by default)
312+
* `args`: Any value to pass to procedure as arguments (empty by default)
310313

311314
_**Return Value**_
312315

@@ -317,6 +320,33 @@ _**Return Value**_
317320

318321
#### Example
319322

323+
``` php
324+
$tnt->call_16("test_2");
325+
$tnt->call_16("test_3", array(3, 4));
326+
```
327+
328+
### Tarantool::call
329+
330+
``` php
331+
public array Tarantool::call(string $procedure [, mixed args])
332+
```
333+
334+
_**Description**_: Call stored procedure.
335+
Similar to "call_16", but – like "eval", "call" returns a list of values,
336+
unconverted. Since tarantool 1.7.2.
337+
338+
_**Parameters**_
339+
* `procedure`: String, procedure to call (mandatory)
340+
* `args`: Any value to pass to procedure as arguments (empty by default)
341+
342+
_**Return Value**_
343+
344+
**Any value**, that was returned by stored procedure..
345+
346+
**BOOL**: False and raises `Exception` in case of error.
347+
348+
#### Example
349+
320350
``` php
321351
$tnt->call("test_2");
322352
$tnt->call("test_3", array(3, 4));

src/php_tarantool.h

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ PHP_METHOD(Tarantool, select);
130130
PHP_METHOD(Tarantool, insert);
131131
PHP_METHOD(Tarantool, replace);
132132
PHP_METHOD(Tarantool, call);
133+
PHP_METHOD(Tarantool, call_16);
133134
PHP_METHOD(Tarantool, eval);
134135
PHP_METHOD(Tarantool, delete);
135136
PHP_METHOD(Tarantool, update);

src/tarantool.c

+26-1
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_tarantool_delete, 0, 0, 2)
543543
ZEND_ARG_INFO(0, index)
544544
ZEND_END_ARG_INFO()
545545

546-
/* call, eval */
546+
/* call_16, call, eval */
547547
ZEND_BEGIN_ARG_INFO_EX(arginfo_tarantool_proc_tuple, 0, 0, 1)
548548
ZEND_ARG_INFO(0, proc)
549549
ZEND_ARG_INFO(0, tuple)
@@ -576,6 +576,7 @@ const zend_function_entry Tarantool_methods[] = {
576576
TNT_MEP(insert, arginfo_tarantool_space_tuple )
577577
TNT_MEP(replace, arginfo_tarantool_space_tuple )
578578
TNT_MEP(call, arginfo_tarantool_proc_tuple )
579+
TNT_MEP(call_16, arginfo_tarantool_proc_tuple )
579580
TNT_MEP(eval, arginfo_tarantool_proc_tuple )
580581
TNT_MEP(delete, arginfo_tarantool_delete )
581582
TNT_MEP(update, arginfo_tarantool_update )
@@ -1479,6 +1480,30 @@ PHP_METHOD(Tarantool, call) {
14791480
TARANTOOL_RETURN_DATA(&body, &header, &body);
14801481
}
14811482

1483+
PHP_METHOD(Tarantool, call_16) {
1484+
char *proc;
1485+
size_t proc_len;
1486+
zval tuple_new;
1487+
zval *tuple = NULL;
1488+
1489+
TARANTOOL_FUNCTION_BEGIN(obj, id, "s|z", &proc, &proc_len, &tuple);
1490+
TARANTOOL_CONNECT_ON_DEMAND(obj);
1491+
1492+
pack_key(tuple, 1, &tuple_new);
1493+
1494+
long sync = TARANTOOL_G(sync_counter)++;
1495+
php_tp_encode_call_16(obj->value, sync, proc, proc_len, &tuple_new);
1496+
zval_ptr_dtor(&tuple_new);
1497+
if (tarantool_stream_send(obj) == FAILURE)
1498+
RETURN_FALSE;
1499+
1500+
zval header, body;
1501+
if (tarantool_step_recv(obj, sync, &header, &body) == FAILURE)
1502+
RETURN_FALSE;
1503+
1504+
TARANTOOL_RETURN_DATA(&body, &header, &body);
1505+
}
1506+
14821507
PHP_METHOD(Tarantool, eval) {
14831508
char *code; size_t code_len;
14841509
zval *tuple = NULL, tuple_new;

src/tarantool_proto.c

+18-8
Original file line numberDiff line numberDiff line change
@@ -172,29 +172,39 @@ void php_tp_encode_delete(smart_string *str, uint32_t sync,
172172
php_mp_pack(str, tuple);
173173
}
174174

175-
size_t php_tp_sizeof_call(uint32_t sync,
176-
uint32_t proc_len, zval *tuple) {
177-
return php_tp_sizeof_header(TNT_CALL, sync) +
175+
static size_t php_tp_sizeof_call(uint32_t sync, uint32_t proc_len,
176+
enum tnt_request_type type, zval *tuple) {
177+
return php_tp_sizeof_header(type, sync) +
178178
php_mp_sizeof_hash(2) +
179179
php_mp_sizeof_long(TNT_FUNCTION) +
180180
php_mp_sizeof_string(proc_len) +
181181
php_mp_sizeof_long(TNT_TUPLE) +
182182
php_mp_sizeof(tuple) ;
183183
}
184184

185-
void php_tp_encode_call(smart_string *str, uint32_t sync,
186-
char *proc, uint32_t proc_len, zval *tuple) {
187-
size_t packet_size = php_tp_sizeof_call(sync,
188-
proc_len, tuple);
185+
static void php_tp_encode_call_common(smart_string *str, uint32_t sync,
186+
char *proc, uint32_t proc_len,
187+
enum tnt_request_type type, zval *tuple) {
188+
size_t packet_size = php_tp_sizeof_call(sync, proc_len, type, tuple);
189189
smart_string_ensure(str, packet_size + 5);
190-
php_tp_pack_header(str, packet_size, TNT_CALL, sync);
190+
php_tp_pack_header(str, packet_size, type, sync);
191191
php_mp_pack_hash(str, 2);
192192
php_mp_pack_long(str, TNT_FUNCTION);
193193
php_mp_pack_string(str, proc, proc_len);
194194
php_mp_pack_long(str, TNT_TUPLE);
195195
php_mp_pack(str, tuple);
196196
}
197197

198+
void php_tp_encode_call(smart_string *str, uint32_t sync, char *proc,
199+
uint32_t proc_len, zval *tuple) {
200+
php_tp_encode_call_common(str,sync, proc, proc_len, TNT_CALL, tuple);
201+
}
202+
203+
void php_tp_encode_call_16(smart_string *str, uint32_t sync, char *proc,
204+
uint32_t proc_len, zval *tuple) {
205+
php_tp_encode_call_common(str,sync, proc, proc_len, TNT_CALL_16, tuple);
206+
}
207+
198208
size_t php_tp_sizeof_eval(uint32_t sync,
199209
uint32_t proc_len, zval *tuple) {
200210
return php_tp_sizeof_header(TNT_EVAL, sync) +

src/tarantool_proto.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,11 @@ enum tnt_request_type {
8585
TNT_REPLACE = 0x03,
8686
TNT_UPDATE = 0x04,
8787
TNT_DELETE = 0x05,
88-
TNT_CALL = 0x06,
88+
TNT_CALL_16 = 0x06,
8989
TNT_AUTH = 0x07,
9090
TNT_EVAL = 0x08,
9191
TNT_UPSERT = 0x09,
92+
TNT_CALL = 0x0a,
9293
TNT_PING = 0x40
9394
};
9495

@@ -136,6 +137,8 @@ void php_tp_encode_delete(smart_string *str, uint32_t sync, uint32_t space_no,
136137
uint32_t index_no, zval *tuple);
137138
void php_tp_encode_call(smart_string *str, uint32_t sync, char *proc,
138139
uint32_t proc_len, zval *tuple);
140+
void php_tp_encode_call_16(smart_string *str, uint32_t sync, char *proc,
141+
uint32_t proc_len, zval *tuple);
139142
void php_tp_encode_eval(smart_string *str, uint32_t sync, char *proc,
140143
uint32_t proc_len, zval *tuple);
141144

test/DMLTest.php

+14-3
Original file line numberDiff line numberDiff line change
@@ -234,19 +234,30 @@ public function test_11_update_error() {
234234
);
235235
}
236236

237-
public function test_12_call() {
238-
$result = self::$tarantool->call("test_6", array(true, false, false));
237+
public function test_12_01_call_16() {
238+
$result = self::$tarantool->call_16("test_6", array(true, false, false));
239239
$this->assertEquals(array(array(true), array(false), array(false)), $result);
240240
$this->assertEquals(
241241
array(
242242
'0' => array(
243243
'0' => array('k1' => 'v2', 'k2' => 'v')
244244
)
245245
),
246+
self::$tarantool->call_16("test_2")
247+
);
248+
$this->assertEquals(
249+
self::$tarantool->call_16("test_3", array(3, 4)), array('0' => array('0' => 7)));
250+
}
251+
252+
public function test_12_02_call() {
253+
$result = self::$tarantool->call("test_6", array(true, false, false));
254+
$this->assertEquals(array(true, false, false), $result);
255+
$this->assertEquals(
256+
array('0' => array('k1' => 'v2', 'k2' => 'v')),
246257
self::$tarantool->call("test_2")
247258
);
248259
$this->assertEquals(
249-
self::$tarantool->call("test_3", array(3, 4)), array('0' => array('0' => 7)));
260+
self::$tarantool->call("test_3", array(3, 4)), array('0' => 7));
250261
}
251262

252263
public function test_13_eval() {

test/MsgPackTest.php

+19-4
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,36 @@ public static function doSetUpBeforeClass()
1717
self::$tarantool->ping();
1818
}
1919

20-
public function test_00_msgpack_call() {
21-
$resp = self::$tarantool->call('test_4', [
20+
public function test_00_01_msgpack_call() {
21+
$resp = self::$tarantool->call_16('test_4', [
2222
'4TL2tLIXqMqyGQm_kiE7mRrS96I5E8nqU', 'B627', 0, [
2323
'browser_stats_first_session_hits' => 1
2424
]
2525
]);
2626
$this->assertEquals($resp[0][0], 2);
27-
$resp = self::$tarantool->call('test_4', [
27+
$resp = self::$tarantool->call_16('test_4', [
2828
'4TL2tLIXqMqyGQm_kiE7mRrS96I5E8nqU', 'B627', 0, [
2929
'browser_stats_first_session_hit' => 1
3030
]
3131
]);
3232
$this->assertEquals($resp[0][0], 2);
3333
}
3434

35+
public function test_00_02_msgpack_call() {
36+
$resp = self::$tarantool->call('test_4', [
37+
'4TL2tLIXqMqyGQm_kiE7mRrS96I5E8nqU', 'B627', 0, [
38+
'browser_stats_first_session_hits' => 1
39+
]
40+
]);
41+
$this->assertEquals($resp[0], 2);
42+
$resp = self::$tarantool->call('test_4', [
43+
'4TL2tLIXqMqyGQm_kiE7mRrS96I5E8nqU', 'B627', 0, [
44+
'browser_stats_first_session_hit' => 1
45+
]
46+
]);
47+
$this->assertEquals($resp[0], 2);
48+
}
49+
3550
public function test_01_msgpack_array_key() {
3651
$this->expectException(TarantoolException::class);
3752
$this->expectExceptionMessage('Bad key type for PHP Array');
@@ -81,6 +96,6 @@ public function test_05_msgpack_string_keys() {
8196
public function test_06_msgpack_array_reference() {
8297
$data = array('key1' => 'value1');
8398
$link = &$data['key1'];
84-
self::$tarantool->call('test_4', [$data]);
99+
self::$tarantool->call_16('test_4', [$data]);
85100
}
86101
}

test/RandomTest.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,14 @@ public function test_02_very_big_response() {
4242

4343
public function test_03_another_big_response() {
4444
for ($i = 100; $i <= 5200; $i += 100) {
45-
$result = self::$tarantool->call('test_5', array($i));
45+
$result = self::$tarantool->call_16('test_5', array($i));
4646
$this->assertEquals($i, count($result));
4747
}
48+
49+
for ($i = 100; $i <= 5200; $i += 100) {
50+
$result = self::$tarantool->call('test_5', array($i));
51+
$this->assertEquals($i, count($result[0]));
52+
}
4853
}
4954

5055
/**

0 commit comments

Comments
 (0)