Skip to content

Commit

Permalink
Mas i1121 reip3 (#1838)
Browse files Browse the repository at this point in the history
* Add reip/3

To allow for reip without loading the riak_core application

* Use alternate name

* Update riak_kv_console.erl

* Update riak_kv_console.erl

* reip_manual inputs are atoms

* Add warning to update riak.conf file after reip

* Make clear where attention is required

And return 'ok' to make clear the op was successful

* Update rebar.config
  • Loading branch information
martinsumner committed Dec 19, 2022
1 parent 167b34d commit a2d2bc9
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/riak_kv_console.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
status/1,
vnode_status/1,
reip/1,
reip_manual/1,
ringready/1,
cluster_info/1,
down/1,
Expand Down Expand Up @@ -234,6 +235,40 @@ reip([OldNode, NewNode]) ->
error
end.

reip_manual([OldNode, NewNode, Dir, ClusterName]) ->
try
%% reip/1 requires riak_core to be loaded to learn the Ring Directory
%% and the Cluster Name. In reip_manual/1 these can be passed in
%% instead
RingDir = atom_to_list(Dir),
Cluster = atom_to_list(ClusterName),
{ok, RingFile} =
riak_core_ring_manager:find_latest_ringfile(RingDir, Cluster),
io:format("~nCHANGE DETAILS:~n"),
io:format("RingFile to update ~p~n", [RingFile]),
BackupFN =
filename:join([RingDir, filename:basename(RingFile)++".BAK"]),
{ok, _} = file:copy(RingFile, BackupFN),
io:format("Backed up existing ring file to ~p~n", [BackupFN]),
Ring = riak_core_ring_manager:read_ringfile(RingFile),
NewRing = riak_core_ring:rename_node(Ring, OldNode, NewNode),
NewRingFN =
riak_core_ring_manager:generate_ring_filename(
RingDir, Cluster),
ok = riak_core_ring_manager:do_write_ringfile(NewRing, NewRingFN),
io:format("New ring file written to ~p~n", [NewRingFN]),
io:format("~nATTENTION REQUIRED:~n"),
io:format(
"Update required to riak.conf nodename before restarting node;"
++ " nodename should be changed to ~s~n",
[atom_to_list(NewNode)]),
io:format("~nok~n")
catch
Exception:Reason ->
io:format("Reip failed ~p:~p", [Exception, Reason]),
error
end.

%% Check if all nodes in the cluster agree on the partition assignment
-spec(ringready([]) -> ok | error).
ringready([]) ->
Expand Down

0 comments on commit a2d2bc9

Please sign in to comment.