@@ -249,13 +249,13 @@ func (r *Router) Call(ctx context.Context, bucketID uint64, mode CallMode,
249249 // poolMode, vshardMode = pool.PreferRO, ReadMode
250250 // since go-tarantool always use balance=true politic,
251251 // we can't support this case until: https://github.com/tarantool/go-tarantool/issues/400
252- return VshardRouterCallResp {}, fmt .Errorf ("mode VshardCallModeRE is not supported yet" )
252+ return VshardRouterCallResp {}, fmt .Errorf ("mode CallModeRE is not supported yet" )
253253 case CallModeBRO :
254254 poolMode , vshardMode = pool .ANY , ReadMode
255255 case CallModeBRE :
256256 poolMode , vshardMode = pool .PreferRO , ReadMode
257257 default :
258- return VshardRouterCallResp {}, fmt .Errorf ("unknown VshardCallMode (%d)" , mode )
258+ return VshardRouterCallResp {}, fmt .Errorf ("unknown CallMode (%d)" , mode )
259259 }
260260
261261 timeout := callTimeoutDefault
@@ -277,6 +277,9 @@ func (r *Router) Call(ctx context.Context, bucketID uint64, mode CallMode,
277277
278278 requestStartTime := time .Now ()
279279
280+ nameToReplicasetRef := r .getNameToReplicaset ()
281+ routerMap := r .getRouteMap ()
282+
280283 var err error
281284
282285 for {
@@ -293,7 +296,7 @@ func (r *Router) Call(ctx context.Context, bucketID uint64, mode CallMode,
293296
294297 var rs * Replicaset
295298
296- rs , err = r .Route (ctx , bucketID )
299+ rs , err = r .route (ctx , nameToReplicasetRef , routerMap , bucketID )
297300 if err != nil {
298301 r .metrics ().RetryOnCall ("bucket_resolve_error" )
299302
@@ -330,14 +333,12 @@ func (r *Router) Call(ctx context.Context, bucketID uint64, mode CallMode,
330333 switch vshardError .Name {
331334 case VShardErrNameWrongBucket , VShardErrNameBucketIsLocked , VShardErrNameTransferIsInProgress :
332335 // We reproduce here behavior in https://github.com/tarantool/vshard/blob/0.1.34/vshard/router/init.lua#L667
333- r .BucketReset ( bucketID )
336+ r .bucketReset ( routerMap , bucketID )
334337
335338 destination := vshardError .Destination
336339 if destination != "" {
337340 var loggedOnce bool
338341 for {
339- nameToReplicasetRef := r .getNameToReplicaset ()
340-
341342 // In some cases destination contains UUID (prior to tnt 3.x), in some cases it contains replicaset name.
342343 // So, at this point we don't know what destination is: a name or an UUID.
343344 // But we need a name to access values in nameToReplicasetRef map, so let's find it out.
@@ -359,11 +360,11 @@ func (r *Router) Call(ctx context.Context, bucketID uint64, mode CallMode,
359360 }
360361
361362 if destinationExists {
362- _ , err := r .BucketSet ( bucketID , destinationName )
363+ _ , err := r .bucketSet ( nameToReplicasetRef , routerMap , bucketID , destinationName )
363364 if err == nil {
364365 break // breaks loop
365366 }
366- r .log ().Warnf (ctx , "Failed set bucket %d to %v (possible race ): %v" , bucketID , destinationName , err )
367+ r .log ().Warnf (ctx , "Failed set bucket %d to %v (this should not happen ): %v" , bucketID , destinationName , err )
367368 }
368369
369370 if ! loggedOnce {
@@ -378,6 +379,9 @@ func (r *Router) Call(ctx context.Context, bucketID uint64, mode CallMode,
378379 if spent := time .Since (requestStartTime ); spent > timeout {
379380 return VshardRouterCallResp {}, vshardError
380381 }
382+
383+ // update nameToReplicasetRef explicitly before next try, the topology might changed.
384+ nameToReplicasetRef = r .getNameToReplicaset ()
381385 }
382386 }
383387
0 commit comments