@@ -22,6 +22,7 @@ local NotInitializedError = errors.new_class('NotInitialized')
22
22
local StorageInfoError = errors .new_class (' StorageInfoError' )
23
23
local VshardRouterError = errors .new_class (' VshardRouterError' , {capture_stack = false })
24
24
local fiber_clock = require (' fiber' ).clock
25
+ local fiber = require (' fiber' )
25
26
26
27
local utils = {}
27
28
@@ -105,19 +106,44 @@ function utils.get_space(space_name, replicasets)
105
106
' perhaps other instances are unavailable or you have configured only the router' )
106
107
end
107
108
108
- if replicaset .master == nil then
109
- local error_msg = string.format (
110
- ' The master was not found in replicaset %s, ' ..
111
- ' check status of the master and repeat the operation later' ,
112
- replicaset .uuid )
113
- return nil , GetSpaceError :new (error_msg )
114
- end
109
+ if replicaset .master == nil or replicaset .master .conn .error ~= nil then
110
+ -- Try to get master again with timeout.
111
+ local deadline = fiber_clock () + const .GET_SPACE_TIMEOUT
112
+ local vshard_router , err = utils .get_vshard_router_instance ()
113
+ if err ~= nil then
114
+ return nil , GetSpaceError :new (err )
115
+ end
116
+ while true do
117
+ :: continue::
118
+ fiber .yield ()
119
+ replicasets = vshard_router :routeall ()
120
+ replicaset = select (2 , next (replicasets ))
121
+
122
+ if replicaset .master ~= nil and replicaset .master .conn .error ~= nil then
123
+ if fiber_clock () < deadline then
124
+ -- Try to get the master again, the connection to it may be established.
125
+ goto continue
126
+ else
127
+ local error_msg = string.format (
128
+ ' The connection to the master of replicaset %s is not valid: %s' ,
129
+ replicaset .uuid , replicaset .master .conn .error )
130
+ return nil , GetSpaceError :new (error_msg )
131
+ end
132
+ end
133
+
134
+ if replicaset .master == nil and fiber_clock () >= deadline then
135
+ local error_msg = string.format (
136
+ ' The master was not found in replicaset %s, ' ..
137
+ ' check status of the master and repeat the operation later' ,
138
+ replicaset .uuid )
139
+ return nil , GetSpaceError :new (error_msg )
140
+ end
115
141
116
- if replicaset .master . conn .error ~ = nil then
117
- local error_msg = string.format (
118
- ' The connection to the master of replicaset %s is not valid: %s ' ,
119
- replicaset . uuid , replicaset . master . conn . error )
120
- return nil , GetSpaceError : new ( error_msg )
142
+ if replicaset .master ~= nil and replicaset . master . conn .error = = nil then
143
+ -- Break if there is master and connection to it is established.
144
+ break
145
+ end
146
+ end
121
147
end
122
148
local space = replicaset .master .conn .space [space_name ]
123
149
0 commit comments