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/04/04 21:04:34 UTC
[5/6] chttpd commit: updated
refs/heads/COUCHDB-3287-pluggable-storage-engines to e70ca89
Remove public db record
COUCHDB-3288
Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/04d26cc7
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/04d26cc7
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/04d26cc7
Branch: refs/heads/COUCHDB-3287-pluggable-storage-engines
Commit: 04d26cc72cf2b3334e1796e48955e8cd79488484
Parents: 7400210
Author: Paul J. Davis <pa...@gmail.com>
Authored: Wed Feb 1 12:32:15 2017 -0600
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Tue Apr 4 16:03:12 2017 -0500
----------------------------------------------------------------------
src/chttpd_db.erl | 21 ++++++++++++---------
src/chttpd_external.erl | 22 ++++++++++++++--------
src/chttpd_show.erl | 3 ++-
3 files changed, 28 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/04d26cc7/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index 37e4669..aed649d 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -84,7 +84,7 @@ handle_changes_req1(#httpd{}=Req, Db) ->
#changes_args{filter=Raw, style=Style} = Args0 = parse_changes_query(Req),
ChangesArgs = Args0#changes_args{
filter_fun = couch_changes:configure_filter(Raw, Style, Req, Db),
- db_open_options = [{user_ctx, Db#db.user_ctx}]
+ db_open_options = [{user_ctx, couch_db:get_user_ctx(Db)}]
},
Max = chttpd:chunked_response_buffer_size(),
case ChangesArgs#changes_args.feed of
@@ -253,7 +253,7 @@ handle_view_cleanup_req(Req, Db) ->
handle_design_req(#httpd{
path_parts=[_DbName, _Design, Name, <<"_",_/binary>> = Action | _Rest]
}=Req, Db) ->
- DbName = mem3:dbname(Db#db.name),
+ DbName = mem3:dbname(couch_db:name(Db)),
case ddoc_cache:open(DbName, <<"_design/", Name/binary>>) of
{ok, DDoc} ->
Handler = chttpd_handlers:design_handler(Action, fun bad_action_req/3),
@@ -309,7 +309,8 @@ delete_db_req(#httpd{}=Req, DbName) ->
do_db_req(#httpd{path_parts=[DbName|_], user_ctx=Ctx}=Req, Fun) ->
fabric:get_security(DbName, [{user_ctx,Ctx}]), % calls check_is_reader
- Fun(Req, #db{name=DbName, user_ctx=Ctx}).
+ {ok, Db} = couch_db:clustered_db(DbName, Ctx),
+ Fun(Req, Db).
db_req(#httpd{method='GET',path_parts=[DbName]}=Req, _Db) ->
% measure the time required to generate the etag, see if it's worth it
@@ -767,16 +768,17 @@ db_doc_req(#httpd{method='PUT', user_ctx=Ctx}=Req, Db, DocId) ->
} = parse_doc_query(Req),
couch_doc:validate_docid(DocId),
+ DbName = couch_db:name(Db),
W = chttpd:qs_value(Req, "w", integer_to_list(mem3:quorum(Db))),
Options = [{user_ctx,Ctx}, {w,W}],
- Loc = absolute_uri(Req, [$/, couch_util:url_encode(Db#db.name),
+ Loc = absolute_uri(Req, [$/, couch_util:url_encode(DbName),
$/, couch_util:url_encode(DocId)]),
RespHeaders = [{"Location", Loc}],
case couch_util:to_list(couch_httpd:header_value(Req, "Content-Type")) of
("multipart/related;" ++ _) = ContentType ->
couch_httpd:check_max_request_length(Req),
- couch_httpd_multipart:num_mp_writers(mem3:n(mem3:dbname(Db#db.name), DocId)),
+ couch_httpd_multipart:num_mp_writers(mem3:n(mem3:dbname(DbName), DocId)),
{ok, Doc0, WaitFun, Parser} = couch_doc:doc_from_multi_part_stream(ContentType,
fun() -> receive_request_data(Req) end),
Doc = couch_doc_from_req(Req, DocId, Doc0),
@@ -833,8 +835,9 @@ db_doc_req(#httpd{method='COPY', user_ctx=Ctx}=Req, Db, SourceDocId) ->
HttpCode = 202
end,
% respond
+ DbName = couch_db:name(Db),
{PartRes} = update_doc_result_to_json(TargetDocId, {ok, NewTargetRev}),
- Loc = absolute_uri(Req, "/" ++ couch_util:url_encode(Db#db.name) ++ "/" ++ couch_util:url_encode(TargetDocId)),
+ Loc = absolute_uri(Req, "/" ++ couch_util:url_encode(DbName) ++ "/" ++ couch_util:url_encode(TargetDocId)),
send_json(Req, HttpCode,
[{"Location", Loc},
{"ETag", "\"" ++ ?b2l(couch_doc:rev_to_str(NewTargetRev)) ++ "\""}],
@@ -1057,8 +1060,8 @@ couch_doc_from_req(Req, DocId, Json) ->
% couch_doc_open(Db, DocId) ->
% couch_doc_open(Db, DocId, nil, []).
-couch_doc_open(#db{} = Db, DocId, Rev, Options0) ->
- Options = [{user_ctx, Db#db.user_ctx} | Options0],
+couch_doc_open(Db, DocId, Rev, Options0) ->
+ Options = [{user_ctx, couch_db:get_user_ctx(Db)} | Options0],
case Rev of
nil -> % open most recent rev
case fabric:open_doc(Db, DocId, Options) of
@@ -1258,7 +1261,7 @@ db_attachment_req(#httpd{method=Method, user_ctx=Ctx}=Req, Db, DocId, FileNamePa
HttpCode = 202
end,
erlang:put(mochiweb_request_recv, true),
- #db{name=DbName} = Db,
+ DbName = couch_db:name(Db),
{Status, Headers} = case Method of
'DELETE' ->
http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/04d26cc7/src/chttpd_external.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_external.erl b/src/chttpd_external.erl
index 4abeecb..64664b9 100644
--- a/src/chttpd_external.erl
+++ b/src/chttpd_external.erl
@@ -120,16 +120,22 @@ json_req_obj_field(<<"secObj">>, #httpd{user_ctx=UserCtx}, Db, _DocId) ->
get_db_security(Db, UserCtx).
-get_db_info(#db{main_pid = nil} = Db) ->
- fabric:get_db_info(Db);
-get_db_info(#db{} = Db) ->
- couch_db:get_db_info(Db).
+get_db_info(Db) ->
+ case couch_db:is_clustered(Db) of
+ true ->
+ fabric:get_db_info(Db);
+ false ->
+ couch_db:get_db_info(Db)
+ end.
-get_db_security(#db{main_pid = nil}=Db, #user_ctx{}) ->
- fabric:get_security(Db);
-get_db_security(#db{}=Db, #user_ctx{}) ->
- couch_db:get_security(Db).
+get_db_security(Db, #user_ctx{}) ->
+ case couch_db:is_clustered(Db) of
+ true ->
+ fabric:get_security(Db);
+ false ->
+ couch_db:get_security(Db)
+ end.
to_json_terms(Data) ->
http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/04d26cc7/src/chttpd_show.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_show.erl b/src/chttpd_show.erl
index 49fed7b..0b45495 100644
--- a/src/chttpd_show.erl
+++ b/src/chttpd_show.erl
@@ -196,7 +196,8 @@ handle_view_list_req(Req, _Db, _DDoc) ->
handle_view_list(Req, Db, DDoc, LName, {ViewDesignName, ViewName}, Keys) ->
%% Will throw an exception if the _list handler is missing
couch_util:get_nested_json_value(DDoc#doc.body, [<<"lists">>, LName]),
- {ok, VDoc} = ddoc_cache:open(Db#db.name, <<"_design/", ViewDesignName/binary>>),
+ DbName = couch_db:name(Db),
+ {ok, VDoc} = ddoc_cache:open(DbName, <<"_design/", ViewDesignName/binary>>),
CB = fun couch_mrview_show:list_cb/2,
QueryArgs = couch_mrview_http:parse_params(Req, Keys),
Options = [{user_ctx, Req#httpd.user_ctx}],