summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorILYA Khlopotov <iilyak@apache.org>2020-07-23 08:05:12 -0700
committerILYA Khlopotov <iilyak@apache.org>2020-07-30 05:10:08 -0700
commit97e7a95c3c25c1ece7db25ee87e6476ba0a11282 (patch)
tree2654459746bb5e539a5200aabe9f38e03a4fc539
parente1b4259a9e0714fb78f740ee763dd12f84bbca1a (diff)
downloadcouchdb-97e7a95c3c25c1ece7db25ee87e6476ba0a11282.tar.gz
Add format_status/2 callback in gen_server implementations
-rw-r--r--src/couch/include/couch_db.hrl3
-rw-r--r--src/couch/src/couch_lru.erl5
-rw-r--r--src/couch/src/couch_multidb_changes.erl14
-rw-r--r--src/couch/src/couch_native_process.erl17
-rw-r--r--src/couch/src/couch_proc_manager.erl16
-rw-r--r--src/couch/src/couch_server.erl6
-rw-r--r--src/couch/src/couch_stream.erl16
-rw-r--r--src/couch/src/couch_work_queue.erl25
-rw-r--r--src/couch_index/src/couch_index.erl19
-rw-r--r--src/couch_jobs/src/couch_jobs_notifier.erl22
-rw-r--r--src/couch_js/src/couch_js_native_process.erl18
-rw-r--r--src/couch_js/src/couch_js_proc_manager.erl16
-rw-r--r--src/couch_log/src/couch_log_config.erl2
-rw-r--r--src/couch_mrview/src/couch_mrview_index.erl12
-rw-r--r--src/couch_peruser/src/couch_peruser.erl13
-rw-r--r--src/couch_replicator/src/couch_replicator_auth_session.erl2
-rw-r--r--src/couch_replicator/src/couch_replicator_httpc_pool.erl14
-rw-r--r--src/couch_stats/src/couch_stats_aggregator.erl17
-rw-r--r--src/couch_views/src/couch_views_server.erl17
-rw-r--r--src/ddoc_cache/src/ddoc_cache_entry.erl21
-rw-r--r--src/dreyfus/src/dreyfus_index.erl26
-rw-r--r--src/fabric/src/fabric2_txids.erl15
-rw-r--r--src/global_changes/src/global_changes_server.erl11
-rw-r--r--src/ken/src/ken_server.erl16
24 files changed, 316 insertions, 27 deletions
diff --git a/src/couch/include/couch_db.hrl b/src/couch/include/couch_db.hrl
index 830b9bcf4..cc1fb5def 100644
--- a/src/couch/include/couch_db.hrl
+++ b/src/couch/include/couch_db.hrl
@@ -219,3 +219,6 @@
-type sec_props() :: [tuple()].
-type sec_obj() :: {sec_props()}.
+
+-define(record_to_keyval(Name, Record),
+ lists:zip(record_info(fields, Name), tl(tuple_to_list(Record)))).
diff --git a/src/couch/src/couch_lru.erl b/src/couch/src/couch_lru.erl
index 6ad7c65cd..a3057136f 100644
--- a/src/couch/src/couch_lru.erl
+++ b/src/couch/src/couch_lru.erl
@@ -11,13 +11,16 @@
% the License.
-module(couch_lru).
--export([new/0, insert/2, update/2, close/1]).
+-export([new/0, sizes/1, insert/2, update/2, close/1]).
-include("couch_server_int.hrl").
new() ->
{gb_trees:empty(), dict:new()}.
+sizes({Tree, Dict}) ->
+ {gb_trees:size(Tree), dict:size(Dict)}.
+
insert(DbName, {Tree0, Dict0}) ->
Lru = couch_util:unique_monotonic_integer(),
{gb_trees:insert(Lru, DbName, Tree0), dict:store(DbName, Lru, Dict0)}.
diff --git a/src/couch/src/couch_multidb_changes.erl b/src/couch/src/couch_multidb_changes.erl
index e2bbda3e3..09278656e 100644
--- a/src/couch/src/couch_multidb_changes.erl
+++ b/src/couch/src/couch_multidb_changes.erl
@@ -24,7 +24,8 @@
handle_call/3,
handle_info/2,
handle_cast/2,
- code_change/3
+ code_change/3,
+ format_status/2
]).
-export([
@@ -174,6 +175,17 @@ code_change(_OldVsn, State, _Extra) ->
{ok, State}.
+format_status(_Opt, [_PDict, State]) ->
+ #state{
+ pids=Pids
+ } = State,
+ Scrubbed = State#state{
+ pids={length, length(Pids)}
+ },
+ [{data, [{"State",
+ ?record_to_keyval(state, Scrubbed)
+ }]}].
+
% Private functions
-spec register_with_event_server(pid()) -> reference().
diff --git a/src/couch/src/couch_native_process.erl b/src/couch/src/couch_native_process.erl
index eee8b2860..0a228d4c5 100644
--- a/src/couch/src/couch_native_process.erl
+++ b/src/couch/src/couch_native_process.erl
@@ -42,7 +42,7 @@
-vsn(1).
-export([start_link/0,init/1,terminate/2,handle_call/3,handle_cast/2,code_change/3,
- handle_info/2]).
+ handle_info/2,format_status/2]).
-export([set_timeout/2, prompt/2]).
-define(STATE, native_proc_state).
@@ -125,6 +125,21 @@ handle_info({'EXIT',_,Reason}, State) ->
terminate(_Reason, _State) -> ok.
code_change(_OldVersion, State, _Extra) -> {ok, State}.
+format_status(_Opt, [_PDict, State]) ->
+ #evstate{
+ ddocs = DDocs,
+ funs = Functions,
+ query_config = QueryConfig
+ } = State,
+ Scrubbed = State#evstate{
+ ddocs = {dict_size, dict:size(DDocs)},
+ funs = {length, length(Functions)},
+ query_config = {length, length(QueryConfig)}
+ },
+ [{data, [{"State",
+ ?record_to_keyval(evstate, Scrubbed)
+ }]}].
+
run(#evstate{list_pid=Pid}=State, [<<"list_row">>, Row]) when is_pid(Pid) ->
Pid ! {self(), list_row, Row},
receive
diff --git a/src/couch/src/couch_proc_manager.erl b/src/couch/src/couch_proc_manager.erl
index 376e12e74..b83d78882 100644
--- a/src/couch/src/couch_proc_manager.erl
+++ b/src/couch/src/couch_proc_manager.erl
@@ -31,7 +31,8 @@
handle_call/3,
handle_cast/2,
handle_info/2,
- code_change/3
+ code_change/3,
+ format_status/2
]).
-export([
@@ -268,6 +269,19 @@ handle_info(_Msg, State) ->
code_change(_OldVsn, #state{}=State, _Extra) ->
{ok, State}.
+
+format_status(_Opt, [_PDict, State]) ->
+ #state{
+ counts=Counts
+ } = State,
+ Scrubbed = State#state{
+ counts={dict_size, dict:size(Counts)}
+ },
+ [{data, [{"State",
+ ?record_to_keyval(state, Scrubbed)
+ }]}].
+
+
handle_config_terminate(_, stop, _) ->
ok;
handle_config_terminate(_Server, _Reason, _State) ->
diff --git a/src/couch/src/couch_server.erl b/src/couch/src/couch_server.erl
index 18fa3fe61..f8de56b78 100644
--- a/src/couch/src/couch_server.erl
+++ b/src/couch/src/couch_server.erl
@@ -18,7 +18,7 @@
-export([open/2,create/2,delete/2,get_version/0,get_version/1,get_git_sha/0,get_uuid/0]).
-export([all_databases/0, all_databases/2]).
-export([init/1, handle_call/3,sup_start_link/0]).
--export([handle_cast/2,code_change/3,handle_info/2,terminate/2]).
+-export([handle_cast/2,code_change/3,handle_info/2,terminate/2,format_status/2]).
-export([dev_start/0,is_admin/2,has_admins/0,get_stats/0]).
-export([close_lru/0]).
-export([close_db_if_idle/1]).
@@ -288,6 +288,10 @@ terminate(Reason, Srv) ->
end, nil, couch_dbs),
ok.
+format_status(_Opt, [_PDict, Srv]) ->
+ Scrubbed = Srv#server{lru=couch_lru:sizes(Srv#server.lru)},
+ [{data, [{"State", ?record_to_keyval(server, Scrubbed)}]}].
+
handle_config_change("couchdb", "database_dir", _, _, _) ->
exit(whereis(couch_server), config_change),
remove_handler;
diff --git a/src/couch/src/couch_stream.erl b/src/couch/src/couch_stream.erl
index 2ab46d7e7..d8b7e0ffe 100644
--- a/src/couch/src/couch_stream.erl
+++ b/src/couch/src/couch_stream.erl
@@ -36,7 +36,8 @@
handle_call/3,
handle_cast/2,
handle_info/2,
- code_change/3
+ code_change/3,
+ format_status/2
]).
@@ -294,6 +295,19 @@ handle_info(_Info, State) ->
{noreply, State}.
+format_status(_Opt, [_PDict, Stream]) ->
+ #stream{
+ written_pointers=Pointers,
+ buffer_list = Buffer
+ } = Stream,
+ Scrubbed = Stream#stream{
+ written_pointers={length, length(Pointers)},
+ buffer_list = {length, length(Buffer)}
+ },
+ [{data, [{"State",
+ ?record_to_keyval(stream, Scrubbed)
+ }]}].
+
do_seek({Engine, EngineState}, Offset) ->
{ok, NewState} = Engine:seek(EngineState, Offset),
{Engine, NewState}.
diff --git a/src/couch/src/couch_work_queue.erl b/src/couch/src/couch_work_queue.erl
index 5d747de82..01271bb35 100644
--- a/src/couch/src/couch_work_queue.erl
+++ b/src/couch/src/couch_work_queue.erl
@@ -21,7 +21,7 @@
% gen_server callbacks
-export([init/1, terminate/2]).
--export([handle_call/3, handle_cast/2, code_change/3, handle_info/2]).
+-export([handle_call/3, handle_cast/2, code_change/3, handle_info/2, format_status/2]).
-record(q, {
queue = queue:new(),
@@ -49,7 +49,7 @@ queue(Wq, Item) ->
dequeue(Wq) ->
dequeue(Wq, all).
-
+
dequeue(Wq, MaxItems) ->
try
gen_server:call(Wq, {dequeue, MaxItems}, infinity)
@@ -76,7 +76,7 @@ size(Wq) ->
close(Wq) ->
gen_server:cast(Wq, close).
-
+
init(Options) ->
Q = #q{
@@ -90,7 +90,7 @@ init(Options) ->
terminate(_Reason, #q{work_waiters=Workers}) ->
lists:foreach(fun({W, _}) -> gen_server:reply(W, closed) end, Workers).
-
+
handle_call({queue, Item, Size}, From, #q{work_waiters = []} = Q0) ->
Q = Q0#q{size = Q0#q.size + Size,
items = Q0#q.items + 1,
@@ -172,7 +172,7 @@ dequeue_items(NumItems, Size, Queue, Blocked, DequeuedAcc) ->
end,
dequeue_items(
NumItems - 1, Size - ItemSize, Queue2, Blocked2, [Item | DequeuedAcc]).
-
+
handle_cast(close, #q{items = 0} = Q) ->
{stop, normal, Q};
@@ -186,3 +186,18 @@ code_change(_OldVsn, State, _Extra) ->
handle_info(X, Q) ->
{stop, X, Q}.
+
+format_status(_Opt, [_PDict, Queue]) ->
+ #q{
+ queue = Q,
+ blocked = Blocked,
+ work_waiters = Waiters
+ } = Queue,
+ Scrubbed = Queue#q{
+ queue = {queue_length, queue:len(Q)},
+ blocked = {length, length(Blocked)},
+ work_waiters = {length, length(Waiters)}
+ },
+ [{data, [{"State",
+ ?record_to_keyval(q, Scrubbed)
+ }]}].
diff --git a/src/couch_index/src/couch_index.erl b/src/couch_index/src/couch_index.erl
index cfe0d9e4f..09bd48c61 100644
--- a/src/couch_index/src/couch_index.erl
+++ b/src/couch_index/src/couch_index.erl
@@ -23,7 +23,7 @@
-export([compact/1, compact/2, get_compactor_pid/1]).
%% gen_server callbacks
--export([init/1, terminate/2, code_change/3]).
+-export([init/1, terminate/2, code_change/3, format_status/2]).
-export([handle_call/3, handle_cast/2, handle_info/2]).
@@ -375,6 +375,23 @@ handle_info({'DOWN', _, _, _Pid, _}, #st{mod=Mod, idx_state=IdxState}=State) ->
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
+format_status(Opt, [PDict, State]) ->
+ #st{
+ mod = Mod,
+ waiters = Waiters,
+ idx_state = IdxState
+ } = State,
+ Scrubbed = State#st{waiters = {length, length(Waiters)}},
+ IdxSafeState = case erlang:function_exported(Mod, format_status, 2) of
+ true ->
+ Mod:format_status(Opt, [PDict, IdxState]);
+ false ->
+ []
+ end,
+ [{data, [{"State",
+ ?record_to_keyval(st, Scrubbed) ++ IdxSafeState
+ }]}].
+
maybe_restart_updater(#st{waiters=[]}) ->
ok;
maybe_restart_updater(#st{idx_state=IdxState}=State) ->
diff --git a/src/couch_jobs/src/couch_jobs_notifier.erl b/src/couch_jobs/src/couch_jobs_notifier.erl
index ff4492bc5..99581cb79 100644
--- a/src/couch_jobs/src/couch_jobs_notifier.erl
+++ b/src/couch_jobs/src/couch_jobs_notifier.erl
@@ -27,7 +27,8 @@
handle_call/3,
handle_cast/2,
handle_info/2,
- code_change/3
+ code_change/3,
+ format_status/2
]).
@@ -135,6 +136,25 @@ code_change(_OldVsn, St, _Extra) ->
{ok, St}.
+format_status(_Opt, [_PDict, State]) ->
+ #st{
+ jtx=JTx,
+ type=Type,
+ monitor_pid=MonitorPid,
+ subs=Subs,
+ pidmap=PidMap,
+ refmap=RefMap
+ } = State,
+ [{data, [{"State", [
+ {jtx, JTx},
+ {type, Type},
+ {monitor_pid, MonitorPid},
+ {subs, {map_size, maps:size(Subs)}},
+ {pidmap, {map_size, maps:size(PidMap)}},
+ {refmap, {map_size, maps:size(RefMap)}}
+ ]}]}].
+
+
update_subs(JobId, Refs, #st{subs = Subs} = St) when map_size(Refs) =:= 0 ->
St#st{subs = maps:remove(JobId, Subs)};
diff --git a/src/couch_js/src/couch_js_native_process.erl b/src/couch_js/src/couch_js_native_process.erl
index d2c4c1ee0..d5ed3f94f 100644
--- a/src/couch_js/src/couch_js_native_process.erl
+++ b/src/couch_js/src/couch_js_native_process.erl
@@ -42,7 +42,7 @@
-vsn(1).
-export([start_link/0,init/1,terminate/2,handle_call/3,handle_cast/2,code_change/3,
- handle_info/2]).
+ handle_info/2,format_status/2]).
-export([set_timeout/2, prompt/2]).
-define(STATE, native_proc_state).
@@ -125,6 +125,22 @@ handle_info({'EXIT',_,Reason}, State) ->
terminate(_Reason, _State) -> ok.
code_change(_OldVersion, State, _Extra) -> {ok, State}.
+format_status(_Opt, [_PDict, State]) ->
+ #evstate{
+ ddocs = DDocs,
+ funs = Funs,
+ query_config = Config
+ } = State,
+ Scrubbed = State#evstate{
+ ddocs = {dict_size, dict:size(DDocs)},
+ funs = {length, length(Funs)},
+ query_config = {length, length(Config)}
+ },
+ [{data, [{"State",
+ ?record_to_keyval(evstate, Scrubbed)
+ }]}].
+
+
run(#evstate{list_pid=Pid}=State, [<<"list_row">>, Row]) when is_pid(Pid) ->
Pid ! {self(), list_row, Row},
receive
diff --git a/src/couch_js/src/couch_js_proc_manager.erl b/src/couch_js/src/couch_js_proc_manager.erl
index 45f173668..db5c492f5 100644
--- a/src/couch_js/src/couch_js_proc_manager.erl
+++ b/src/couch_js/src/couch_js_proc_manager.erl
@@ -30,7 +30,8 @@
handle_call/3,
handle_cast/2,
handle_info/2,
- code_change/3
+ code_change/3,
+ format_status/2
]).
-export([
@@ -267,6 +268,19 @@ handle_info(_Msg, State) ->
code_change(_OldVsn, #state{}=State, _Extra) ->
{ok, State}.
+
+format_status(_Opt, [_PDict, State]) ->
+ #state{
+ counts = Counts
+ } = State,
+ Scrubbed = State#state{
+ counts = {dict_size, dict:size(Counts)}
+ },
+ [{data, [{"State",
+ ?record_to_keyval(state, Scrubbed)
+ }]}].
+
+
handle_config_terminate(_, stop, _) ->
ok;
handle_config_terminate(_Server, _Reason, _State) ->
diff --git a/src/couch_log/src/couch_log_config.erl b/src/couch_log/src/couch_log_config.erl
index a7a469cc3..ab076cc69 100644
--- a/src/couch_log/src/couch_log_config.erl
+++ b/src/couch_log/src/couch_log_config.erl
@@ -104,4 +104,4 @@ transform(strip_last_msg, "false") ->
false;
transform(strip_last_msg, _) ->
- true. \ No newline at end of file
+ true.
diff --git a/src/couch_mrview/src/couch_mrview_index.erl b/src/couch_mrview/src/couch_mrview_index.erl
index cc013c5bd..6ae7874c9 100644
--- a/src/couch_mrview/src/couch_mrview_index.erl
+++ b/src/couch_mrview/src/couch_mrview_index.erl
@@ -20,6 +20,7 @@
-export([index_file_exists/1]).
-export([update_local_purge_doc/2, verify_index_exists/2]).
-export([ensure_local_purge_docs/2]).
+-export([format_status/2]).
-include_lib("couch/include/couch_db.hrl").
-include_lib("couch_mrview/include/couch_mrview.hrl").
@@ -324,3 +325,14 @@ update_local_purge_doc(Db, State, PSeq) ->
BaseDoc
end,
couch_db:update_doc(Db, Doc, []).
+
+format_status(_Opt, [_PDict, State]) ->
+ Scrubbed = State#mrst{
+ lib = nil,
+ views = nil,
+ id_btree = nil,
+ doc_acc = nil,
+ doc_queue = nil,
+ write_queue = nil
+ },
+ ?record_to_keyval(mrst, Scrubbed).
diff --git a/src/couch_peruser/src/couch_peruser.erl b/src/couch_peruser/src/couch_peruser.erl
index 886fb4f6e..4c06e8f27 100644
--- a/src/couch_peruser/src/couch_peruser.erl
+++ b/src/couch_peruser/src/couch_peruser.erl
@@ -19,7 +19,7 @@
% gen_server callbacks
-export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2,
- terminate/2, code_change/3]).
+ terminate/2, code_change/3, format_status/2]).
-export([init_changes_handler/1, changes_handler/3]).
@@ -410,3 +410,14 @@ terminate(_Reason, _State) ->
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
+
+ format_status(_Opt, [_PDict, State]) ->
+ #state{
+ states = States
+ } = State,
+ Scrubbed = State#state{
+ states = {length, length(States)}
+ },
+ [{data, [{"State",
+ ?record_to_keyval(state, Scrubbed)
+ }]}]. \ No newline at end of file
diff --git a/src/couch_replicator/src/couch_replicator_auth_session.erl b/src/couch_replicator/src/couch_replicator_auth_session.erl
index 30f499a33..a59c770b4 100644
--- a/src/couch_replicator/src/couch_replicator_auth_session.erl
+++ b/src/couch_replicator/src/couch_replicator_auth_session.erl
@@ -187,7 +187,7 @@ format_status(_Opt, [_PDict, State]) ->
[
{epoch, State#state.epoch},
{user, State#state.user},
- {session_url, State#state.session_url},
+ {session_url, couch_util:url_strip_password(State#state.session_url)},
{refresh_tstamp, State#state.refresh_tstamp}
].
diff --git a/src/couch_replicator/src/couch_replicator_httpc_pool.erl b/src/couch_replicator/src/couch_replicator_httpc_pool.erl
index 90234a6a0..c63a5efa6 100644
--- a/src/couch_replicator/src/couch_replicator_httpc_pool.erl
+++ b/src/couch_replicator/src/couch_replicator_httpc_pool.erl
@@ -20,7 +20,7 @@
% gen_server API
-export([init/1, handle_call/3, handle_info/2, handle_cast/2]).
--export([code_change/3, terminate/2]).
+-export([code_change/3, terminate/2, format_status/2]).
-include_lib("couch/include/couch_db.hrl").
@@ -145,6 +145,18 @@ code_change(_OldVsn, #state{}=State, _Extra) ->
terminate(_Reason, _State) ->
ok.
+format_status(_Opt, [_PDict, State]) ->
+ #state{
+ url = Url,
+ proxy_url = ProxyURL,
+ limit = Limit
+ } = State,
+ {[
+ {url, couch_util:url_strip_password(Url)},
+ {proxy_url, couch_util:url_strip_password(ProxyURL)},
+ {limit, Limit}
+ ]}.
+
monitor_client(Callers, Worker, {ClientPid, _}) ->
[{Worker, erlang:monitor(process, ClientPid)} | Callers].
diff --git a/src/couch_stats/src/couch_stats_aggregator.erl b/src/couch_stats/src/couch_stats_aggregator.erl
index 0416636c9..8d8cdf7e5 100644
--- a/src/couch_stats/src/couch_stats_aggregator.erl
+++ b/src/couch_stats/src/couch_stats_aggregator.erl
@@ -27,7 +27,8 @@
handle_cast/2,
handle_info/2,
code_change/3,
- terminate/2
+ terminate/2,
+ format_status/2
]).
@@ -88,6 +89,20 @@ terminate(_Reason, _State) ->
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
+format_status(_Opt, [_PDict, State]) ->
+ #st{
+ descriptions=Descs,
+ stats=Stats,
+ collect_timer=CollectT,
+ reload_timer=ReloadT
+ } = State,
+ [{data, [{"State", [
+ {descriptions, {set_size, sets:size(Descs)}},
+ {stats, {length, length(Stats)}},
+ {collect_timer,CollectT},
+ {reload_timer,ReloadT}
+ ]}]}].
+
comparison_set(Metrics) ->
sets:from_list(
[{Name, proplists:get_value(type, Props)} || {Name, Props} <- Metrics]
diff --git a/src/couch_views/src/couch_views_server.erl b/src/couch_views/src/couch_views_server.erl
index e45a9f315..71a4abb8d 100644
--- a/src/couch_views/src/couch_views_server.erl
+++ b/src/couch_views/src/couch_views_server.erl
@@ -30,7 +30,8 @@
handle_call/3,
handle_cast/2,
handle_info/2,
- code_change/3
+ code_change/3,
+ format_status/2
]).
-define(MAX_ACCEPTORS, 5).
@@ -108,6 +109,20 @@ code_change(_OldVsn, St, _Extra) ->
{ok, St}.
+format_status(_Opt, [_PDict, State]) ->
+ #{
+ workers := Workers,
+ acceptors := Acceptors
+ } = State,
+ Scrubbed = State#{
+ workers => {map_size, maps:size(Workers)},
+ acceptors => {map_size, maps:size(Acceptors)}
+ },
+ [{data, [{"State",
+ Scrubbed
+ }]}].
+
+
% Worker process exit handlers
handle_acceptor_exit(#{acceptors := Acceptors} = St, Pid, Reason) ->
diff --git a/src/ddoc_cache/src/ddoc_cache_entry.erl b/src/ddoc_cache/src/ddoc_cache_entry.erl
index 4cc3d7e52..ed0311bbd 100644
--- a/src/ddoc_cache/src/ddoc_cache_entry.erl
+++ b/src/ddoc_cache/src/ddoc_cache_entry.erl
@@ -34,7 +34,8 @@
handle_call/3,
handle_cast/2,
handle_info/2,
- code_change/3
+ code_change/3,
+ format_status/2
]).
-export([
@@ -282,6 +283,24 @@ code_change(_, St, _) ->
{ok, St}.
+format_status(_Opt, [_PDict, State]) ->
+ #st{
+ key = Key,
+ val = Val,
+ opener = Opener,
+ waiters = Waiters,
+ ts = TS,
+ accessed = Accepted
+ } = State,
+ [{data, [{"State", [
+ {key, Key},
+ {val, Val},
+ {opener, Opener},
+ {waiters, {length, length(Waiters)}},
+ {ts, TS},
+ {accessed, Accepted}
+ ]}]}].
+
spawn_opener(Key) ->
{Pid, _} = erlang:spawn_monitor(?MODULE, do_open, [Key]),
Pid.
diff --git a/src/dreyfus/src/dreyfus_index.erl b/src/dreyfus/src/dreyfus_index.erl
index 2bf560f37..7236eb16b 100644
--- a/src/dreyfus/src/dreyfus_index.erl
+++ b/src/dreyfus/src/dreyfus_index.erl
@@ -29,7 +29,7 @@
% gen_server api.
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
- code_change/3]).
+ code_change/3, format_status/2]).
% private definitions.
-record(state, {
@@ -244,6 +244,30 @@ terminate(_Reason, _State) ->
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
+format_status(_Opt, [_PDict, #state{index = #index{} = Index} = State]) ->
+ #index{
+ ddoc_id=Id,
+ name=IndexName,
+ sig=Sig
+ } = Index,
+ IndexScrubbed = [{
+ {ddoc_id, Id},
+ {name, IndexName},
+ {sig, Sig}
+ }],
+ Scrubbed = State#state{
+ index = IndexScrubbed,
+ waiting_list = {length, length(State#state.waiting_list)}
+ },
+ ?record_to_keyval(state, Scrubbed);
+
+format_status(_Opt, [_PDict, #state{} = State]) ->
+ Scrubbed = State#state{
+ index = nil,
+ waiting_list = {length, length(State#state.waiting_list)}
+ },
+ ?record_to_keyval(state, Scrubbed).
+
% private functions.
open_index(DbName, #index{analyzer=Analyzer, sig=Sig}) ->
diff --git a/src/fabric/src/fabric2_txids.erl b/src/fabric/src/fabric2_txids.erl
index 046a7484a..285e342ed 100644
--- a/src/fabric/src/fabric2_txids.erl
+++ b/src/fabric/src/fabric2_txids.erl
@@ -28,7 +28,8 @@
handle_call/3,
handle_cast/2,
handle_info/2,
- code_change/3
+ code_change/3,
+ format_status/2
]).
@@ -110,6 +111,18 @@ code_change(_OldVsn, St, _Extra) ->
{ok, St}.
+format_status(_Opt, [_PDict, State]) ->
+ #{
+ txids := TxIds
+ } = State,
+ Scrubbed = State#{
+ txids => {length, length(TxIds)}
+ },
+ [{data, [{"State",
+ Scrubbed
+ }]}].
+
+
clean(St, NeedsSweep) ->
#{
last_sweep := LastSweep,
diff --git a/src/global_changes/src/global_changes_server.erl b/src/global_changes/src/global_changes_server.erl
index 7e3062586..a116e0668 100644
--- a/src/global_changes/src/global_changes_server.erl
+++ b/src/global_changes/src/global_changes_server.erl
@@ -25,7 +25,8 @@
handle_call/3,
handle_cast/2,
handle_info/2,
- code_change/3
+ code_change/3,
+ format_status/2
]).
-export([
@@ -143,7 +144,13 @@ handle_info(_, State) ->
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
-
+format_status(_Opt, [_PDict, State]) ->
+ Scrubbed = State#state{
+ pending_updates=nil
+ },
+ [{data, [{"State",
+ ?record_to_keyval(state, Scrubbed)
+ }]}].
flush_updates(State) ->
DocIds = sets:to_list(State#state.pending_updates),
diff --git a/src/ken/src/ken_server.erl b/src/ken/src/ken_server.erl
index b33d01f35..74c8e25ac 100644
--- a/src/ken/src/ken_server.erl
+++ b/src/ken/src/ken_server.erl
@@ -16,7 +16,9 @@
-behaviour(gen_server).
-vsn(1).
-export([init/1, terminate/2]).
--export([handle_call/3, handle_cast/2, handle_info/2, code_change/3]).
+-export([
+ handle_call/3, handle_cast/2, handle_info/2, code_change/3,format_status/2
+]).
% Public interface
-export([start_link/0]).
@@ -228,6 +230,18 @@ handle_info(Msg, State) ->
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
+
+format_status(_Opt, [_PDict, State]) ->
+ #state{
+ q = Queue
+ } = State,
+ Scrubbed = State#state{
+ q = {queue_length, queue:len(Queue)}
+ },
+ [{data, [{"State",
+ ?record_to_keyval(state, Scrubbed)
+ }]}].
+
%% private functions
maybe_start_next_queued_job(#state{dbworker = {_,_}} = State) ->