Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure legacy nodes are probed when new capabilities registered #219

Merged
merged 1 commit into from Aug 3, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 23 additions & 11 deletions src/riak_core_capability.erl
Expand Up @@ -205,11 +205,12 @@ init_state(Registered) ->


handle_call({register, Capability, Info}, _From, State) -> handle_call({register, Capability, Info}, _From, State) ->
State2 = register_capability(node(), Capability, Info, State), State2 = register_capability(node(), Capability, Info, State),
State3 = renegotiate_capabilities(State2), State3 = update_supported(State2),
publish_supported(State3), State4 = renegotiate_capabilities(State3),
update_local_cache(State3), publish_supported(State4),
save_registered(State3#state.registered), update_local_cache(State4),
{reply, ok, State3}; save_registered(State4#state.registered),
{reply, ok, State4};


handle_call({ring_changed, Ring}, _From, State) -> handle_call({ring_changed, Ring}, _From, State) ->
State2 = update_supported(Ring, State), State2 = update_supported(Ring, State),
Expand Down Expand Up @@ -265,6 +266,10 @@ reload(State) ->
save_registered(State3#state.registered), save_registered(State3#state.registered),
State3. State3.


update_supported(State) ->
{ok, Ring} = riak_core_ring_manager:get_raw_ring(),
update_supported(Ring, State).

%% Update this node's view of cluster capabilities based on a received ring %% Update this node's view of cluster capabilities based on a received ring
update_supported(Ring, State) -> update_supported(Ring, State) ->
AllSupported = get_supported_from_ring(Ring), AllSupported = get_supported_from_ring(Ring),
Expand All @@ -278,11 +283,7 @@ update_supported(Ring, State) ->
{[], []} -> {[], []} ->
add_node(Node, Supported, StateAcc); add_node(Node, Supported, StateAcc);
{[], _} -> {[], _} ->
%% While the ring has no knowledge of Node's add_node(Node, Supported, StateAcc);
%% supported modes, the local view has prior
%% knowledge. Do nothing and continue to use
%% the existing modes.
StateAcc;
{Same, Same} -> {Same, Same} ->
StateAcc; StateAcc;
{_, _} -> {_, _} ->
Expand Down Expand Up @@ -552,15 +553,26 @@ get_supported_from_ring(Ring) ->
%% Determine capabilities of legacy nodes based on app.config settings and %% Determine capabilities of legacy nodes based on app.config settings and
%% the provided app-var -> mode mapping associated with capabilities when %% the provided app-var -> mode mapping associated with capabilities when
%% registered. %% registered.
query_capabilities(Node, #state{registered=Registered}) -> query_capabilities(Node, State=#state{registered=Registered}) ->
%% Only query results we do not already have local knowledge of
Known = dict:from_list(get_supported(Node, State)),
lists:mapfoldl(fun({Capability, Info}, ResolvedAcc) -> lists:mapfoldl(fun({Capability, Info}, ResolvedAcc) ->
{Resv, Cap} = query_capability(Node, {Resv, Cap} = query_capability(Node,
Known,
Capability, Capability,
Info#capability.default, Info#capability.default,
Info#capability.legacy), Info#capability.legacy),
{Cap, ResolvedAcc and Resv} {Cap, ResolvedAcc and Resv}
end, true, Registered). end, true, Registered).


query_capability(Node, Known, Capability, DefaultSup, LegacyVar) ->
case dict:find(Capability, Known) of
{ok, Supported} ->
{true, {Capability, Supported}};
error ->
query_capability(Node, Capability, DefaultSup, LegacyVar)
end.

query_capability(_, Capability, DefaultSup, undefined) -> query_capability(_, Capability, DefaultSup, undefined) ->
Default = {Capability, [DefaultSup]}, Default = {Capability, [DefaultSup]},
{true, Default}; {true, Default};
Expand Down