Skip to content

Commit

Permalink
Support forced renaming with cluster_run
Browse files Browse the repository at this point in the history
Change-Id: Ied65fea6bebaba767053a694cbef7a41ec5832f4
Reviewed-on: http://review.membase.org/4521
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
  • Loading branch information
Sean Lynch authored and alk committed Feb 11, 2011
1 parent 901cc51 commit de9fb03
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
32 changes: 16 additions & 16 deletions cluster_run
Expand Up @@ -8,7 +8,7 @@ def testament_child_death():
os._exit(0)
os.waitpid(rv, os.WUNTRACED)

def start_cluster(num_nodes):
def start_cluster(num_nodes, extra_args):
path_str = subprocess.Popen(["find", ".", "-name", "ebin", "-type", "d"],
stdout=subprocess.PIPE).communicate()[0]
path = path_str.split()
Expand All @@ -21,20 +21,20 @@ def start_cluster(num_nodes):
except:
pass

args = ["erl", "+A", "16", "-pa"] + path + \
["-setcookie", "nocookie",
"-run", "ns_bootstrap",
"-kernel", "inet_dist_listen_min", "21100",
"inet_dist_listen_max", "21199",
"-ns_server", "error_logger_mf_dir", '"{0}"'.format(logdir),
"error_logger_mf_maxbytes", "10485760",
"error_logger_mf_maxfiles", "10",
"path_prefix", '"n_{0}"'.format(i),
"rest_port", str(base_api_port + i),
"memcached_port", str(base_direct_port + i * 2),
"moxi_port", str(base_direct_port + i * 2 + 1),
"--",
"-name", "n_{0}@127.0.0.1".format(i)]
args = ["erl", "+A", "16", "-pa"] + path + [
"-setcookie", "nocookie",
"-run", "ns_bootstrap",
"-kernel", "inet_dist_listen_min", "21100",
"inet_dist_listen_max", "21199",
"-ns_server", "error_logger_mf_dir", '"{0}"'.format(logdir),
"error_logger_mf_maxbytes", "10485760",
"error_logger_mf_maxfiles", "10",
"path_prefix", '"n_{0}"'.format(i),
"rest_port", str(base_api_port + i),
"memcached_port", str(base_direct_port + i * 2),
"moxi_port", str(base_direct_port + i * 2 + 1),
"short_name", '"n_{0}"'.format(i)
] + extra_args
if i == 0:
return subprocess.Popen(args)
else:
Expand Down Expand Up @@ -71,7 +71,7 @@ def main():
except:
pass

nodes = start_cluster(num_nodes)
nodes = start_cluster(num_nodes, sys.argv[1:])

for node in nodes:
node.wait()
Expand Down
11 changes: 6 additions & 5 deletions src/dist_manager.erl
Expand Up @@ -19,6 +19,8 @@

-behaviour(gen_server).

-include("ns_common.hrl").

-export([start_link/0]).

-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
Expand Down Expand Up @@ -102,7 +104,9 @@ adjust_my_address(MyIP) ->

%% Bring up distributed erlang.
bringup(MyIP) ->
MyNodeName = list_to_atom("ns_1@" ++ MyIP),
ShortName = misc:get_env_default(short_name, "ns_1"),
MyNodeName = list_to_atom(ShortName ++ "@" ++ MyIP),
?log_info("Attempting to bring up net_kernel with name ~p", [MyNodeName]),
net_kernel:set_net_ticktime(misc:get_env_default(set_net_ticktime, 10)),
Rv = decode_status(net_kernel:start([MyNodeName, longnames])),
#state{self_started = Rv, my_ip = MyIP}.
Expand All @@ -112,7 +116,7 @@ teardown() ->
ok = net_kernel:stop().

handle_call({adjust_my_address, MyIP}, _From,
#state{self_started = true, my_ip = MyOldIP} = State) ->
#state{my_ip = MyOldIP} = State) ->
case MyIP =:= MyOldIP of
true -> {reply, nothing, State};
false -> Cookie = erlang:get_cookie(),
Expand All @@ -130,9 +134,6 @@ handle_call({adjust_my_address, MyIP}, _From,
error_logger:info_msg("save_address_config: ~p~n", [RV]),
{reply, net_restarted, NewState}
end;
handle_call({adjust_my_address, _}, _From,
#state{self_started = false} = State) ->
{reply, nothing, State};
handle_call(_Request, _From, State) ->
{reply, unhandled, State}.

Expand Down
7 changes: 4 additions & 3 deletions src/ns_cluster.erl
Expand Up @@ -242,15 +242,16 @@ check_host_connectivity(OtherHost) ->

do_change_address(NewAddr) ->
MyNode = node(),
NewAddr1 = misc:get_env_default(rename_ip, NewAddr),
case misc:node_name_host(MyNode) of
{_, NewAddr} ->
{_, NewAddr1} ->
%% Don't do anything if we already have the right address.
ok;
{_, _} ->
CookieBefore = erlang:get_cookie(),
?log_info("Decided to change address to ~p~n", [NewAddr]),
?log_info("Decided to change address to ~p~n", [NewAddr1]),
ns_mnesia:prepare_rename(),
case dist_manager:adjust_my_address(NewAddr) of
case dist_manager:adjust_my_address(NewAddr1) of
nothing ->
ok;
net_restarted ->
Expand Down

0 comments on commit de9fb03

Please sign in to comment.