diff options
author | Robert Newson <rnewson@apache.org> | 2023-01-25 14:55:26 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-25 14:55:26 +0000 |
commit | 88ebc65c0d0c464bf45b10ad6a3234dd07361975 (patch) | |
tree | c12332317ae09076ea8eb4388e66e7615d4d6c60 | |
parent | e5f6c581b0444e528efa3b41ca5889e4e5d4707c (diff) | |
parent | f11491568748aa66b72bff227d172025b8228980 (diff) | |
download | couchdb-88ebc65c0d0c464bf45b10ad6a3234dd07361975.tar.gz |
Merge pull request #4404 from apache/503-if-search-not-available
503 if search not available
-rw-r--r-- | src/dreyfus/src/dreyfus_httpd.erl | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/dreyfus/src/dreyfus_httpd.erl b/src/dreyfus/src/dreyfus_httpd.erl index 39d205b95..f6607d644 100644 --- a/src/dreyfus/src/dreyfus_httpd.erl +++ b/src/dreyfus/src/dreyfus_httpd.erl @@ -42,6 +42,7 @@ handle_search_req( ) when Method == 'GET'; Method == 'POST' -> + verify_search_available(), DbName = couch_db:name(Db), Start = os:timestamp(), QueryArgs = @@ -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} -> @@ -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} -> @@ -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), @@ -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. |