summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Klishin <michael@clojurewerkz.org>2016-10-04 16:54:00 +0300
committerMichael Klishin <michael@clojurewerkz.org>2016-10-04 16:54:00 +0300
commit8b500cd2ef48787bff4208c6abfd2e95ca1e7531 (patch)
tree1ccf14e86fe1bd8ae96ab5819dca38bc12283994 /src
parentd9cb0050d82a85d4f9a2ea72f28143c2946b798a (diff)
downloadrabbitmq-server-git-8b500cd2ef48787bff4208c6abfd2e95ca1e7531.tar.gz
Switch config-driven automatic clustering to the new behaviour
Diffstat (limited to 'src')
-rw-r--r--src/rabbit.app.src8
-rw-r--r--src/rabbit_mnesia.erl18
-rw-r--r--src/rabbit_peer_discovery.erl59
-rw-r--r--src/rabbit_peer_discovery_classic_config.erl45
4 files changed, 122 insertions, 8 deletions
diff --git a/src/rabbit.app.src b/src/rabbit.app.src
index 2e17bbbc3c..1a894c3620 100644
--- a/src/rabbit.app.src
+++ b/src/rabbit.app.src
@@ -44,7 +44,6 @@
{default_permissions, [<<".*">>, <<".*">>, <<".*">>]},
{loopback_users, [<<"guest">>]},
{password_hashing_module, rabbit_password_hashing_sha256},
- {cluster_nodes, {[], disc}},
{server_properties, []},
{collect_statistics, none},
{collect_statistics_interval, 5000},
@@ -102,5 +101,10 @@
{credit_flow_default_credit, {200, 100}},
%% see rabbitmq-server#248
%% and rabbitmq-server#667
- {channel_operation_timeout, 15000}
+ {channel_operation_timeout, 15000},
+
+ %% see rabbitmq-server#486
+ {peer_discovery_backend, rabbit_peer_discovery_classic_config},
+ %% used by rabbit_peer_discovery_classic_config
+ {cluster_nodes, {[], disc}}
]}]}.
diff --git a/src/rabbit_mnesia.erl b/src/rabbit_mnesia.erl
index 43dd2c3bb8..d638185aef 100644
--- a/src/rabbit_mnesia.erl
+++ b/src/rabbit_mnesia.erl
@@ -98,8 +98,11 @@ init() ->
ensure_mnesia_dir(),
case is_virgin_node() of
true ->
- rabbit_log:info("Database directory at ~s is empty. Initialising from scratch...~n",
+ rabbit_log:info("Database directory at ~s is empty. "
+ "Assuming we need to join an existing cluster or initialise from scratch...~n",
[dir()]),
+ rabbit_log:info("Using ~p as peer discovery backend~n",
+ [rabbit_peer_discovery:backend()]),
init_from_config();
false ->
NodeType = node_type(),
@@ -117,8 +120,8 @@ init_from_config() ->
(Name, BadNames) when is_atom(Name) -> BadNames;
(Name, BadNames) -> [Name | BadNames]
end,
- {TryNodes, NodeType} =
- case application:get_env(rabbit, cluster_nodes) of
+ {DiscoveredNodes, NodeType} =
+ case rabbit_peer_discovery:discover_cluster_nodes() of
{ok, {Nodes, Type} = Config}
when is_list(Nodes) andalso (Type == disc orelse Type == ram) ->
case lists:foldr(FindBadNodeNames, [], Nodes) of
@@ -137,9 +140,12 @@ init_from_config() ->
{ok, _} ->
e(invalid_cluster_nodes_conf)
end,
- case TryNodes of
+ case DiscoveredNodes of
[] -> init_db_and_upgrade([node()], disc, false);
- _ -> auto_cluster(TryNodes, NodeType)
+ _ ->
+ rabbit_log:info("Discovered peer nodes: ~s~n",
+ [rabbit_peer_discovery:format_discovered_nodes(DiscoveredNodes)]),
+ auto_cluster(DiscoveredNodes, NodeType)
end.
auto_cluster(TryNodes, NodeType) ->
@@ -891,7 +897,7 @@ find_auto_cluster_node([]) ->
find_auto_cluster_node([Node | Nodes]) ->
Fail = fun (Fmt, Args) ->
rabbit_log:warning(
- "Could not auto-cluster with ~s: " ++ Fmt, [Node | Args]),
+ "Could not auto-cluster with node ~s: " ++ Fmt, [Node | Args]),
find_auto_cluster_node(Nodes)
end,
case remote_node_info(Node) of
diff --git a/src/rabbit_peer_discovery.erl b/src/rabbit_peer_discovery.erl
new file mode 100644
index 0000000000..87c3fdeeb8
--- /dev/null
+++ b/src/rabbit_peer_discovery.erl
@@ -0,0 +1,59 @@
+%% The contents of this file are subject to the Mozilla Public License
+%% Version 1.1 (the "License"); you may not use this file except in
+%% compliance with the License. You may obtain a copy of the License
+%% at http://www.mozilla.org/MPL/
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and
+%% limitations under the License.
+%%
+%% The Original Code is RabbitMQ.
+%%
+%% The Initial Developer of the Original Code is Pivotal Software, Inc.
+%% Copyright (c) 2007-2015 Pivotal Software, Inc. All rights reserved.
+%%
+
+-module(rabbit_peer_discovery).
+
+%% API
+-export([discover_cluster_nodes/0, backend/0,
+ normalize/1, format_discovered_nodes/1]).
+
+
+
+-spec backend() -> atom().
+
+backend() ->
+ case application:get_env(rabbit, peer_discovery_backend) of
+ {ok, Backend} when is_atom(Backend) -> Backend;
+ undefined -> rabbit_peer_discovery_classic_config
+ end.
+
+
+-spec discover_cluster_nodes() -> {ok, Nodes :: list()} |
+ {ok, {Nodes :: list(), NodeType :: rabbit_types:node_type()}} |
+ {error, Reason :: string()}.
+
+discover_cluster_nodes() ->
+ Backend = backend(),
+ normalize(Backend:list_nodes()).
+
+
+-spec normalize({ok, Nodes :: list()} |
+ {ok, {Nodes :: list(), NodeType :: rabbit_types:node_type()}} |
+ {error, Reason :: string()}) -> {ok, {Nodes :: list(), NodeType :: rabbit_types:node_type()}} |
+ {error, Reason :: string()}.
+
+normalize({ok, Nodes}) when is_list(Nodes) ->
+ {ok, {Nodes, disc}};
+normalize({ok, {Nodes, NodeType}}) when is_list(Nodes) andalso is_atom(NodeType) ->
+ {ok, {Nodes, NodeType}};
+normalize({error, Reason}) ->
+ {error, Reason}.
+
+
+-spec format_discovered_nodes(Nodes :: list()) -> string().
+
+format_discovered_nodes(Nodes) ->
+ string:join(lists:map(fun (Val) -> hd(io_lib:format("~s", [Val])) end, Nodes), ", ").
diff --git a/src/rabbit_peer_discovery_classic_config.erl b/src/rabbit_peer_discovery_classic_config.erl
new file mode 100644
index 0000000000..a3d3d50617
--- /dev/null
+++ b/src/rabbit_peer_discovery_classic_config.erl
@@ -0,0 +1,45 @@
+%% The contents of this file are subject to the Mozilla Public License
+%% Version 1.1 (the "License"); you may not use this file except in
+%% compliance with the License. You may obtain a copy of the License at
+%% http://www.mozilla.org/MPL/
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+%% License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% The Original Code is RabbitMQ.
+%%
+%% The Initial Developer of the Original Code is GoPivotal, Inc.
+%% Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved.
+%%
+
+-module(rabbit_peer_discovery_classic_config).
+-behaviour(rabbit_peer_discovery_backend).
+
+-include("rabbit.hrl").
+
+-export([list_nodes/0, register/0, unregister/0]).
+
+%%
+%% API
+%%
+
+-spec list_nodes() -> {ok, Nodes :: list()} | {error, Reason :: string()}.
+
+list_nodes() ->
+ case application:get_env(rabbit, cluster_nodes) of
+ {_Nodes, _NodeType} = Pair -> Pair;
+ Nodes when is_list(Nodes) -> {Nodes, disc};
+ undefined -> {[], disc}
+ end.
+
+-spec register() -> ok.
+
+register() ->
+ ok.
+
+-spec unregister() -> ok.
+
+unregister() ->
+ ok.