From 5ae82d11e1ce79e09ef1ff0c01321e7132705010 Mon Sep 17 00:00:00 2001 From: Martin Sumner Date: Tue, 22 Nov 2022 11:14:48 +0000 Subject: [PATCH 1/8] Add reip/3 To allow for reip without loading the riak_core application --- rebar.config | 2 +- src/riak_kv_console.erl | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/rebar.config b/rebar.config index 65a632c676..0115b3973a 100644 --- a/rebar.config +++ b/rebar.config @@ -42,7 +42,7 @@ ]}. {deps, [ - {riak_core, {git, "https://github.com/basho/riak_core.git", {tag, "riak_kv-3.0.10"}}}, + {riak_core, {git, "https://github.com/basho/riak_core.git", {branch, "mas-i1121-passringdir"}}}, {sidejob, {git, "https://github.com/basho/sidejob.git", {tag, "2.1.0"}}}, {bitcask, {git, "https://github.com/basho/bitcask.git", {tag, "2.1.0"}}}, {redbug, {git, "https://github.com/massemanet/redbug", {tag, "1.2.2"}}}, diff --git a/src/riak_kv_console.erl b/src/riak_kv_console.erl index 6962690d50..3a43b4c5cb 100644 --- a/src/riak_kv_console.erl +++ b/src/riak_kv_console.erl @@ -31,6 +31,7 @@ status/1, vnode_status/1, reip/1, + reip/3, ringready/1, cluster_info/1, down/1, @@ -232,6 +233,29 @@ reip([OldNode, NewNode]) -> error end. +reip([OldNode, NewNode], RingDir, ClusterName) -> + try + %% reip/1 requires riak_core to be loaded to learn the Ring Directory + %% and the Cluster Name. In reip/3 these can be passed in instead + {ok, RingFile} = riak_core_ring_manager:find_latest_ringfile(RingDir), + 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, ClusterName), + ok = riak_core_ring_manager:do_write_ringfile(NewRing, NewRingFN), + io:format("New ring file written to ~p~n", + [element(2, riak_core_ring_manager:find_latest_ringfile(RingDir))]) + 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([]) -> From 7ed0b98d3a87a4d3888e470300e33e3dcd8b537f Mon Sep 17 00:00:00 2001 From: Martin Sumner Date: Tue, 22 Nov 2022 11:34:23 +0000 Subject: [PATCH 2/8] Use alternate name --- src/riak_kv_console.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/riak_kv_console.erl b/src/riak_kv_console.erl index 3a43b4c5cb..e68523cedc 100644 --- a/src/riak_kv_console.erl +++ b/src/riak_kv_console.erl @@ -31,7 +31,7 @@ status/1, vnode_status/1, reip/1, - reip/3, + reip_manual/3, ringready/1, cluster_info/1, down/1, @@ -233,7 +233,7 @@ reip([OldNode, NewNode]) -> error end. -reip([OldNode, NewNode], RingDir, ClusterName) -> +reip_manual([OldNode, NewNode], RingDir, ClusterName) -> try %% reip/1 requires riak_core to be loaded to learn the Ring Directory %% and the Cluster Name. In reip/3 these can be passed in instead From 09f3d256212546667e1902912c7803b3e3fd8f89 Mon Sep 17 00:00:00 2001 From: Martin Sumner Date: Tue, 22 Nov 2022 11:35:00 +0000 Subject: [PATCH 3/8] Update riak_kv_console.erl --- src/riak_kv_console.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/riak_kv_console.erl b/src/riak_kv_console.erl index e68523cedc..ad0d643117 100644 --- a/src/riak_kv_console.erl +++ b/src/riak_kv_console.erl @@ -31,7 +31,7 @@ status/1, vnode_status/1, reip/1, - reip_manual/3, + reip_manual/1, ringready/1, cluster_info/1, down/1, @@ -233,7 +233,7 @@ reip([OldNode, NewNode]) -> error end. -reip_manual([OldNode, NewNode], RingDir, ClusterName) -> +reip_manual([OldNode, NewNode, RingDir, ClusterName]) -> try %% reip/1 requires riak_core to be loaded to learn the Ring Directory %% and the Cluster Name. In reip/3 these can be passed in instead From 7b4c9e7862e0279c94bb2ebdfba5ed0eaed761f1 Mon Sep 17 00:00:00 2001 From: Martin Sumner Date: Tue, 22 Nov 2022 15:07:01 +0000 Subject: [PATCH 4/8] Update riak_kv_console.erl --- src/riak_kv_console.erl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/riak_kv_console.erl b/src/riak_kv_console.erl index ad0d643117..e1fd681613 100644 --- a/src/riak_kv_console.erl +++ b/src/riak_kv_console.erl @@ -236,8 +236,10 @@ reip([OldNode, NewNode]) -> reip_manual([OldNode, NewNode, RingDir, ClusterName]) -> try %% reip/1 requires riak_core to be loaded to learn the Ring Directory - %% and the Cluster Name. In reip/3 these can be passed in instead - {ok, RingFile} = riak_core_ring_manager:find_latest_ringfile(RingDir), + %% and the Cluster Name. In reip_manual/1 these can be passed in + %% instead + {ok, RingFile} = + riak_core_ring_manager:find_latest_ringfile(RingDir, ClusterName), BackupFN = filename:join([RingDir, filename:basename(RingFile)++".BAK"]), {ok, _} = file:copy(RingFile, BackupFN), From a8addf524b7dd4c6bb5d06ea7ac8ba86214e0220 Mon Sep 17 00:00:00 2001 From: Martin Sumner Date: Tue, 22 Nov 2022 17:09:20 +0000 Subject: [PATCH 5/8] reip_manual inputs are atoms --- src/riak_kv_console.erl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/riak_kv_console.erl b/src/riak_kv_console.erl index e1fd681613..fa5cd83442 100644 --- a/src/riak_kv_console.erl +++ b/src/riak_kv_console.erl @@ -233,13 +233,16 @@ reip([OldNode, NewNode]) -> error end. -reip_manual([OldNode, NewNode, RingDir, ClusterName]) -> +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, ClusterName), + riak_core_ring_manager:find_latest_ringfile(RingDir, Cluster), + io:format("RingFile to update ~p~n", [RingFile]), BackupFN = filename:join([RingDir, filename:basename(RingFile)++".BAK"]), {ok, _} = file:copy(RingFile, BackupFN), @@ -248,10 +251,9 @@ reip_manual([OldNode, NewNode, RingDir, ClusterName]) -> NewRing = riak_core_ring:rename_node(Ring, OldNode, NewNode), NewRingFN = riak_core_ring_manager:generate_ring_filename( - RingDir, ClusterName), + RingDir, Cluster), ok = riak_core_ring_manager:do_write_ringfile(NewRing, NewRingFN), - io:format("New ring file written to ~p~n", - [element(2, riak_core_ring_manager:find_latest_ringfile(RingDir))]) + io:format("New ring file written to ~p~n", [NewRingFN]) catch Exception:Reason -> io:format("Reip failed ~p:~p", [Exception, Reason]), From adddf491c1b5a6839ea6be6d19756a2d5d17574b Mon Sep 17 00:00:00 2001 From: Martin Sumner Date: Tue, 6 Dec 2022 15:12:21 +0000 Subject: [PATCH 6/8] Add warning to update riak.conf file after reip --- src/riak_kv_console.erl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/riak_kv_console.erl b/src/riak_kv_console.erl index fa5cd83442..a600765c08 100644 --- a/src/riak_kv_console.erl +++ b/src/riak_kv_console.erl @@ -253,7 +253,11 @@ reip_manual([OldNode, NewNode, Dir, ClusterName]) -> 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("New ring file written to ~p~n", [NewRingFN]), + io:format( + "~nUpdate required to riak.conf nodename before restarting node" ++ + "nodename should be changed to ~p~n", + [NewNode]) catch Exception:Reason -> io:format("Reip failed ~p:~p", [Exception, Reason]), From b2b5fd3f135b3fce49ad4f6a001b8209c75f33f2 Mon Sep 17 00:00:00 2001 From: Martin Sumner Date: Tue, 6 Dec 2022 15:44:40 +0000 Subject: [PATCH 7/8] Make clear where attention is required And return 'ok' to make clear the op was successful --- src/riak_kv_console.erl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/riak_kv_console.erl b/src/riak_kv_console.erl index a600765c08..540236491d 100644 --- a/src/riak_kv_console.erl +++ b/src/riak_kv_console.erl @@ -242,6 +242,7 @@ reip_manual([OldNode, NewNode, Dir, ClusterName]) -> 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"]), @@ -254,10 +255,12 @@ reip_manual([OldNode, NewNode, Dir, ClusterName]) -> 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( - "~nUpdate required to riak.conf nodename before restarting node" ++ - "nodename should be changed to ~p~n", - [NewNode]) + "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]), From 6207fabc289c4ffd777caabb3e7b6d61c2075a2d Mon Sep 17 00:00:00 2001 From: Martin Sumner Date: Tue, 6 Dec 2022 16:49:47 +0000 Subject: [PATCH 8/8] Update rebar.config --- rebar.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rebar.config b/rebar.config index 0115b3973a..de4cee2d19 100644 --- a/rebar.config +++ b/rebar.config @@ -42,7 +42,7 @@ ]}. {deps, [ - {riak_core, {git, "https://github.com/basho/riak_core.git", {branch, "mas-i1121-passringdir"}}}, + {riak_core, {git, "https://github.com/basho/riak_core.git", {branch, "develop-3.0"}}}, {sidejob, {git, "https://github.com/basho/sidejob.git", {tag, "2.1.0"}}}, {bitcask, {git, "https://github.com/basho/bitcask.git", {tag, "2.1.0"}}}, {redbug, {git, "https://github.com/massemanet/redbug", {tag, "1.2.2"}}},