couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [2/2] fabric commit: updated refs/heads/1993-bigcouch-couch-mrview to 017430d
Date Thu, 27 Feb 2014 20:02:21 GMT
HACK: send a meta callback from fabric_view_reduce:handle_message/3

Hack alert. This sends a meta row from the handle_message callback in
fabric_view_reduce for the case of receiving a total_and_offset
messsage. Prior to couch_mrview, the view reduce implementation did
not send this message to fabric_view_reduce.

The hack is that we don't do the proper row collection worker dance
like we do in the handle_message callback for #view_row. I added a
temporary field to the #collector record to keep track of whether
we've sent the meta row yet to ensure it only gets sent once.

The primary motivation for this hack is that it provides a clean and
elegant solution to understanding when a view output stream is
starting. This is used to cleanup unecessary code in
couch_mrview_http:view_cb/2, and it's also essential for doing multi
query views through fabric.

I strongly feel sending the meta row is the right general approach,
but the devil is in the details as usual. To do this properly, we need
to funnel this through fabric_view:maybe_send_row, which gets awkward
in a hurry. So I've decided to temporarily introduce this hack to
solidify the API allowing the multi_query_view implementation to be
completed. Next step is to figure out how to fix this hack.



Branch: refs/heads/1993-bigcouch-couch-mrview
Commit: 017430dc393a7b36a83e0e8faa63b80859e4bc2f
Parents: 634b55e
Author: Russell Branca <>
Authored: Thu Feb 27 12:02:26 2014 -0800
Committer: Russell Branca <>
Committed: Thu Feb 27 12:02:26 2014 -0800

 include/fabric.hrl         |  3 ++-
 src/fabric_view_reduce.erl | 23 +++++++++++++++++++++--
 2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/include/fabric.hrl b/include/fabric.hrl
index 94769bd..00765c5 100644
--- a/include/fabric.hrl
+++ b/include/fabric.hrl
@@ -29,7 +29,8 @@
-    user_acc
+    user_acc,
+    meta_sent = false
 -record(view_row, {key, id, value, doc, worker}).
diff --git a/src/fabric_view_reduce.erl b/src/fabric_view_reduce.erl
index c21c8ab..6be5c13 100644
--- a/src/fabric_view_reduce.erl
+++ b/src/fabric_view_reduce.erl
@@ -74,10 +74,29 @@ handle_message({rexi_EXIT, Reason}, Worker, State) ->
         {error, Resp}
-%% TODO: what to do with this message?
+%% HACK: this just sends meta once. Instead we should move the counter logic
+%% from the #view_row handle_message below into this function and and pass the
+%% meta call through maybe_send_row. This will also be more efficient doing it
+%% here as it's one less worker round trip reply.
+%% Prior to switching to couch_mrview, the fabric_view_reduce implementation
+%% did not get a total_and_offset call, whereas now we do. We now use this
+%% message as a clean way to indicate to couch_mrview_http:view_cb that the
+%% reduce response is starting.
 handle_message({total_and_offset, _, _}, {_Worker, From}, State) ->
     gen_server:reply(From, ok),
-    {ok, State};
+    #collector{
+        callback = Callback,
+        user_acc = AccIn,
+        meta_sent = MetaSent
+    } = State,
+    {Go, Acc} = case MetaSent of
+        false ->
+            Callback({meta, []}, AccIn);
+        _ ->
+            {ok, AccIn}
+    end,
+    {Go, State#collector{meta_sent=true, user_acc = Acc}};
 handle_message(#view_row{key=Key} = Row, {Worker, From}, State) ->
     #collector{counters = Counters0, rows = Rows0} = State,

View raw message