You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ko...@apache.org on 2017/03/01 16:37:35 UTC

[01/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Repository: couchdb-couch-mrview
Updated Branches:
  refs/heads/2971-count-distinct 6ec35971e -> f7c3c24db


Render update_seq if number or binary

COUCHDB-2849


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/65b7a3a6
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/65b7a3a6
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/65b7a3a6

Branch: refs/heads/2971-count-distinct
Commit: 65b7a3a64ae087901d2d2fbe785233b04f135b4b
Parents: 6ec3597
Author: Robert Newson <rn...@apache.org>
Authored: Sun Apr 17 19:21:20 2016 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Sun Apr 17 19:21:20 2016 +0100

----------------------------------------------------------------------
 src/couch_mrview_http.erl | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/65b7a3a6/src/couch_mrview_http.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_http.erl b/src/couch_mrview_http.erl
index 9eb306b..1f08961 100644
--- a/src/couch_mrview_http.erl
+++ b/src/couch_mrview_http.erl
@@ -349,7 +349,10 @@ view_cb({meta, Meta}, #vacc{}=Acc) ->
         Offset -> [io_lib:format("\"offset\":~p", [Offset])]
     end ++ case couch_util:get_value(update_seq, Meta) of
         undefined -> [];
-        UpdateSeq -> [io_lib:format("\"update_seq\":~p", [UpdateSeq])]
+        UpdateSeq when is_integer(UpdateSeq) ->
+            [io_lib:format("\"update_seq\":~B", [UpdateSeq])];
+        UpdateSeq when is_binary(UpdateSeq) ->
+            [io_lib:format("\"update_seq\":\"~s\"", [UpdateSeq])]
     end ++ ["\"rows\":["],
     Chunk = [prepend_val(Acc), "{", string:join(Parts, ","), "\r\n"],
     {ok, AccOut} = maybe_flush_response(Acc, Chunk, iolist_size(Chunk)),


[15/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Fix sorted=false feature

1. Enable the sorted=false parameter to map views
2. Enhance view_cb to tolerate rows before meta
3. Enhance view_cb to only send meta if no row has been sent

COUCHDB-3060


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/3ce28641
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/3ce28641
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/3ce28641

Branch: refs/heads/2971-count-distinct
Commit: 3ce28641c85af0d5054df47e9ac7de917a9d33cd
Parents: cfc3549
Author: Robert Newson <rn...@apache.org>
Authored: Fri Jul 15 11:53:16 2016 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Fri Jul 15 17:47:21 2016 +0100

----------------------------------------------------------------------
 include/couch_mrview.hrl  |  3 ++-
 src/couch_mrview_http.erl | 12 +++++++++++-
 src/couch_mrview_util.erl |  5 +++++
 3 files changed, 18 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/3ce28641/include/couch_mrview.hrl
----------------------------------------------------------------------
diff --git a/include/couch_mrview.hrl b/include/couch_mrview.hrl
index 7dc7190..2dfd398 100644
--- a/include/couch_mrview.hrl
+++ b/include/couch_mrview.hrl
@@ -98,7 +98,8 @@
     should_close = false,
     buffer = [],
     bufsize = 0,
-    threshold = 1490
+    threshold = 1490,
+    row_sent = false
 }).
 
 -record(lacc, {

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/3ce28641/src/couch_mrview_http.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_http.erl b/src/couch_mrview_http.erl
index 191198c..3a9aa33 100644
--- a/src/couch_mrview_http.erl
+++ b/src/couch_mrview_http.erl
@@ -340,6 +340,9 @@ view_cb({meta, Meta}, #vacc{resp=undefined}=Acc) ->
     Headers = [],
     {ok, Resp} = chttpd:start_delayed_json_response(Acc#vacc.req, 200, Headers),
     view_cb({meta, Meta}, Acc#vacc{resp=Resp, should_close=true});
+view_cb({meta, _Meta}, #vacc{row_sent=true}=Acc) ->
+    % sorted=false and meta arrived late, ignore it.
+    {ok, Acc};
 view_cb({meta, Meta}, #vacc{}=Acc) ->
     % Sending metadata
     Parts = case couch_util:get_value(total, Meta) of
@@ -358,10 +361,15 @@ view_cb({meta, Meta}, #vacc{}=Acc) ->
     Chunk = [prepend_val(Acc), "{", string:join(Parts, ","), "\r\n"],
     {ok, AccOut} = maybe_flush_response(Acc, Chunk, iolist_size(Chunk)),
     {ok, AccOut#vacc{prepend=""}};
+view_cb({row, Row}, #vacc{resp=undefined}=Acc) ->
+    % sorted=false and a row arrived before meta, start response.
+    Pre = "{\"rows\":[\r\n",
+    {ok, Resp} = chttpd:start_delayed_json_response(Acc#vacc.req, 200, []),
+    view_cb({row, Row}, Acc#vacc{row_sent=true,resp=Resp, prepend=Pre, should_close=true});
 view_cb({row, Row}, Acc) ->
     % Adding another row
     Chunk = [prepend_val(Acc), row_to_json(Row)],
-    maybe_flush_response(Acc, Chunk, iolist_size(Chunk));
+    maybe_flush_response(Acc#vacc{row_sent=true}, Chunk, iolist_size(Chunk));
 view_cb(complete, #vacc{resp=undefined}=Acc) ->
     % Nothing in view
     {ok, Resp} = chttpd:send_json(Acc#vacc.req, 200, {[{rows, []}]}),
@@ -538,6 +546,8 @@ parse_param(Key, Val, Args, IsDecoded) ->
             Args#mrargs{conflicts=parse_boolean(Val)};
         "callback" ->
             Args#mrargs{callback=couch_util:to_binary(Val)};
+        "sorted" ->
+            Args#mrargs{sorted=parse_boolean(Val)};
         _ ->
             BKey = couch_util:to_binary(Key),
             BVal = couch_util:to_binary(Val),

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/3ce28641/src/couch_mrview_util.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_util.erl b/src/couch_mrview_util.erl
index 51e51d8..934dcd3 100644
--- a/src/couch_mrview_util.erl
+++ b/src/couch_mrview_util.erl
@@ -510,6 +510,11 @@ validate_args(Args) ->
         {_, EKDocId1} -> EKDocId1
     end,
 
+    case is_boolean(Args#mrargs.sorted) of
+        true -> ok;
+        _ -> mrverror(<<"Invalid value for `sorted`.">>)
+    end,
+
     Args#mrargs{
         start_key_docid=SKDocId,
         end_key_docid=EKDocId,


[42/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Merge remote branch 'cloudant:refactor-mrview-index-get'

This closes #65

Signed-off-by: Eric Avdey <ei...@eiri.ca>


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

Branch: refs/heads/2971-count-distinct
Commit: e1d13a983a0ba56fcb1eb31c4e4fe56bc3692719
Parents: 15a1ae9 8b1c137
Author: Eric Avdey <ei...@eiri.ca>
Authored: Thu Feb 9 09:57:22 2017 -0400
Committer: Eric Avdey <ei...@eiri.ca>
Committed: Thu Feb 9 09:57:22 2017 -0400

----------------------------------------------------------------------
 src/couch_mrview_index.erl | 149 +++++++++++++++++++---------------------
 1 file changed, 71 insertions(+), 78 deletions(-)
----------------------------------------------------------------------



[24/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
don't send undefined etag (COUCHDB-3134)


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

Branch: refs/heads/2971-count-distinct
Commit: a0b0392afe66ece9ef3bb4fdd5a4f159c97c47eb
Parents: ed52b77
Author: Robert Newson <rn...@apache.org>
Authored: Wed Sep 7 14:04:23 2016 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Wed Sep 7 14:04:23 2016 +0100

----------------------------------------------------------------------
 src/couch_mrview_show.erl | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/a0b0392a/src/couch_mrview_show.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_show.erl b/src/couch_mrview_show.erl
index 0e5217c..52e07a7 100644
--- a/src/couch_mrview_show.erl
+++ b/src/couch_mrview_show.erl
@@ -317,6 +317,8 @@ send_non_empty_chunk(#lacc{resp=Resp} = Acc, Chunk) ->
     Acc.
 
 
+apply_etag(JsonResp, undefined) ->
+    JsonResp;
 apply_etag({ExternalResponse}, CurrentEtag) ->
     % Here we embark on the delicate task of replacing or creating the
     % headers on the JsonResponse object. We need to control the Etag and


[12/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Merge remote branch 'cloudant:make-decode-in-parse_params-optional'

This closes #48

Signed-off-by: Eric Avdey <ei...@eiri.ca>


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/8567b433
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/8567b433
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/8567b433

Branch: refs/heads/2971-count-distinct
Commit: 8567b43377f7a5999a2dd18a2a46e7963e43bea8
Parents: d07771a 26f5af7
Author: Eric Avdey <ei...@eiri.ca>
Authored: Mon Jun 13 15:49:28 2016 -0300
Committer: Eric Avdey <ei...@eiri.ca>
Committed: Mon Jun 13 15:49:28 2016 -0300

----------------------------------------------------------------------
 src/couch_mrview_http.erl | 45 ++++++++++++++++++++++++++----------------
 1 file changed, 28 insertions(+), 17 deletions(-)
----------------------------------------------------------------------



[19/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Reset row_sent at end of query

We need to reset row_sent to false at the end of the query so that we
will emit '{"rows":{' for the next query (if we're in a multi-query
request).

COUCHDB-3060


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

Branch: refs/heads/2971-count-distinct
Commit: e9e84c5d55ec5ef9b83dba0800bc27c23b4b35f6
Parents: 82f7913
Author: Robert Newson <rn...@apache.org>
Authored: Thu Aug 25 13:08:21 2016 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Aug 25 13:08:58 2016 +0100

----------------------------------------------------------------------
 src/couch_mrview_http.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/e9e84c5d/src/couch_mrview_http.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_http.erl b/src/couch_mrview_http.erl
index 341495e..529d208 100644
--- a/src/couch_mrview_http.erl
+++ b/src/couch_mrview_http.erl
@@ -382,7 +382,7 @@ view_cb(complete, #vacc{resp=Resp, buffer=Buf, threshold=Max}=Acc) ->
             {ok, Resp2} = chttpd:end_delayed_json_response(Resp1),
             {ok, Acc#vacc{resp=Resp2}};
         _ ->
-            {ok, Acc#vacc{resp=Resp1,
+            {ok, Acc#vacc{resp=Resp1, row_sent=false,
                 prepend=",\r\n", buffer=[], bufsize=0}}
     end;
 view_cb({error, Reason}, #vacc{resp=undefined}=Acc) ->


[22/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Fix sorted=false for multi-query

I've reordered view_cb for readability, moving all response starting
logic to the front, in order to simplify how meta and row messages are
handled

COUCHDB-3060


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/9133f6d1
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/9133f6d1
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/9133f6d1

Branch: refs/heads/2971-count-distinct
Commit: 9133f6d1612374e73f18f13244a32ce8678aab67
Parents: e936267
Author: Robert Newson <rn...@apache.org>
Authored: Thu Aug 25 17:58:34 2016 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Aug 25 18:27:19 2016 +0100

----------------------------------------------------------------------
 include/couch_mrview.hrl  |  3 +-
 src/couch_mrview_http.erl | 94 +++++++++++++++++++++++-------------------
 2 files changed, 54 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/9133f6d1/include/couch_mrview.hrl
----------------------------------------------------------------------
diff --git a/include/couch_mrview.hrl b/include/couch_mrview.hrl
index 2dfd398..bfd20ad 100644
--- a/include/couch_mrview.hrl
+++ b/include/couch_mrview.hrl
@@ -99,7 +99,8 @@
     buffer = [],
     bufsize = 0,
     threshold = 1490,
-    row_sent = false
+    row_sent = false,
+    meta_sent = false
 }).
 
 -record(lacc, {

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/9133f6d1/src/couch_mrview_http.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_http.erl b/src/couch_mrview_http.erl
index aa39912..b554e36 100644
--- a/src/couch_mrview_http.erl
+++ b/src/couch_mrview_http.erl
@@ -309,7 +309,7 @@ multi_query_view(Req, Db, DDoc, ViewName, Queries) ->
         VAcc1 = VAcc0#vacc{resp=Resp0},
         VAcc2 = lists:foldl(fun(Args, Acc0) ->
             {ok, Acc1} = couch_mrview:query_view(Db, DDoc, ViewName, Args, fun view_cb/2, Acc0),
-            reset_vacc(Acc1)
+            Acc1
         end, VAcc1, ArgQueries),
         {ok, Resp1} = chttpd:send_delayed_chunk(VAcc2#vacc.resp, "\r\n]}"),
         {ok, Resp2} = chttpd:end_delayed_json_response(Resp1),
@@ -320,11 +320,6 @@ multi_query_view(Req, Db, DDoc, ViewName, Queries) ->
         _ -> {ok, Resp2}
     end.
 
-%% reset between queries in multi-query
-reset_vacc(Vacc) ->
-    Vacc#vacc{row_sent=false}.
-
-
 filtered_view_cb({row, Row0}, Acc) ->
   Row1 = lists:map(fun({doc, null}) ->
         {doc, null};
@@ -339,16 +334,44 @@ filtered_view_cb(Obj, Acc) ->
     view_cb(Obj, Acc).
 
 
-view_cb({meta, Meta}, #vacc{resp=undefined}=Acc) ->
-    % Map function starting
+%% these clauses start (and possibly end) the response
+view_cb({error, Reason}, #vacc{resp=undefined}=Acc) ->
+    {ok, Resp} = chttpd:send_error(Acc#vacc.req, Reason),
+    {ok, Acc#vacc{resp=Resp}};
+
+view_cb(complete, #vacc{resp=undefined}=Acc) ->
+    % Nothing in view
+    {ok, Resp} = chttpd:send_json(Acc#vacc.req, 200, {[{rows, []}]}),
+    {ok, Acc#vacc{resp=Resp}};
+
+view_cb(Msg, #vacc{resp=undefined}=Acc) ->
+    %% Start response
     Headers = [],
     {ok, Resp} = chttpd:start_delayed_json_response(Acc#vacc.req, 200, Headers),
-    view_cb({meta, Meta}, Acc#vacc{resp=Resp, should_close=true});
-view_cb({meta, _Meta}, #vacc{row_sent=true}=Acc) ->
-    % sorted=false and meta arrived late, ignore it.
-    {ok, Acc};
-view_cb({meta, Meta}, #vacc{}=Acc) ->
-    % Sending metadata
+    view_cb(Msg, Acc#vacc{resp=Resp, should_close=true});
+
+%% ---------------------------------------------------
+
+%% From here on down, the response has been started.
+
+view_cb({error, Reason}, #vacc{resp=Resp}=Acc) ->
+    {ok, Resp1} = chttpd:send_delayed_error(Resp, Reason),
+    {ok, Acc#vacc{resp=Resp1}};
+
+view_cb(complete, #vacc{resp=Resp, buffer=Buf, threshold=Max}=Acc) ->
+    % Finish view output and possibly end the response
+    {ok, Resp1} = chttpd:close_delayed_json_object(Resp, Buf, "\r\n]}", Max),
+    case Acc#vacc.should_close of
+        true ->
+            {ok, Resp2} = chttpd:end_delayed_json_response(Resp1),
+            {ok, Acc#vacc{resp=Resp2}};
+        _ ->
+            {ok, Acc#vacc{resp=Resp1, meta_sent=false, row_sent=false,
+                prepend=",\r\n", buffer=[], bufsize=0}}
+    end;
+
+view_cb({meta, Meta}, #vacc{meta_sent=false, row_sent=false}=Acc) ->
+    % Sending metadata as we've not sent it or any row yet
     Parts = case couch_util:get_value(total, Meta) of
         undefined -> [];
         Total -> [io_lib:format("\"total_rows\":~p", [Total])]
@@ -364,36 +387,23 @@ view_cb({meta, Meta}, #vacc{}=Acc) ->
     end ++ ["\"rows\":["],
     Chunk = [prepend_val(Acc), "{", string:join(Parts, ","), "\r\n"],
     {ok, AccOut} = maybe_flush_response(Acc, Chunk, iolist_size(Chunk)),
-    {ok, AccOut#vacc{prepend=""}};
-view_cb({row, Row}, #vacc{resp=undefined}=Acc) ->
-    % sorted=false and a row arrived before meta, start response.
-    Pre = "{\"rows\":[\r\n",
-    {ok, Resp} = chttpd:start_delayed_json_response(Acc#vacc.req, 200, []),
-    view_cb({row, Row}, Acc#vacc{row_sent=true,resp=Resp, prepend=Pre, should_close=true});
-view_cb({row, Row}, Acc) ->
+    {ok, AccOut#vacc{prepend="", meta_sent=true}};
+
+view_cb({meta, _Meta}, #vacc{}=Acc) ->
+    %% ignore metadata
+    {ok, Acc};
+
+view_cb({row, Row}, #vacc{meta_sent=false}=Acc) ->
+    %% sorted=false and row arrived before meta
+    % Adding another row
+    Chunk = [prepend_val(Acc), "{\"rows\":[\r\n", row_to_json(Row)],
+    maybe_flush_response(Acc#vacc{meta_sent=true, row_sent=true}, Chunk, iolist_size(Chunk));
+
+view_cb({row, Row}, #vacc{meta_sent=true}=Acc) ->
     % Adding another row
     Chunk = [prepend_val(Acc), row_to_json(Row)],
-    maybe_flush_response(Acc#vacc{row_sent=true}, Chunk, iolist_size(Chunk));
-view_cb(complete, #vacc{resp=undefined}=Acc) ->
-    % Nothing in view
-    {ok, Resp} = chttpd:send_json(Acc#vacc.req, 200, {[{rows, []}]}),
-    {ok, Acc#vacc{resp=Resp}};
-view_cb(complete, #vacc{resp=Resp, buffer=Buf, threshold=Max}=Acc) ->
-    % Finish view output and possibly end the response
-    {ok, Resp1} = chttpd:close_delayed_json_object(Resp, Buf, "\r\n]}", Max),
-    case Acc#vacc.should_close of
-        true ->
-            {ok, Resp2} = chttpd:end_delayed_json_response(Resp1),
-            {ok, Acc#vacc{resp=Resp2}};
-        _ ->
-            {ok, Acc#vacc{resp=Resp1, prepend=",\r\n", buffer=[], bufsize=0}}
-    end;
-view_cb({error, Reason}, #vacc{resp=undefined}=Acc) ->
-    {ok, Resp} = chttpd:send_error(Acc#vacc.req, Reason),
-    {ok, Acc#vacc{resp=Resp}};
-view_cb({error, Reason}, #vacc{resp=Resp}=Acc) ->
-    {ok, Resp1} = chttpd:send_delayed_error(Resp, Reason),
-    {ok, Acc#vacc{resp=Resp1}}.
+    maybe_flush_response(Acc#vacc{row_sent=true}, Chunk, iolist_size(Chunk)).
+
 
 maybe_flush_response(#vacc{bufsize=Size, threshold=Max} = Acc, Data, Len)
         when Size > 0 andalso (Size + Len) > Max ->


[20/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Introduce reset_vacc

COUCHDB-3060


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/0db83c4c
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/0db83c4c
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/0db83c4c

Branch: refs/heads/2971-count-distinct
Commit: 0db83c4c8ce9819c00975f0a024e246bf4e3bd6f
Parents: e9e84c5
Author: Robert Newson <rn...@apache.org>
Authored: Thu Aug 25 16:01:25 2016 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Aug 25 16:01:26 2016 +0100

----------------------------------------------------------------------
 src/couch_mrview_http.erl | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/0db83c4c/src/couch_mrview_http.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_http.erl b/src/couch_mrview_http.erl
index 529d208..253ee30 100644
--- a/src/couch_mrview_http.erl
+++ b/src/couch_mrview_http.erl
@@ -309,7 +309,7 @@ multi_query_view(Req, Db, DDoc, ViewName, Queries) ->
         VAcc1 = VAcc0#vacc{resp=Resp0},
         VAcc2 = lists:foldl(fun(Args, Acc0) ->
             {ok, Acc1} = couch_mrview:query_view(Db, DDoc, ViewName, Args, fun view_cb/2, Acc0),
-            Acc1
+            reset_vacc(Acc1)
         end, VAcc1, ArgQueries),
         {ok, Resp1} = chttpd:send_delayed_chunk(VAcc2#vacc.resp, "\r\n]}"),
         {ok, Resp2} = chttpd:end_delayed_json_response(Resp1),
@@ -320,6 +320,10 @@ multi_query_view(Req, Db, DDoc, ViewName, Queries) ->
         _ -> {ok, Resp2}
     end.
 
+%% reset between queries in multi-query
+reset_vacc(Vacc) ->
+    Vacc#vacc{row_sent=false}.
+
 
 filtered_view_cb({row, Row0}, Acc) ->
   Row1 = lists:map(fun({doc, null}) ->


[39/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Merge remote branch 'cloudant:77867-convert-pid-to-binary'

This closes #63

Signed-off-by: ILYA Khlopotov <ii...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/15a1ae92
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/15a1ae92
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/15a1ae92

Branch: refs/heads/2971-count-distinct
Commit: 15a1ae928850854a218cc05569cdcc302126748f
Parents: 5899436 c49211c
Author: ILYA Khlopotov <ii...@apache.org>
Authored: Fri Dec 2 07:52:16 2016 -0800
Committer: ILYA Khlopotov <ii...@apache.org>
Committed: Fri Dec 2 07:52:16 2016 -0800

----------------------------------------------------------------------
 src/couch_mrview_updater.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------



[09/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
gen_event: handle_call suppose to return `{ok, Reply, State}`


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/1a179cbc
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/1a179cbc
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/1a179cbc

Branch: refs/heads/2971-count-distinct
Commit: 1a179cbca8a6654bde61826cbfc69f7eb0a23a0d
Parents: 9bafdca
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue May 24 18:34:25 2016 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue May 24 18:34:25 2016 -0700

----------------------------------------------------------------------
 src/couch_mrview_update_notifier.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/1a179cbc/src/couch_mrview_update_notifier.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_update_notifier.erl b/src/couch_mrview_update_notifier.erl
index 7c7ff1b..803d397 100644
--- a/src/couch_mrview_update_notifier.erl
+++ b/src/couch_mrview_update_notifier.erl
@@ -39,7 +39,7 @@ handle_event(Event, Fun) ->
     {ok, Fun}.
 
 handle_call(_Request, State) ->
-    {reply, ok, State}.
+    {ok, ok, State}.
 
 handle_info({'EXIT', Pid, Reason}, Pid) ->
     couch_log:error("View update notification process ~p died: ~p", [Pid, Reason]),


[31/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Merge remote-tracking branch 'cloudant/3184-retry-recompact-failure'


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/853c6080
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/853c6080
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/853c6080

Branch: refs/heads/2971-count-distinct
Commit: 853c608054fd8efe5e44a699714028ca7f76c2ef
Parents: d450960 3421463
Author: Paul J. Davis <pa...@gmail.com>
Authored: Thu Oct 20 11:45:35 2016 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Thu Oct 20 11:45:35 2016 -0500

----------------------------------------------------------------------
 src/couch_mrview_compactor.erl | 66 +++++++++++++++++++++++++++++++++++--
 1 file changed, 64 insertions(+), 2 deletions(-)
----------------------------------------------------------------------



[25/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Add new function to get the view index pid.
Refactored the code to add a new function to return index pid for a
given view and design document.

COUCHDB-3150


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

Branch: refs/heads/2971-count-distinct
Commit: fdaebcf0fd26ed1d402ac6ec6448a8a2b7fbc808
Parents: a0b0392
Author: brkolla <bk...@cloudant.com>
Authored: Wed Sep 21 14:52:57 2016 -0400
Committer: brkolla <bk...@cloudant.com>
Committed: Fri Sep 23 11:29:56 2016 -0400

----------------------------------------------------------------------
 src/couch_mrview.erl      |  6 +++++-
 src/couch_mrview_util.erl | 16 ++++++++++------
 2 files changed, 15 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/fdaebcf0/src/couch_mrview.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview.erl b/src/couch_mrview.erl
index 20eb4be..088327c 100644
--- a/src/couch_mrview.erl
+++ b/src/couch_mrview.erl
@@ -14,7 +14,7 @@
 
 -export([validate/2]).
 -export([query_all_docs/2, query_all_docs/4]).
--export([query_view/3, query_view/4, query_view/6]).
+-export([query_view/3, query_view/4, query_view/6, get_view_index_pid/4]).
 -export([view_changes_since/5]).
 -export([view_changes_since/6, view_changes_since/7]).
 -export([count_view_changes_since/4, count_view_changes_since/5]).
@@ -249,6 +249,10 @@ query_view(Db, DDoc, VName, Args0, Callback, Acc0) ->
     query_view(Db, VInfo, Args, Callback, Acc1).
 
 
+get_view_index_pid(Db, DDoc, ViewName, Args0) ->
+    couch_mrview_util:get_view_index_pid(Db, DDoc, ViewName, Args0).
+
+
 query_view(Db, {Type, View, Ref}, Args, Callback, Acc) ->
     try
         case Type of

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/fdaebcf0/src/couch_mrview_util.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_util.erl b/src/couch_mrview_util.erl
index 934dcd3..fa81ac9 100644
--- a/src/couch_mrview_util.erl
+++ b/src/couch_mrview_util.erl
@@ -12,7 +12,7 @@
 
 -module(couch_mrview_util).
 
--export([get_view/4]).
+-export([get_view/4, get_view_index_pid/4]).
 -export([ddoc_to_mrst/2, init_state/4, reset_index/3]).
 -export([make_header/1]).
 -export([index_file/2, compaction_file/2, open_file/1]).
@@ -40,11 +40,7 @@
 
 
 get_view(Db, DDoc, ViewName, Args0) ->
-    ArgCheck = fun(InitState) ->
-        Args1 = set_view_type(Args0, ViewName, InitState#mrst.views),
-        {ok, validate_args(Args1)}
-    end,
-    {ok, Pid, Args2} = couch_index_server:get_index(?MOD, Db, DDoc, ArgCheck),
+    {ok, Pid, Args2} = get_view_index_pid(Db, DDoc, ViewName, Args0),
     DbUpdateSeq = couch_util:with_db(Db, fun(WDb) ->
         couch_db:get_update_seq(WDb)
     end),
@@ -67,6 +63,14 @@ get_view(Db, DDoc, ViewName, Args0) ->
     {ok, {Type, View, Ref}, Sig, Args3}.
 
 
+get_view_index_pid(Db, DDoc, ViewName, Args0) ->
+    ArgCheck = fun(InitState) ->
+        Args1 = set_view_type(Args0, ViewName, InitState#mrst.views),
+        {ok, validate_args(Args1)}
+    end,
+    couch_index_server:get_index(?MOD, Db, DDoc, ArgCheck).
+
+
 ddoc_to_mrst(DbName, #doc{id=Id, body={Fields}}) ->
     MakeDict = fun({Name, {MRFuns}}, DictBySrcAcc) ->
         case couch_util:get_value(<<"map">>, MRFuns) of


[03/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Merge remote branch 'cloudant:3002-use-ioq-for-view_updades'

This closes #43

Signed-off-by: ILYA Khlopotov <ii...@ca.ibm.com>


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

Branch: refs/heads/2971-count-distinct
Commit: 37351726a03aaa224ba08f475bfb7c403f94d5ee
Parents: 65b7a3a abc94a4
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Mon Apr 25 09:25:56 2016 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Mon Apr 25 09:25:56 2016 -0700

----------------------------------------------------------------------
 src/couch_mrview_updater.erl | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------



[41/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Re-use get update_options in get(info)


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/8b1c137e
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/8b1c137e
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/8b1c137e

Branch: refs/heads/2971-count-distinct
Commit: 8b1c137ea4decca2ac4f3717b71f369fbdb5d7b5
Parents: f7f4db2
Author: Eric Avdey <ei...@eiri.ca>
Authored: Wed Feb 8 14:05:37 2017 -0400
Committer: Eric Avdey <ei...@eiri.ca>
Committed: Wed Feb 8 14:05:37 2017 -0400

----------------------------------------------------------------------
 src/couch_mrview_index.erl | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/8b1c137e/src/couch_mrview_index.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_index.erl b/src/couch_mrview_index.erl
index 47245bd..a65bc94 100644
--- a/src/couch_mrview_index.erl
+++ b/src/couch_mrview_index.erl
@@ -74,12 +74,9 @@ get(info, State) ->
     LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false),
     SeqIndexed = couch_util:get_value(<<"seq_indexed">>, Opts, false),
     KeySeqIndexed = couch_util:get_value(<<"keyseq_indexed">>, Opts, false),
-    UpdateOptions =
-        if IncDesign -> [<<"include_design">>]; true -> [] end
-        ++ if LocalSeq -> [<<"local_seq">>]; true -> [] end
-        ++ if KeySeqIndexed -> [<<"keyseq_indexed">>]; true -> [] end
-        ++ if SeqIndexed -> [<<"seq_indexed">>]; true -> [] end,
 
+    UpdateOptions0 = get(update_options, State),
+    UpdateOptions = [atom_to_binary(O, latin1) || O <- UpdateOptions0],
 
     {ok, [
         {signature, list_to_binary(couch_index_util:hexsig(Sig))},


[14/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Merge remote branch 'cloudant:2847-list_when_no_rows'

This closes #49

Signed-off-by: ILYA Khlopotov <ii...@ca.ibm.com>


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

Branch: refs/heads/2971-count-distinct
Commit: cfc354989a28865ec83efc0f745e91b8c6a3a6c3
Parents: 8567b43 f9a58d8
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Mon Jun 20 09:22:06 2016 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Mon Jun 20 09:22:06 2016 -0700

----------------------------------------------------------------------
 src/couch_mrview_show.erl | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
----------------------------------------------------------------------



[40/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Refactor mrview_index get

This is a simple refactoring of mrview's
get function that uses function's pattern
matching instead of staircase case.

Arguably this makes code easier to read
and more idiomatic.


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

Branch: refs/heads/2971-count-distinct
Commit: f7f4db2660f3196916ccbdb9dc25cfc5d709a19f
Parents: 15a1ae9
Author: Eric Avdey <ei...@eiri.ca>
Authored: Tue Feb 7 10:39:46 2017 -0400
Committer: Eric Avdey <ei...@eiri.ca>
Committed: Wed Feb 8 12:31:18 2017 -0400

----------------------------------------------------------------------
 src/couch_mrview_index.erl | 152 +++++++++++++++++++---------------------
 1 file changed, 74 insertions(+), 78 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/f7f4db26/src/couch_mrview_index.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_index.erl b/src/couch_mrview_index.erl
index 95698bc..47245bd 100644
--- a/src/couch_mrview_index.erl
+++ b/src/couch_mrview_index.erl
@@ -23,84 +23,80 @@
 -include_lib("couch_mrview/include/couch_mrview.hrl").
 
 
-get(Property, State) ->
-    case Property of
-        db_name ->
-            State#mrst.db_name;
-        idx_name ->
-            State#mrst.idx_name;
-        signature ->
-            State#mrst.sig;
-        update_seq ->
-            State#mrst.update_seq;
-        purge_seq ->
-            State#mrst.purge_seq;
-        update_options ->
-            Opts = State#mrst.design_opts,
-            IncDesign = couch_util:get_value(<<"include_design">>, Opts, false),
-            LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false),
-            SeqIndexed = couch_util:get_value(<<"seq_indexed">>, Opts, false),
-            KeySeqIndexed = couch_util:get_value(<<"keyseq_indexed">>, Opts, false),
-            if IncDesign -> [include_design]; true -> [] end
-                ++ if LocalSeq -> [local_seq]; true -> [] end
-                ++ if KeySeqIndexed -> [keyseq_indexed]; true -> [] end
-                ++ if SeqIndexed -> [seq_indexed]; true -> [] end;
-        fd ->
-            State#mrst.fd;
-        language ->
-            State#mrst.language;
-        views ->
-            State#mrst.views;
-        info ->
-            #mrst{
-                fd = Fd,
-                sig = Sig,
-                id_btree = IdBtree,
-                log_btree = LogBtree,
-                language = Lang,
-                update_seq = UpdateSeq,
-                purge_seq = PurgeSeq,
-                views = Views,
-                design_opts = Opts
-            } = State,
-            {ok, FileSize} = couch_file:bytes(Fd),
-            {ok, ExternalSize} = couch_mrview_util:calculate_external_size(Views),
-            LogBtSize = case LogBtree of
-                nil ->
-                    0;
-                _ ->
-                    couch_btree:size(LogBtree)
-            end,
-            ActiveSize = couch_btree:size(IdBtree) + LogBtSize + ExternalSize,
-
-            IncDesign = couch_util:get_value(<<"include_design">>, Opts, false),
-            LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false),
-            SeqIndexed = couch_util:get_value(<<"seq_indexed">>, Opts, false),
-            KeySeqIndexed = couch_util:get_value(<<"keyseq_indexed">>, Opts, false),
-            UpdateOptions =
-                if IncDesign -> [<<"include_design">>]; true -> [] end
-                ++ if LocalSeq -> [<<"local_seq">>]; true -> [] end
-                ++ if KeySeqIndexed -> [<<"keyseq_indexed">>]; true -> [] end
-                ++ if SeqIndexed -> [<<"seq_indexed">>]; true -> [] end,
-
-
-            {ok, [
-                {signature, list_to_binary(couch_index_util:hexsig(Sig))},
-                {language, Lang},
-                {disk_size, FileSize}, % legacy
-                {data_size, ExternalSize}, % legacy
-                {sizes, {[
-                    {file, FileSize},
-                    {active, ActiveSize},
-                    {external, ExternalSize}
-                ]}},
-                {update_seq, UpdateSeq},
-                {purge_seq, PurgeSeq},
-                {update_options, UpdateOptions}
-            ]};
-        Other ->
-            throw({unknown_index_property, Other})
-    end.
+get(db_name, #mrst{db_name = DbName}) ->
+    DbName;
+get(idx_name, #mrst{idx_name = IdxName}) ->
+    IdxName;
+get(signature, #mrst{sig = Signature}) ->
+    Signature;
+get(update_seq, #mrst{update_seq = UpdateSeq}) ->
+    UpdateSeq;
+get(purge_seq, #mrst{purge_seq = PurgeSeq}) ->
+    PurgeSeq;
+get(update_options, #mrst{design_opts = Opts}) ->
+    IncDesign = couch_util:get_value(<<"include_design">>, Opts, false),
+    LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false),
+    SeqIndexed = couch_util:get_value(<<"seq_indexed">>, Opts, false),
+    KeySeqIndexed = couch_util:get_value(<<"keyseq_indexed">>, Opts, false),
+    if IncDesign -> [include_design]; true -> [] end
+        ++ if LocalSeq -> [local_seq]; true -> [] end
+        ++ if KeySeqIndexed -> [keyseq_indexed]; true -> [] end
+        ++ if SeqIndexed -> [seq_indexed]; true -> [] end;
+get(fd, #mrst{fd = Fd}) ->
+    Fd;
+get(language, #mrst{language = Language}) ->
+    Language;
+get(views, #mrst{views = Views}) ->
+    Views;
+get(info, State) ->
+    #mrst{
+        fd = Fd,
+        sig = Sig,
+        id_btree = IdBtree,
+        log_btree = LogBtree,
+        language = Lang,
+        update_seq = UpdateSeq,
+        purge_seq = PurgeSeq,
+        views = Views,
+        design_opts = Opts
+    } = State,
+    {ok, FileSize} = couch_file:bytes(Fd),
+    {ok, ExternalSize} = couch_mrview_util:calculate_external_size(Views),
+    LogBtSize = case LogBtree of
+        nil ->
+            0;
+        _ ->
+            couch_btree:size(LogBtree)
+    end,
+    ActiveSize = couch_btree:size(IdBtree) + LogBtSize + ExternalSize,
+
+    IncDesign = couch_util:get_value(<<"include_design">>, Opts, false),
+    LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false),
+    SeqIndexed = couch_util:get_value(<<"seq_indexed">>, Opts, false),
+    KeySeqIndexed = couch_util:get_value(<<"keyseq_indexed">>, Opts, false),
+    UpdateOptions =
+        if IncDesign -> [<<"include_design">>]; true -> [] end
+        ++ if LocalSeq -> [<<"local_seq">>]; true -> [] end
+        ++ if KeySeqIndexed -> [<<"keyseq_indexed">>]; true -> [] end
+        ++ if SeqIndexed -> [<<"seq_indexed">>]; true -> [] end,
+
+
+    {ok, [
+        {signature, list_to_binary(couch_index_util:hexsig(Sig))},
+        {language, Lang},
+        {disk_size, FileSize}, % legacy
+        {data_size, ExternalSize}, % legacy
+        {sizes, {[
+            {file, FileSize},
+            {active, ActiveSize},
+            {external, ExternalSize}
+        ]}},
+        {update_seq, UpdateSeq},
+        {purge_seq, PurgeSeq},
+        {update_options, UpdateOptions}
+    ]};
+get(Other, _) ->
+    throw({unknown_index_property, Other}).
 
 
 init(Db, DDoc) ->


[28/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Retry failures in couch_mrview_compactor:recompact

Currently, if there's an error in the spawned couch_index_updater:update
process, the receive block will not match the message, and the calling
process will block forever.

This commit changes the receive pattern to match both successful updates
as well as errors, logging the errors, and retrying the recompact a
configurable number of times. If the configured retry count is exceeded,
it logs an error, and returns the original state.

COUCHDB-3184


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/1d5c6a5d
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/1d5c6a5d
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/1d5c6a5d

Branch: refs/heads/2971-count-distinct
Commit: 1d5c6a5d92977308fd94b2b8f43463b9f2bdac71
Parents: d450960
Author: Jay Doane <ja...@gmail.com>
Authored: Fri Oct 7 13:04:13 2016 -0700
Committer: Jay Doane <ja...@gmail.com>
Committed: Fri Oct 7 13:04:13 2016 -0700

----------------------------------------------------------------------
 src/couch_mrview_compactor.erl | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/1d5c6a5d/src/couch_mrview_compactor.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_compactor.erl b/src/couch_mrview_compactor.erl
index 9dba094..d5ea763 100644
--- a/src/couch_mrview_compactor.erl
+++ b/src/couch_mrview_compactor.erl
@@ -26,6 +26,7 @@
    total_changes
 }).
 
+-define(DEFAULT_RECOMPACT_RETRY_COUNT, 3).
 
 compact(_Db, State, Opts) ->
     case lists:member(recompact, Opts) of
@@ -148,14 +149,30 @@ compact(State) ->
 
 
 recompact(State) ->
+    RetryCount = config:get_integer("view_compaction", "recompact_retry_count",
+        ?DEFAULT_RECOMPACT_RETRY_COUNT),
+    recompact(State, RetryCount).
+
+recompact(State, 0) ->
+    couch_log:error("couch_mrview_compactor:recompact max retries exceeded ~p",
+        [State]),
+    {ok, State};
+recompact(State, Attempt) ->
     link(State#mrst.fd),
     {Pid, Ref} = erlang:spawn_monitor(fun() ->
         couch_index_updater:update(couch_mrview_index, State)
     end),
     receive
-        {'DOWN', Ref, _, _, {updated, Pid, State2}} ->
+        {'DOWN', Ref, _, _, Result} ->
             unlink(State#mrst.fd),
-            {ok, State2}
+            case Result of
+                {updated, Pid, State2} ->
+                    {ok, State2};
+                Error ->
+                    couch_log:info("couch_mrview_compactor:recompact error ~p",
+                        [Error]),
+                    recompact(State, Attempt - 1)
+            end
     end.
 
 compact_log(LogBtree, BufferSize, Acc0) ->


[34/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Add reference to indexer Pid to task status

When we run re-compaction stage we start second index updater from
view compactor. In this case couch_task_status:all would return two
identical entries for the same `design_document` and `shard`. Which is
very confusing. Add reference to indexer Pid to disambiguate them.
For the recompaction case the indexer_pid will be pointing to compaction task.


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

Branch: refs/heads/2971-count-distinct
Commit: b3b1b121f6a153f0e3febc95cfbace597e4a9aab
Parents: e875745
Author: ILYA Khlopotov <ii...@apache.org>
Authored: Fri Nov 18 14:19:11 2016 -0800
Committer: ILYA Khlopotov <ii...@apache.org>
Committed: Fri Nov 18 14:42:19 2016 -0800

----------------------------------------------------------------------
 src/couch_mrview_updater.erl | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/b3b1b121/src/couch_mrview_updater.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_updater.erl b/src/couch_mrview_updater.erl
index 8a85887..645f02b 100644
--- a/src/couch_mrview_updater.erl
+++ b/src/couch_mrview_updater.erl
@@ -38,6 +38,7 @@ start_update(Partial, State, NumChanges) ->
     Self = self(),
     MapFun = fun() ->
         couch_task_status:add_task([
+            {indexer_pid, Partial},
             {type, indexer},
             {database, State#mrst.db_name},
             {design_document, State#mrst.idx_name},


[21/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Revert "Reset row_sent at end of query"

This is now handled at a higher level.

COUCHDB-3060


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

Branch: refs/heads/2971-count-distinct
Commit: e936267dca63e78775c7c1ed3580f92a50e61b54
Parents: 0db83c4
Author: Robert Newson <rn...@apache.org>
Authored: Thu Aug 25 16:01:47 2016 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Aug 25 16:01:47 2016 +0100

----------------------------------------------------------------------
 src/couch_mrview_http.erl | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/e936267d/src/couch_mrview_http.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_http.erl b/src/couch_mrview_http.erl
index 253ee30..aa39912 100644
--- a/src/couch_mrview_http.erl
+++ b/src/couch_mrview_http.erl
@@ -386,8 +386,7 @@ view_cb(complete, #vacc{resp=Resp, buffer=Buf, threshold=Max}=Acc) ->
             {ok, Resp2} = chttpd:end_delayed_json_response(Resp1),
             {ok, Acc#vacc{resp=Resp2}};
         _ ->
-            {ok, Acc#vacc{resp=Resp1, row_sent=false,
-                prepend=",\r\n", buffer=[], bufsize=0}}
+            {ok, Acc#vacc{resp=Resp1, prepend=",\r\n", buffer=[], bufsize=0}}
     end;
 view_cb({error, Reason}, #vacc{resp=undefined}=Acc) ->
     {ok, Resp} = chttpd:send_error(Acc#vacc.req, Reason),


[30/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Implement recompact unit tests


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

Branch: refs/heads/2971-count-distinct
Commit: 342146305fbe7dbd35b655b6f704e6b60a3b679c
Parents: 0d382f5
Author: Jay Doane <ja...@gmail.com>
Authored: Sat Oct 15 19:28:35 2016 -0700
Committer: Jay Doane <ja...@gmail.com>
Committed: Sat Oct 15 19:28:35 2016 -0700

----------------------------------------------------------------------
 src/couch_mrview_compactor.erl | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/34214630/src/couch_mrview_compactor.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_compactor.erl b/src/couch_mrview_compactor.erl
index 50e7eae..e343ac8 100644
--- a/src/couch_mrview_compactor.erl
+++ b/src/couch_mrview_compactor.erl
@@ -291,3 +291,39 @@ swap_compacted(OldState, NewState) ->
     erlang:demonitor(OldState#mrst.fd_monitor, [flush]),
     
     {ok, NewState#mrst{fd_monitor=Ref}}.
+
+
+-ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
+
+recompact_test_() ->
+    [
+        recompact_success_after_progress(),
+        recompact_exceeded_retry_count()
+    ].
+
+recompact_success_after_progress() ->
+    ?_test(begin
+        ok = meck:expect(couch_index_updater, update, fun
+            (Pid, _, #mrst{update_seq=0} = State) ->
+                Pid ! {'$gen_cast', {new_state, State#mrst{update_seq=1}}};
+            (_, _, State) ->
+                exit({updated, self(), State})
+        end),
+        State = #mrst{fd=self(), update_seq=0},
+        ?assertEqual({ok, State#mrst{update_seq=1}}, recompact(State)),
+        meck:unload(couch_index_updater)
+    end).
+
+recompact_exceeded_retry_count() ->
+    ?_test(begin
+        ok = meck:expect(couch_index_updater, update,
+            fun(_, _, _) ->
+                exit(error)
+        end),
+        State = #mrst{fd=self()},
+        ?assertError(exceeded_recompact_retry_count, recompact(State)),
+        meck:unload(couch_index_updater)
+    end).
+
+-endif.


[33/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Merge remote branch 'cloudant:improve-exceeded_recompact_retry_count-error-message'

This closes #59

Signed-off-by: ILYA Khlopotov <ii...@apache.org>


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

Branch: refs/heads/2971-count-distinct
Commit: e875745afa665f568c08f582da80c732293a47b8
Parents: 853c608 f0f7d30
Author: ILYA Khlopotov <ii...@apache.org>
Authored: Wed Nov 2 16:53:15 2016 -0700
Committer: ILYA Khlopotov <ii...@apache.org>
Committed: Wed Nov 2 16:53:15 2016 -0700

----------------------------------------------------------------------
 src/couch_mrview_compactor.erl | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
----------------------------------------------------------------------



[26/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Merge remote-tracking branch 'cloudant/COUCHDB-3150-add-new-function-to-get-view-index-pid'


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

Branch: refs/heads/2971-count-distinct
Commit: d27941193516b925959cf3d27db7ba8f6524ba25
Parents: a0b0392 fdaebcf
Author: Paul J. Davis <pa...@gmail.com>
Authored: Wed Sep 28 12:25:46 2016 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Sep 28 12:25:46 2016 -0500

----------------------------------------------------------------------
 src/couch_mrview.erl      |  6 +++++-
 src/couch_mrview_util.erl | 16 ++++++++++------
 2 files changed, 15 insertions(+), 7 deletions(-)
----------------------------------------------------------------------



[23/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Use canonical case for ETag response header (COUCHDB-3134)


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

Branch: refs/heads/2971-count-distinct
Commit: ed52b77cd7255155d57874fe31896deae3d57efa
Parents: 9133f6d
Author: Robert Newson <rn...@apache.org>
Authored: Wed Sep 7 12:54:35 2016 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Wed Sep 7 12:54:35 2016 +0100

----------------------------------------------------------------------
 src/couch_mrview_show.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/ed52b77c/src/couch_mrview_show.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_show.erl b/src/couch_mrview_show.erl
index f7e0f56..0e5217c 100644
--- a/src/couch_mrview_show.erl
+++ b/src/couch_mrview_show.erl
@@ -323,7 +323,7 @@ apply_etag({ExternalResponse}, CurrentEtag) ->
     % Vary headers. If the external function controls the Etag, we'd have to
     % run it to check for a match, which sort of defeats the purpose.
     apply_headers(ExternalResponse, [
-        {<<"Etag">>, CurrentEtag},
+        {<<"ETag">>, CurrentEtag},
         {<<"Vary">>, <<"Accept">>}
     ]).
 


[08/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Fix match of a result from couch_mrview_util:get_view


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/9bafdca7
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/9bafdca7
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/9bafdca7

Branch: refs/heads/2971-count-distinct
Commit: 9bafdca7006f97924ecd68b9fdc87f5b3564d159
Parents: e36509b
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue May 24 18:33:29 2016 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue May 24 18:33:29 2016 -0700

----------------------------------------------------------------------
 src/couch_mrview.erl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/9bafdca7/src/couch_mrview.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview.erl b/src/couch_mrview.erl
index 3d06a1e..20eb4be 100644
--- a/src/couch_mrview.erl
+++ b/src/couch_mrview.erl
@@ -297,8 +297,8 @@ count_view_changes_since(Db, DDoc, VName, SinceSeq) ->
 
 count_view_changes_since(Db, DDoc, VName, SinceSeq, Options) ->
     Args0 = make_view_changes_args(Options),
-    {ok, {_, View}, _, Args} = couch_mrview_util:get_view(Db, DDoc, VName,
-                                                          Args0),
+    {ok, {_Type, View, _Ref}, _, Args} = couch_mrview_util:get_view(
+        Db, DDoc, VName, Args0),
     case View#mrview.seq_indexed of
         true ->
             OptList = make_view_changes_opts(SinceSeq, Options, Args),


[37/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Merge remote branch 'cloudant:make-accumulate_more-pure'

This closes #61

Signed-off-by: Eric Avdey <ei...@eiri.ca>


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/5899436a
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/5899436a
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/5899436a

Branch: refs/heads/2971-count-distinct
Commit: 5899436ae7b8d7198bfcbef48475d8c6dd4d9dd9
Parents: f4aaf8d b7362d0
Author: Eric Avdey <ei...@eiri.ca>
Authored: Tue Nov 22 10:42:43 2016 -0400
Committer: Eric Avdey <ei...@eiri.ca>
Committed: Tue Nov 22 10:42:43 2016 -0400

----------------------------------------------------------------------
 src/couch_mrview_updater.erl | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------



[16/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Replace `stale` with `stable` and `update`

The `stale` mechanism for view queries conflates two independent
concerns:

1. Whether or not the view results should be returned from a "stable"
   set of shards; i.e., mem3:ushards. This semantic is new in 2.0,
   having originated in Cloudant code in 2011[1].

2. Whether or not the view in question should be updated prior to
   responding to the user, i.e., the pre-2.0 semantics.

Both of these concerns represent consistency/availability tradeoffs, but
they're addressing rather different aspects of that continuum. As such,
the "stale" mechanism limits flexibility.

For example, it's quite likely that a user would want to retrieve
"stale" view responses from the fastest available shards - the
"available/available" choice - and this choice is not available with the
existing "stale" mechanism. A similar argument could be made for the
"consistent/consistent" choice.

This patch introduces two new view API keywords - "stable" and "update"
- to address concerns #1 and #2, respectively. The semantics of the
"stale" mechanism is implemented in terms of these new keywords.

COUCHDB-3063

[1]: apache/couchdb-fabric@93923fda51c714c015b8621e41f3c425bfb3e61a


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/459a548f
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/459a548f
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/459a548f

Branch: refs/heads/2971-count-distinct
Commit: 459a548f269b00bf2d2ace0170c583e72fde4cb9
Parents: 3ce2864
Author: Benjamin Anderson <b...@banjiewen.net>
Authored: Sun Jul 17 14:25:22 2016 -0700
Committer: Benjamin Anderson <b...@banjiewen.net>
Committed: Sun Jul 17 14:42:55 2016 -0700

----------------------------------------------------------------------
 include/couch_mrview.hrl  |  3 ++-
 src/couch_mrview_http.erl | 18 ++++++++++++++++--
 src/couch_mrview_util.erl | 20 +++++++++++++-------
 3 files changed, 31 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/459a548f/include/couch_mrview.hrl
----------------------------------------------------------------------
diff --git a/include/couch_mrview.hrl b/include/couch_mrview.hrl
index 2dfd398..e74d6ec 100644
--- a/include/couch_mrview.hrl
+++ b/include/couch_mrview.hrl
@@ -77,7 +77,8 @@
     skip = 0,
     group_level = 0,
     group = undefined,
-    stale = false,
+    stable = false,
+    update = true,
     multi_get = false,
     inclusive_end = true,
     include_docs = false,

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/459a548f/src/couch_mrview_http.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_http.erl b/src/couch_mrview_http.erl
index 3a9aa33..5f52d08 100644
--- a/src/couch_mrview_http.erl
+++ b/src/couch_mrview_http.erl
@@ -504,11 +504,25 @@ parse_param(Key, Val, Args, IsDecoded) ->
         "limit" ->
             Args#mrargs{limit=parse_pos_int(Val)};
         "stale" when Val == "ok" orelse Val == <<"ok">> ->
-            Args#mrargs{stale=ok};
+            Args#mrargs{stable=true, update=false};
         "stale" when Val == "update_after" orelse Val == <<"update_after">> ->
-            Args#mrargs{stale=update_after};
+            Args#mrargs{stable=true, update=lazy};
         "stale" ->
             throw({query_parse_error, <<"Invalid value for `stale`.">>});
+        "stable" when Val == "true" orelse Val == <<"true">> ->
+            Args#mrargs{stable=true};
+        "stable" when Val == "false" orelse Val == <<"false">> ->
+            Args#mrargs{stable=false};
+        "stable" ->
+            throw({query_parse_error, <<"Invalid value for `stable`.">>});
+        "update" when Val == "true" orelse Val == <<"true">> ->
+            Args#mrargs{update=true};
+        "update" when Val == "false" orelse Val == <<"false">> ->
+            Args#mrargs{update=false};
+        "update" when Val == "lazy" orelse Val == <<"lazy">> ->
+            Args#mrargs{update=lazy};
+        "update" ->
+            throw({query_parse_error, <<"Invalid value for `update`.">>});
         "descending" ->
             case parse_boolean(Val) of
                 true -> Args#mrargs{direction=rev};

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/459a548f/src/couch_mrview_util.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_util.erl b/src/couch_mrview_util.erl
index 934dcd3..11bd0df 100644
--- a/src/couch_mrview_util.erl
+++ b/src/couch_mrview_util.erl
@@ -48,15 +48,15 @@ get_view(Db, DDoc, ViewName, Args0) ->
     DbUpdateSeq = couch_util:with_db(Db, fun(WDb) ->
         couch_db:get_update_seq(WDb)
     end),
-    MinSeq = case Args2#mrargs.stale of
-        ok -> 0; update_after -> 0; _ -> DbUpdateSeq
+    MinSeq = case Args2#mrargs.update of
+        false -> 0; lazy -> 0; _ -> DbUpdateSeq
     end,
     {ok, State} = case couch_index:get_state(Pid, MinSeq) of
         {ok, _} = Resp -> Resp;
         Error -> throw(Error)
     end,
     Ref = erlang:monitor(process, State#mrst.fd),
-    if Args2#mrargs.stale == update_after ->
+    if Args2#mrargs.update == lazy ->
         spawn(fun() -> catch couch_index:get_state(Pid, DbUpdateSeq) end);
         true -> ok
     end,
@@ -472,11 +472,17 @@ validate_args(Args) ->
         {map, _} -> mrverror(<<"Invalid use of grouping on a map view.">>)
     end,
 
-    case Args#mrargs.stale of
-        ok -> ok;
-        update_after -> ok;
+    case Args#mrargs.stable of
+        true -> ok;
+        false -> ok;
+        _ -> mrverror(<<"Invalid value for `stable`.">>)
+    end,
+
+    case Args#mrargs.update of
+        true -> ok;
         false -> ok;
-        _ -> mrverror(<<"Invalid value for `stale`.">>)
+        lazy -> ok;
+        _ -> mrverror(<<"Invalid value for `update`.">>)
     end,
 
     case is_boolean(Args#mrargs.inclusive_end) of


[04/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Make view updater couch_work_queue configurable

For performance reasons in some cases there is a need to put a cap
on a queue size.

COUCHDB-3005


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/3f8230cb
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/3f8230cb
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/3f8230cb

Branch: refs/heads/2971-count-distinct
Commit: 3f8230cbfc5b226080364cc9801cb0eeafc1985f
Parents: 3735172
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Apr 26 13:55:11 2016 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Apr 26 13:58:03 2016 -0700

----------------------------------------------------------------------
 src/couch_mrview_updater.erl | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/3f8230cb/src/couch_mrview_updater.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_updater.erl b/src/couch_mrview_updater.erl
index da7381a..8a85887 100644
--- a/src/couch_mrview_updater.erl
+++ b/src/couch_mrview_updater.erl
@@ -21,7 +21,9 @@
 
 
 start_update(Partial, State, NumChanges) ->
-    QueueOpts = [{max_size, 100000}, {max_items, 500}],
+    MaxSize = config:get_integer("view_updater", "queue_memory_cap", 100000),
+    MaxItems = config:get_integer("view_updater", "queue_item_cap", 500),
+    QueueOpts = [{max_size, MaxSize}, {max_items, MaxItems}],
     {ok, DocQueue} = couch_work_queue:new(QueueOpts),
     {ok, WriteQueue} = couch_work_queue:new(QueueOpts),
 


[17/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Remove outdated test

The module load tests date all the way back to when I first learned
about etap from Nick Gerakines. In the age of meck these are even more
brittle as mocked modules can interfere with the `code:load_file/1`
depending on execution.

Also, given that we were missing almost half of the couch_mrview modules
we obviously don't keep these up to date so they're not serving any
purpose.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/157132c6
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/157132c6
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/157132c6

Branch: refs/heads/2971-count-distinct
Commit: 157132c6e603b1870a08c04e8459a177387932ed
Parents: 3ce2864
Author: Paul J. Davis <pa...@gmail.com>
Authored: Fri Jul 22 17:34:03 2016 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Fri Jul 22 17:36:54 2016 -0500

----------------------------------------------------------------------
 test/couch_mrview_modules_load_tests.erl | 37 ---------------------------
 1 file changed, 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/157132c6/test/couch_mrview_modules_load_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_modules_load_tests.erl b/test/couch_mrview_modules_load_tests.erl
deleted file mode 100644
index 15ce443..0000000
--- a/test/couch_mrview_modules_load_tests.erl
+++ /dev/null
@@ -1,37 +0,0 @@
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-%   http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
--module(couch_mrview_modules_load_tests).
-
--include_lib("couch/include/couch_eunit.hrl").
-
-
-modules_load_test_() ->
-    {
-        "Verify that all modules loads",
-        should_load_modules()
-    }.
-
-
-should_load_modules() ->
-    Modules = [
-        couch_mrview,
-        couch_mrview_compactor,
-        couch_mrview_http,
-        couch_mrview_index,
-        couch_mrview_updater,
-        couch_mrview_util
-    ],
-    [should_load_module(Mod) || Mod <- Modules].
-
-should_load_module(Mod) ->
-    {atom_to_list(Mod), ?_assertMatch({module, _}, code:load_file(Mod))}.


[13/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Send empty string from _list if no result

There is a corner case when list function does not return any Chunk.
In this case we would want to return empty string to the client.

COUCHDB-2847


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

Branch: refs/heads/2971-count-distinct
Commit: f9a58d891daba03556a19d6bc10176bcd6e587e3
Parents: 8567b43
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Fri Jun 17 16:09:50 2016 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Fri Jun 17 16:09:50 2016 -0700

----------------------------------------------------------------------
 src/couch_mrview_show.erl | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/f9a58d89/src/couch_mrview_show.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_show.erl b/src/couch_mrview_show.erl
index 5a01b84..f7e0f56 100644
--- a/src/couch_mrview_show.erl
+++ b/src/couch_mrview_show.erl
@@ -227,7 +227,7 @@ list_cb({row, Row}, #lacc{code=undefined} = Acc) ->
 list_cb({row, Row}, Acc) ->
     send_list_row(Row, Acc);
 list_cb(complete, Acc) ->
-    #lacc{qserver = {Proc, _}, resp = Resp0} = Acc,
+    #lacc{qserver = {Proc, _}, req = Req, resp = Resp0} = Acc,
     if Resp0 =:= nil ->
         {ok, #lacc{resp = Resp}} = start_list_resp({[]}, Acc);
     true ->
@@ -240,7 +240,7 @@ list_cb(complete, Acc) ->
         [<<"end">>, Data] ->
             #lacc{resp = Resp2} = send_non_empty_chunk(Acc#lacc{resp=Resp}, Data)
     end,
-    last_chunk(Resp2),
+    last_chunk(Req, Resp2),
     {ok, Resp2}.
 
 start_list_resp(Head, Acc) ->
@@ -262,7 +262,7 @@ fixup_headers(Headers, #lacc{etag=ETag} = Acc) ->
     Headers3 = chttpd_external:default_or_content_type(CType, ExtHeaders),
     Acc#lacc{code=Code, headers=Headers3}.
 
-send_list_row(Row, #lacc{qserver = {Proc, _}, resp = Resp} = Acc) ->
+send_list_row(Row, #lacc{qserver = {Proc, _}, req = Req, resp = Resp} = Acc) ->
     RowObj = case couch_util:get_value(id, Row) of
         undefined -> [];
         Id -> [{id, Id}]
@@ -286,12 +286,12 @@ send_list_row(Row, #lacc{qserver = {Proc, _}, resp = Resp} = Acc) ->
     [<<"end">>, Chunk, Headers] ->
         Acc2 = send_non_empty_chunk(fixup_headers(Headers, Acc), Chunk),
         #lacc{resp = Resp2} = Acc2,
-        last_chunk(Resp2),
+        last_chunk(Req, Resp2),
         {stop, Acc2};
     [<<"end">>, Chunk] ->
         Acc2 = send_non_empty_chunk(Acc, Chunk),
         #lacc{resp = Resp2} = Acc2,
-        last_chunk(Resp2),
+        last_chunk(Req, Resp2),
         {stop, Acc2}
     catch Error ->
         case Resp of
@@ -372,7 +372,9 @@ json_req_obj(Req, Db) ->
     spawn_monitor(fun() -> exit(chttpd_external:json_req_obj(Req, Db)) end),
     receive {'DOWN', _, _, _, JsonReq} -> JsonReq end.
 
-last_chunk(Resp) ->
+last_chunk(Req, undefined) ->
+    chttpd:send_response(Req, 200, [], <<"">>);
+last_chunk(_Req, Resp) ->
     chttpd:send_chunk(Resp, []).
 
 


[02/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Use ioq to separately prioritise view updates

COUCHDB-3002


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

Branch: refs/heads/2971-count-distinct
Commit: abc94a40da81211395501d91cd5d1fb73e6afbe9
Parents: 65b7a3a
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Thu Apr 21 12:45:34 2016 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Thu Apr 21 12:45:34 2016 -0700

----------------------------------------------------------------------
 src/couch_mrview_updater.erl | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/abc94a40/src/couch_mrview_updater.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_updater.erl b/src/couch_mrview_updater.erl
index 0745c2a..da7381a 100644
--- a/src/couch_mrview_updater.erl
+++ b/src/couch_mrview_updater.erl
@@ -168,7 +168,8 @@ finish_update(#mrst{doc_acc=Acc}=State) ->
     end.
 
 
-map_docs(Parent, State0) ->
+map_docs(Parent, #mrst{db_name = DbName, idx_name = IdxName} = State0) ->
+    erlang:put(io_priority, {view_update, DbName, IdxName}),
     case couch_work_queue:dequeue(State0#mrst.doc_queue) of
         closed ->
             couch_query_servers:stop_doc_map(State0#mrst.qserver),
@@ -201,11 +202,12 @@ map_docs(Parent, State0) ->
     end.
 
 
-write_results(Parent, State) ->
+write_results(Parent, #mrst{db_name = DbName, idx_name = IdxName} = State) ->
     case accumulate_writes(State, State#mrst.write_queue, nil) of
         stop ->
             Parent ! {new_state, State};
         {Go, {Seq, ViewKVs, DocIdKeys, Seqs, Log}} ->
+            erlang:put(io_priority, {view_update, DbName, IdxName}),
             NewState = write_kvs(State, Seq, ViewKVs, DocIdKeys, Seqs, Log),
             if Go == stop ->
                 Parent ! {new_state, NewState};


[06/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Use couch_file:delete/3 in views cleanup


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/7293bfb6
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/7293bfb6
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/7293bfb6

Branch: refs/heads/2971-count-distinct
Commit: 7293bfb64041d6bb1243ecc8c3ddd71d02811294
Parents: 56b66b4
Author: Eric Avdey <ei...@eiri.ca>
Authored: Wed Apr 20 14:55:52 2016 -0300
Committer: Eric Avdey <ei...@eiri.ca>
Committed: Thu Apr 28 14:08:00 2016 -0300

----------------------------------------------------------------------
 src/couch_mrview_cleanup.erl | 66 +--------------------------------------
 1 file changed, 1 insertion(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/7293bfb6/src/couch_mrview_cleanup.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_cleanup.erl b/src/couch_mrview_cleanup.erl
index b96622a..380376d 100644
--- a/src/couch_mrview_cleanup.erl
+++ b/src/couch_mrview_cleanup.erl
@@ -41,71 +41,7 @@ run(Db) ->
 
     lists:foreach(fun(FN) ->
         couch_log:debug("Deleting stale view file: ~s", [FN]),
-        delete_view_file(RootDir, FN)
+        couch_file:delete(RootDir, FN, [sync])
     end, ToDelete),
 
     ok.
-
-delete_view_file(RootDir, FullFilePath) ->
-    couch_server:delete_file(RootDir, FullFilePath, [sync]).
-
--ifdef(TEST).
--include_lib("couch/include/couch_eunit.hrl").
-
-setup(rename) ->
-    setup(true);
-setup(delete) ->
-    setup(false);
-setup(RenameOnDelete) ->
-    meck:new(config, [passthrough]),
-    meck:expect(config, get_boolean, fun
-        ("couchdb", "rename_on_delete", _Default) -> RenameOnDelete
-    end),
-    ViewFile = ?tempfile() ++ ".view",
-    RootDir = filename:dirname(ViewFile),
-    ok = couch_file:init_delete_dir(RootDir),
-    ok = file:write_file(ViewFile, <<>>),
-    {RootDir, ViewFile}.
-
-teardown(_, {_, ViewFile}) ->
-    (catch meck:unload(config)),
-    (catch file:delete(ViewFile)).
-
-delete_view_file_test_() ->
-    Funs = [
-        fun should_rename_on_delete/2,
-        fun should_delete/2
-    ],
-    [
-        make_test_case(rename, [fun should_rename_on_delete/2]),
-        make_test_case(delete, [fun should_delete/2])
-    ].
-
-make_test_case(Mod, Funs) ->
-    {
-        lists:flatten(io_lib:format("~s", [Mod])),
-        {foreachx, fun setup/1, fun teardown/2, [{Mod, Fun} || Fun <- Funs]}
-    }.
-
-should_rename_on_delete(_, {RootDir, ViewFile}) ->
-    ?_test(begin
-        ?assert(filelib:is_regular(ViewFile)),
-        Result = delete_view_file(RootDir, ViewFile),
-        ?assertNot(filelib:is_regular(ViewFile)),
-        ?assertMatch({ok, {renamed, _}}, Result),
-        {ok, {renamed, RenamedViewFile}} = Result,
-        ?assert(filelib:is_regular(RenamedViewFile))
-    end).
-
-should_delete(_, {RootDir, ViewFile}) ->
-    ?_test(begin
-        ?assert(filelib:is_regular(ViewFile)),
-        delete_view_file(RootDir, ViewFile),
-        ?assertNot(filelib:is_regular(ViewFile)),
-        ?assertMatch([], deleted_files(ViewFile))
-    end).
-
-deleted_files(ViewFile) ->
-    filelib:wildcard(filename:rootname(ViewFile) ++ "*.deleted.*").
-
--endif.


[43/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Add _distinct as a built-in reduce

COUCHDB-2971


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

Branch: refs/heads/2971-count-distinct
Commit: f7c3c24db17db5908894447e1822936212d61fcd
Parents: e1d13a9
Author: Adam Kocoloski <ko...@apache.org>
Authored: Wed Mar 1 10:37:00 2017 -0500
Committer: Adam Kocoloski <ko...@apache.org>
Committed: Wed Mar 1 11:37:04 2017 -0500

----------------------------------------------------------------------
 src/couch_mrview.erl | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/f7c3c24d/src/couch_mrview.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview.erl b/src/couch_mrview.erl
index 088327c..7449e5a 100644
--- a/src/couch_mrview.erl
+++ b/src/couch_mrview.erl
@@ -184,6 +184,8 @@ validate(DbName,  DDoc) ->
                 ok;
             ({_RedName, <<"_stats", _/binary>>}) ->
                 ok;
+            ({_RedName, <<"_distinct", _/binary>>}) ->
+                ok;
             ({_RedName, <<"_", _/binary>> = Bad}) ->
                 Msg = ["`", Bad, "` is not a supported reduce function."],
                 throw({invalid_design_doc, Msg});


[27/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Merge remote-tracking branch 'banjiewen/stale-stable-update'


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

Branch: refs/heads/2971-count-distinct
Commit: d4509606f3aacc4bec94b8936bedf6d1d597ff5f
Parents: d279411 459a548
Author: Robert Newson <rn...@apache.org>
Authored: Thu Oct 6 19:02:23 2016 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Oct 6 19:02:23 2016 +0100

----------------------------------------------------------------------
 include/couch_mrview.hrl  |  3 ++-
 src/couch_mrview_http.erl | 18 ++++++++++++++++--
 src/couch_mrview_util.erl | 20 +++++++++++++-------
 3 files changed, 31 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d4509606/include/couch_mrview.hrl
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d4509606/src/couch_mrview_http.erl
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d4509606/src/couch_mrview_util.erl
----------------------------------------------------------------------


[35/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Merge remote branch 'cloudant:77867-add-indexer-pid-to-task-status'

This closes #62

Signed-off-by: ILYA Khlopotov <ii...@apache.org>


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

Branch: refs/heads/2971-count-distinct
Commit: f4aaf8de5a9d05ecd4b69707efa0d5ee89c98736
Parents: e875745 b3b1b12
Author: ILYA Khlopotov <ii...@apache.org>
Authored: Fri Nov 18 14:56:27 2016 -0800
Committer: ILYA Khlopotov <ii...@apache.org>
Committed: Fri Nov 18 14:56:27 2016 -0800

----------------------------------------------------------------------
 src/couch_mrview_updater.erl | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------



[29/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Update with couch_index_updater:update/3

Handle '$gen_cast' messages in receive


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/0d382f5f
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/0d382f5f
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/0d382f5f

Branch: refs/heads/2971-count-distinct
Commit: 0d382f5fd210b3413b3e4c07ad65458004821bf6
Parents: 1d5c6a5
Author: Jay Doane <ja...@gmail.com>
Authored: Mon Oct 10 13:19:56 2016 -0700
Committer: Jay Doane <ja...@gmail.com>
Committed: Mon Oct 10 13:19:56 2016 -0700

----------------------------------------------------------------------
 src/couch_mrview_compactor.erl | 47 ++++++++++++++++++++++---------------
 1 file changed, 28 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/0d382f5f/src/couch_mrview_compactor.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_compactor.erl b/src/couch_mrview_compactor.erl
index d5ea763..50e7eae 100644
--- a/src/couch_mrview_compactor.erl
+++ b/src/couch_mrview_compactor.erl
@@ -149,32 +149,41 @@ compact(State) ->
 
 
 recompact(State) ->
-    RetryCount = config:get_integer("view_compaction", "recompact_retry_count",
-        ?DEFAULT_RECOMPACT_RETRY_COUNT),
-    recompact(State, RetryCount).
-
-recompact(State, 0) ->
-    couch_log:error("couch_mrview_compactor:recompact max retries exceeded ~p",
-        [State]),
-    {ok, State};
-recompact(State, Attempt) ->
+    recompact(State, recompact_retry_count()).
+
+recompact(_State, 0) ->
+    erlang:error(exceeded_recompact_retry_count);
+
+recompact(State, RetryCount) ->
+    Self = self(),
     link(State#mrst.fd),
     {Pid, Ref} = erlang:spawn_monitor(fun() ->
-        couch_index_updater:update(couch_mrview_index, State)
+        couch_index_updater:update(Self, couch_mrview_index, State)
     end),
+    recompact_loop(Pid, Ref, State, RetryCount).
+
+recompact_loop(Pid, Ref, State, RetryCount) ->
     receive
-        {'DOWN', Ref, _, _, Result} ->
+        {'$gen_cast', {new_state, State2}} ->
+            % We've made progress so reset RetryCount
+            recompact_loop(Pid, Ref, State2, recompact_retry_count());
+        {'DOWN', Ref, _, _, {updated, Pid, State2}} ->
             unlink(State#mrst.fd),
-            case Result of
-                {updated, Pid, State2} ->
-                    {ok, State2};
-                Error ->
-                    couch_log:info("couch_mrview_compactor:recompact error ~p",
-                        [Error]),
-                    recompact(State, Attempt - 1)
-            end
+            {ok, State2};
+        {'DOWN', Ref, _, _, Reason} ->
+            unlink(State#mrst.fd),
+            couch_log:warning("Error during recompaction: ~r", [Reason]),
+            recompact(State, RetryCount - 1)
     end.
 
+recompact_retry_count() ->
+    config:get_integer(
+        "view_compaction",
+        "recompact_retry_count",
+        ?DEFAULT_RECOMPACT_RETRY_COUNT
+    ).
+
+
 compact_log(LogBtree, BufferSize, Acc0) ->
     FoldFun = fun(KV, Acc) ->
         #acc{btree = Bt, kvs = Kvs, kvs_size = KvsSize} = Acc,


[32/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
exceeded_recompact_retry_count: add DbName/IdxName


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

Branch: refs/heads/2971-count-distinct
Commit: f0f7d30014c8abdd2e232768d8b2b87183054770
Parents: 853c608
Author: ILYA Khlopotov <ii...@apache.org>
Authored: Wed Nov 2 16:44:22 2016 -0700
Committer: ILYA Khlopotov <ii...@apache.org>
Committed: Wed Nov 2 16:44:22 2016 -0700

----------------------------------------------------------------------
 src/couch_mrview_compactor.erl | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/f0f7d300/src/couch_mrview_compactor.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_compactor.erl b/src/couch_mrview_compactor.erl
index e343ac8..5957908 100644
--- a/src/couch_mrview_compactor.erl
+++ b/src/couch_mrview_compactor.erl
@@ -151,8 +151,9 @@ compact(State) ->
 recompact(State) ->
     recompact(State, recompact_retry_count()).
 
-recompact(_State, 0) ->
-    erlang:error(exceeded_recompact_retry_count);
+recompact(#mrst{db_name=DbName, idx_name=IdxName}, 0) ->
+    erlang:error({exceeded_recompact_retry_count,
+        [{db_name, DbName}, {idx_name, IdxName}]});
 
 recompact(State, RetryCount) ->
     Self = self(),
@@ -321,8 +322,10 @@ recompact_exceeded_retry_count() ->
             fun(_, _, _) ->
                 exit(error)
         end),
-        State = #mrst{fd=self()},
-        ?assertError(exceeded_recompact_retry_count, recompact(State)),
+        State = #mrst{fd=self(), db_name=foo, idx_name=bar},
+        ExpectedError = {exceeded_recompact_retry_count,
+            [{db_name, foo}, {idx_name, bar}]},
+        ?assertError(ExpectedError, recompact(State)),
         meck:unload(couch_index_updater)
     end).
 


[18/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Wrap line

whitespace-only change

COUCHDB-3060


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/82f7913d
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/82f7913d
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/82f7913d

Branch: refs/heads/2971-count-distinct
Commit: 82f7913d95a1e418725408cbbc1f822d20dfa77d
Parents: 157132c
Author: Robert Newson <rn...@apache.org>
Authored: Thu Aug 25 12:47:49 2016 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Aug 25 13:08:44 2016 +0100

----------------------------------------------------------------------
 src/couch_mrview_http.erl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/82f7913d/src/couch_mrview_http.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_http.erl b/src/couch_mrview_http.erl
index 3a9aa33..341495e 100644
--- a/src/couch_mrview_http.erl
+++ b/src/couch_mrview_http.erl
@@ -382,7 +382,8 @@ view_cb(complete, #vacc{resp=Resp, buffer=Buf, threshold=Max}=Acc) ->
             {ok, Resp2} = chttpd:end_delayed_json_response(Resp1),
             {ok, Acc#vacc{resp=Resp2}};
         _ ->
-            {ok, Acc#vacc{resp=Resp1, prepend=",\r\n", buffer=[], bufsize=0}}
+            {ok, Acc#vacc{resp=Resp1,
+                prepend=",\r\n", buffer=[], bufsize=0}}
     end;
 view_cb({error, Reason}, #vacc{resp=undefined}=Acc) ->
     {ok, Resp} = chttpd:send_error(Acc#vacc.req, Reason),


[36/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Remove side effect from accumulate_more


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

Branch: refs/heads/2971-count-distinct
Commit: b7362d0473769fd52716309562dd5eddf9544d07
Parents: f4aaf8d
Author: Eric Avdey <ei...@eiri.ca>
Authored: Fri Nov 18 15:04:32 2016 -0400
Committer: Eric Avdey <ei...@eiri.ca>
Committed: Tue Nov 22 10:40:01 2016 -0400

----------------------------------------------------------------------
 src/couch_mrview_updater.erl | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/b7362d04/src/couch_mrview_updater.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_updater.erl b/src/couch_mrview_updater.erl
index 645f02b..0ceaa40 100644
--- a/src/couch_mrview_updater.erl
+++ b/src/couch_mrview_updater.erl
@@ -244,18 +244,18 @@ accumulate_writes(State, W, Acc0) ->
             {stop, {Seq, ViewKVs, DocIdKVs, Seqs, Log}};
         {ok, Info} ->
             {_, _, NewIds, _, _} = Acc = merge_results(Info, Seq, ViewKVs, DocIdKVs, Seqs, Log),
-            case accumulate_more(length(NewIds)) of
+            case accumulate_more(length(NewIds), Acc) of
                 true -> accumulate_writes(State, W, Acc);
                 false -> {ok, Acc}
             end
     end.
 
 
-accumulate_more(NumDocIds) ->
+accumulate_more(NumDocIds, Acc) ->
     % check if we have enough items now
     MinItems = config:get("view_updater", "min_writer_items", "100"),
     MinSize = config:get("view_updater", "min_writer_size", "16777216"),
-    {memory, CurrMem} = process_info(self(), memory),
+    CurrMem = ?term_size(Acc),
     NumDocIds < list_to_integer(MinItems)
         andalso CurrMem < list_to_integer(MinSize).
 


[11/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Allow json decode in parse_params to be optional

This allows explicitly indicate if ifunction parse_params
should decode passed parameter's value instead of trying
to guess it by value's term type.

It makes it possible to use this function both with GET
and POST queries.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/26f5af7c
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/26f5af7c
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/26f5af7c

Branch: refs/heads/2971-count-distinct
Commit: 26f5af7c6d2c7642e9463cd26f3c4070c9add2e8
Parents: d07771a
Author: Eric Avdey <ei...@eiri.ca>
Authored: Mon Jun 13 13:28:17 2016 -0300
Committer: Eric Avdey <ei...@eiri.ca>
Committed: Mon Jun 13 15:48:00 2016 -0300

----------------------------------------------------------------------
 src/couch_mrview_http.erl | 45 ++++++++++++++++++++++++++----------------
 1 file changed, 28 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/26f5af7c/src/couch_mrview_http.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_http.erl b/src/couch_mrview_http.erl
index 1f08961..191198c 100644
--- a/src/couch_mrview_http.erl
+++ b/src/couch_mrview_http.erl
@@ -32,6 +32,7 @@
     prepend_val/1,
     parse_params/2,
     parse_params/3,
+    parse_params/4,
     view_cb/2,
     row_to_json/1,
     row_to_json/2,
@@ -439,39 +440,55 @@ parse_params(Props, Keys) ->
     parse_params(Props, Keys, Args).
 
 
-parse_params(Props, Keys, #mrargs{}=Args0) ->
+parse_params(Props, Keys, Args) ->
+    parse_params(Props, Keys, Args, []).
+
+parse_params(Props, Keys, #mrargs{}=Args0, Options) ->
+    IsDecoded = lists:member(decoded, Options),
     % group_level set to undefined to detect if explicitly set by user
     Args1 = Args0#mrargs{keys=Keys, group=undefined, group_level=undefined},
     lists:foldl(fun({K, V}, Acc) ->
-        parse_param(K, V, Acc)
+        parse_param(K, V, Acc, IsDecoded)
     end, Args1, Props).
 
 
-parse_param(Key, Val, Args) when is_binary(Key) ->
-    parse_param(binary_to_list(Key), Val, Args);
-parse_param(Key, Val, Args) ->
+parse_param(Key, Val, Args, IsDecoded) when is_binary(Key) ->
+    parse_param(binary_to_list(Key), Val, Args, IsDecoded);
+parse_param(Key, Val, Args, IsDecoded) ->
     case Key of
         "" ->
             Args;
         "reduce" ->
             Args#mrargs{reduce=parse_boolean(Val)};
+        "key" when IsDecoded ->
+            Args#mrargs{start_key=Val, end_key=Val};
         "key" ->
-            JsonKey = parse_json(Val),
+            JsonKey = ?JSON_DECODE(Val),
             Args#mrargs{start_key=JsonKey, end_key=JsonKey};
+        "keys" when IsDecoded ->
+            Args#mrargs{keys=Val};
         "keys" ->
-            Args#mrargs{keys=parse_json(Val)};
+            Args#mrargs{keys=?JSON_DECODE(Val)};
+        "startkey" when IsDecoded ->
+            Args#mrargs{start_key=Val};
+        "start_key" when IsDecoded ->
+            Args#mrargs{start_key=Val};
         "startkey" ->
-            Args#mrargs{start_key=parse_json(Val)};
+            Args#mrargs{start_key=?JSON_DECODE(Val)};
         "start_key" ->
-            Args#mrargs{start_key=parse_json(Val)};
+            Args#mrargs{start_key=?JSON_DECODE(Val)};
         "startkey_docid" ->
             Args#mrargs{start_key_docid=couch_util:to_binary(Val)};
         "start_key_doc_id" ->
             Args#mrargs{start_key_docid=couch_util:to_binary(Val)};
+        "endkey" when IsDecoded ->
+            Args#mrargs{end_key=Val};
+        "end_key" when IsDecoded ->
+            Args#mrargs{end_key=Val};
         "endkey" ->
-            Args#mrargs{end_key=parse_json(Val)};
+            Args#mrargs{end_key=?JSON_DECODE(Val)};
         "end_key" ->
-            Args#mrargs{end_key=parse_json(Val)};
+            Args#mrargs{end_key=?JSON_DECODE(Val)};
         "endkey_docid" ->
             Args#mrargs{end_key_docid=couch_util:to_binary(Val)};
         "end_key_doc_id" ->
@@ -573,9 +590,3 @@ check_view_etag(Sig, Acc0, Req) ->
         true -> throw({etag_match, ETag});
         false -> {ok, Acc0#vacc{etag=ETag}}
     end.
-
-
-parse_json(V) when is_list(V) ->
-    ?JSON_DECODE(V);
-parse_json(V) ->
-    V.


[05/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Merge remote branch 'cloudant:3005-configurable_queue_size'

This closes #45

Signed-off-by: ILYA Khlopotov <ii...@ca.ibm.com>


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/56b66b48
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/56b66b48
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/56b66b48

Branch: refs/heads/2971-count-distinct
Commit: 56b66b48390732d1bbb2917ca25c4cdb3e196d1e
Parents: 3735172 3f8230c
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Wed Apr 27 17:37:36 2016 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Wed Apr 27 17:37:36 2016 -0700

----------------------------------------------------------------------
 src/couch_mrview_updater.erl | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------



[38/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Convert pid of indexer to binary

This is a fixup for https://github.com/apache/couchdb-couch-mrview/pull/62
Properties passed to couch_task_status:add_task cannot contain complex
types. Because the status need to be representable in JSON.


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

Branch: refs/heads/2971-count-distinct
Commit: c49211cdca99a198235a6a8798692d8b1163f6bf
Parents: 5899436
Author: ILYA Khlopotov <ii...@apache.org>
Authored: Thu Dec 1 16:51:46 2016 -0800
Committer: ILYA Khlopotov <ii...@apache.org>
Committed: Thu Dec 1 16:51:46 2016 -0800

----------------------------------------------------------------------
 src/couch_mrview_updater.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/c49211cd/src/couch_mrview_updater.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_updater.erl b/src/couch_mrview_updater.erl
index 0ceaa40..214f487 100644
--- a/src/couch_mrview_updater.erl
+++ b/src/couch_mrview_updater.erl
@@ -38,7 +38,7 @@ start_update(Partial, State, NumChanges) ->
     Self = self(),
     MapFun = fun() ->
         couch_task_status:add_task([
-            {indexer_pid, Partial},
+            {indexer_pid, ?l2b(pid_to_list(Partial))},
             {type, indexer},
             {database, State#mrst.db_name},
             {design_document, State#mrst.idx_name},


[07/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Merge remote branch 'github/pr/44'

This closes #44

Signed-off-by: Eric Avdey <ei...@eiri.ca>


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

Branch: refs/heads/2971-count-distinct
Commit: e36509b2dfb7bba5f09fcb62f0e23a538451afb5
Parents: 56b66b4 7293bfb
Author: Eric Avdey <ei...@eiri.ca>
Authored: Thu Apr 28 14:12:50 2016 -0300
Committer: Eric Avdey <ei...@eiri.ca>
Committed: Thu Apr 28 14:12:50 2016 -0300

----------------------------------------------------------------------
 src/couch_mrview_cleanup.erl | 66 +--------------------------------------
 1 file changed, 1 insertion(+), 65 deletions(-)
----------------------------------------------------------------------



[10/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Posted by ko...@apache.org.
Merge remote branch 'cloudant:fix-some-type-errors'

This closes #46

Signed-off-by: ILYA Khlopotov <ii...@ca.ibm.com>


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

Branch: refs/heads/2971-count-distinct
Commit: d07771ac4255d3b217a993e807f1e9620b38dbee
Parents: e36509b 1a179cb
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Wed May 25 05:52:09 2016 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Wed May 25 05:52:09 2016 -0700

----------------------------------------------------------------------
 src/couch_mrview.erl                 | 4 ++--
 src/couch_mrview_update_notifier.erl | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------