diff options
author | Adam Kocoloski <kocolosk@apache.org> | 2019-06-14 23:14:57 -0400 |
---|---|---|
committer | Adam Kocoloski <kocolosk@apache.org> | 2019-06-14 23:20:58 -0400 |
commit | 93275c34f1140fec306e2822aa30943d40759e4b (patch) | |
tree | bdf251591e0164803c348ae63a2adc96a4121df6 | |
parent | 2650981e84298494ebbf87854c788cf086821b2a (diff) | |
download | couchdb-93275c34f1140fec306e2822aa30943d40759e4b.tar.gz |
Improve detection of Search subsystem
Previously we had been using module_loaded(dreyfus_index) as a check
for the presence of the Search system. There are two issues with this
approach going forward:
1. Dreyfus is going to be included in every build
2. An Erlang release loads modules lazily and so this check could
accidentally fail even on a Search-enabled system.
This patch changes the check to one that makes an RPC request
to the Clouseau (Java) subsystem. This should be a low-cost operation,
but I haven't benchmarked it.
-rw-r--r-- | src/dreyfus/src/clouseau_rpc.erl | 9 | ||||
-rw-r--r-- | src/mango/src/mango_idx.erl | 8 | ||||
-rw-r--r-- | src/mango/src/mango_native_proc.erl | 2 |
3 files changed, 14 insertions, 5 deletions
diff --git a/src/dreyfus/src/clouseau_rpc.erl b/src/dreyfus/src/clouseau_rpc.erl index aed03e37f..38d6142d6 100644 --- a/src/dreyfus/src/clouseau_rpc.erl +++ b/src/dreyfus/src/clouseau_rpc.erl @@ -23,6 +23,7 @@ -export([delete/2, update/3, cleanup/1, cleanup/2, rename/1]). -export([analyze/2, version/0, disk_size/1]). -export([set_purge_seq/2, get_purge_seq/1, get_root_dir/0]). +-export([connected/0]). open_index(Peer, Path, Analyzer) -> rpc({main, clouseau()}, {open, Peer, Path, Analyzer}). @@ -91,6 +92,14 @@ analyze(Analyzer, Text) -> version() -> rpc({main, clouseau()}, version). +connected() -> + case version() of + {'EXIT', noconnection} -> + false; + _ -> + true + end. + rpc(Ref, Msg) -> ioq:call(Ref, Msg, erlang:get(io_priority)). diff --git a/src/mango/src/mango_idx.erl b/src/mango/src/mango_idx.erl index c2c26958c..5d06a8fe3 100644 --- a/src/mango/src/mango_idx.erl +++ b/src/mango/src/mango_idx.erl @@ -182,7 +182,7 @@ from_ddoc(Db, {Props}) -> _ -> ?MANGO_ERROR(invalid_query_ddoc_language) end, - IdxMods = case module_loaded(dreyfus_index) of + IdxMods = case clouseau_rpc:connected() of true -> [mango_idx_view, mango_idx_text]; false -> @@ -268,7 +268,7 @@ cursor_mod(#idx{type = <<"json">>}) -> cursor_mod(#idx{def = all_docs, type= <<"special">>}) -> mango_cursor_special; cursor_mod(#idx{type = <<"text">>}) -> - case module_loaded(dreyfus_index) of + case clouseau_rpc:connected() of true -> mango_cursor_text; false -> @@ -281,7 +281,7 @@ idx_mod(#idx{type = <<"json">>}) -> idx_mod(#idx{type = <<"special">>}) -> mango_idx_special; idx_mod(#idx{type = <<"text">>}) -> - case module_loaded(dreyfus_index) of + case clouseau_rpc:connected() of true -> mango_idx_text; false -> @@ -309,7 +309,7 @@ get_idx_def(Opts) -> get_idx_type(Opts) -> case proplists:get_value(type, Opts) of <<"json">> -> <<"json">>; - <<"text">> -> case module_loaded(dreyfus_index) of + <<"text">> -> case clouseau_rpc:connected() of true -> <<"text">>; false -> diff --git a/src/mango/src/mango_native_proc.erl b/src/mango/src/mango_native_proc.erl index ab161469a..274ae11de 100644 --- a/src/mango/src/mango_native_proc.erl +++ b/src/mango/src/mango_native_proc.erl @@ -345,7 +345,7 @@ make_text_field_name([P | Rest], Type) -> validate_index_info(IndexInfo) -> - IdxTypes = case module_loaded(dreyfus_index) of + IdxTypes = case clouseau_rpc:connected() of true -> [mango_idx_view, mango_idx_text]; false -> |