Skip to content

Commit c7c8376

Browse files
committed
rebalancer: refactoring of rebalancer_request_state
Before this patch the function `rebalancer_request_state` returned only nil in case of errors (e.g. presence of SENDING, RECEIVING, GARBAGE buckets, not active rebalancer). This makes it inconsistent compared to other rebalancer functions. Now, in case of errors we return `(nil, err)` instead of `nil`. It can help us to propagate a meaningful error in rebalancer service. NO_TEST=refactoring NO_DOC=refactoring
1 parent 06c15b0 commit c7c8376

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

test/unit/rebalancer.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,16 @@ _bucket:replace{1, consts.BUCKET.RECEIVING}
325325
...
326326
get_state()
327327
---
328+
- null
329+
- name: PROC_LUA
330+
code: 32
331+
base_type: ClientError
332+
type: ClientError
333+
details: Replica _ has receiving buckets
334+
message: Replica _ has receiving buckets
335+
trace:
336+
- file: /home/mrforza/Desktop/vshard/vshard/error.lua
337+
line: 284
328338
...
329339
vshard.storage.internal.is_master = false
330340
---

vshard/storage/init.lua

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2945,18 +2945,23 @@ local function rebalancer_request_state()
29452945
return nil, err
29462946
end
29472947
if not M.is_rebalancer_active or rebalancing_is_in_progress() then
2948-
return
2948+
return nil, lerror.make('Rebalancer is not active or is in progress')
29492949
end
29502950
local _bucket = box.space._bucket
29512951
local status_index = _bucket.index.status
2952+
local repl_id = M.this_replica and M.this_replica.id or '_'
2953+
local buckets_invalid_state = 'Replica %s has %s buckets'
29522954
if #status_index:select({BSENDING}, {limit = 1}) > 0 then
2953-
return
2955+
return nil, lerror.make(string.format(buckets_invalid_state, repl_id,
2956+
consts.BUCKET.SENDING))
29542957
end
29552958
if #status_index:select({BRECEIVING}, {limit = 1}) > 0 then
2956-
return
2959+
return nil, lerror.make(string.format(buckets_invalid_state, repl_id,
2960+
consts.BUCKET.RECEIVING))
29572961
end
29582962
if #status_index:select({BGARBAGE}, {limit = 1}) > 0 then
2959-
return
2963+
return nil, lerror.make(string.format(buckets_invalid_state, repl_id,
2964+
consts.BUCKET.GARBAGE))
29602965
end
29612966
return {
29622967
bucket_active_count = status_index:count({BACTIVE}),

0 commit comments

Comments
 (0)