Anonymous avatar Anonymous committed 9fd6917

Handle case where merge_index returns error

tags: az442

Comments (0)

Files changed (5)

apps/riak_search/src/merge_index_backend.erl

 
 iterate(eof, Sender) ->
     riak_search_backend:response_done(Sender);
+iterate({error, Reason}, Sender) ->
+    riak_search_backend:response_error(Sender, Reason);
 iterate({Results, Iter}, Sender) ->
     riak_search_backend:response_results(Sender, Results),
     iterate(Iter(), Sender).
+

apps/riak_search/src/riak_search_backend.erl

 -export([
          response_results/2, 
          response_done/1,
+         response_error/2,
          info_response/2, 
          collect_info_response/3]).
 
 %% Send a response to a stream() request
 response_results(Sender, Results) ->
     riak_core_vnode:reply(Sender, {result_vec, Results}).
+
 response_done(Sender) ->
     riak_core_vnode:reply(Sender, done).
 
+response_error(Sender, Reason) ->
+    riak_core_vnode:reply(Sender, {error, Reason}).
+
 collect_info_response(0, _Ref, Acc) ->
     {ok, Acc};
 collect_info_response(RepliesRemaining, Ref, Acc) ->

apps/riak_search/src/riak_search_client.erl

                         {NewAcc, NewAccCount}
                 end
         end,
-    {ok, SearchRef2, {Results, _}} = fold_results(SearchRef1, Timeout, F, {[], 0}),
-    SortedResults = sort_by_score(SearchRef2, Results),
+    case fold_results(SearchRef1, Timeout, F, {[], 0}) of
+        {ok, SearchRef2, {Results, _}} ->
+            SortedResults = sort_by_score(SearchRef2, Results),
 
-    %% Dedup, and handle start and max results. Return matching
-    %% documents.
-    Results1 = truncate_list(QueryStart, QueryRows, SortedResults),
-    Length = length(SortedResults),
-    {Length, Results1}.
+            %% Dedup, and handle start and max results. Return matching
+            %% documents.
+            Results1 = truncate_list(QueryStart, QueryRows, SortedResults),
+            Length = length(SortedResults),
+            {Length, Results1};
+        {error, Reason} ->
+            {error, Reason}
+    end.
 
 %% Run the search query, fold results through function, return final
 %% accumulator.
 search_fold(IndexOrSchema, QueryOps, Fun, AccIn, Timeout) ->
     %% Execute the search, collect the results,.
     SearchRef = stream_search(IndexOrSchema, QueryOps),
-    {ok, _NewSearchRef, AccOut} = fold_results(SearchRef, Timeout, Fun, AccIn),
-    AccOut.
+    case fold_results(SearchRef, Timeout, Fun, AccIn) of
+        {ok, _NewSearchRef, AccOut} ->
+            AccOut;
+        {error, Reason} ->
+            {error, Reason}
+    end.
 
 search_doc(IndexOrSchema, QueryOps, QueryStart, QueryRows, Timeout) ->
     %% Get results...
     case collect_result(SearchRef, Timeout) of
         {done, Ref} ->
             {ok, Ref, Acc};
-        {error, timeout} ->
-            {error, timeout};
+        {error, Reason} ->
+            {error, Reason};
         {Results, Ref} ->
             NewAcc = Fun(Results, Acc),
             fold_results(Ref, Timeout, Fun, NewAcc)
         {results, Results, Id} ->
             {Results, SearchRef};
         {disconnect, Id} ->
-            {[], SearchRef#riak_search_ref{inputcount=InputCount - 1}}
+            {[], SearchRef#riak_search_ref{inputcount=InputCount - 1}};
+        {error, Reason} ->
+            {error, Reason}
         after Timeout ->
              {error, timeout}
     end.

apps/riak_search/src/riak_search_cmd.erl

     io:format("~n :: Searching for '~s' in ~s...~n~n", [Query, DefaultIndex]),
     io:format("------------------------------~n~n"),
     case search:search(DefaultIndex, Query) of
+        {error, Reason} ->
+            io:format(" :: ERROR: ~p", [Reason]);
         {Length, Results} ->
             F = fun(X) ->
                 {Index, DocID, Props} = X,
                 io:format("~n------------------------------~n~n")
             end,
             [F(X) || X <- Results],
-            io:format(" :: Found ~p results.~n", [Length]);
-        Other ->
-            io:format(" :: ERROR: ~p", [Other])
+            io:format(" :: Found ~p results.~n", [Length])
     end.
 
 search_doc(DefaultIndex, Query) -> 
     io:format("~n :: Searching for '~s' in ~s...~n~n", [Query, DefaultIndex]),
     io:format("------------------------------~n~n"),
     case search:search_doc(DefaultIndex, Query) of
+        {error, Reason} ->
+            io:format("ERROR: ~p", [Reason]);
         {Length, MaxScore, Results} ->
             F = fun(X) ->
                 %% Index.
             end,
             [F(X) || X <- Results],
             io:format(" :: Found ~p results.~n", [Length]),
-            io:format(" :: Maximum score ~p.~n", [MaxScore]);
-        Other ->
-            io:format("ERROR: ~p", [Other])
+            io:format(" :: Maximum score ~p.~n", [MaxScore])
     end.
 
 explain(DefaultIndex, Query) -> 

apps/riak_search/src/riak_search_op_utils.erl

             OutputPid!{results, ResultVec2, OutputRef},
             gather_stream_results(Ref, OutputPid, OutputRef, TransformFun);
 
+        {Ref, {error, Reason}} ->
+            OutputPid ! {error, Reason};
+
         %% TODO: Check if this is dead code
         {Ref, {result, {DocID, Props}}} ->
             NewResult = TransformFun({DocID, Props}),
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.