You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ro...@apache.org on 2023/09/14 22:57:15 UTC
[couchdb] 01/01: Return erlang map for smoosh:status
This is an automated email from the ASF dual-hosted git repository.
ronny pushed a commit to branch fix-4705
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit f5bdeb8f6a48c15da48cd92c15795c764fd9acfc
Author: Ronny Berndt <ro...@apache.org>
AuthorDate: Fri Sep 15 00:56:20 2023 +0200
Return erlang map for smoosh:status
---
src/chttpd/src/chttpd_node.erl | 7 +++++++
src/smoosh/src/smoosh_channel.erl | 14 +++++++-------
src/smoosh/src/smoosh_priority_queue.erl | 19 ++++++++-----------
src/smoosh/src/smoosh_server.erl | 10 +++++++---
4 files changed, 29 insertions(+), 21 deletions(-)
diff --git a/src/chttpd/src/chttpd_node.erl b/src/chttpd/src/chttpd_node.erl
index 46850fc4e..9d4f0ad12 100644
--- a/src/chttpd/src/chttpd_node.erl
+++ b/src/chttpd/src/chttpd_node.erl
@@ -39,6 +39,13 @@ handle_node_req(#httpd{path_parts = [_, <<"_local">>]} = Req) ->
send_json(Req, 200, {[{name, node()}]});
handle_node_req(#httpd{path_parts = [A, <<"_local">> | Rest]} = Req) ->
handle_node_req(Req#httpd{path_parts = [A, node()] ++ Rest});
+% GET /_node/$node/_smoosh/status
+handle_node_req(#httpd{method = 'GET', path_parts = [_, _Node, <<"_smoosh">>, <<"status">>]} = Req) ->
+ {ok, Status} = smoosh:status(),
+ couch_log:info("~p",[Status]),
+ send_json(Req, 200, Status);
+handle_node_req(#httpd{path_parts = [_, _Node, <<"_smoosh">>, <<"status">>]} = Req) ->
+ send_method_not_allowed(Req, "GET");
% GET /_node/$node/_versions
handle_node_req(#httpd{method = 'GET', path_parts = [_, _Node, <<"_versions">>]} = Req) ->
IcuVer = couch_ejson_compare:get_icu_version(),
diff --git a/src/smoosh/src/smoosh_channel.erl b/src/smoosh/src/smoosh_channel.erl
index 92fd3413b..3cfbcdec6 100644
--- a/src/smoosh/src/smoosh_channel.erl
+++ b/src/smoosh/src/smoosh_channel.erl
@@ -77,10 +77,10 @@ enqueue(ServerRef, Object, Priority) ->
get_status(StatusTab) when is_reference(StatusTab) ->
try ets:lookup(StatusTab, status) of
[{status, Status}] -> Status;
- [] -> []
+ [] -> #{}
catch
error:badarg ->
- []
+ #{}
end.
close(ServerRef) ->
@@ -235,11 +235,11 @@ unpersist(Name) ->
%
set_status(#state{} = State) ->
#state{active = Active, starting = Starting, waiting = Waiting} = State,
- Status = [
- {active, map_size(Active)},
- {starting, map_size(Starting)},
- {waiting, smoosh_priority_queue:info(Waiting)}
- ],
+ Status = #{
+ active => map_size(Active),
+ starting => map_size(Starting),
+ waiting => smoosh_priority_queue:info(Waiting)
+ },
true = ets:insert(State#state.stab, {status, Status}),
State.
diff --git a/src/smoosh/src/smoosh_priority_queue.erl b/src/smoosh/src/smoosh_priority_queue.erl
index b2ef4393d..d95f47120 100644
--- a/src/smoosh/src/smoosh_priority_queue.erl
+++ b/src/smoosh/src/smoosh_priority_queue.erl
@@ -64,17 +64,14 @@ qsize(#priority_queue{tree = Tree}) ->
gb_trees:size(Tree).
info(#priority_queue{tree = Tree} = Q) ->
- [
- {size, qsize(Q)}
- | case gb_trees:is_empty(Tree) of
- true ->
- [];
- false ->
- {{Min, _}, _} = gb_trees:smallest(Tree),
- {{Max, _}, _} = gb_trees:largest(Tree),
- [{min, Min}, {max, Max}]
- end
- ].
+ case gb_trees:is_empty(Tree) of
+ true ->
+ #{size => qsize(Q), min => 0, max => 0};
+ false ->
+ {{Min, _}, _} = gb_trees:smallest(Tree),
+ {{Max, _}, _} = gb_trees:largest(Tree),
+ #{size => qsize(Q), min => Min, max => Max}
+ end.
insert(Key, Priority, Capacity, #priority_queue{tree = Tree, map = Map} = Q) ->
TreeKey = {Priority, make_ref()},
diff --git a/src/smoosh/src/smoosh_server.erl b/src/smoosh/src/smoosh_server.erl
index 10368a549..6f12d9c7f 100644
--- a/src/smoosh/src/smoosh_server.erl
+++ b/src/smoosh/src/smoosh_server.erl
@@ -96,11 +96,11 @@ flush() ->
gen_server:call(?MODULE, flush, infinity).
status() ->
- try ets:foldl(fun get_channel_status/2, [], ?MODULE) of
+ try ets:foldl(fun get_channel_status/2, #{}, ?MODULE) of
Res -> {ok, Res}
catch
error:badarg ->
- {ok, []}
+ {ok, #{}}
end.
enqueue(Object0) ->
@@ -286,7 +286,11 @@ remove_enqueue_ref(Ref, #state{} = State) when is_reference(Ref) ->
get_channel_status(#channel{name = Name, stab = Tab}, Acc) ->
Status = smoosh_channel:get_status(Tab),
- [{Name, Status} | Acc];
+ couch_log:info("~nAcc:~p~n",[Acc]),
+ Acc#{Name => Status};
+ %maps:put(Name, Status, Acc);
+ %#{Name => Status, Acc};
+ %[{Name, Status} | Acc];
get_channel_status(_, Acc) ->
Acc.