99--- safe_mode change during execution.
1010
1111local vshard = require (' vshard' )
12+ local errors = require (' errors' )
1213
13- local M = {}
14+ local M = {
15+ BucketRefError = errors .new_class (' bucket_ref_error' , {capture_stack = false })
16+ }
17+
18+ local function make_bucket_ref_err (bucket_id , vshard_ref_err )
19+ local err = M .BucketRefError :new (M .BucketRefError :new (" failed bucket_ref: %s, bucket_id: %s" , vshard_ref_err .name , bucket_id ))
20+ err .bucket_ref_errs = {
21+ {
22+ bucket_id = bucket_id ,
23+ vshard_err = vshard_ref_err ,
24+ }
25+ }
26+ return err
27+ end
1428
1529--- on module initialization safe_mode_status func must be set
1630--- it's rebalance.safe_mode_status
@@ -31,7 +45,13 @@ function M.bucket_refrw(bucket_id)
3145 if not M .safe_mode_status () then
3246 return true
3347 end
34- return vshard .storage .bucket_refrw (bucket_id )
48+
49+ local ref_ok , vshard_ref_err = vshard .storage .bucket_refrw (bucket_id )
50+ if not ref_ok then
51+ return false , make_bucket_ref_err (bucket_id , vshard_ref_err )
52+ end
53+
54+ return true
3555end
3656
3757--- bucket_unrefrw calls vshard.storage.bucket_unrefrw if safe mode enabled
@@ -41,6 +61,7 @@ function M.bucket_unrefrw(bucket_id)
4161 if not M .safe_mode_status () then
4262 return true
4363 end
64+
4465 return vshard .storage .bucket_unrefrw (bucket_id )
4566end
4667
@@ -50,7 +71,13 @@ function M.bucket_refro(bucket_id)
5071 if not M .safe_mode_status () then
5172 return true
5273 end
53- return vshard .storage .bucket_refro (bucket_id )
74+
75+ local ref_ok , vshard_ref_err = vshard .storage .bucket_refro (bucket_id )
76+ if not ref_ok then
77+ return false , make_bucket_ref_err (bucket_id , vshard_ref_err )
78+ end
79+
80+ return true
5481end
5582
5683--- bucket_unrefro calls vshard.storage.bucket_unrefro if safe mode enabled
@@ -62,28 +89,4 @@ function M.bucket_unrefro(bucket_id)
6289 return vshard .storage .bucket_unrefro (bucket_id )
6390end
6491
65- --- bucket_unrefro calls vshard.storage.bucket_unrefrw for every bucket if safe mode enabled
66- --- otherwise returns true
67- --- @param bucket_ids table<number , true>
68- function M .bucket_unrefrw_many (bucket_ids )
69- if not M .safe_mode_status () then
70- return true
71- end
72-
73- local unref_all_ok = true
74- local unref_last_err
75- for reffed_bucket_id in pairs (bucket_ids ) do
76- local unref_ok , unref_err = M .bucket_unrefrw (reffed_bucket_id )
77- if not unref_ok then
78- unref_all_ok = nil
79- unref_last_err = unref_err
80- end
81- end
82-
83- if not unref_all_ok then
84- return nil , unref_last_err
85- end
86- return true
87- end
88-
8992return M
0 commit comments