diff --git a/riak_test/yz_index_admin.erl b/riak_test/yz_index_admin.erl index e9fab04a..b2e6d1d0 100644 --- a/riak_test/yz_index_admin.erl +++ b/riak_test/yz_index_admin.erl @@ -96,12 +96,50 @@ ">>). +-define(SCHEMA_FIELDS_DOUBLE, + <<" + + + + + + + + + + + + + + + + _yz_id + + + + + + + + + + + + + + + + + +">>). + 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">>]), @@ -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]), diff --git a/src/yz_pb_admin.erl b/src/yz_pb_admin.erl index 73319fcd..a0583c96 100644 --- a/src/yz_pb_admin.erl +++ b/src/yz_pb_admin.erl @@ -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) -> diff --git a/src/yz_wm_index.erl b/src/yz_wm_index.erl index be7a2078..babb7a2f 100644 --- a/src/yz_wm_index.erl +++ b/src/yz_wm_index.erl @@ -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,