You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2016/04/11 16:27:28 UTC

[1/4] couch commit: updated refs/heads/local-docs-2978 to 2531c3b [Forced Update!]

Repository: couchdb-couch
Updated Branches:
  refs/heads/local-docs-2978 64b29d7ff -> 2531c3b81 (forced update)


Fix normalize_dbname to work with slashes

We shouldn't rely on dbname being the last part of path. Since database
name could include slashes.
normalize_dbname as the name suggests should accept either binary or
list and return only binary.


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

Branch: refs/heads/local-docs-2978
Commit: 910770d3faf0a23bd8dfb08abc6906fe45de4a41
Parents: c256ef5
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Wed Mar 30 15:02:52 2016 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Thu Apr 7 09:34:19 2016 -0700

----------------------------------------------------------------------
 src/couch_db.erl | 80 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 77 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/910770d3/src/couch_db.erl
----------------------------------------------------------------------
diff --git a/src/couch_db.erl b/src/couch_db.erl
index 1a9f669..c34d59a 100644
--- a/src/couch_db.erl
+++ b/src/couch_db.erl
@@ -1513,10 +1513,8 @@ select_gt(V1, _V2) -> V1.
 select_lt(V1, V2) when V1 > V2 -> V2;
 select_lt(V1, _V2) -> V1.
 
-normalize_dbname(<<"shards/", _/binary>> = Path) ->
-    lists:last(binary:split(mem3:dbname(Path), <<"/">>, [global]));
 normalize_dbname(DbName) ->
-    DbName.
+    mem3:dbname(DbName).
 
 validate_dbname(DbName) when is_list(DbName) ->
     validate_dbname(?l2b(DbName));
@@ -1546,3 +1544,79 @@ is_systemdb(<<"shards/", _/binary>> = Path) when is_binary(Path) ->
     is_systemdb(normalize_dbname(Path));
 is_systemdb(DbName) when is_binary(DbName) ->
     lists:member(DbName, ?SYSTEM_DATABASES).
+
+-ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
+
+setup() ->
+    ok = meck:new(couch_db_plugin, [passthrough]),
+    ok = meck:expect(couch_db_plugin, validate_dbname, fun(_, _) -> false end),
+    ok.
+
+teardown(_) ->
+    (catch meck:unload(couch_db_plugin)).
+
+validate_dbname_success_test_() ->
+    Cases =
+        generate_cases_with_shards("long/co$mplex-/path+/_something")
+        ++ generate_cases_with_shards("something")
+        ++ lists:append(
+            [generate_cases_with_shards(?b2l(SystemDb))
+                || SystemDb <- ?SYSTEM_DATABASES]),
+    {
+        foreach, fun setup/0, fun teardown/1,
+        [{test_name(A), fun() -> should_pass_validate_dbname(A) end} || {_, A} <- Cases]
+    }.
+
+validate_dbname_fail_test_() ->
+    Cases = generate_cases("_long/co$mplex-/path+/_something")
+       ++ generate_cases("_something")
+       ++ generate_cases_with_shards("long/co$mplex-/path+/_something#")
+       ++ generate_cases_with_shards("long/co$mplex-/path+/some.thing"),
+    {
+        foreach, fun setup/0, fun teardown/1,
+        [{test_name(A), fun() -> should_fail_validate_dbname(A) end} || {_, A} <- Cases]
+    }.
+
+validate_normalize_dbname_test_() ->
+    Cases = generate_cases_with_shards("long/co$mplex-/path+/_something")
+       ++ generate_cases_with_shards("something"),
+    [{test_name(B), fun() -> should_normalize_dbname(A, B) end} || {A, B} <- Cases].
+
+
+should_pass_validate_dbname(DbName) ->
+    {test_name(DbName), ?_assertEqual(ok, validate_dbname(DbName))}.
+
+should_fail_validate_dbname(DbName) ->
+    {test_name(DbName), ?_test(begin
+        Result = validate_dbname(DbName),
+        ?assertMatch({error, {illegal_database_name, _}}, Result),
+        {error, {illegal_database_name, FailedDbName}} = Result,
+        ?assertEqual(to_binary(DbName), FailedDbName),
+        ok
+    end)}.
+
+should_normalize_dbname(Arg, DbName) ->
+    Result = ?l2b(filename:rootname(Arg)),
+    {test_name(DbName), ?_assertEqual(Result, normalize_dbname(DbName))}.
+
+to_binary(DbName) when is_list(DbName) ->
+    ?l2b(DbName);
+to_binary(DbName) when is_binary(DbName) ->
+    DbName.
+
+test_name(DbName) ->
+    lists:flatten(io_lib:format("~p", [DbName])).
+
+generate_cases_with_shards(DbName) ->
+    DbNameWithShard = add_shard(DbName),
+    Cases = [DbName, ?l2b(DbName), DbNameWithShard, ?l2b(DbNameWithShard)],
+    [{DbName, Case} || Case <- Cases].
+
+add_shard(DbName) ->
+    "shards/00000000-3fffffff/" ++ DbName ++ ".1415960794".
+
+generate_cases(DbName) ->
+    [{DbName, DbName}, {DbName, ?l2b(DbName)}].
+
+-endif.


