diff options
author | Emile Joubert <emile@rabbitmq.com> | 2013-10-03 10:18:20 +0100 |
---|---|---|
committer | Emile Joubert <emile@rabbitmq.com> | 2013-10-03 10:18:20 +0100 |
commit | e5d2110f4f5d9752a8f9b11af2b7415d38bcce00 (patch) | |
tree | a47dd1d0e5180f2bb98daa18e86f5c0bcf74c89d /src | |
parent | eb7fd23916133584ee6d93e612e80972a48406ae (diff) | |
parent | 8fa54c3ada9349f32397017a1fede03a28a20424 (diff) | |
download | rabbitmq-server-e5d2110f4f5d9752a8f9b11af2b7415d38bcce00.tar.gz |
Merged bug25726 into default
Diffstat (limited to 'src')
-rw-r--r-- | src/rabbit_mirror_queue_slave.erl | 46 | ||||
-rw-r--r-- | src/rabbit_mnesia.erl | 5 | ||||
-rw-r--r-- | src/rabbit_node_monitor.erl | 21 |
3 files changed, 41 insertions, 31 deletions
diff --git a/src/rabbit_mirror_queue_slave.erl b/src/rabbit_mirror_queue_slave.erl index 56a397b4..b1a86493 100644 --- a/src/rabbit_mirror_queue_slave.erl +++ b/src/rabbit_mirror_queue_slave.erl @@ -133,28 +133,38 @@ init(Q = #amqqueue { name = QName }) -> {stop, {duplicate_live_master, Node}}; existing -> gm:leave(GM), + ignore; + master_in_recovery -> + %% The queue record vanished - we must have a master starting + %% concurrently with us. In that case we can safely decide to do + %% nothing here, and the master will start us in + %% master:init_with_existing_bq/3 ignore end. init_it(Self, GM, Node, QName) -> - [Q = #amqqueue { pid = QPid, slave_pids = SPids, gm_pids = GMPids }] = - mnesia:read({rabbit_queue, QName}), - case [Pid || Pid <- [QPid | SPids], node(Pid) =:= Node] of - [] -> add_slave(Q, Self, GM), - {new, QPid, GMPids}; - [QPid] -> case rabbit_misc:is_process_alive(QPid) of - true -> duplicate_live_master; - false -> {stale, QPid} - end; - [SPid] -> case rabbit_misc:is_process_alive(SPid) of - true -> existing; - false -> Q1 = Q#amqqueue { - slave_pids = SPids -- [SPid], - gm_pids = [T || T = {_, S} <- GMPids, - S =/= SPid] }, - add_slave(Q1, Self, GM), - {new, QPid, GMPids} - end + case mnesia:read({rabbit_queue, QName}) of + [Q = #amqqueue { pid = QPid, slave_pids = SPids, gm_pids = GMPids }] -> + case [Pid || Pid <- [QPid | SPids], node(Pid) =:= Node] of + [] -> add_slave(Q, Self, GM), + {new, QPid, GMPids}; + [QPid] -> case rabbit_misc:is_process_alive(QPid) of + true -> duplicate_live_master; + false -> {stale, QPid} + end; + [SPid] -> case rabbit_misc:is_process_alive(SPid) of + true -> existing; + false -> GMPids = [T || T = {_, S} <- GMPids, + S =/= SPid], + Q1 = Q#amqqueue{ + slave_pids = SPids -- [SPid], + gm_pids = GMPids}, + add_slave(Q1, Self, GM), + {new, QPid, GMPids} + end + end; + [] -> + master_in_recovery end. %% Add to the end, so they are in descending order of age, see diff --git a/src/rabbit_mnesia.erl b/src/rabbit_mnesia.erl index 85958400..3a8fae7f 100644 --- a/src/rabbit_mnesia.erl +++ b/src/rabbit_mnesia.erl @@ -399,7 +399,8 @@ node_info() -> cluster_status_from_mnesia()}. node_type() -> - DiscNodes = cluster_nodes(disc), + {_AllNodes, DiscNodes, _RunningNodes} = + rabbit_node_monitor:read_cluster_status(), case DiscNodes =:= [] orelse me_in_nodes(DiscNodes) of true -> disc; false -> ram @@ -519,7 +520,7 @@ copy_db(Destination) -> rabbit_file:recursive_copy(dir(), Destination). force_load_filename() -> - filename:join(rabbit_mnesia:dir(), "force_load"). + filename:join(dir(), "force_load"). force_load_next_boot() -> rabbit_file:write_file(force_load_filename(), <<"">>). diff --git a/src/rabbit_node_monitor.erl b/src/rabbit_node_monitor.erl index 57dce7cd..10e68198 100644 --- a/src/rabbit_node_monitor.erl +++ b/src/rabbit_node_monitor.erl @@ -104,23 +104,19 @@ prepare_cluster_status_files() -> %% The running nodes file might contain a set or a list, in case %% of the legacy file RunningNodes2 = lists:usort(ThisNode ++ RunningNodes1), - {AllNodes1, WantDiscNode} = + {AllNodes1, DiscNodes} = case try_read_file(cluster_status_filename()) of {ok, [{AllNodes, DiscNodes0}]} -> - {AllNodes, lists:member(node(), DiscNodes0)}; + {AllNodes, DiscNodes0}; {ok, [AllNodes0]} when is_list(AllNodes0) -> - {legacy_cluster_nodes(AllNodes0), - legacy_should_be_disc_node(AllNodes0)}; + {legacy_cluster_nodes(AllNodes0), legacy_disc_nodes(AllNodes0)}; {ok, Files} -> Corrupt(Files); {error, enoent} -> - {legacy_cluster_nodes([]), true} + LegacyNodes = legacy_cluster_nodes([]), + {LegacyNodes, LegacyNodes} end, AllNodes2 = lists:usort(AllNodes1 ++ RunningNodes2), - DiscNodes = case WantDiscNode of - true -> ThisNode; - false -> [] - end, ok = write_cluster_status({AllNodes2, DiscNodes, RunningNodes2}). write_cluster_status({All, Disc, Running}) -> @@ -441,8 +437,11 @@ legacy_cluster_nodes(Nodes) -> %% list otherwise) lists:usort(Nodes ++ mnesia:system_info(db_nodes)). -legacy_should_be_disc_node(DiscNodes) -> - DiscNodes == [] orelse lists:member(node(), DiscNodes). +legacy_disc_nodes(AllNodes) -> + case AllNodes == [] orelse lists:member(node(), AllNodes) of + true -> [node()]; + false -> [] + end. add_node(Node, Nodes) -> lists:usort([Node | Nodes]). |