Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Write plan to /tmp/rebalance_plan.txt
Was a request by @mattwhite to help with automation.  I was fairly
sloppy in the implementation here, could leave this off and do a better
job next time.
  • Loading branch information
kocolosk authored and rnewson committed Jul 23, 2014
1 parent c63fc05 commit e147621ce9b4703228fc548280503a64eb65750b
Showing 1 changed file with 16 additions and 2 deletions.
@@ -51,10 +51,14 @@ expand() ->
%% @doc Expands a cluster without requiring each DB to be optimally balanced.
-spec expand(integer() | global) -> [{atom(), #shard{}, node()}].
expand(global) ->
{ok, FD} = file:open("/tmp/rebalance_plan.txt", [write]),
erlang:put(fd, FD),
global_expand(surviving_nodes(), [], 1000);

%% @doc Expands all databases in the cluster, stopping at Limit operations.
expand(Limit) when is_integer(Limit), Limit > 0 ->
{ok, FD} = file:open("/tmp/rebalance_plan.txt", [write]),
erlang:put(fd, FD),
TargetNodes = surviving_nodes(),
LocalBalanceFun = fun(Db, Moves) -> expand(Db, TargetNodes, Moves) end,
LocalBalanceOps = apply_to_cluster(LocalBalanceFun, Limit),
@@ -85,6 +89,8 @@ contract() ->
%% @doc Computes a plan to remove up to Limit shards from nodes in "decom" zone.
-spec contract(integer()) -> [{atom(), #shard{}, node()}].
contract(Limit) when is_integer(Limit), Limit > 0 ->
{ok, FD} = file:open("/tmp/rebalance_plan.txt", [write]),
erlang:put(fd, FD),
TargetNodes = surviving_nodes(),
apply_to_cluster(fun(Db, Moves) -> contract(Db, TargetNodes, Moves) end, Limit);

@@ -111,6 +117,8 @@ fix_zoning() ->
%% levels and improper zoning.
-spec fix_zoning(integer()) -> [{atom(), #shard{}, node()}].
fix_zoning(Limit) when is_integer(Limit), Limit > 0 ->
{ok, FD} = file:open("/tmp/rebalance_plan.txt", [write]),
erlang:put(fd, FD),
apply_to_cluster(fun fix_zoning/2, Limit);

fix_zoning(DbName) when is_binary(DbName); is_list(DbName) ->
@@ -485,8 +493,14 @@ print({Op, Shard, TargetNode} = Operation) ->
[{capture, all_but_first, binary}]
),
OpName = case Op of move -> move2; _ -> Op end,
io:format("clou shard ~s ~s ~s ~s ~s ~s ~s~n", [OpName, Cluster, Account, DbName,
Range, SourceId, TargetId]),
case get(fd) of
undefined ->
io:format("clou shard ~s ~s ~s ~s ~s ~s ~s~n", [OpName,
Cluster, Account, DbName, Range, SourceId, TargetId]);
FD ->
io:format(FD, "clou shard ~s ~s ~s ~s ~s ~s ~s~n", [OpName,
Cluster, Account, DbName, Range, SourceId, TargetId])
end,
Operation;

print(Operations) when is_list(Operations) ->

0 comments on commit e147621

Please sign in to comment.