Skip to content

Commit

Permalink
Merge pull request #972 from basho/mas-i970-simpleleave
Browse files Browse the repository at this point in the history
Refactor leave - balance and tail violations
  • Loading branch information
martinsumner authored Oct 8, 2021
2 parents 6d25900 + cc95353 commit b36a7ae
Show file tree
Hide file tree
Showing 4 changed files with 329 additions and 57 deletions.
16 changes: 16 additions & 0 deletions priv/riak_core.schema
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,22 @@
hidden
]}.

%% @doc On cluster leave - force full rebalance partitions
%% By default on a cluster leave there will first be an attempt to handoff
%% vnodes to safe (in terms of target_n_val) locations. In small clusters,
%% there may be insufficient safe locations, and a temporary state can be
%% created where a single node has a large number of vnodes.
%% To mitigate this, a full rebalance (a re-assignment that does not optimise
%% based on the starting position), can be forced by setting this option on
%% all nodes.
%% Please carefully consider any cluster plan created with this option before
%% committing
{mapping, "full_rebalance_onleave", "riak_core.full_rebalance_onleave", [
{datatype, flag},
{default, off}
]}.


%% Async Job Management
%%
%% This is a translation for mappings that appear in other schema files.
Expand Down
7 changes: 6 additions & 1 deletion src/riak_core_claim.erl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
choose_claim_v2/1, choose_claim_v2/2, choose_claim_v2/3,
choose_claim_v3/1, choose_claim_v3/2, choose_claim_v3/3,
claim_rebalance_n/2, claim_diversify/3, claim_diagonal/3,
wants/1, wants_owns_diff/2, meets_target_n/2, diagonal_stripe/2]).
wants/1, wants_owns_diff/2, meets_target_n/2, diagonal_stripe/2,
sequential_claim/2, get_counts/2]).

-ifdef(TEST).
-compile(export_all).
Expand Down Expand Up @@ -620,6 +621,10 @@ claim_diagonal(Wants, Owners, Params) ->
end,
{lists:flatten([lists:duplicate(Reps, Claiming), Last]), [diagonalized]}.

sequential_claim(Ring, Node) ->
TN = app_helper:get_env(riak_core, target_n_val, ?DEF_TARGET_N),
sequential_claim(Ring, Node, TN).

%% @private fall back to diagonal striping vnodes across nodes in a
%% sequential round robin (eg n1 | n2 | n3 | n4 | n5 | n1 | n2 | n3
%% etc) However, different to `claim_rebalance_n', this function
Expand Down
10 changes: 10 additions & 0 deletions src/riak_core_console.erl
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,16 @@ print_plan(Changes, Ring, NextRings) ->
"cluster transitions~n~n", [Transitions])
end,

Leaves = length(lists:filter(fun({_N, A}) -> A == leave end, Changes)) > 0,

case Leaves and app_helper:get_env(riak_core, full_rebalance_onleave) of
true ->
io:format("WARNING: Full rebalance forced by non-default "
"option riak_core.full_rebalance_onleave = true~n~n");
_ ->
ok
end,

_ = lists:foldl(fun({Ring1, Ring2}, I) ->
io:format("~79..#s~n", [""]),
io:format("~24.. s After cluster transition ~b/~b~n",
Expand Down
Loading

0 comments on commit b36a7ae

Please sign in to comment.