You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2022/07/01 21:24:49 UTC

[GitHub] [couchdb] noahshaw11 commented on a diff in pull request #4033: Implement view_report function

noahshaw11 commented on code in PR #4033:
URL: https://github.com/apache/couchdb/pull/4033#discussion_r912256762


##########
src/couch_mrview/src/couch_mrview_debug.erl:
##########
@@ -48,3 +86,154 @@ view_signature(DbName, DDocName) ->
     {ok, DDoc} = couch_db:open_doc_int(Db, <<"_design/", DDocName/binary>>, []),
     {ok, IdxState} = couch_mrview_util:ddoc_to_mrst(DDocName, DDoc),
     couch_util:to_hex(IdxState#mrst.sig).
+
+first_call(Pid) ->
+    IC =
+        case process_info(Pid, initial_call) of
+            {initial_call, IC0} -> IC0;
+            undefined -> undefined
+        end,
+    Dict =
+        case process_info(Pid, dictionary) of
+            {dictionary, Dict0} -> Dict0;
+            undefined -> []
+        end,
+    MaybeCall = proplists:get_value('$initial_call', Dict, IC),
+    proplists:get_value(initial_call, Dict, MaybeCall).
+
+find_by_first_call(Module, Function) ->
+    FilterPids = fun(Pid) ->
+        case first_call(Pid) of
+            {Module, Function, _} -> true;
+            _ -> false
+        end
+    end,
+    lists:filter(FilterPids, processes()).
+
+get_indexer_pid() ->
+    IndexerPids = find_by_first_call(couch_index, init),
+    hd(IndexerPids).
+
+index_state(Pid) when is_pid(Pid) ->
+    {ok, IdxState} = couch_index:get_state(Pid, 0),
+    case IdxState of
+        #mrst{} ->
+            {ok, Info} = couch_index:get_info(Pid),
+            Sig = IdxState#mrst.sig,
+            DbName = IdxState#mrst.db_name,
+            {pending_updates, PendingUpdates} = lists:keyfind(pending_updates, 1, Info),
+            State = #{
+                signature => couch_util:to_hex(Sig),
+                db_name => DbName,
+                idx_name => IdxState#mrst.idx_name,
+                update_seq => IdxState#mrst.update_seq,
+                purge_seq => IdxState#mrst.purge_seq,
+                view_file_path => couch_mrview_util:index_file(DbName, Sig),
+                pending_updates => PendingUpdates
+            },
+            {ok, State};
+        _ ->
+            {error, not_mrview_index}
+    end.
+
+view_state(Pid) when is_pid(Pid) ->
+    {ok, IdxState} = couch_index:get_state(Pid, 0),
+    view_state(IdxState, undefined);
+view_state(IdxState) ->

Review Comment:
   What do you mean by consistent. `view_state/2` returns a map of either
   ```
   #{
       ViewName1 => #{
           id_num => MrView#mrview.id_num,
           update_seq => MrView#mrview.update_seq,
           purge_seq => MrView#mrview.purge_seq,
           reduce_funs => ReduceFuns,
           def => MrView#mrview.def,
           btree_size => couch_btree:size(MrView#mrview.btree),
           options => MrView#mrview.options
       },
       ViewName2 => #{
           id_num => MrView#mrview.id_num,
           update_seq => MrView#mrview.update_seq,
           purge_seq => MrView#mrview.purge_seq,
           reduce_funs => ReduceFuns,
           def => MrView#mrview.def,
           btree_size => couch_btree:size(MrView#mrview.btree),
           options => MrView#mrview.options
       },
   ...
   }
   ```
   if no `ViewName` is specified or
   ```
   #{
       ViewName => #{
           id_num => MrView#mrview.id_num,
           update_seq => MrView#mrview.update_seq,
           purge_seq => MrView#mrview.purge_seq,
           reduce_funs => ReduceFuns,
           def => MrView#mrview.def,
           btree_size => couch_btree:size(MrView#mrview.btree),
           options => MrView#mrview.options
       }
   }
   ```
   if a `ViewName` is specified.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org