Skip to content

Commit

Permalink
Merge pull request #4404 from apache/503-if-search-not-available
Browse files Browse the repository at this point in the history
503 if search not available
  • Loading branch information
rnewson committed Jan 25, 2023
2 parents e5f6c58 + f114915 commit 88ebc65
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/dreyfus/src/dreyfus_httpd.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ handle_search_req(
) when
Method == 'GET'; Method == 'POST'
->
verify_search_available(),
DbName = couch_db:name(Db),
Start = os:timestamp(),
QueryArgs =
Expand Down Expand Up @@ -140,6 +141,7 @@ handle_info_req(
Db,
#doc{id = Id} = DDoc
) ->
verify_search_available(),
DbName = couch_db:name(Db),
case dreyfus_fabric_info:go(DbName, DDoc, IndexName, info) of
{ok, IndexInfoList} ->
Expand All @@ -162,6 +164,7 @@ handle_info_req(Req, _Db, _DDoc) ->
handle_disk_size_req(
#httpd{method = 'GET', path_parts = [_, _, _, _, IndexName]} = Req, Db, #doc{id = Id} = DDoc
) ->
verify_search_available(),
DbName = couch_db:name(Db),
case dreyfus_fabric_info:go(DbName, DDoc, IndexName, disk_size) of
{ok, IndexInfoList} ->
Expand All @@ -188,10 +191,12 @@ handle_cleanup_req(Req, _Db) ->
send_method_not_allowed(Req, "POST").

handle_analyze_req(#httpd{method = 'GET'} = Req) ->
verify_search_available(),
Analyzer = couch_httpd:qs_value(Req, "analyzer"),
Text = couch_httpd:qs_value(Req, "text"),
analyze(Req, Analyzer, Text);
handle_analyze_req(#httpd{method = 'POST'} = Req) ->
verify_search_available(),
couch_httpd:validate_ctype(Req, "application/json"),
{Fields} = chttpd:json_body_obj(Req),
Analyzer = couch_util:get_value(<<"analyzer">>, Fields),
Expand Down Expand Up @@ -707,3 +712,11 @@ backoff_and_retry(Req, Db, DDoc, RetryCount, RetryPause, Error) ->
timer:sleep(RetryPause),
handle_search_req(Req, Db, DDoc, RetryCount + 1, RetryPause * 2)
end.

verify_search_available() ->
case dreyfus:available() of
true ->
ok;
false ->
throw({service_unavailable, <<"Search is not available">>})
end.

0 comments on commit 88ebc65

Please sign in to comment.