Skip to content

Commit 85bc56c

Browse files
Make refresh before request
Remove useless reconnect kwarg. Some test clean up Fix compat with init mesh builder Fix compat Mesh class with original Connection Fixed variables names. Reworked strategy class. Reorked and added tests. Some small cleanup. Make validation parts. Add warning on config validation. Make cluster discovery after connect Add reconnect to refresh. More tests
1 parent 2768bf9 commit 85bc56c

File tree

10 files changed

+376
-232
lines changed

10 files changed

+376
-232
lines changed

README.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,10 @@ How to use the connector
8888
con = tarantool.Connection(host='localhost',
8989
port=3301,
9090
user='test',
91-
password='test',
92-
connect_now=True)
91+
password='test')
9392
9493
95-
resp = con.eval('return "Hello Wrold!"')
94+
resp = con.eval('return "Hello World!"')
9695
if resp.data[0] == "Hello World!":
9796
print('Ok')
9897

tarantool/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,19 @@ def connect(host="localhost", port=33013, user=None, password=None,
5151
encoding=encoding)
5252

5353

54-
def connectmesh(addrs=({'host': 'localhost', 'port': 3301},), user=None,
54+
def connectmesh(addresses=({'host': 'localhost', 'port': 3301},), user=None,
5555
password=None, encoding=ENCODING_DEFAULT):
5656
'''
5757
Create a connection to the mesh of Tarantool servers.
5858
59-
:param list addrs: A list of maps: {'host':(HOSTNAME|IP_ADDR), 'port':PORT}.
59+
:param list addesses: A list of maps: {'host':(HOSTNAME|IP_ADDR), 'port':PORT}.
6060
6161
:rtype: :class:`~tarantool.mesh_connection.MeshConnection`
6262
6363
:raise: `NetworkError`
6464
'''
6565

66-
return MeshConnection(addrs=addrs,
66+
return MeshConnection(addresses=addresses,
6767
user=user,
6868
password=password,
6969
socket_timeout=SOCKET_TIMEOUT,

tarantool/connection.py

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,19 @@ def __init__(self, host, port,
126126
self.encoding = encoding
127127
self.call_16 = call_16
128128
self.connection_timeout = connection_timeout
129-
self.authenticated = False
130129
if connect_now:
131130
self.connect()
132131

133132
def close(self):
134133
'''
135134
Close connection to the server
136135
'''
136+
self.connected = False
137137
self._socket.close()
138138
self._socket = None
139139

140140
def connect_basic(self):
141-
if self.host == None:
141+
if self.host is None:
142142
self.connect_unix()
143143
else:
144144
self.connect_tcp()
@@ -201,11 +201,9 @@ def connect(self):
201201
:raise: `NetworkError`
202202
'''
203203
try:
204-
self.authenticated = False
205204
self.connect_basic()
206205
self.handshake()
207206
self.load_schema()
208-
self.authenticated = True
209207
except Exception as e:
210208
self.connected = False
211209
raise NetworkError(e)
@@ -295,13 +293,12 @@ def check(): # Check that connection is alive
295293
retbytes = self._sys_recv(sock_fd, buf, 1, flag)
296294

297295
err = 0
298-
if os.name!= 'nt':
296+
if os.name != 'nt':
299297
err = ctypes.get_errno()
300298
else:
301299
err = ctypes.get_last_error()
302300
self._socket.setblocking(True)
303301

304-
305302
WWSAEWOULDBLOCK = 10035
306303
if (retbytes < 0) and (err == errno.EAGAIN or
307304
err == errno.EWOULDBLOCK or
@@ -368,38 +365,20 @@ def call(self, func_name, *args):
368365
369366
:param func_name: stored Lua function name
370367
:type func_name: str
371-
:param args: list of function arguments
372-
:type args: list or tuple
368+
:param args: function arguments
369+
:type args: tuple
373370
374371
:rtype: `Response` instance
375372
'''
376373

374+
assert isinstance(func_name, str)
375+
377376
# This allows to use a tuple or list as an argument
378377
if len(args) == 1 and isinstance(args[0], (list, tuple)):
379378
args = args[0]
380379

381-
return self.call_ex(func_name, args, True)
382-
383-
def call_ex(self, func_name, args=[], reconnect=True):
384-
'''
385-
Execute CALL request. Call stored Lua function.
386-
387-
:param func_name: stored Lua function name
388-
:type func_name: str
389-
:param args: list of function arguments
390-
:type args: list or tuple
391-
:param reconnect: reconnect before call
392-
:type reconnect: boolean
393-
394-
:rtype: `Response` instance
395-
'''
396-
assert isinstance(func_name, str)
397-
398380
request = RequestCall(self, func_name, args, self.call_16)
399-
if reconnect:
400-
response = self._send_request(request)
401-
else:
402-
response = self._send_request_wo_reconnect(request)
381+
response = self._send_request(request)
403382
return response
404383

405384
def eval(self, expr, *args):
@@ -413,34 +392,14 @@ def eval(self, expr, *args):
413392
414393
:rtype: `Response` instance
415394
'''
395+
assert isinstance(expr, str)
416396

417397
# This allows to use a tuple or list as an argument
418398
if len(args) == 1 and isinstance(args[0], (list, tuple)):
419399
args = args[0]
420400

421-
return self.eval_ex(expr, args, True)
422-
423-
def eval_ex(self, expr, args=[], reconnect=True):
424-
'''
425-
Execute EVAL request. Eval Lua expression.
426-
427-
:param expr: Lua expression
428-
:type expr: str
429-
:param args: list of function arguments
430-
:type args: list or tuple
431-
:param reconnect: reconnect before call
432-
:type reconnect: boolean
433-
434-
:rtype: `Response` instance
435-
'''
436-
assert isinstance(expr, str)
437-
438401
request = RequestEval(self, expr, args)
439-
if reconnect:
440-
response = self._send_request(request)
441-
else:
442-
response = self._send_request_wo_reconnect(request)
443-
return response
402+
return self._send_request(request)
444403

445404
def replace(self, space_name, values):
446405
'''

tarantool/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,4 @@
8787
# Default delay between attempts to reconnect (seconds)
8888
RECONNECT_DELAY = 0.1
8989
# Default cluster nodes list refresh interval (seconds)
90-
NODES_REFRESH_INTERVAL = 300
90+
CLUSTER_DISCOVERY_DELAY = 60

tarantool/error.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ class NetworkWarning(UserWarning):
151151
'''Warning related to network'''
152152
pass
153153

154+
class ConfigurationWarning(UserWarning):
155+
'''Warning in configuration validation'''
156+
pass
154157

155158
# always print this warnings
156159
warnings.filterwarnings("always", category=NetworkWarning)

0 commit comments

Comments
 (0)