summaryrefslogtreecommitdiff
path: root/src/rabbit_mnesia.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rabbit_mnesia.erl')
-rw-r--r--src/rabbit_mnesia.erl73
1 files changed, 34 insertions, 39 deletions
diff --git a/src/rabbit_mnesia.erl b/src/rabbit_mnesia.erl
index 6a442fec..c39e898c 100644
--- a/src/rabbit_mnesia.erl
+++ b/src/rabbit_mnesia.erl
@@ -11,7 +11,7 @@
%% The Original Code is RabbitMQ.
%%
%% The Initial Developer of the Original Code is VMware, Inc.
-%% Copyright (c) 2007-2012 VMware, Inc. All rights reserved.
+%% Copyright (c) 2007-2013 VMware, Inc. All rights reserved.
%%
-module(rabbit_mnesia).
@@ -41,10 +41,7 @@
]).
%% Used internally in rpc calls
--export([node_info/0,
- remove_node_if_mnesia_running/1,
- is_running_remote/0
- ]).
+-export([node_info/0, remove_node_if_mnesia_running/1]).
-include("rabbit.hrl").
@@ -278,16 +275,16 @@ forget_cluster_node(Node, RemoveWhenOffline) ->
true -> ok;
false -> e(not_a_cluster_node)
end,
- case {RemoveWhenOffline, mnesia:system_info(is_running)} of
- {true, no} -> remove_node_offline_node(Node);
- {true, yes} -> e(online_node_offline_flag);
- {false, no} -> e(offline_node_no_offline_flag);
- {false, yes} -> rabbit_misc:local_info_msg(
- "Removing node ~p from cluster~n", [Node]),
- case remove_node_if_mnesia_running(Node) of
- ok -> ok;
- {error, _} = Err -> throw(Err)
- end
+ case {RemoveWhenOffline, is_running()} of
+ {true, false} -> remove_node_offline_node(Node);
+ {true, true} -> e(online_node_offline_flag);
+ {false, false} -> e(offline_node_no_offline_flag);
+ {false, true} -> rabbit_misc:local_info_msg(
+ "Removing node ~p from cluster~n", [Node]),
+ case remove_node_if_mnesia_running(Node) of
+ ok -> ok;
+ {error, _} = Err -> throw(Err)
+ end
end.
remove_node_offline_node(Node) ->
@@ -334,11 +331,11 @@ status() ->
end,
[{nodes, (IfNonEmpty(disc, cluster_nodes(disc)) ++
IfNonEmpty(ram, cluster_nodes(ram)))}] ++
- case mnesia:system_info(is_running) of
- yes -> RunningNodes = cluster_nodes(running),
- [{running_nodes, cluster_nodes(running)},
- {partitions, mnesia_partitions(RunningNodes)}];
- no -> []
+ case is_running() of
+ true -> RunningNodes = cluster_nodes(running),
+ [{running_nodes, RunningNodes},
+ {partitions, mnesia_partitions(RunningNodes)}];
+ false -> []
end.
mnesia_partitions(Nodes) ->
@@ -346,6 +343,8 @@ mnesia_partitions(Nodes) ->
Nodes, rabbit_node_monitor, partitions, []),
[Reply || Reply = {_, R} <- Replies, R =/= []].
+is_running() -> mnesia:system_info(is_running) =:= yes.
+
is_clustered() -> AllNodes = cluster_nodes(all),
AllNodes =/= [] andalso AllNodes =/= [node()].
@@ -355,10 +354,10 @@ cluster_nodes(WhichNodes) -> cluster_status(WhichNodes).
%% the data from mnesia. Obviously it'll work only when mnesia is
%% running.
cluster_status_from_mnesia() ->
- case mnesia:system_info(is_running) of
- no ->
+ case is_running() of
+ false ->
{error, mnesia_not_running};
- yes ->
+ true ->
%% If the tables are not present, it means that
%% `init_db/3' hasn't been run yet. In other words, either
%% we are a virgin node or a restarted RAM node. In both
@@ -601,19 +600,16 @@ discover_cluster(Nodes) when is_list(Nodes) ->
lists:foldl(fun (_, {ok, Res}) -> {ok, Res};
(Node, {error, _}) -> discover_cluster(Node)
end, {error, no_nodes_provided}, Nodes);
+discover_cluster(Node) when Node == node() ->
+ {error, {cannot_discover_cluster, "Cannot cluster node with itself"}};
discover_cluster(Node) ->
OfflineError =
{error, {cannot_discover_cluster,
"The nodes provided are either offline or not running"}},
- case node() of
- Node -> {error, {cannot_discover_cluster,
- "Cannot cluster node with itself"}};
- _ -> case rpc:call(Node,
- rabbit_mnesia, cluster_status_from_mnesia, []) of
- {badrpc, _Reason} -> OfflineError;
- {error, mnesia_not_running} -> OfflineError;
- {ok, Res} -> {ok, Res}
- end
+ case rpc:call(Node, rabbit_mnesia, cluster_status_from_mnesia, []) of
+ {badrpc, _Reason} -> OfflineError;
+ {error, mnesia_not_running} -> OfflineError;
+ {ok, Res} -> {ok, Res}
end.
schema_ok_or_move() ->
@@ -672,20 +668,21 @@ move_db() ->
ok.
remove_node_if_mnesia_running(Node) ->
- case mnesia:system_info(is_running) of
- yes ->
+ case is_running() of
+ false ->
+ {error, mnesia_not_running};
+ true ->
%% Deleting the the schema copy of the node will result in
%% the node being removed from the cluster, with that
%% change being propagated to all nodes
case mnesia:del_table_copy(schema, Node) of
{atomic, ok} ->
+ rabbit_amqqueue:forget_all_durable(Node),
rabbit_node_monitor:notify_left_cluster(Node),
ok;
{aborted, Reason} ->
{error, {failed_to_remove_node, Node, Reason}}
- end;
- no ->
- {error, mnesia_not_running}
+ end
end.
leave_cluster() ->
@@ -735,8 +732,6 @@ change_extra_db_nodes(ClusterNodes0, CheckOtherNodes) ->
Nodes
end.
-is_running_remote() -> {mnesia:system_info(is_running) =:= yes, node()}.
-
check_consistency(OTP, Rabbit) ->
rabbit_misc:sequence_error(
[check_otp_consistency(OTP), check_rabbit_consistency(Rabbit)]).