You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by mi...@apache.org on 2014/10/30 00:19:56 UTC

[1/4] couch commit: updated refs/heads/2365-fix-failed-multipart-process-leak to f02a101

Repository: couchdb-couch
Updated Branches:
  refs/heads/2365-fix-failed-multipart-process-leak fd7f88895 -> f02a1013d (forced update)


Respond with HTTP 400 Bad Request on invalid revision number

CouchDB should return HTTP 400 instead of HTTP 500 response
when revision number isn't integer like "foo-bar" as like as it does
for completely invalid revisions like "foo".

COUCHDB-2375


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

Branch: refs/heads/2365-fix-failed-multipart-process-leak
Commit: ed360325cacbc3f5320b28f3c42ef2bc3ca3c716
Parents: 46cb6a4
Author: Alexander Shorin <kx...@apache.org>
Authored: Fri Oct 10 22:00:03 2014 +0400
Committer: Alexander Shorin <kx...@apache.org>
Committed: Mon Oct 13 21:25:21 2014 +0400

----------------------------------------------------------------------
 src/couch_doc.erl        |  8 +++++++-
 test/couch_doc_tests.erl | 22 ++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/ed360325/src/couch_doc.erl
----------------------------------------------------------------------
diff --git a/src/couch_doc.erl b/src/couch_doc.erl
index de3141d..6fc9b09 100644
--- a/src/couch_doc.erl
+++ b/src/couch_doc.erl
@@ -140,7 +140,13 @@ parse_rev(Rev) when is_binary(Rev) ->
 parse_rev(Rev) when is_list(Rev) ->
     SplitRev = lists:splitwith(fun($-) -> false; (_) -> true end, Rev),
     case SplitRev of
-        {Pos, [$- | RevId]} -> {list_to_integer(Pos), parse_revid(RevId)};
+        {Pos, [$- | RevId]} ->
+            IntPos = try list_to_integer(Pos) of
+                Val -> Val
+            catch
+                error:badarg -> throw({bad_request, <<"Invalid rev format">>})
+            end,
+            {IntPos, parse_revid(RevId)};
         _Else -> throw({bad_request, <<"Invalid rev format">>})
     end;
 parse_rev(_BadRev) ->

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/ed360325/test/couch_doc_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_doc_tests.erl b/test/couch_doc_tests.erl
new file mode 100644
index 0000000..ca944dc
--- /dev/null
+++ b/test/couch_doc_tests.erl
@@ -0,0 +1,22 @@
+% 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_doc_tests).
+
+-include_lib("couch/include/couch_eunit.hrl").
+
+
+parse_rev_test() ->
+    ?assertEqual({1, <<"123">>}, couch_doc:parse_rev("1-123")),
+    ?assertEqual({1, <<"123">>}, couch_doc:parse_rev(<<"1-123">>)),
+    ?assertException(throw, {bad_request, _}, couch_doc:parse_rev("1f-123")),
+    ?assertException(throw, {bad_request, _}, couch_doc:parse_rev("bar")).


[2/4] couch commit: updated refs/heads/2365-fix-failed-multipart-process-leak to f02a101

Posted by mi...@apache.org.
Move query server related stats from couch to couch_mrview


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

Branch: refs/heads/2365-fix-failed-multipart-process-leak
Commit: c6c3c1eec396574b792b4e86b96f48816a0fc0ee
Parents: ed36032
Author: Alexander Shorin <kx...@apache.org>
Authored: Mon Oct 13 23:51:17 2014 +0400
Committer: Alexander Shorin <kx...@apache.org>
Committed: Mon Oct 13 23:51:17 2014 +0400

----------------------------------------------------------------------
 priv/stats_descriptions.cfg | 8 --------
 1 file changed, 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/c6c3c1ee/priv/stats_descriptions.cfg
----------------------------------------------------------------------
diff --git a/priv/stats_descriptions.cfg b/priv/stats_descriptions.cfg
index 998bb77..53aca37 100644
--- a/priv/stats_descriptions.cfg
+++ b/priv/stats_descriptions.cfg
@@ -182,11 +182,3 @@
     {type, counter},
     {desc, <<"number of couch_server LRU operations skipped">>}
 ]}.
