diff options
| author | Michael Klishin <mklishin@pivotal.io> | 2019-05-23 16:39:11 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-23 16:39:11 +0100 |
| commit | 6e4a6aea122a04810004c571bce104abc0bb8996 (patch) | |
| tree | dcc6139a50ee0aeb70c288c985562f6e82dd46fb | |
| parent | ba0436b30bbb5682116d0bcbbfb10a3565ab40f0 (diff) | |
| parent | ee12c561b5f073d4a3b5a19863ef582c34c7016e (diff) | |
| download | rabbitmq-server-git-6e4a6aea122a04810004c571bce104abc0bb8996.tar.gz | |
Merge pull request #2014 from rabbitmq/quorum-status
Improve quorum_status command
| -rw-r--r-- | src/rabbit_quorum_queue.erl | 50 |
1 files changed, 41 insertions, 9 deletions
diff --git a/src/rabbit_quorum_queue.erl b/src/rabbit_quorum_queue.erl index 8258584e3c..75bd9515f1 100644 --- a/src/rabbit_quorum_queue.erl +++ b/src/rabbit_quorum_queue.erl @@ -644,7 +644,6 @@ cluster_state(Name) -> end. -spec status(rabbit_types:vhost(), Name :: rabbit_misc:resource_name()) -> rabbit_types:infos() | {error, term()}. - status(Vhost, QueueName) -> %% Handle not found queues QName = #resource{virtual_host = Vhost, name = QueueName, kind = queue}, @@ -653,19 +652,52 @@ status(Vhost, QueueName) -> {ok, Q} when ?amqqueue_is_classic(Q) -> {error, classic_queue_not_supported}; {ok, Q} when ?amqqueue_is_quorum(Q) -> - {_, Leader} = amqqueue:get_pid(Q), Nodes = amqqueue:get_quorum_nodes(Q), - Info = [{leader, Leader}, {members, Nodes}], - case ets:lookup(ra_state, RName) of - [{_, State}] -> - [{local_state, State} | Info]; - [] -> - Info - end; + [begin + case get_sys_status({RName, N}) of + {ok, Sys} -> + {_, M} = lists:keyfind(ra_server_state, 1, Sys), + {_, RaftState} = lists:keyfind(raft_state, 1, Sys), + #{commit_index := Commit, + machine_version := MacVer, + current_term := Term, + log := #{last_index := Last, + snapshot_index := SnapIdx}} = M, + [{<<"Node Name">>, N}, + {<<"Raft State">>, RaftState}, + {<<"Log Index">>, Last}, + {<<"Commit Index">>, Commit}, + {<<"Snapshot Index">>, SnapIdx}, + {<<"Term">>, Term}, + {<<"Machine Version">>, MacVer} + ]; + {error, Err} -> + [{<<"Node Name">>, N}, + {<<"Raft State">>, Err}, + {<<"Log Index">>, <<>>}, + {<<"Commit Index">>, <<>>}, + {<<"Snapshot Index">>, <<>>}, + {<<"Term">>, <<>>}, + {<<"Machine Version">>, <<>>} + ] + end + end || N <- Nodes]; {error, not_found} = E -> E end. +get_sys_status(Proc) -> + try lists:nth(5, element(4, sys:get_status(Proc))) of + Sys -> {ok, Sys} + catch + _:Err when is_tuple(Err) -> + {error, element(1, Err)}; + _:_ -> + {error, other} + + end. + + add_member(VHost, Name, Node) -> QName = #resource{virtual_host = VHost, name = Name, kind = queue}, case rabbit_amqqueue:lookup(QName) of |
