You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2017/09/08 14:54:41 UTC

[couchdb] branch improve-reduce-limit-errors updated (e0e67ad -> 8d33cd7)

This is an automated email from the ASF dual-hosted git repository.

davisp pushed a change to branch improve-reduce-limit-errors
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


    omit e0e67ad  Return reduce overflow errors to the client
     new 8d33cd7  Return reduce overflow errors to the client

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (e0e67ad)
            \
             N -- N -- N   refs/heads/improve-reduce-limit-errors (8d33cd7)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/couch_mrview/src/couch_mrview_http.erl | 6 +++++-
 src/fabric/src/fabric_util.erl             | 2 --
 src/fabric/src/fabric_view.erl             | 4 ++--
 test/javascript/tests/view_errors.js       | 4 ++--
 4 files changed, 9 insertions(+), 7 deletions(-)

-- 
To stop receiving notification emails like this one, please contact
['"commits@couchdb.apache.org" <co...@couchdb.apache.org>'].

[couchdb] 01/01: Return reduce overflow errors to the client

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch improve-reduce-limit-errors
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 8d33cd725d01cd7a2a0dd76e62755283cdd556a3
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Thu Sep 7 14:37:36 2017 -0500

    Return reduce overflow errors to the client
    
    This changes the reduce overflow error to return an error to the client
    rather than blowing up the view build. This allows views that have a
    single bad reduce to build while not crushing the server's RAM usage.
---
 src/couch/src/couch_query_servers.erl      | 29 ++++++++++++++++++++++++-----
 src/couch_mrview/src/couch_mrview_http.erl |  6 +++++-
 src/fabric/src/fabric_util.erl             |  2 --
 src/fabric/src/fabric_view.erl             |  2 ++
 test/javascript/tests/view_errors.js       |  4 ++--
 5 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/src/couch/src/couch_query_servers.erl b/src/couch/src/couch_query_servers.erl
index 63b0e39..4928eea 100644
--- a/src/couch/src/couch_query_servers.erl
+++ b/src/couch/src/couch_query_servers.erl
@@ -125,20 +125,39 @@ os_reduce(Lang, OsRedSrcs, KVs) ->
     Proc = get_os_process(Lang),
     OsResults = try proc_prompt(Proc, [<<"reduce">>, OsRedSrcs, KVs]) of
         [true, Reductions] -> Reductions
+    catch
+        throw:{reduce_overflow_error, Msg} ->
+            [{[{reduce_overflow_error, Msg}]} || _ <- OsRedSrcs]
     after
         ok = ret_os_process(Proc)
     end,
     {ok, OsResults}.
 
 os_rereduce(Lang, OsRedSrcs, KVs) ->
-    Proc = get_os_process(Lang),
-    try proc_prompt(Proc, [<<"rereduce">>, OsRedSrcs, KVs]) of
-        [true, [Reduction]] -> Reduction
-    after
-        ok = ret_os_process(Proc)
+    case get_overflow_error(KVs) of
+        undefined ->
+            Proc = get_os_process(Lang),
+            try proc_prompt(Proc, [<<"rereduce">>, OsRedSrcs, KVs]) of
+                [true, [Reduction]] -> Reduction
+            catch
+                throw:{reduce_overflow_error, Msg} ->
+                    {[{reduce_overflow_error, Msg}]}
+            after
+                ok = ret_os_process(Proc)
+            end;
+        Error ->
+            Error
     end.
 
 
+get_overflow_error([]) ->
+    undefined;
+get_overflow_error([{[{reduce_overflow_error, _}]} = Error | _]) ->
+    Error;
+get_overflow_error([_ | Rest]) ->
+    get_overflow_error(Rest).
+
+
 builtin_reduce(_Re, [], _KVs, Acc) ->
     {ok, lists:reverse(Acc)};
 builtin_reduce(Re, [<<"_sum",_/binary>>|BuiltinReds], KVs, Acc) ->
diff --git a/src/couch_mrview/src/couch_mrview_http.erl b/src/couch_mrview/src/couch_mrview_http.erl
index a94f48d..52253a8 100644
--- a/src/couch_mrview/src/couch_mrview_http.erl
+++ b/src/couch_mrview/src/couch_mrview_http.erl
@@ -440,7 +440,11 @@ row_to_json(error, Row) ->
     % match prior behavior.
     Key = couch_util:get_value(key, Row),
     Val = couch_util:get_value(value, Row),
-    Obj = {[{key, Key}, {error, Val}]},
+    Reason = couch_util:get_value(reason, Row),
+    ReasonProp = if Reason == undefined -> []; true ->
+        [{reason, Reason}]
+    end,
+    Obj = {[{key, Key}, {error, Val}] ++ ReasonProp},
     ?JSON_ENCODE(Obj);
 row_to_json(Id0, Row) ->
     Id = case Id0 of
diff --git a/src/fabric/src/fabric_util.erl b/src/fabric/src/fabric_util.erl
index 7655613..92e93a7 100644
--- a/src/fabric/src/fabric_util.erl
+++ b/src/fabric/src/fabric_util.erl
@@ -203,8 +203,6 @@ get_shard([#shard{node = Node, name = Name} | Rest], Opts, Timeout, Factor) ->
         rexi_monitor:stop(Mon)
     end.
 
-error_info({{<<"reduce_overflow_error">>, _} = Error, _Stack}) ->
-    Error;
 error_info({{timeout, _} = Error, _Stack}) ->
     Error;
 error_info({{Error, Reason}, Stack}) ->
diff --git a/src/fabric/src/fabric_view.erl b/src/fabric/src/fabric_view.erl
index 45262e4..dd0fcfd 100644
--- a/src/fabric/src/fabric_view.erl
+++ b/src/fabric/src/fabric_view.erl
@@ -258,6 +258,8 @@ find_next_key([], _, _, _) ->
 find_next_key([Key|Rest], _, _, _) ->
     {Key, Rest}.
 
+transform_row(#view_row{value={[{reduce_overflow_error, Msg}]}}) ->
+    {row, [{key,null}, {id,error}, {value,reduce_overflow_error}, {reason,Msg}]};
 transform_row(#view_row{key=Key, id=reduced, value=Value}) ->
     {row, [{key,Key}, {value,Value}]};
 transform_row(#view_row{key=Key, id=undefined}) ->
diff --git a/test/javascript/tests/view_errors.js b/test/javascript/tests/view_errors.js
index b53a3c7..0d9cd79 100644
--- a/test/javascript/tests/view_errors.js
+++ b/test/javascript/tests/view_errors.js
@@ -174,9 +174,9 @@ couchTests.view_errors = function(debug) {
       // if the reduce grows to fast, throw an overflow error
       var path = "/" + db_name + "/_design/testbig/_view/reduce_too_big";
       xhr = CouchDB.request("GET", path);
-      T(xhr.status == 500);
+      T(xhr.status == 200);
       result = JSON.parse(xhr.responseText);
-      T(result.error == "reduce_overflow_error");
+      T(result.rows[0].error == "reduce_overflow_error");
 
       try {
           db.query(function() {emit(null, null)}, null, {startkey: 2, endkey:1});

-- 
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.