You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2019/07/19 18:02:15 UTC
[couchdb] branch access updated: fix _changes and _all_docs
This is an automated email from the ASF dual-hosted git repository.
jan pushed a commit to branch access
in repository https://gitbox.apache.org/repos/asf/couchdb.git
The following commit(s) were added to refs/heads/access by this push:
new 7787d61 fix _changes and _all_docs
7787d61 is described below
commit 7787d61859ebc4c4a51aea8e317962629609e902
Author: Jan Lehnardt <ja...@apache.org>
AuthorDate: Fri Jul 19 20:02:01 2019 +0200
fix _changes and _all_docs
---
src/couch/src/couch_db.erl | 10 ++++-----
src/couch/src/couch_doc.erl | 4 ++--
src/couch/test/couchdb_access_tests.erl | 6 +++--
src/couch_index/src/couch_index_updater.erl | 14 +++++++-----
src/couch_mrview/src/couch_mrview.erl | 5 +++--
src/fabric/src/fabric_rpc.erl | 2 ++
t.sh | 34 ++++++++++++++---------------
7 files changed, 41 insertions(+), 34 deletions(-)
diff --git a/src/couch/src/couch_db.erl b/src/couch/src/couch_db.erl
index 0f26669..410dd70 100644
--- a/src/couch/src/couch_db.erl
+++ b/src/couch/src/couch_db.erl
@@ -1739,19 +1739,19 @@ open_doc_int(Db, <<?LOCAL_DOC_PREFIX, _/binary>> = Id, Options) ->
[not_found] ->
{not_found, missing}
end;
-open_doc_int(Db, #doc_info{id=Id,revs=[RevInfo|_]}=DocInfo, Options) ->
-% couch_log:info(">>> open_doc_int 2", []),
+open_doc_int(Db, #doc_info{id=Id,revs=[RevInfo|_],access=Access}=DocInfo, Options) ->
+ couch_log:info(">>> open_doc_int 2, DocInfo: ~p", [DocInfo]),
#rev_info{deleted=IsDeleted,rev={Pos,RevId},body_sp=Bp} = RevInfo,
- Doc = make_doc(Db, Id, IsDeleted, Bp, {Pos,[RevId]}),
+ Doc = make_doc(Db, Id, IsDeleted, Bp, {Pos,[RevId]}, Access),
apply_open_options(Db,
{ok, Doc#doc{meta=doc_meta_info(DocInfo, [], Options)}}, Options);
open_doc_int(Db, #full_doc_info{id=Id,rev_tree=RevTree,access=Access}=FullDocInfo, Options) ->
-% couch_log:info(">>> open_doc_int 3, FDI: ~p, Access: ~p", [FullDocInfo, Access]),
+ couch_log:info(">>> open_doc_int 3, FDI: ~p, Access: ~p", [FullDocInfo, Access]),
#doc_info{revs=[#rev_info{deleted=IsDeleted,rev=Rev,body_sp=Bp}|_]} =
DocInfo = couch_doc:to_doc_info(FullDocInfo),
{[{_, RevPath}], []} = couch_key_tree:get(RevTree, [Rev]),
Doc = make_doc(Db, Id, IsDeleted, Bp, RevPath, Access),
-% couch_log:info(">>> ***** open_doc_int 3 made that doc: ~p", [Doc]),
+ couch_log:info(">>> ***** open_doc_int 3 made that doc: ~p", [Doc]),
apply_open_options(Db,
{ok, Doc#doc{meta=doc_meta_info(DocInfo, RevTree, Options)}}, Options);
open_doc_int(Db, Id, Options) ->
diff --git a/src/couch/src/couch_doc.erl b/src/couch/src/couch_doc.erl
index 8eb6845..e7d7095 100644
--- a/src/couch/src/couch_doc.erl
+++ b/src/couch/src/couch_doc.erl
@@ -351,7 +351,7 @@ max_seq(Tree, UpdateSeq) ->
end,
couch_key_tree:fold(FoldFun, UpdateSeq, Tree).
-to_doc_info_path(#full_doc_info{id=Id,rev_tree=Tree,update_seq=FDISeq}) ->
+to_doc_info_path(#full_doc_info{id=Id,rev_tree=Tree,update_seq=FDISeq,access=Access}) ->
RevInfosAndPath = [
{rev_info(Node), Path} || {_Leaf, Path} = Node <-
couch_key_tree:get_all_leafs(Tree)
@@ -364,7 +364,7 @@ to_doc_info_path(#full_doc_info{id=Id,rev_tree=Tree,update_seq=FDISeq}) ->
end, RevInfosAndPath),
[{_RevInfo, WinPath}|_] = SortedRevInfosAndPath,
RevInfos = [RevInfo || {RevInfo, _Path} <- SortedRevInfosAndPath],
- {#doc_info{id=Id, high_seq=max_seq(Tree, FDISeq), revs=RevInfos}, WinPath}.
+ {#doc_info{id=Id, high_seq=max_seq(Tree, FDISeq), revs=RevInfos,access=Access}, WinPath}.
rev_info({#leaf{} = Leaf, {Pos, [RevId | _]}}) ->
#rev_info{
diff --git a/src/couch/test/couchdb_access_tests.erl b/src/couch/test/couchdb_access_tests.erl
index 4b83c28..df58805 100644
--- a/src/couch/test/couchdb_access_tests.erl
+++ b/src/couch/test/couchdb_access_tests.erl
@@ -34,8 +34,6 @@ setup(_) ->
% create users
UserDbUrl = AdminUrl ++ "/_users",
{ok, 201, _, _} = test_request:put(UserDbUrl, ""),
- timer:sleep(10000),
-
UserXUrl = AdminUrl ++ "/_users/x",
UserXBody = "{ \"name\":\"x\", \"roles\": [], \"password\":\"x\", \"type\": \"user\" }",
@@ -44,6 +42,10 @@ setup(_) ->
UserYUrl = AdminUrl ++ "/_users/y",
UserYBody = "{ \"name\":\"y\", \"roles\": [], \"password\":\"y\", \"type\": \"user\" }",
{ok, 201, _, _} = test_request:put(UserYUrl, UserYBody),
+
+ ?debugFmt("~n~p", [test_request:get(UserXUrl)]),
+ ?debugFmt("~n~p", [test_request:get(UserYUrl)]),
+
timer:sleep(10000),
{AdminUrl, XUrl, YUrl}.
diff --git a/src/couch_index/src/couch_index_updater.erl b/src/couch_index/src/couch_index_updater.erl
index ef8582e..e2bf1f6 100644
--- a/src/couch_index/src/couch_index_updater.erl
+++ b/src/couch_index/src/couch_index_updater.erl
@@ -152,14 +152,15 @@ update(Idx, Mod, IdxState) ->
end,
GetInfo = fun
- (#full_doc_info{id=Id, update_seq=Seq, deleted=Del}=FDI) ->
- {Id, Seq, Del, couch_doc:to_doc_info(FDI)};
- (#doc_info{id=Id, high_seq=Seq, revs=[RI|_]}=DI) ->
- {Id, Seq, RI#rev_info.deleted, DI}
+ (#full_doc_info{id=Id, update_seq=Seq, deleted=Del,access=Access}=FDI) ->
+ {Id, Seq, Del, couch_doc:to_doc_info(FDI), Access};
+ (#doc_info{id=Id, high_seq=Seq, revs=[RI|_],access=Access}=DI) ->
+ {Id, Seq, RI#rev_info.deleted, DI, Access}
end,
LoadDoc = fun(DI) ->
- {DocId, Seq, Deleted, DocInfo} = GetInfo(DI),
+
+ {DocId, Seq, Deleted, DocInfo, Access} = GetInfo(DI),
case {IncludeDesign, DocId} of
{false, <<"_design/", _/binary>>} ->
@@ -170,7 +171,8 @@ update(Idx, Mod, IdxState) ->
{ok, Doc} = couch_db:open_doc_int(Db, DocInfo, DocOpts),
[RevInfo] = DocInfo#doc_info.revs,
Doc1 = Doc#doc{
- meta = [{body_sp, RevInfo#rev_info.body_sp}]
+ meta = [{body_sp, RevInfo#rev_info.body_sp}],
+ access = Access
},
{Doc1, Seq}
end
diff --git a/src/couch_mrview/src/couch_mrview.erl b/src/couch_mrview/src/couch_mrview.erl
index 3fda8e0..8222dde 100644
--- a/src/couch_mrview/src/couch_mrview.erl
+++ b/src/couch_mrview/src/couch_mrview.erl
@@ -258,7 +258,7 @@ query_changes_access(Db, StartSeq, Fun, Options, Acc) ->
({row, Props}, Acc0) ->
% turn row into FDI
Value = couch_util:get_value(value, Props),
- [_Owner, Seq] = couch_util:get_value(key, Props),
+ [Owner, Seq] = couch_util:get_value(key, Props),
Rev = couch_util:get_value(rev, Value),
Deleted = couch_util:get_value(deleted, Value, false),
@@ -270,7 +270,8 @@ query_changes_access(Db, StartSeq, Fun, Options, Acc) ->
rev_tree = [{list_to_integer(Pos), {?l2b(RevId), #leaf{deleted=Deleted, ptr=BodySp, seq=Seq, sizes=#size_info{}}, []}}],
deleted = Deleted,
update_seq = 0,
- sizes = #size_info{}
+ sizes = #size_info{},
+ access = [Owner]
},
Fun(FDI, Acc0);
(_Else, Acc0) ->
diff --git a/src/fabric/src/fabric_rpc.erl b/src/fabric/src/fabric_rpc.erl
index 2b00a36..fd1d170 100644
--- a/src/fabric/src/fabric_rpc.erl
+++ b/src/fabric/src/fabric_rpc.erl
@@ -503,6 +503,7 @@ changes_enumerator(#full_doc_info{} = FDI, Acc) ->
changes_enumerator(#doc_info{id= <<"_local/", _/binary>>, high_seq=Seq}, Acc) ->
{ok, Acc#fabric_changes_acc{seq = Seq, pending = Acc#fabric_changes_acc.pending-1}};
changes_enumerator(DocInfo, Acc) ->
+ couch_log:info("~n@@@@@@@@@@@ fabric_rpc:changes_enumerator() DocInfo: ~p~n", [DocInfo]),
#fabric_changes_acc{
db = Db,
args = #changes_args{
@@ -535,6 +536,7 @@ changes_enumerator(DocInfo, Acc) ->
{ok, Acc#fabric_changes_acc{seq = Seq, pending = Pending-1}}.
doc_member(Shard, DocInfo, Opts, Filter) ->
+ couch_log:info("~n^^^^^^^^^^^^^^^^^^^^^ fabric_rpc:doc_member() DocInfo: ~p~n", [DocInfo]),
case couch_db:open_doc(Shard, DocInfo, [deleted | Opts]) of
{ok, Doc} ->
{doc, maybe_filtered_json_doc(Doc, Opts, Filter)};
diff --git a/t.sh b/t.sh
index e9a7694..8b89269 100755
--- a/t.sh
+++ b/t.sh
@@ -1,39 +1,39 @@
#!/bin/sh -x
DB=http://a:a@127.0.0.1:15984 #
-XDB=http://xxxx:x@127.0.0.1:15984
+XDB=http://x:x@127.0.0.1:15984
YDB=http://y:y@127.0.0.1:15984
-curl -sX PUT $DB/_users/org.couchdb.user:xxxx -d @user.json > /dev/null #
+curl -sX PUT $DB/_users/org.couchdb.user:x -d @user.json > /dev/null #
curl -sX PUT $DB/_users/org.couchdb.user:y -d @user2.json > /dev/null #
curl -sX DELETE $DB/db
curl -sX PUT $DB/db?q=1'&access=true'
##############
-curl -sX PUT $DB/db/a -d '{"a":1,"_access":["xxxx"]}'
+curl -sX PUT $DB/db/a -d '{"a":1,"_access":["x"]}'
curl -s $DB/db/a
curl -s $XDB/db/a
curl -s $YDB/db/a
#
-# curl -sX PUT $DB/db/b -d '{"b":2,"_access":["x"]}'
-# curl -sX PUT $DB/db/c -d '{"c":3,"_access":["y"]}'
-# curl -X PUT $XDB/db/c?rev="1-0865d643568aa9be6bcdc15d88b25912" -d '{"c":6,"_access":["y"]}'
-# #
-# curl -sX PUT $DB/db/d -d '{"d":4,"_access":["y"]}'
-# #
-# curl -sX DELETE $DB/db/a?rev="1-967a00dff5e02add41819138abb3284d"
+curl -sX PUT $DB/db/b -d '{"b":2,"_access":["x"]}'
+curl -sX PUT $DB/db/c -d '{"c":3,"_access":["y"]}'
+curl -X PUT $XDB/db/c?rev="1-0865d643568aa9be6bcdc15d88b25912" -d '{"c":6,"_access":["y"]}'
+#
+curl -sX PUT $DB/db/d -d '{"d":4,"_access":["y"]}'
#
+curl -sX DELETE $DB/db/a?rev="1-967a00dff5e02add41819138abb3284d"
+
# echo
# echo "setup done"
# echo
#
# #
-# curl -s $DB/db/_all_docs?include_docs=true
-# curl -s $XDB/db/_all_docs?include_docs=true
-# curl -s $YDB/db/_all_docs?include_docs=true
+curl -s $DB/db/_all_docs?include_docs=true
+curl -s $XDB/db/_all_docs?include_docs=true
+curl -s $YDB/db/_all_docs?include_docs=true
# #
-# curl -s $DB/db/_changes?include_docs=true
-# curl -s $XDB/db/_changes?include_docs=true
-# curl -s $YDB/db/_changes?include_docs=true
+curl -s $DB/db/_changes?include_docs=true
+curl -s $XDB/db/_changes?include_docs=true
+curl -s $YDB/db/_changes?include_docs=true
# # #
# curl -s $DB/db/a
# curl -s $DB/db/b
@@ -49,7 +49,7 @@ curl -s $YDB/db/a
# curl -s $YDB/db/b
# curl -s $YDB/db/c
# curl -s $YDB/db/d
-#
+# #
# curl -sX PUT $XDB/db/b?rev="1-809cfddb59a4f02dc1009785fad978b4" -d '{"b":5,"_access":["x"]}'
# curl -sX PUT $XDB/db/c?rev="1-0865d643568aa9be6bcdc15d88b25912" -d '{"c":6,"_access":["y"]}'
# curl -sX PUT $XDB/db/d?rev="1-87adddda059e643409c43bea87c37bfe" -d '{"d":7,"_access":["y"]}'