@@ -18,8 +18,49 @@ local CRUD_CALL_FUNC_NAME = utils.get_storage_call(CALL_FUNC_NAME)
1818
1919local call = {}
2020
21- local function call_on_storage (run_as_user , func_name , ...)
22- return box .session .su (run_as_user , call_cache .func_name_to_func (func_name ), ... )
21+ local bucket_ref_many
22+ local bucket_unref_many
23+
24+ bucket_ref_many = function (bucket_ids , mode )
25+ local reffed = {}
26+ for _ , bucket_id in pairs (bucket_ids ) do
27+ local ok , err = vshard .storage .bucket_ref (bucket_id , mode )
28+ if not ok then
29+ bucket_unref_many (reffed , mode )
30+ return nil , err
31+ end
32+ table.insert (reffed , bucket_id )
33+ end
34+ return true , nil
35+ end
36+
37+ bucket_unref_many = function (bucket_ids , mode )
38+ local all_ok = true
39+ local last_err = nil
40+ for _ , bucket_id in pairs (bucket_ids ) do
41+ local ok , err = vshard .storage .bucket_unref (bucket_id , mode )
42+ if not ok then
43+ all_ok = nil
44+ last_err = err
45+ end
46+ end
47+ return all_ok , last_err
48+ end
49+
50+ local function call_on_storage (run_as_user , bucket_ids , mode , func_name , ...)
51+ local ok , ref_err = bucket_ref_many (bucket_ids , mode )
52+ if not ok then
53+ return nil , ref_err
54+ end
55+
56+ local res = {box .session .su (run_as_user , call_cache .func_name_to_func (func_name ), ... )}
57+
58+ ok , ref_err = bucket_unref_many (bucket_ids , mode )
59+ if not ok then
60+ return nil , ref_err
61+ end
62+
63+ return unpack (res , 1 , table.maxn (res ))
2364end
2465
2566call .storage_api = {[CALL_FUNC_NAME ] = call_on_storage }
@@ -82,8 +123,8 @@ local function wrap_vshard_err(vshard_router, err, func_name, replicaset_id, buc
82123 ))
83124end
84125
85- local function retry_call_with_master_discovery (replicaset , method , func_name , func_args , call_opts )
86- local func_args_ext = utils .append_array ({ box .session .effective_user (), func_name }, func_args )
126+ local function retry_call_with_master_discovery (replicaset , method , func_name , func_args , call_opts , mode , bucket_ids )
127+ local func_args_ext = utils .append_array ({ box .session .effective_user (), bucket_ids , mode , func_name }, func_args )
87128
88129 -- In case cluster was just bootstrapped with auto master discovery,
89130 -- replicaset may miss master.
@@ -148,7 +189,7 @@ function call.map(vshard_router, func_name, func_args, opts)
148189 local args , replicaset , replicaset_id = iter :get ()
149190
150191 local future , err = retry_call_with_master_discovery (replicaset , vshard_call_name ,
151- func_name , args , call_opts )
192+ func_name , args , call_opts , opts . mode , {}) -- TODO: provide bucket_ids
152193
153194 if err ~= nil then
154195 local result_info = {
@@ -222,8 +263,8 @@ function call.single(vshard_router, bucket_id, func_name, func_args, opts)
222263 local request_timeout = opts .mode == ' read' and opts .request_timeout or nil
223264
224265 local res , err = retry_call_with_master_discovery (replicaset , vshard_call_name ,
225- func_name , func_args , {timeout = timeout ,
226- request_timeout = request_timeout })
266+ func_name , func_args , {timeout = timeout , request_timeout = request_timeout },
267+ opts . mode , { bucket_id })
227268 if err ~= nil then
228269 return nil , wrap_vshard_err (vshard_router , err , func_name , nil , bucket_id )
229270 end
@@ -249,7 +290,8 @@ function call.any(vshard_router, func_name, func_args, opts)
249290 local replicaset_id , replicaset = next (replicasets )
250291
251292 local res , err = retry_call_with_master_discovery (replicaset , ' call' ,
252- func_name , func_args , {timeout = timeout })
293+ func_name , func_args , {timeout = timeout },
294+ ' read' , {})
253295 if err ~= nil then
254296 return nil , wrap_vshard_err (vshard_router , err , func_name , replicaset_id )
255297 end
0 commit comments