[3/4] couch commit: updated refs/heads/local-docs-2978 to 2531c3b

Posted by ga...@apache.org.
Revert "Merge remote branch 'github/pr/158'"

This reverts commit 05b40a8ef7e544b1313018d000f0c6d3d6255f1a, reversing
changes made to c256ef5d098dce5b9624e117dab912205334c327.


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

Branch: refs/heads/local-docs-2978
Commit: 79c98d8ceef2004350c6c3086c083ee021f3a854
Parents: 05b40a8
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Thu Apr 7 10:50:54 2016 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Thu Apr 7 10:50:54 2016 -0700

----------------------------------------------------------------------
 src/couch_db.erl | 80 ++-------------------------------------------------
 1 file changed, 3 insertions(+), 77 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/79c98d8c/src/couch_db.erl
----------------------------------------------------------------------
diff --git a/src/couch_db.erl b/src/couch_db.erl
index c34d59a..1a9f669 100644
--- a/src/couch_db.erl
+++ b/src/couch_db.erl
@@ -1513,8 +1513,10 @@ select_gt(V1, _V2) -> V1.
 select_lt(V1, V2) when V1 > V2 -> V2;
 select_lt(V1, _V2) -> V1.
 
+normalize_dbname(<<"shards/", _/binary>> = Path) ->
+    lists:last(binary:split(mem3:dbname(Path), <<"/">>, [global]));
 normalize_dbname(DbName) ->
-    mem3:dbname(DbName).
+    DbName.
 
 validate_dbname(DbName) when is_list(DbName) ->
     validate_dbname(?l2b(DbName));
@@ -1544,79 +1546,3 @@ is_systemdb(<<"shards/", _/binary>> = Path) when is_binary(Path) ->
     is_systemdb(normalize_dbname(Path));
 is_systemdb(DbName) when is_binary(DbName) ->
     lists:member(DbName, ?SYSTEM_DATABASES).
-
--ifdef(TEST).
--include_lib("eunit/include/eunit.hrl").
-
-setup() ->
-    ok = meck:new(couch_db_plugin, [passthrough]),
-    ok = meck:expect(couch_db_plugin, validate_dbname, fun(_, _) -> false end),
-    ok.
-
-teardown(_) ->
-    (catch meck:unload(couch_db_plugin)).
-
-validate_dbname_success_test_() ->
-    Cases =
-        generate_cases_with_shards("long/co$mplex-/path+/_something")
-        ++ generate_cases_with_shards("something")
-        ++ lists:append(
-            [generate_cases_with_shards(?b2l(SystemDb))
-                || SystemDb <- ?SYSTEM_DATABASES]),
-    {
-        foreach, fun setup/0, fun teardown/1,
-        [{test_name(A), fun() -> should_pass_validate_dbname(A) end} || {_, A} <- Cases]
-    }.
-
-validate_dbname_fail_test_() ->
-    Cases = generate_cases("_long/co$mplex-/path+/_something")
-       ++ generate_cases("_something")
-       ++ generate_cases_with_shards("long/co$mplex-/path+/_something#")
-       ++ generate_cases_with_shards("long/co$mplex-/path+/some.thing"),
-    {
-        foreach, fun setup/0, fun teardown/1,
-        [{test_name(A), fun() -> should_fail_validate_dbname(A) end} || {_, A} <- Cases]
-    }.
-
-validate_normalize_dbname_test_() ->
-    Cases = generate_cases_with_shards("long/co$mplex-/path+/_something")
-       ++ generate_cases_with_shards("something"),
-    [{test_name(B), fun() -> should_normalize_dbname(A, B) end} || {A, B} <- Cases].
-
-
-should_pass_validate_dbname(DbName) ->
-    {test_name(DbName), ?_assertEqual(ok, validate_dbname(DbName))}.
-
-should_fail_validate_dbname(DbName) ->
-    {test_name(DbName), ?_test(begin
-        Result = validate_dbname(DbName),
-        ?assertMatch({error, {illegal_database_name, _}}, Result),
-        {error, {illegal_database_name, FailedDbName}} = Result,
-        ?assertEqual(to_binary(DbName), FailedDbName),
-        ok
-    end)}.
-
-should_normalize_dbname(Arg, DbName) ->
-    Result = ?l2b(filename:rootname(Arg)),
-    {test_name(DbName), ?_assertEqual(Result, normalize_dbname(DbName))}.
-
-to_binary(DbName) when is_list(DbName) ->
-    ?l2b(DbName);
-to_binary(DbName) when is_binary(DbName) ->
-    DbName.
-
-test_name(DbName) ->
-    lists:flatten(io_lib:format("~p", [DbName])).
-
-generate_cases_with_shards(DbName) ->
-    DbNameWithShard = add_shard(DbName),
-    Cases = [DbName, ?l2b(DbName), DbNameWithShard, ?l2b(DbNameWithShard)],
-    [{DbName, Case} || Case <- Cases].
-
-add_shard(DbName) ->
-    "shards/00000000-3fffffff/" ++ DbName ++ ".1415960794".
-
-generate_cases(DbName) ->
-    [{DbName, DbName}, {DbName, ?l2b(DbName)}].
-
--endif.


