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

warn about inability to downgrade after activating bucket type #827

Merged
merged 1 commit into from
Feb 12, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 44 additions & 6 deletions src/riak_kv_console.erl
Original file line number Diff line number Diff line change
Expand Up @@ -471,13 +471,22 @@ bucket_type_print_props(Props) ->

bucket_type_activate([TypeStr]) ->
Type = list_to_binary(TypeStr),
bucket_type_print_activate_result(Type, riak_core_bucket_type:activate(Type)).
IsFirst = bucket_type_is_first(),
bucket_type_print_activate_result(Type, riak_core_bucket_type:activate(Type), IsFirst).

bucket_type_print_activate_result(Type, ok) ->
io:format("~s has been activated~n", [Type]);
bucket_type_print_activate_result(Type, {error, undefined}) ->
bucket_type_print_activate_result(Type, ok, IsFirst) ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of passing in IsFirst as a new argument, the entire case clause below should be abstracted into a maybe_print_warning/1 function that takes a Type parameter. This same function can be used in bucket_type_print_create_result/2 below. The /3 versions of these functions will no longer be needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason IsFirst is passed through here is because bucket_type_is_first() must be called before the operation has completed otherwise the warning is never printed (the check finds the just activated type, which is the condition for skipping the warning). But perhaps there is still a way to clean that up...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. In that case don't worry about it. I was thinking about maybe just abstracting the message itself, but that's no big deal.

io:format("~s has been activated~n", [Type]),
case IsFirst of
true ->
io:format("~n"),
io:format("WARNING: Nodes in this cluster can no longer be~n"
"downgraded to a version of Riak prior to 2.0~n");
false ->
ok
end;
bucket_type_print_activate_result(Type, {error, undefined}, _IsFirst) ->
bucket_type_print_status(Type, undefined);
bucket_type_print_activate_result(Type, {error, not_ready}) ->
bucket_type_print_activate_result(Type, {error, not_ready}, _IsFirst) ->
bucket_type_print_status(Type, created).

bucket_type_create([TypeStr, PropsStr]) ->
Expand All @@ -498,7 +507,16 @@ bucket_type_create(Type, _) ->
error.

bucket_type_print_create_result(Type, ok) ->
io:format("~s created~n", [Type]);
io:format("~s created~n", [Type]),
case bucket_type_is_first() of
true ->
io:format("~n"),
io:format("WARNING: After activating ~s, nodes in this cluster~n"
"can no longer be downgraded to a version of Riak "
"prior to 2.0~n", [Type]);
false ->
ok
end;
bucket_type_print_create_result(Type, {error, Reason}) ->
io:format("Error creating bucket type ~s: ~p~n", [Type, Reason]),
error.
Expand Down Expand Up @@ -555,6 +573,26 @@ bucket_type_print_list(It) ->
bucket_type_print_list(riak_core_bucket_type:itr_next(It))
end.

bucket_type_is_first() ->
It = riak_core_bucket_type:iterator(),
bucket_type_is_first(It, false).

bucket_type_is_first(It, true) ->
%% found an active bucket type
riak_core_bucket_type:itr_close(It),
false;
bucket_type_is_first(It, false) ->
case riak_core_bucket_type:itr_done(It) of
true ->
%% no active bucket types found
ok = riak_core_bucket_type:itr_close(It),
true;
false ->
{_, Props} = riak_core_bucket_type:itr_value(It),
Active = proplists:get_value(active, Props, false),
bucket_type_is_first(riak_core_bucket_type:itr_next(It), Active)
end.

repair_2i(["status"]) ->
try
Status = riak_kv_2i_aae:get_status(),
Expand Down