summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Holley <willholley@gmail.com>2020-01-08 11:29:59 +0000
committerWill Holley <willholley@gmail.com>2020-01-08 19:28:05 +0000
commit75b6838ee2dbb050337ad4c19a03ae5ba5d7b63f (patch)
treef801811463863cdc9fd3413274a96f9e8257ccc7
parente8508952ce76a5842a51d0c632f12fcbfabb6e41 (diff)
downloadcouchdb-75b6838ee2dbb050337ad4c19a03ae5ba5d7b63f.tar.gz
Fix missing mango execution stats (part 1)
Adds message handlers to mango / all_docs / mrview fabric to recieve an execution_stats message.
-rw-r--r--src/fabric/src/fabric_view_all_docs.erl7
-rw-r--r--src/fabric/src/fabric_view_map.erl6
-rw-r--r--src/mango/src/mango_cursor_view.erl16
3 files changed, 23 insertions, 6 deletions
diff --git a/src/fabric/src/fabric_view_all_docs.erl b/src/fabric/src/fabric_view_all_docs.erl
index 07cd1b180..e4d3d4a40 100644
--- a/src/fabric/src/fabric_view_all_docs.erl
+++ b/src/fabric/src/fabric_view_all_docs.erl
@@ -239,8 +239,13 @@ handle_message(#view_row{} = Row, {Worker, From}, State) ->
handle_message(complete, Worker, State) ->
Counters = fabric_dict:update_counter(Worker, 1, State#collector.counters),
- fabric_view:maybe_send_row(State#collector{counters = Counters}).
+ fabric_view:maybe_send_row(State#collector{counters = Counters});
+handle_message({execution_stats, _} = Msg, {_,From}, St) ->
+ #collector{callback=Callback, user_acc=AccIn} = St,
+ {Go, Acc} = Callback(Msg, AccIn),
+ rexi:stream_ack(From),
+ {Go, St#collector{user_acc=Acc}}.
merge_row(fwd, Row, Rows) ->
lists:keymerge(#view_row.id, [Row], Rows);
diff --git a/src/fabric/src/fabric_view_map.erl b/src/fabric/src/fabric_view_map.erl
index 5a5cc138b..b8d0d392a 100644
--- a/src/fabric/src/fabric_view_map.erl
+++ b/src/fabric/src/fabric_view_map.erl
@@ -180,6 +180,12 @@ handle_message(complete, Worker, State) ->
Counters = fabric_dict:update_counter(Worker, 1, State#collector.counters),
fabric_view:maybe_send_row(State#collector{counters = Counters});
+handle_message({execution_stats, _} = Msg, {_,From}, St) ->
+ #collector{callback=Callback, user_acc=AccIn} = St,
+ {Go, Acc} = Callback(Msg, AccIn),
+ rexi:stream_ack(From),
+ {Go, St#collector{user_acc=Acc}};
+
handle_message(ddoc_updated, _Worker, State) ->
{stop, State}.
diff --git a/src/mango/src/mango_cursor_view.erl b/src/mango/src/mango_cursor_view.erl
index 1c4b3423e..f5cd3822f 100644
--- a/src/mango/src/mango_cursor_view.erl
+++ b/src/mango/src/mango_cursor_view.erl
@@ -44,7 +44,7 @@ create(Db, Indexes, Selector, Opts) ->
Limit = couch_util:get_value(limit, Opts, mango_opts:default_limit()),
Skip = couch_util:get_value(skip, Opts, 0),
Fields = couch_util:get_value(fields, Opts, all_fields),
- Bookmark = couch_util:get_value(bookmark, Opts),
+ Bookmark = couch_util:get_value(bookmark, Opts),
{ok, #cursor{
db = Db,
@@ -124,7 +124,7 @@ execute(#cursor{db = Db, index = Idx, execution_stats = Stats} = Cursor0, UserFu
BaseArgs = base_args(Cursor),
#cursor{opts = Opts, bookmark = Bookmark} = Cursor,
Args0 = apply_opts(Opts, BaseArgs),
- Args = mango_json_bookmark:update_args(Bookmark, Args0),
+ Args = mango_json_bookmark:update_args(Bookmark, Args0),
UserCtx = couch_util:get_value(user_ctx, Opts, #user_ctx{}),
DbOpts = [{user_ctx, UserCtx}],
Result = case mango_idx:def(Idx) of
@@ -302,6 +302,12 @@ handle_message({row, Props}, Cursor) ->
couch_log:error("~s :: Error loading doc: ~p", [?MODULE, Error]),
{ok, Cursor}
end;
+handle_message({execution_stats, ShardStats}, #cursor{execution_stats = Stats} = Cursor) ->
+ {docs_examined, DocsExamined} = ShardStats,
+ Cursor1 = Cursor#cursor{
+ execution_stats = mango_execution_stats:incr_docs_examined(Stats, DocsExamined)
+ },
+ {ok, Cursor1};
handle_message(complete, Cursor) ->
{ok, Cursor};
handle_message({error, Reason}, _Cursor) ->
@@ -410,7 +416,7 @@ apply_opts([{_, _} | Rest], Args) ->
doc_member(Cursor, RowProps) ->
- Db = Cursor#cursor.db,
+ Db = Cursor#cursor.db,
Opts = Cursor#cursor.opts,
ExecutionStats = Cursor#cursor.execution_stats,
Selector = Cursor#cursor.selector,
@@ -460,8 +466,8 @@ is_design_doc(RowProps) ->
update_bookmark_keys(#cursor{limit = Limit} = Cursor, Props) when Limit > 0 ->
- Id = couch_util:get_value(id, Props),
- Key = couch_util:get_value(key, Props),
+ Id = couch_util:get_value(id, Props),
+ Key = couch_util:get_value(key, Props),
Cursor#cursor {
bookmark_docid = Id,
bookmark_key = Key