@@ -20,13 +20,14 @@ local GetSpaceError = errors.new_class('GetSpaceError')
20
20
local GetSpaceFormatError = errors .new_class (' GetSpaceFormatError' , {capture_stack = false })
21
21
local FilterFieldsError = errors .new_class (' FilterFieldsError' , {capture_stack = false })
22
22
local NotInitializedError = errors .new_class (' NotInitialized' )
23
- local StorageInfoError = errors .new_class (' StorageInfoError' )
24
23
local VshardRouterError = errors .new_class (' VshardRouterError' , {capture_stack = false })
25
24
local UtilsInternalError = errors .new_class (' UtilsInternalError' , {capture_stack = false })
26
25
local fiber = require (' fiber' )
27
26
28
27
local utils = {}
29
28
29
+ utils .STORAGE_NAMESPACE = ' _crud'
30
+
30
31
--- Returns a full call string for a storage function name.
31
32
--
32
33
-- @param string name a base name of the storage function.
@@ -35,11 +36,9 @@ local utils = {}
35
36
function utils .get_storage_call (name )
36
37
dev_checks (' string' )
37
38
38
- return ' _crud. ' .. name
39
+ return ( ' %s.%s ' ): format ( utils . STORAGE_NAMESPACE , name )
39
40
end
40
41
41
- local CRUD_STORAGE_INFO_FUNC_NAME = utils .get_storage_call (' storage_info_on_storage' )
42
-
43
42
local space_format_cache = setmetatable ({}, {__mode = ' k' })
44
43
45
44
-- copy from LuaJIT lj_char.c
@@ -1131,100 +1130,6 @@ function utils.list_slice(list, start_index, end_index)
1131
1130
return slice
1132
1131
end
1133
1132
1134
- --- Polls replicas for storage state
1135
- --
1136
- -- @function storage_info
1137
- --
1138
- -- @tparam ?number opts.timeout
1139
- -- Function call timeout
1140
- --
1141
- -- @tparam ?string|table opts.vshard_router
1142
- -- Cartridge vshard group name or vshard router instance.
1143
- --
1144
- -- @return a table of storage states by replica id.
1145
- function utils .storage_info (opts )
1146
- opts = opts or {}
1147
-
1148
- local vshard_router , err = utils .get_vshard_router_instance (opts .vshard_router )
1149
- if err ~= nil then
1150
- return nil , StorageInfoError :new (err )
1151
- end
1152
-
1153
- local replicasets , err = vshard_router :routeall ()
1154
- if replicasets == nil then
1155
- return nil , StorageInfoError :new (" Failed to get router replicasets: %s" , err .err )
1156
- end
1157
-
1158
- local futures_by_replicas = {}
1159
- local replica_state_by_id = {}
1160
- local async_opts = {is_async = true }
1161
- local timeout = opts .timeout or const .DEFAULT_VSHARD_CALL_TIMEOUT
1162
-
1163
- for _ , replicaset in pairs (replicasets ) do
1164
- for replica_id , replica in pairs (replicaset .replicas ) do
1165
- local master = utils .get_replicaset_master (replicaset , {cached = false })
1166
-
1167
- replica_state_by_id [replica_id ] = {
1168
- status = " error" ,
1169
- is_master = master == replica
1170
- }
1171
-
1172
- local ok , res = pcall (replica .conn .call , replica .conn , CRUD_STORAGE_INFO_FUNC_NAME ,
1173
- {}, async_opts )
1174
- if ok then
1175
- futures_by_replicas [replica_id ] = res
1176
- else
1177
- local err_msg = string.format (" Error getting storage info for %s" , replica_id )
1178
- if res ~= nil then
1179
- log .error (" %s: %s" , err_msg , res )
1180
- replica_state_by_id [replica_id ].message = tostring (res )
1181
- else
1182
- log .error (err_msg )
1183
- replica_state_by_id [replica_id ].message = err_msg
1184
- end
1185
- end
1186
- end
1187
- end
1188
-
1189
- local deadline = fiber .clock () + timeout
1190
- for replica_id , future in pairs (futures_by_replicas ) do
1191
- local wait_timeout = deadline - fiber .clock ()
1192
- if wait_timeout < 0 then
1193
- wait_timeout = 0
1194
- end
1195
-
1196
- local result , err = future :wait_result (wait_timeout )
1197
- if result == nil then
1198
- future :discard ()
1199
- local err_msg = string.format (" Error getting storage info for %s" , replica_id )
1200
- if err ~= nil then
1201
- if err .type == ' ClientError' and err .code == box .error .NO_SUCH_PROC then
1202
- replica_state_by_id [replica_id ].status = " uninitialized"
1203
- else
1204
- log .error (" %s: %s" , err_msg , err )
1205
- replica_state_by_id [replica_id ].message = tostring (err )
1206
- end
1207
- else
1208
- log .error (err_msg )
1209
- replica_state_by_id [replica_id ].message = err_msg
1210
- end
1211
- else
1212
- replica_state_by_id [replica_id ].status = result [1 ].status or " uninitialized"
1213
- end
1214
- end
1215
-
1216
- return replica_state_by_id
1217
- end
1218
-
1219
- --- Storage status information.
1220
- --
1221
- -- @function storage_info_on_storage
1222
- --
1223
- -- @return a table with storage status.
1224
- function utils .storage_info_on_storage ()
1225
- return {status = " running" }
1226
- end
1227
-
1228
1133
--- Initializes a storage function by its name.
1229
1134
--
1230
1135
-- It adds the function into the global scope by its name and required
@@ -1240,7 +1145,7 @@ end
1240
1145
function utils .init_storage_call (user , name , func )
1241
1146
dev_checks (' ?string' , ' string' , ' function' )
1242
1147
1243
- rawset (_G [' _crud ' ], name , func )
1148
+ rawset (_G [utils . STORAGE_NAMESPACE ], name , func )
1244
1149
1245
1150
if user ~= nil then
1246
1151
name = utils .get_storage_call (name )
0 commit comments