Skip to content

Commit

Permalink
Adding helpful utilities for diagnosing and fixing rings
Browse files Browse the repository at this point in the history
  • Loading branch information
dizzyd committed Oct 20, 2010
1 parent c5ae7dd commit c9a2cee
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions ebin/riak_core.app
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
riak_core_ring_events,
riak_core_ring_handler,
riak_core_ring_manager,
riak_core_ring_util,
riak_core_sup,
riak_core_test_util,
riak_core_util,
Expand Down
57 changes: 57 additions & 0 deletions src/riak_core_ring_util.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
%% -------------------------------------------------------------------
%%
%% riak_core: Core Riak Application
%%
%% Copyright (c) 2007-2010 Basho Technologies, Inc. All Rights Reserved.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
%% except in compliance with the License. You may obtain
%% a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing,
%% software distributed under the License is distributed on an
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
%% KIND, either express or implied. See the License for the
%% specific language governing permissions and limitations
%% under the License.
%%
%% -------------------------------------------------------------------
-module(riak_core_ring_util).

-export([assign/2,
check_ring/0,
check_ring/1]).

%% @doc Forcibly assign a partition to a specific node
assign(Partition, ToNode) ->
F = fun(Ring, _) ->
{new_ring, riak_core_ring:transfer_node(Partition, ToNode, Ring)}
end,
{ok, _} = riak_core_ring_manager:ring_trans(F, undefined),
%% TODO: ring_trans really should kick off a write of the ringfile, but
%% currently doesn't. Do so manually.
riak_core_ring_manager:do_write_ringfile(),
ok.

%% @doc Check the local ring for any preflists that do not satisfy n_val
check_ring() ->
{ok, R} = riak_core_ring_manager:get_my_ring(),
check_ring(R).

%% @doc Check a ring for any preflists that do not satisfy n_val
check_ring(Ring) ->
{ok, Props} = application:get_env(riak_core, default_bucket_props),
{n_val, Nval} = lists:keyfind(n_val, 1, Props),
Preflists = riak_core_ring:all_preflists(Ring, Nval),
lists:foldl(fun(PL,Acc) ->
PLNodes = lists:usort([Node || {_,Node} <- PL]),
case length(PLNodes) of
Nval ->
Acc;
_ ->
ordsets:add_element(PL, Acc)
end
end, [], Preflists).

0 comments on commit c9a2cee

Please sign in to comment.