[2/4] couch commit: updated refs/heads/local-docs-2978 to 2531c3b

Posted by ga...@apache.org.
Merge remote branch 'github/pr/158'

This closes #158

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


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

Branch: refs/heads/local-docs-2978
Commit: 05b40a8ef7e544b1313018d000f0c6d3d6255f1a
Parents: c256ef5 910770d
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Thu Apr 7 09:35:26 2016 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Thu Apr 7 09:35:26 2016 -0700

----------------------------------------------------------------------
 src/couch_db.erl | 80 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 77 insertions(+), 3 deletions(-)
----------------------------------------------------------------------



[4/4] couch commit: updated refs/heads/local-docs-2978 to 2531c3b

Posted by ga...@apache.org.
Create md5 etag for _local docs

This makes a unique ETAG for _local docs, so that they are cached
correctly, and fetched again when the document changes.

fixes COUCHDB-2978


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

Branch: refs/heads/local-docs-2978
Commit: 2531c3b81aa5430d50b32ae44f2a034681ddce69
Parents: 79c98d8
Author: Garren Smith <ga...@gmail.com>
Authored: Thu Apr 7 16:06:31 2016 +0200
Committer: Garren Smith <ga...@gmail.com>
Committed: Mon Apr 11 16:27:12 2016 +0200

----------------------------------------------------------------------
 src/couch_httpd.erl       | 15 ++++++++++++---
 test/couch_etag_tests.erl | 28 ++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/2531c3b8/src/couch_httpd.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd.erl b/src/couch_httpd.erl
index 7370594..c4f5a9c 100644
--- a/src/couch_httpd.erl
+++ b/src/couch_httpd.erl
@@ -21,7 +21,7 @@
 -export([make_fun_spec_strs/1]).
 -export([make_arity_1_fun/1, make_arity_2_fun/1, make_arity_3_fun/1]).
 -export([parse_form/1,json_body/1,json_body_obj/1,body/1]).
--export([doc_etag/1, make_etag/1, etag_match/2, etag_respond/3, etag_maybe/2]).
+-export([doc_etag/1, doc_etag/3, make_etag/1, etag_match/2, etag_respond/3, etag_maybe/2]).
 -export([primary_header_value/2,partition/1,serve_file/3,serve_file/4, server_header/0]).
 -export([start_chunked_response/3,send_chunk/2,log_request/2]).
 -export([start_response_length/4, start_response/3, send/2]).
@@ -594,8 +594,17 @@ maybe_decompress(Httpd, Body) ->
         throw({bad_ctype, [Else, " is not a supported content encoding."]})
     end.
 
-doc_etag(#doc{revs={Start, [DiskRev|_]}}) ->
-    "\"" ++ ?b2l(couch_doc:rev_to_str({Start, DiskRev})) ++ "\"".
+doc_etag(#doc{id=Id, body=Body, revs={Start, [DiskRev|_]}}) ->
+    doc_etag(Id, Body, {Start, DiskRev}).
+
+doc_etag(<<"_local/", _/binary>>, Body, {Start, DiskRev}) ->
+    make_etag({Start, DiskRev, Body});
+doc_etag(_Id, _Body, {Start, DiskRev}) ->
+    rev_etag({Start, DiskRev}).
+
+rev_etag({Start, DiskRev}) ->
+    Rev = couch_doc:rev_to_str({Start, DiskRev}),
+     <<$", Rev/binary, $">>.
 
 make_etag(Term) ->
     <<SigInt:128/integer>> = couch_crypto:hash(md5, term_to_binary(Term)),

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/2531c3b8/test/couch_etag_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_etag_tests.erl b/test/couch_etag_tests.erl
new file mode 100644
index 0000000..0e3125b
--- /dev/null
+++ b/test/couch_etag_tests.erl
@@ -0,0 +1,28 @@
+% 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_etag_tests).
+
+-include_lib("eunit/include/eunit.hrl").
+
+local_with_empty_body_test() ->
+    Etag = couch_httpd:doc_etag(<<"_local/local-and-empty">>, {[]}, {0, <<"1">>}),
+    ?assertEqual(Etag, <<"\"5ZVXQYO7VLEOU0TL9VXDNP5PV\"">>).
+
+
+local_with_body_test() ->
+    Etag = couch_httpd:doc_etag(<<"_local/local-with-body">>, {[{<<"hello">>,<<"world">>},{<<"relax">>,true}]}, {0, <<"1">>}),
+    ?assertEqual(Etag, <<"\"CEFXP6WH8OKYIWO1GLGBHKCCA\"">>).
+
+normal_doc_uses_rev() ->
+    Etag = couch_httpd:doc_etag(<<"nomal-doc">>, {[{<<"hello">>,<<"again">>},{<<"relax">>,true}]}, {1, <<"efda11e34e88ebe31a2f83e84a0435b6">>}),
+    ?assertEqual(Etag, <<"\"2-efda11e34e88ebe31a2f83e84a0435b6\"">>).