feat(ds): Add a CLI interface to inspect status of DS databases

This commit is contained in:
ieQu1 2024-02-02 09:50:16 +01:00
parent fc55b429f5
commit 3d2ac97c61
2 changed files with 34 additions and 6 deletions

View File

@ -127,15 +127,24 @@ print_status() ->
end,
eval_qlc(mnesia:table(?NODE_TAB))
),
io:format("~nSHARDS~n", []),
io:format(
"~nSHARDS:~nId Leader Status~n", []
),
lists:foreach(
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 =
case lists:member(Leader, Nodes) of
true -> up;
false -> down
true ->
case node() of
Leader -> "up *";
_ -> "up"
end;
false ->
"down"
end,
io:format("~p/~s ~p ~p~n", [DB, Shard, Leader, Status])
io:format("~s ~s ~s~n", [ShardStr, LeaderStr, Status])
end,
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");
%% you may not use this file except in compliance with the License.
@ -43,7 +43,8 @@
authz/1,
pem_cache/1,
olp/1,
data/1
data/1,
ds/1
]).
-spec load() -> ok.
@ -796,6 +797,24 @@ 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
%%--------------------------------------------------------------------