couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chewbra...@apache.org
Subject [5/5] fabric commit: updated refs/heads/1993-bigcouch-couch-mrview to aeac2df
Date Fri, 28 Mar 2014 18:45:06 GMT
Call fabric view reduce callback with meta information

This is a temporary hack to allow passing meta through
fabric_view_reduce:handle_message. The meta rows were not present on
reduce functions in the previous views implementation, but they
provide an excellent place to determine which a view is about to start
streaming, which is essential for the multi query view implementation.

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. For now this
sets a process dict flag to indicate meta has been sent so that we
only send it once. The proper fix is to send meta through
fabric_view:maybe_send_row, but that gets ugly in a hurry and can be
addressed separately.

COUCHDB-523
COUCHDB-1993


Project: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/commit/aeac2dfe
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/tree/aeac2dfe
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/diff/aeac2dfe

Branch: refs/heads/1993-bigcouch-couch-mrview
Commit: aeac2dfe5014dc9fe1f10300669ea9244cae3a67
Parents: efddaf1
Author: Russell Branca <chewbranca@gmail.com>
Authored: Thu Mar 27 15:48:16 2014 -0700
Committer: Russell Branca <chewbranca@gmail.com>
Committed: Fri Mar 28 11:33:19 2014 -0700

----------------------------------------------------------------------
 src/fabric_view.erl        |  2 ++
 src/fabric_view_reduce.erl | 24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fabric/blob/aeac2dfe/src/fabric_view.erl
----------------------------------------------------------------------
diff --git a/src/fabric_view.erl b/src/fabric_view.erl
index 31c25d9..09e13f2 100644
--- a/src/fabric_view.erl
+++ b/src/fabric_view.erl
@@ -98,6 +98,7 @@ maybe_send_row(#collector{limit=0} = State) ->
         % we still need to send the total/offset header
         {ok, State};
     false ->
+        erase(meta_sent),
         {_, Acc} = Callback(complete, AccIn),
         {stop, State#collector{user_acc=Acc}}
     end;
@@ -124,6 +125,7 @@ maybe_send_row(State) ->
                 maybe_send_row(NewState#collector{user_acc=Acc, limit=Limit-1})
             end
         catch complete ->
+            erase(meta_sent),
             {_, Acc} = Callback(complete, AccIn),
             {stop, State#collector{user_acc=Acc}}
         end

http://git-wip-us.apache.org/repos/asf/couchdb-fabric/blob/aeac2dfe/src/fabric_view_reduce.erl
----------------------------------------------------------------------
diff --git a/src/fabric_view_reduce.erl b/src/fabric_view_reduce.erl
index d2ea464..6b40a6a 100644
--- a/src/fabric_view_reduce.erl
+++ b/src/fabric_view_reduce.erl
@@ -74,6 +74,30 @@ handle_message({rexi_EXIT, Reason}, Worker, State) ->
         {error, Resp}
     end;
 
+%% 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({meta, Meta}, {_Worker, From}, State) ->
+    gen_server:reply(From, ok),
+    #collector{
+        callback = Callback,
+        user_acc = AccIn
+    } = State,
+
+    {Go, Acc} = case get(meta_sent) of
+        undefined ->
+            put(meta_sent, true),
+            Callback({meta, Meta}, AccIn);
+        _ ->
+            {ok, AccIn}
+    end,
+    {Go, State#collector{user_acc = Acc}};
+
 handle_message(#view_row{key=Key} = Row, {Worker, From}, State) ->
     #collector{counters = Counters0, rows = Rows0} = State,
     case fabric_dict:lookup_element(Worker, Counters0) of


Mime
View raw message