Skip to content

Commit

Permalink
Merge pull request basho#397 from basho/er/list-working-indexes-only
Browse files Browse the repository at this point in the history
Filter indexes that do not exist on Solr

Reviewed-by: rzezeski
  • Loading branch information
borshop committed Jun 4, 2014
2 parents 1e24275 + e587597 commit 64a6c02
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
68 changes: 68 additions & 0 deletions riak_test/yz_index_admin.erl
Expand Up @@ -96,12 +96,50 @@
</types>
</schema>">>).

-define(SCHEMA_FIELDS_DOUBLE,
<<"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
<schema name=\"test\" version=\"1.5\">
<fields>
<field name=\"_yz_id\" type=\"_yz_str\" indexed=\"true\" stored=\"true\" required=\"true\" multiValued=\"false\"/>
<field name=\"_yz_ed\" type=\"_yz_str\" indexed=\"true\" multiValued=\"false\"/>
<field name=\"_yz_pn\" type=\"_yz_str\" indexed=\"true\" multiValued=\"false\"/>
<field name=\"_yz_fpn\" type=\"_yz_str\" indexed=\"true\" multiValued=\"false\"/>
<field name=\"_yz_vtag\" type=\"_yz_str\" indexed=\"true\" multiValued=\"false\"/>
<field name=\"_yz_rt\" type=\"_yz_str\" indexed=\"true\" stored=\"true\" multiValued=\"false\"/>
<field name=\"_yz_rk\" type=\"_yz_str\" indexed=\"true\" stored=\"true\" multiValued=\"false\"/>
<field name=\"_yz_rb\" type=\"_yz_str\" indexed=\"true\" stored=\"true\" multiValued=\"false\"/>
<field name=\"_yz_err\" type=\"_yz_str\" indexed=\"true\" stored=\"true\" multiValued=\"false\"/>
<field name=\"a_field\" type=\"_yz_str\" indexed=\"true\" stored=\"true\" />
<field name=\"a_field\" type=\"_yz_str\" indexed=\"true\" stored=\"true\" />
</fields>
<uniqueKey>_yz_id</uniqueKey>
<types>
<fieldType name=\"_yz_str\" class=\"solr.StrField\" sortMissingLast=\"true\" />
<fieldType name=\"text_general\" class=\"solr.TextField\" positionIncrementGap=\"100\">
<analyzer type=\"index\">
<tokenizer class=\"solr.StandardTokenizerFactory\"/>
<filter class=\"solr.StopFilterFactory\" ignoreCase=\"true\" words=\"stopwords.txt\" enablePositionIncrements=\"true\" />
<filter class=\"solr.LowerCaseFilterFactory\"/>
</analyzer>
<analyzer type=\"query\">
<tokenizer class=\"solr.StandardTokenizerFactory\"/>
<filter class=\"solr.StopFilterFactory\" ignoreCase=\"true\" words=\"stopwords.txt\" enablePositionIncrements=\"true\" />
<filter class=\"solr.SynonymFilterFactory\" synonyms=\"synonyms.txt\" ignoreCase=\"true\" expand=\"true\"/>
<filter class=\"solr.LowerCaseFilterFactory\"/>
</analyzer>
</fieldType>
</types>
</schema>">>).

confirm() ->
Cluster = rt:build_cluster(4, ?CFG),
rt:wait_for_cluster_service(Cluster, yokozuna),
confirm_create_index_1(Cluster),
confirm_create_index_2(Cluster),
confirm_409(Cluster),
confirm_create_index_bad_schema(Cluster),
confirm_bad_name(Cluster),
confirm_bad_n_val(Cluster),
confirm_list(Cluster, [<<"test_index_1">>, <<"test_index_2">>, <<"test_index_409">>]),
Expand Down Expand Up @@ -181,6 +219,36 @@ confirm_409(Cluster) ->
{ok, Status2, _, _} = http(put, URL, ?NO_HEADERS, ?NO_BODY),
?assertEqual("409", Status2).

%% @doc Test index creation with a broken schema
confirm_create_index_bad_schema(Cluster) ->
Index = <<"test_index_bad_schema">>,
Schema = <<"bad_schema">>,
HP = select_random(host_entries(rt:connection_info(Cluster))),
lager:info("confirm_create_index_bad_schema ~s [~p]", [Index, HP]),

lager:info("upload schema ~s [~p]", [Schema, HP]),
SchemaURL = schema_url(HP, Schema),
SchemaHeaders = [{"content-type", "application/xml"}],
{ok, Status1, _, _} = http(put, SchemaURL, SchemaHeaders, ?SCHEMA_FIELDS_DOUBLE),
?assertEqual("204", Status1),

URL = index_url(HP, Index),
Headers = [{"content-type", "application/json"}],
Body = <<"{\"schema\":\"",Schema/binary,"\"}">>,
{ok, Status, _, _} = http(put, URL, Headers, Body),
?assertEqual("204", Status),
%% wait for the index to fail to create
InitFailure = fun(Node) ->
lager:info("Waiting for init failure of ~s [~p]", [Index, Node]),
{ok,_,S} = rpc:call(Node, yz_solr, core, [status, [{wt,json},{core,Index}]]),
{struct,[]} /= kvc:path([<<"initFailures">>], mochijson2:decode(S))
end,
yz_rt:wait_until(Cluster, InitFailure),
%% ensure index doesn't return
{ok, GetStatus, _, _} = http(get, URL, ?NO_HEADERS, ?NO_BODY),
?assertEqual("404", GetStatus),
ok.

confirm_list(Cluster, Indexes) ->
HP = select_random(host_entries(rt:connection_info(Cluster))),
lager:info("confirm_list ~p [~p]", [Indexes, HP]),
Expand Down
3 changes: 2 additions & 1 deletion src/yz_pb_admin.erl
Expand Up @@ -121,7 +121,8 @@ process(#rpbyokozunaindexputreq{

process(rpbyokozunaindexgetreq, State) ->
Indexes = yz_index:get_indexes_from_meta(),
Details = [index_details(IndexName) || IndexName <- Indexes],
Details = [index_details(IndexName)
|| IndexName <- Indexes, yz_index:exists(IndexName)],
{reply, #rpbyokozunaindexgetresp{index=Details}, State};

process(#rpbyokozunaindexgetreq{name = IndexName}, State) ->
Expand Down
3 changes: 2 additions & 1 deletion src/yz_wm_index.erl
Expand Up @@ -206,7 +206,8 @@ read_index(RD, S) ->
case S#ctx.index_name of
undefined ->
Indexes = yz_index:get_indexes_from_meta(),
Details = [index_body(IndexName) || IndexName <- Indexes];
Details = [index_body(IndexName)
|| IndexName <- Indexes, yz_index:exists(IndexName)];
IndexName ->
Details = index_body(IndexName)
end,
Expand Down

0 comments on commit 64a6c02

Please sign in to comment.