This is an automated email from the ASF dual-hosted git repository. davisp pushed a commit to branch prototype/fdb-layer-get-dbs-info in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 3d4970fec724d49c7565317a3f1d6ca95d344369 Author: Paul J. Davis <paul.joseph.da...@gmail.com> AuthorDate: Tue Dec 3 13:44:35 2019 -0600 Support `GET /_dbs_info` endpoint Previously only `POST` with a list of keys was supported. The new `GET` support just dumps all database info blobs in a single ordered response. --- src/chttpd/src/chttpd_misc.erl | 49 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/chttpd/src/chttpd_misc.erl b/src/chttpd/src/chttpd_misc.erl index 186ec9f..b181f3c 100644 --- a/src/chttpd/src/chttpd_misc.erl +++ b/src/chttpd/src/chttpd_misc.erl @@ -157,6 +157,37 @@ all_dbs_callback({error, Reason}, #vacc{resp=Resp0}=Acc) -> {ok, Resp1} = chttpd:send_delayed_error(Resp0, Reason), {ok, Acc#vacc{resp=Resp1}}. +handle_dbs_info_req(#httpd{method = 'GET'} = Req) -> + ok = chttpd:verify_is_server_admin(Req), + + #mrargs{ + start_key = StartKey, + end_key = EndKey, + direction = Dir, + limit = Limit, + skip = Skip + } = couch_mrview_http:parse_params(Req, undefined), + + Options = [ + {start_key, StartKey}, + {end_key, EndKey}, + {dir, Dir}, + {limit, Limit}, + {skip, Skip} + ], + + % TODO: Figure out if we can't calculate a valid + % ETag for this request. \xFFmetadataVersion won't + % work as we don't bump versions on size changes + + {ok, Resp} = chttpd:start_delayed_json_response(Req, 200, []), + Callback = fun dbs_info_callback/2, + Acc = #vacc{req = Req, resp = Resp}, + {ok, Resp} = fabric2_db:list_dbs_info(Callback, Acc, Options), + case is_record(Resp, vacc) of + true -> {ok, Resp#vacc.resp}; + _ -> {ok, Resp} + end; handle_dbs_info_req(#httpd{method='POST', user_ctx=UserCtx}=Req) -> chttpd:validate_ctype(Req, "application/json"), Props = chttpd:json_body_obj(Req), @@ -188,7 +219,23 @@ handle_dbs_info_req(#httpd{method='POST', user_ctx=UserCtx}=Req) -> send_chunk(Resp, "]"), chttpd:end_json_response(Resp); handle_dbs_info_req(Req) -> - send_method_not_allowed(Req, "POST"). + send_method_not_allowed(Req, "GET,HEAD,POST"). + +dbs_info_callback({meta, _Meta}, #vacc{resp = Resp0} = Acc) -> + {ok, Resp1} = chttpd:send_delayed_chunk(Resp0, "["), + {ok, Acc#vacc{resp = Resp1}}; +dbs_info_callback({row, Props}, #vacc{resp = Resp0} = Acc) -> + Prepend = couch_mrview_http:prepend_val(Acc), + Chunk = [Prepend, ?JSON_ENCODE({Props})], + {ok, Resp1} = chttpd:send_delayed_chunk(Resp0, Chunk), + {ok, Acc#vacc{prepend = ",", resp = Resp1}}; +dbs_info_callback(complete, #vacc{resp = Resp0} = Acc) -> + {ok, Resp1} = chttpd:send_delayed_chunk(Resp0, "]"), + {ok, Resp2} = chttpd:end_delayed_json_response(Resp1), + {ok, Acc#vacc{resp = Resp2}}; +dbs_info_callback({error, Reason}, #vacc{resp = Resp0} = Acc) -> + {ok, Resp1} = chttpd:send_delayed_error(Resp0, Reason), + {ok, Acc#vacc{resp = Resp1}}. handle_task_status_req(#httpd{method='GET'}=Req) -> ok = chttpd:verify_is_server_admin(Req),