Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
yosukehara committed Jul 29, 2015
1 parent 2a4c70b commit ec22232
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 50 deletions.
14 changes: 2 additions & 12 deletions src/leo_mdcr_tbl_cluster_info.erl
Original file line number Diff line number Diff line change
Expand Up @@ -338,20 +338,10 @@ transform_2() ->
%% @private
transform_3([]) ->
ok;
transform_3([#?CLUSTER_INFO{cluster_id = ClusterId}|Rest]) when is_atom(ClusterId) ->
transform_3(Rest);
transform_3([#?CLUSTER_INFO{cluster_id = ClusterId,
dc_id = DCId} = ClusterInfo|Rest]) ->
ClusterId_1 = case is_atom(ClusterId) of
true -> ClusterId;
false -> list_to_atom(ClusterId)
end,
DCId_1 = case is_atom(DCId) of
true -> DCId;
false -> list_to_atom(DCId)
end,
NewClusterInfo = ClusterInfo#?CLUSTER_INFO{cluster_id = ClusterId_1,
dc_id = DCId_1},
NewClusterInfo = ClusterInfo#?CLUSTER_INFO{cluster_id = ClusterId,
dc_id = DCId},
case update(NewClusterInfo) of
ok ->
void;
Expand Down
2 changes: 1 addition & 1 deletion src/leo_membership_cluster_remote.erl
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ exec([#cluster_manager{node = Node,


%% @private
-spec(exec_1(atom(), #?CLUSTER_STAT{}, #?CLUSTER_STAT{}) ->
-spec(exec_1(atom(), #?CLUSTER_STAT{}, #?CLUSTER_STAT{}|undefined) ->
ok | {error, any()}).
exec_1(Node,
#?CLUSTER_STAT{checksum = Checksum_1,
Expand Down
4 changes: 2 additions & 2 deletions src/leo_redundant_manager.erl
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ has_member(Node) ->
%% @doc Retrieve all members.
%%
-spec(get_members() ->
{ok, [#member{}]}).
{ok, [#member{}]} | {error, any()}).
get_members() ->
gen_server:call(?MODULE, {get_members, ?VER_CUR}, ?DEF_TIMEOUT).

-spec(get_members(Ver) ->
{ok, [#member{}]} when Ver::?VER_CUR|?VER_PREV).
{ok, [#member{}]} | {error, any()} when Ver::?VER_CUR|?VER_PREV).
get_members(Ver) ->
gen_server:call(?MODULE, {get_members, Ver}, ?DEF_TIMEOUT).

Expand Down
31 changes: 8 additions & 23 deletions src/leo_redundant_manager_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,8 @@ checksum(?CHECKSUM_RING) ->
checksum(?CHECKSUM_WORKER) ->
leo_redundant_manager_worker:checksum();
checksum(?CHECKSUM_SYS_CONF) ->
case get_options() of
{ok, SysConf} ->
{ok, erlang:crc32(term_to_binary(SysConf))};
_ ->
{ok, -1}
end;
{ok, SysConf} = get_options(),
{ok, erlang:crc32(term_to_binary(SysConf))};
checksum(_) ->
{error, invalid_type}.

Expand Down Expand Up @@ -583,14 +579,10 @@ get_redundancies_by_key(Key) ->
{error, any()} when Method::method(),
Key::binary()).
get_redundancies_by_key(Method, Key) ->
case get_options() of
{ok, Options} ->
BitOfRing = leo_misc:get_value(?PROP_RING_BIT, Options),
AddrId = leo_redundant_manager_chash:vnode_id(BitOfRing, Key),
get_redundancies_by_addr_id_1(ring_table(Method), AddrId, Options);
_ ->
{error, not_found}
end.
{ok, Options} = get_options(),
BitOfRing = leo_misc:get_value(?PROP_RING_BIT, Options),
AddrId = leo_redundant_manager_chash:vnode_id(BitOfRing, Key),
get_redundancies_by_addr_id_1(ring_table(Method), AddrId, Options).


%% @doc Retrieve redundancies from the ring-table.
Expand All @@ -605,15 +597,8 @@ get_redundancies_by_addr_id(AddrId) ->
{ok, #redundancies{}} |
{error, any()} when Method::method(), AddrId::integer()).
get_redundancies_by_addr_id(Method, AddrId) ->
Options_1 = case get_options() of
{ok, Options} ->
Options;
_ ->
{ok, Options} = get_options(),
ok = set_options(Options),
Options
end,
get_redundancies_by_addr_id_1(ring_table(Method), AddrId, Options_1).
{ok, Options} = get_options(),
get_redundancies_by_addr_id_1(ring_table(Method), AddrId, Options).

%% @private
-spec(get_redundancies_by_addr_id_1({_,atom()}, integer(), [_]) ->
Expand Down
20 changes: 8 additions & 12 deletions src/leo_redundant_manager_worker.erl
Original file line number Diff line number Diff line change
Expand Up @@ -309,18 +309,14 @@ timestamp() ->
%% @doc Retrieve the number of replicas
%% @private
update_state(State) ->
case leo_redundant_manager_api:get_options() of
{ok, Options} ->
NumOfReplica = leo_misc:get_value(?PROP_N, Options, 0),
case (NumOfReplica > 0) of
true ->
NumOfL2 = leo_misc:get_value(?PROP_L2, Options, 0),
State#state{num_of_replicas = NumOfReplica,
num_of_rack_awareness = NumOfL2};
false ->
State
end;
_ ->
{ok, Options} = leo_redundant_manager_api:get_options(),
NumOfReplica = leo_misc:get_value(?PROP_N, Options, 0),
case (NumOfReplica > 0) of
true ->
NumOfL2 = leo_misc:get_value(?PROP_L2, Options, 0),
State#state{num_of_replicas = NumOfReplica,
num_of_rack_awareness = NumOfL2};
false ->
State
end.

Expand Down

0 comments on commit ec22232

Please sign in to comment.