-{[couchdb, couchjs, map_doc], [
-    {type, counter},
-    {desc, <<"number of documents mapped in the couchjs view server">>}
-]}.
-{[couchdb, couchjs, emits], [
-    {type, counter},
-    {desc, <<"number of invocations of `emit' in map functions in the couchjs view server">>}
-]}.


[4/4] couch commit: updated refs/heads/2365-fix-failed-multipart-process-leak to f02a101

Posted by mi...@apache.org.
Make couch_stream monitor the stream opener

This commit fixes a process leak which would happen when a process
opened a couch_stream and exited with reason normal before closing
the stream.

This patch makes the couch_stream gen_server monitor the process
which opens the stream. When that monitor sends an exit signal
the couch_stream gen_server is stopped and the process dies.

Closes COUCHDB-2365


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

Branch: refs/heads/2365-fix-failed-multipart-process-leak
Commit: f02a1013dc61f011ccb58f1fddb689a93795af98
Parents: 40c5c85
Author: Mike Wallace <mi...@apache.org>
Authored: Tue Oct 7 23:45:11 2014 +0100
Committer: Mike Wallace <mi...@apache.org>
Committed: Wed Oct 29 23:12:27 2014 +0000

----------------------------------------------------------------------
 src/couch_stream.erl        | 10 ++++++++--
 test/couch_stream_tests.erl | 18 +++++++++++++++++-
 2 files changed, 25 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/f02a1013/src/couch_stream.erl
