Merge pull request #12464 from ieQu1/dev/feat-ds-cli

feat(ds): Add a CLI interface to inspect status of DS databases
This commit is contained in:
ieQu1 2024-02-02 14:14:48 +01:00 committed by GitHub
commit e0b5d9fae7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 6 deletions

View File

@ -127,15 +127,24 @@ print_status() ->
end, end,
eval_qlc(mnesia:table(?NODE_TAB)) eval_qlc(mnesia:table(?NODE_TAB))
), ),
io:format("~nSHARDS~n", []), io:format(
"~nSHARDS:~nId Leader Status~n", []
),
lists:foreach( lists:foreach(
fun(#?SHARD_TAB{shard = {DB, Shard}, leader = Leader}) -> fun(#?SHARD_TAB{shard = {DB, Shard}, leader = Leader}) ->
ShardStr = string:pad(io_lib:format("~p/~s", [DB, Shard]), 30),
LeaderStr = string:pad(atom_to_list(Leader), 33),
Status = Status =
case lists:member(Leader, Nodes) of case lists:member(Leader, Nodes) of
true -> up; true ->
false -> down case node() of
Leader -> "up *";
_ -> "up"
end;
false ->
"down"
end, end,
io:format("~p/~s ~p ~p~n", [DB, Shard, Leader, Status]) io:format("~s ~s ~s~n", [ShardStr, LeaderStr, Status])
end, end,
eval_qlc(mnesia:table(?SHARD_TAB)) eval_qlc(mnesia:table(?SHARD_TAB))
). ).

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2020-2023 EMQ Technologies Co., Ltd. All Rights Reserved. %% Copyright (c) 2020-2024 EMQ Technologies Co., Ltd. All Rights Reserved.
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -43,7 +43,8 @@
authz/1, authz/1,
pem_cache/1, pem_cache/1,
olp/1, olp/1,
data/1 data/1,
ds/1
]). ]).
-spec load() -> ok. -spec load() -> ok.
@ -796,6 +797,24 @@ data(_) ->
{"data export", "Export data"} {"data export", "Export data"}
]). ]).
%%--------------------------------------------------------------------
%% @doc Durable storage command
ds(CMD) ->
case emqx_persistent_message:is_persistence_enabled() of
true ->
do_ds(CMD);
false ->
emqx_ctl:usage([{"ds", "Durable storage is disabled"}])
end.
do_ds(["info"]) ->
emqx_ds_replication_layer_meta:print_status();
do_ds(_) ->
emqx_ctl:usage([
{"ds info", "Show overview of the embedded durable storage state"}
]).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Dump ETS %% Dump ETS
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------