9
9
RECONNECT_DELAY , RECONNECT_MAX_ATTEMPTS ,
10
10
SOCKET_TIMEOUT )
11
11
from tarantool .error import (ClusterConnectWarning , ClusterTolopogyWarning ,
12
- ConfigurationError , warn )
12
+ ConfigurationError , DatabaseError , tnt_strerror ,
13
+ warn )
13
14
from tarantool .utils import ENCODING_DEFAULT
14
15
15
16
try :
@@ -184,10 +185,9 @@ def close(self):
184
185
def is_closed (self ):
185
186
raise NotImplementedError
186
187
187
- def connect (self ):
188
+ def update_ro_info (self ):
188
189
for addr in self .addrs :
189
190
key = json .dumps (addr )
190
- self .pool [key ]['conn' ].connect ()
191
191
192
192
if not self .pool [key ]['conn' ].connected :
193
193
msg = 'Failed to connect to %s:%s' % str (addr ['host' ], addr ['port' ])
@@ -203,14 +203,45 @@ def connect(self):
203
203
204
204
self .strategy .update (self .pool )
205
205
206
+ def connect (self ):
207
+ for addr in self .addrs :
208
+ key = json .dumps (addr )
209
+ self .pool [key ]['conn' ].connect ()
210
+
211
+ self .update_ro_info ()
212
+
206
213
def call (self , func_name , * args , ** kwargs ):
207
214
mode = kwargs .get ('mode' , Mode .PREFER_RW )
208
215
conn = self .strategy .getnext (mode )
209
216
210
- return conn .call (func_name , args )
217
+ # try:
218
+ resp = conn .call (func_name , args )
219
+ # except ValueError:
220
+ #reload
221
+ # resp = conn.call(func_name, args)
222
+
223
+ return resp
211
224
212
- def eval (self , expr , * args ):
213
- raise NotImplementedError
225
+ def eval (self , expr , * args , ** kwargs ):
226
+ mode = kwargs .get ('mode' , Mode .PREFER_RW )
227
+ conn = self .strategy .getnext (mode )
228
+
229
+ try :
230
+ resp = conn .eval (expr , args )
231
+ except DatabaseError as e :
232
+ if len (e .args ) > 0 :
233
+ strerror = tnt_strerror (e .args [0 ])
234
+ else :
235
+ raise
236
+
237
+ if strerror != 'UNDEFINED' and strerror [0 ] == 'ER_READONLY' :
238
+ self .update_ro_info ()
239
+ conn = self .strategy .getnext (mode )
240
+ resp = conn .eval (expr , args )
241
+ else :
242
+ raise
243
+
244
+ return resp
214
245
215
246
def replace (self , space_name , values ):
216
247
raise NotImplementedError
0 commit comments