----------------------------------------------------------------------
diff --git a/src/couch_stream.erl b/src/couch_stream.erl
index e71542c..6877f0f 100644
--- a/src/couch_stream.erl
+++ b/src/couch_stream.erl
@@ -29,6 +29,7 @@
 
 -record(stream,
     {fd = 0,
+    opener_monitor,
     written_pointers=[],
     buffer_list = [],
     buffer_len = 0,
@@ -50,7 +51,7 @@ open(Fd) ->
     open(Fd, []).
 
 open(Fd, Options) ->
-    gen_server:start_link(couch_stream, {Fd, Options}, []).
+    gen_server:start_link(couch_stream, {Fd, self(), Options}, []).
 
 close(Pid) ->
     gen_server:call(Pid, close, infinity).
@@ -197,7 +198,7 @@ write(Pid, Bin) ->
     gen_server:call(Pid, {write, Bin}, infinity).
 
 
-init({Fd, Options}) ->
+init({Fd, OpenerPid, Options}) ->
     {EncodingFun, EndEncodingFun} =
     case couch_util:get_value(encoding, Options, identity) of
     identity ->
@@ -207,6 +208,7 @@ init({Fd, Options}) ->
     end,
     {ok, #stream{
             fd=Fd,
+            opener_monitor=erlang:monitor(process, OpenerPid),
             md5=couch_util:md5_init(),
             identity_md5=couch_util:md5_init(),
             encoding_fun=EncodingFun,
@@ -266,6 +268,7 @@ handle_call({write, Bin}, _From, Stream) ->
 handle_call(close, _From, Stream) ->
     #stream{
         fd = Fd,
+        opener_monitor = MonRef,
         written_len = WrittenLen,
         written_pointers = Written,
         buffer_list = Buffer,
@@ -288,6 +291,7 @@ handle_call(close, _From, Stream) ->
         StreamLen = WrittenLen + iolist_size(WriteBin2),
         {StreamInfo, StreamLen, IdenLen, Md5Final, IdenMd5Final}
     end,
+    erlang:demonitor(MonRef),
     {stop, normal, Result, Stream}.
 
 handle_cast(_Msg, State) ->
@@ -296,5 +300,7 @@ handle_cast(_Msg, State) ->
 code_change(_OldVsn, State, _Extra) ->
     {ok, State}.
 
+handle_info({'DOWN', Ref, _, _, _}, #stream{opener_monitor=Ref} = State) ->
+    {stop, normal, State};
 handle_info(_Info, State) ->
     {noreply, State}.

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/f02a1013/test/couch_stream_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_stream_tests.erl b/test/couch_stream_tests.erl
index 3e84ca0..e12e714 100644
--- a/test/couch_stream_tests.erl
+++ b/test/couch_stream_tests.erl
@@ -38,7 +38,8 @@ stream_test_() ->
                 fun should_return_stream_size_on_close/1,
                 fun should_return_valid_pointers/1,
                 fun should_recall_last_pointer_position/1,
-                fun should_stream_more_with_4K_chunk_size/1
+                fun should_stream_more_with_4K_chunk_size/1,
+                fun should_stop_on_normal_exit_of_stream_opener/1
             ]
         }
     }.
@@ -94,6 +95,21 @@ should_stream_more_with_4K_chunk_size({Fd, _}) ->
     ?_assertMatch({[{0, 4100}, {4106, 1020}], 5120, _, _, _},
                   couch_stream:close(Stream)).
 
+should_stop_on_normal_exit_of_stream_opener({Fd, _}) ->
+    RunnerPid = self(),
+    OpenerPid = spawn(
+        fun() ->
+            {ok, StreamPid} = couch_stream:open(Fd),
+            RunnerPid ! {pid, StreamPid}
+        end),
+    StreamPid = receive
+        {pid, StreamPid0} -> StreamPid0
+    end,
+    % Confirm the validity of the test by verifying the stream opener has died
+    ?_assertNot(is_process_alive(OpenerPid)),
+    % Verify the stream itself has also died
+    ?_assertNot(is_process_alive(StreamPid)).
+
 
 read_all(Fd, PosList) ->
     Data = couch_stream:foldl(Fd, PosList, fun(Bin, Acc) -> [Bin, Acc] end, []),


[3/4] couch commit: updated refs/heads/2365-fix-failed-multipart-process-leak to f02a101

Posted by mi...@apache.org.
Remove couch_query_servers:map_docs/2

It's not being used since couch_mrview introduction which provides own
couch_mrview_updater:map_docs/2 and actually uses it instead.


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

Branch: refs/heads/2365-fix-failed-multipart-process-leak
Commit: 40c5c85d3bf60c73f28389394058ec1f27207335
Parents: c6c3c1e
Author: Alexander Shorin <kx...@apache.org>
Authored: Mon Oct 13 23:54:44 2014 +0400
Committer: Alexander Shorin <kx...@apache.org>
Committed: Mon Oct 13 23:54:44 2014 +0400

----------------------------------------------------------------------
 src/couch_query_servers.erl | 25 +------------------------
 1 file changed, 1 insertion(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/40c5c85d/src/couch_query_servers.erl
----------------------------------------------------------------------
diff --git a/src/couch_query_servers.erl b/src/couch_query_servers.erl
index 13b0b91..d38f040 100644
--- a/src/couch_query_servers.erl
+++ b/src/couch_query_servers.erl
@@ -13,7 +13,7 @@
 -module(couch_query_servers).
 
 -export([try_compile/4]).
--export([start_doc_map/3, map_docs/2, map_doc_raw/2, stop_doc_map/1, raw_to_ejson/1]).
+-export([start_doc_map/3, map_doc_raw/2, stop_doc_map/1, raw_to_ejson/1]).
 -export([reduce/3, rereduce/3,validate_doc_update/5]).
 -export([filter_docs/5]).
 -export([filter_view/3]).
@@ -56,29 +56,6 @@ start_doc_map(Lang, Functions, Lib) ->
     end, Functions),
     {ok, Proc}.
 
-map_docs(Proc, Docs) ->
-    % send the documents
-    Results = lists:map(
-        fun(Doc) ->
-            Json = couch_doc:to_json_obj(Doc, []),
-
-            FunsResults = proc_prompt(Proc, [<<"map_doc">>, Json]),
-            % the results are a json array of function map yields like this:
-            % [FunResults1, FunResults2 ...]
-            % where funresults is are json arrays of key value pairs:
-            % [[Key1, Value1], [Key2, Value2]]
-            % Convert the key, value pairs to tuples like
-            % [{Key1, Value1}, {Key2, Value2}]
-            lists:map(
-                fun(FunRs) ->
-                    [list_to_tuple(FunResult) || FunResult <- FunRs]
-                end,
-            FunsResults)
-        end,
-        Docs),
-    couch_stats:increment_counter([couchdb, couchjs, map_doc], length(Docs)),
-    {ok, Results}.
-
 map_doc_raw(Proc, Doc) ->
     Json = couch_doc:to_json_obj(Doc, []),
     {ok, proc_prompt_raw(Proc, [<<"map_doc">>, Json])}.