summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@rabbitmq.com>2012-02-01 16:48:35 +0000
committerMatthias Radestock <matthias@rabbitmq.com>2012-02-01 16:48:35 +0000
commitc6a6066ab88296f6c37f2a8eae549e907f01106b (patch)
treec9a1b6505ac36f710d5e08bb9eab1929df1996d4
parent91d719f2c84363efd989bc3d81c1f59d062a7898 (diff)
parent7a85b10188cf8ef2349d508ec31786522e5b3483 (diff)
downloadrabbitmq-server-c6a6066ab88296f6c37f2a8eae549e907f01106b.tar.gz
merge bug24703 into default
-rw-r--r--src/rabbit_mnesia.erl47
-rw-r--r--src/rabbit_tests.erl11
2 files changed, 31 insertions, 27 deletions
diff --git a/src/rabbit_mnesia.erl b/src/rabbit_mnesia.erl
index bf997a6f..0f33a38a 100644
--- a/src/rabbit_mnesia.erl
+++ b/src/rabbit_mnesia.erl
@@ -98,8 +98,8 @@ status() ->
init() ->
ensure_mnesia_running(),
ensure_mnesia_dir(),
- ok = init_db(read_cluster_nodes_config(), true,
- fun maybe_upgrade_local_or_record_desired/0),
+ Nodes = read_cluster_nodes_config(),
+ ok = init_db(Nodes, should_be_disc_node(Nodes)),
%% We intuitively expect the global name server to be synced when
%% Mnesia is up. In fact that's not guaranteed to be the case - let's
%% make it so.
@@ -174,8 +174,7 @@ cluster(ClusterNodes, Force) ->
%% Join the cluster
start_mnesia(),
try
- ok = init_db(ClusterNodes, Force,
- fun maybe_upgrade_local_or_record_desired/0),
+ ok = init_db(ClusterNodes, Force),
ok = create_cluster_nodes_config(ClusterNodes)
after
stop_mnesia()
@@ -501,6 +500,18 @@ delete_previously_running_nodes() ->
FileName, Reason}})
end.
+init_db(ClusterNodes, Force) ->
+ init_db(
+ ClusterNodes, Force,
+ fun () ->
+ case rabbit_upgrade:maybe_upgrade_local() of
+ ok -> ok;
+ %% If we're just starting up a new node we won't have a
+ %% version
+ version_not_available -> ok = rabbit_version:record_desired()
+ end
+ end).
+
%% Take a cluster node config and create the right kind of node - a
%% standalone disk node, or disk or ram node connected to the
%% specified cluster nodes. If Force is false, don't allow
@@ -509,20 +520,12 @@ init_db(ClusterNodes, Force, SecondaryPostMnesiaFun) ->
UClusterNodes = lists:usort(ClusterNodes),
ProperClusterNodes = UClusterNodes -- [node()],
case mnesia:change_config(extra_db_nodes, ProperClusterNodes) of
+ {ok, []} when not Force andalso ProperClusterNodes =/= [] ->
+ throw({error, {failed_to_cluster_with, ProperClusterNodes,
+ "Mnesia could not connect to any disc nodes."}});
{ok, Nodes} ->
- case Force of
- false -> FailedClusterNodes = ProperClusterNodes -- Nodes,
- case FailedClusterNodes of
- [] -> ok;
- _ -> throw({error, {failed_to_cluster_with,
- FailedClusterNodes,
- "Mnesia could not connect "
- "to some nodes."}})
- end;
- true -> ok
- end,
- WantDiscNode = should_be_disc_node(ClusterNodes),
WasDiscNode = is_disc_node(),
+ WantDiscNode = should_be_disc_node(ClusterNodes),
%% We create a new db (on disk, or in ram) in the first
%% two cases and attempt to upgrade the in the other two
case {Nodes, WasDiscNode, WantDiscNode} of
@@ -572,14 +575,6 @@ init_db(ClusterNodes, Force, SecondaryPostMnesiaFun) ->
throw({error, {unable_to_join_cluster, ClusterNodes, Reason}})
end.
-maybe_upgrade_local_or_record_desired() ->
- case rabbit_upgrade:maybe_upgrade_local() of
- ok -> ok;
- %% If we're just starting up a new node we won't have a
- %% version
- version_not_available -> ok = rabbit_version:record_desired()
- end.
-
schema_ok_or_move() ->
case check_schema_integrity() of
ok ->
@@ -745,7 +740,9 @@ reset(Force) ->
start_mnesia(),
{Nodes, RunningNodes} =
try
- ok = init(),
+ %% Force=true here so that reset still works when clustered
+ %% with a node which is down
+ ok = init_db(read_cluster_nodes_config(), true),
{all_clustered_nodes() -- [Node],
running_clustered_nodes() -- [Node]}
after
diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl
index 96acbd9b..343e79e5 100644
--- a/src/rabbit_tests.erl
+++ b/src/rabbit_tests.erl
@@ -889,6 +889,14 @@ test_cluster_management2(SecondaryNode) ->
ok = control_action(stop_app, []),
ok = assert_ram_node(),
+ %% ram node will not start by itself
+ ok = control_action(stop_app, []),
+ ok = control_action(stop_app, SecondaryNode, [], []),
+ {error, _} = control_action(start_app, []),
+ ok = control_action(start_app, SecondaryNode, [], []),
+ ok = control_action(start_app, []),
+ ok = control_action(stop_app, []),
+
%% change cluster config while remaining in same cluster
ok = control_action(force_cluster, ["invalid2@invalid", SecondaryNodeS]),
ok = control_action(start_app, []),
@@ -897,8 +905,7 @@ test_cluster_management2(SecondaryNode) ->
%% join non-existing cluster as a ram node
ok = control_action(force_cluster, ["invalid1@invalid",
"invalid2@invalid"]),
- ok = control_action(start_app, []),
- ok = control_action(stop_app, []),
+ {error, _} = control_action(start_app, []),
ok = assert_ram_node(),
%% join empty cluster as a ram node (converts to disc)