55
55
REQUEST_TYPE_ERROR ,
56
56
IPROTO_GREETING_SIZE ,
57
57
ITERATOR_EQ ,
58
- ITERATOR_ALL
58
+ ITERATOR_ALL ,
59
+ IPROTO_CHUNK
59
60
)
60
61
from tarantool .error import (
61
62
Error ,
@@ -748,7 +749,7 @@ def _read_response(self):
748
749
# Read the packet
749
750
return self ._recv (length )
750
751
751
- def _send_request_wo_reconnect (self , request ):
752
+ def _send_request_wo_reconnect (self , request , on_push_ctx = [] ):
752
753
"""
753
754
Send request without trying to reconnect.
754
755
Reload schema, if required.
@@ -772,6 +773,11 @@ def _send_request_wo_reconnect(self, request):
772
773
try :
773
774
self ._socket .sendall (bytes (request ))
774
775
response = request .response_class (self , self ._read_response ())
776
+ if response ._code == IPROTO_CHUNK :
777
+ # Сase of receiving an out-of-band message
778
+ on_push_ctx .append (response ._data )
779
+ # Next comes the main message
780
+ response = request .response_class (self , self ._read_response ())
775
781
break
776
782
except SchemaReloadException as e :
777
783
self .update_schema (e .schema_version )
@@ -851,7 +857,7 @@ def check(): # Check that connection is alive
851
857
self .wrap_socket_ssl ()
852
858
self .handshake ()
853
859
854
- def _send_request (self , request ):
860
+ def _send_request (self , request , on_push_ctx = [] ):
855
861
"""
856
862
Send a request to the server through the socket.
857
863
@@ -872,7 +878,7 @@ def _send_request(self, request):
872
878
873
879
self ._opt_reconnect ()
874
880
875
- return self ._send_request_wo_reconnect (request )
881
+ return self ._send_request_wo_reconnect (request , on_push_ctx )
876
882
877
883
def load_schema (self ):
878
884
"""
@@ -914,7 +920,7 @@ def flush_schema(self):
914
920
self .schema .flush ()
915
921
self .load_schema ()
916
922
917
- def call (self , func_name , * args ):
923
+ def call (self , func_name , * args , ** kwargs ):
918
924
"""
919
925
Execute a CALL request: call a stored Lua function.
920
926
@@ -930,19 +936,26 @@ def call(self, func_name, *args):
930
936
:exc:`~tarantool.error.SchemaError`,
931
937
:exc:`~tarantool.error.NetworkError`,
932
938
:exc:`~tarantool.error.SslError`
939
+
940
+ !!!
941
+ TODO: write docs
942
+ !!!
933
943
"""
934
944
935
945
assert isinstance (func_name , str )
936
946
937
947
# This allows to use a tuple or list as an argument
938
948
if len (args ) == 1 and isinstance (args [0 ], (list , tuple )):
939
949
args = args [0 ]
950
+ # Case for absence of optional arg for accepting out-of-band msg data
951
+ if not 'on_push_ctx' in kwargs :
952
+ kwargs ['on_push_ctx' ] = []
940
953
941
954
request = RequestCall (self , func_name , args , self .call_16 )
942
- response = self ._send_request (request )
955
+ response = self ._send_request (request , kwargs [ 'on_push_ctx' ] )
943
956
return response
944
957
945
- def eval (self , expr , * args ):
958
+ def eval (self , expr , * args , ** kwargs ):
946
959
"""
947
960
Execute an EVAL request: evaluate a Lua expression.
948
961
@@ -966,12 +979,15 @@ def eval(self, expr, *args):
966
979
# This allows to use a tuple or list as an argument
967
980
if len (args ) == 1 and isinstance (args [0 ], (list , tuple )):
968
981
args = args [0 ]
982
+ # Case for absence of optional arg for accepting out-of-band msg data
983
+ if not 'on_push_ctx' in kwargs :
984
+ kwargs ['on_push_ctx' ] = []
969
985
970
986
request = RequestEval (self , expr , args )
971
- response = self ._send_request (request )
987
+ response = self ._send_request (request , kwargs [ 'on_push_ctx' ] )
972
988
return response
973
989
974
- def replace (self , space_name , values ):
990
+ def replace (self , space_name , values , ** kwargs ):
975
991
"""
976
992
Execute a REPLACE request: `replace`_ a tuple in the space.
977
993
Doesn't throw an error if there is no tuple with the specified
@@ -994,10 +1010,14 @@ def replace(self, space_name, values):
994
1010
.. _replace: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_space/replace/
995
1011
"""
996
1012
1013
+ # Case for absence of optional arg for accepting out-of-band msg data
1014
+ if not 'on_push_ctx' in kwargs :
1015
+ kwargs ['on_push_ctx' ] = []
1016
+
997
1017
if isinstance (space_name , str ):
998
1018
space_name = self .schema .get_space (space_name ).sid
999
1019
request = RequestReplace (self , space_name , values )
1000
- return self ._send_request (request )
1020
+ return self ._send_request (request , kwargs [ 'on_push_ctx' ] )
1001
1021
1002
1022
def authenticate (self , user , password ):
1003
1023
"""
@@ -1149,7 +1169,7 @@ def subscribe(self, cluster_uuid, server_uuid, vclock=None):
1149
1169
return
1150
1170
self .close () # close connection after SUBSCRIBE
1151
1171
1152
- def insert (self , space_name , values ):
1172
+ def insert (self , space_name , values , ** kwargs ):
1153
1173
"""
1154
1174
Execute an INSERT request: `insert`_ a tuple to the space.
1155
1175
Throws an error if there is already a tuple with the same
@@ -1172,12 +1192,16 @@ def insert(self, space_name, values):
1172
1192
.. _insert: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_space/insert/
1173
1193
"""
1174
1194
1195
+ # Case for absence of optional arg for accepting out-of-band msg data
1196
+ if not 'on_push_ctx' in kwargs :
1197
+ kwargs ['on_push_ctx' ] = []
1198
+
1175
1199
if isinstance (space_name , str ):
1176
1200
space_name = self .schema .get_space (space_name ).sid
1177
1201
request = RequestInsert (self , space_name , values )
1178
- return self ._send_request (request )
1202
+ return self ._send_request (request , kwargs [ 'on_push_ctx' ] )
1179
1203
1180
- def delete (self , space_name , key , * , index = 0 ):
1204
+ def delete (self , space_name , key , * , index = 0 , ** kwargs ):
1181
1205
"""
1182
1206
Execute a DELETE request: `delete`_ a tuple in the space.
1183
1207
@@ -1202,15 +1226,19 @@ def delete(self, space_name, key, *, index=0):
1202
1226
.. _delete: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_space/delete/
1203
1227
"""
1204
1228
1229
+ # Case for absence of optional arg for accepting out-of-band msg data
1230
+ if not 'on_push_ctx' in kwargs :
1231
+ kwargs ['on_push_ctx' ] = []
1232
+
1205
1233
key = check_key (key )
1206
1234
if isinstance (space_name , str ):
1207
1235
space_name = self .schema .get_space (space_name ).sid
1208
1236
if isinstance (index , str ):
1209
1237
index = self .schema .get_index (space_name , index ).iid
1210
1238
request = RequestDelete (self , space_name , index , key )
1211
- return self ._send_request (request )
1239
+ return self ._send_request (request , kwargs [ 'on_push_ctx' ] )
1212
1240
1213
- def upsert (self , space_name , tuple_value , op_list , * , index = 0 ):
1241
+ def upsert (self , space_name , tuple_value , op_list , * , index = 0 , ** kwargs ):
1214
1242
"""
1215
1243
Execute an UPSERT request: `upsert`_ a tuple to the space.
1216
1244
@@ -1252,16 +1280,20 @@ def upsert(self, space_name, tuple_value, op_list, *, index=0):
1252
1280
.. _upsert: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_space/upsert/
1253
1281
"""
1254
1282
1283
+ # Case for absence of optional arg for accepting out-of-band msg data
1284
+ if not 'on_push_ctx' in kwargs :
1285
+ kwargs ['on_push_ctx' ] = []
1286
+
1255
1287
if isinstance (space_name , str ):
1256
1288
space_name = self .schema .get_space (space_name ).sid
1257
1289
if isinstance (index , str ):
1258
1290
index = self .schema .get_index (space_name , index ).iid
1259
1291
op_list = self ._ops_process (space_name , op_list )
1260
1292
request = RequestUpsert (self , space_name , index , tuple_value ,
1261
1293
op_list )
1262
- return self ._send_request (request )
1294
+ return self ._send_request (request , kwargs [ 'on_push_ctx' ] )
1263
1295
1264
- def update (self , space_name , key , op_list , * , index = 0 ):
1296
+ def update (self , space_name , key , op_list , * , index = 0 , ** kwargs ):
1265
1297
"""
1266
1298
Execute an UPDATE request: `update`_ a tuple in the space.
1267
1299
@@ -1331,14 +1363,18 @@ def update(self, space_name, key, op_list, *, index=0):
1331
1363
.. _update: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_space/update/
1332
1364
"""
1333
1365
1366
+ # Case for absence of optional arg for accepting out-of-band msg data
1367
+ if not 'on_push_ctx' in kwargs :
1368
+ kwargs ['on_push_ctx' ] = []
1369
+
1334
1370
key = check_key (key )
1335
1371
if isinstance (space_name , str ):
1336
1372
space_name = self .schema .get_space (space_name ).sid
1337
1373
if isinstance (index , str ):
1338
1374
index = self .schema .get_index (space_name , index ).iid
1339
1375
op_list = self ._ops_process (space_name , op_list )
1340
1376
request = RequestUpdate (self , space_name , index , key , op_list )
1341
- return self ._send_request (request )
1377
+ return self ._send_request (request , kwargs [ 'on_push_ctx' ] )
1342
1378
1343
1379
def ping (self , notime = False ):
1344
1380
"""
@@ -1368,7 +1404,7 @@ def ping(self, notime=False):
1368
1404
return "Success"
1369
1405
return t1 - t0
1370
1406
1371
- def select (self , space_name , key = None , * , offset = 0 , limit = 0xffffffff , index = 0 , iterator = None ):
1407
+ def select (self , space_name , key = None , * , offset = 0 , limit = 0xffffffff , index = 0 , iterator = None , ** kwargs ):
1372
1408
"""
1373
1409
Execute a SELECT request: `select`_ a tuple from the space.
1374
1410
@@ -1518,13 +1554,17 @@ def select(self, space_name, key=None, *, offset=0, limit=0xffffffff, index=0, i
1518
1554
# tuples)
1519
1555
key = check_key (key , select = True )
1520
1556
1557
+ # Case for absence of optional arg for accepting out-of-band msg data
1558
+ if not 'on_push_ctx' in kwargs :
1559
+ kwargs ['on_push_ctx' ] = []
1560
+
1521
1561
if isinstance (space_name , str ):
1522
1562
space_name = self .schema .get_space (space_name ).sid
1523
1563
if isinstance (index , str ):
1524
1564
index = self .schema .get_index (space_name , index ).iid
1525
1565
request = RequestSelect (self , space_name , index , key , offset ,
1526
1566
limit , iterator )
1527
- response = self ._send_request (request )
1567
+ response = self ._send_request (request , kwargs [ 'on_push_ctx' ] )
1528
1568
return response
1529
1569
1530
1570
def space (self , space_name ):
0 commit comments