0

I've running the following Riak map phase:

-module(delete_map_function).

-export([get_keys/3]).

%Returns bucket and key pairs from a map phase
get_keys(Value,_Keydata,_Arg) ->
  [[riak_object:bucket(Value),riak_object:key(Value)]].

And the following Riak reduce phase: http://contrib.basho.com/delete_keys.html

I keep getting this error message:

{"phase":0,"error":"function_clause","input":"{{error,notfound},{<<\"my_bucket\">>,<<\"item_key\">>},undefined}","type":"error","stack":"[{riak_object,bucket,[{error,notfound}],[{file,\"src/riak_object.erl\"},{line,251}]},{delete_map_function,get_keys,3,[{file,\"delete_map_function.erl\"},{line,7}]},{riak_kv_mrc_map,map,3,[{file,\"src/riak_kv_mrc_map.erl\"},{line,164}]},{riak_kv_mrc_map,process,3,[{file,\"src/riak_kv_mrc_map.erl\"},{line,140}]},{riak_pipe_vnode_worker,process_input,3,[{file,\"src/riak_pipe_vnode_worker.erl\"},{line,444}]},{riak_pipe_vnode_worker,wait_for_input,2,[{file,\"src/riak_pipe_vnode_worker.erl\"},{line,376}]},{gen_fsm,...},...]"}

I'm running the job via Java:

MapReduceResult mapReduceResult = RiakUtils.getPBClient().mapReduce(iq)
                 .addMapPhase(new NamedErlangFunction("delete_map_function", "get_keys"))
                 .addReducePhase(new NamedErlangFunction("delete_reduce_function", "delete"))
                 .execute();

I've read somewhere that I should use the filter_notfound argument in the Map phase, but I still keep getting the error even after adding it:

MapReduceResult mapReduceResult = RiakUtils.getPBClient().mapReduce(iq)
                 .addMapPhase(new NamedErlangFunction("delete_map_function", "get_keys"), "filter_notfound")
                 .addReducePhase(new NamedErlangFunction("delete_reduce_function", "delete"))
                 .execute();

I'm running Riak 1.3 and using the Riak Java client v1.1.0

Mark
  • 67,098
  • 47
  • 117
  • 162

1 Answers1

1

First. I think it is not efficient way to delete keys via map/reduce phases. if you got keys list and feed it to map phase riak will first read all objects and then give it to your functions. So if you only need to delete object, better do it without read.

Second. All your map/reduce functions should be written with following exceptions:

  • instead of Value, you can get {error, notfound} because of eventual nature of riak.
  • also you can get deleted riak object as Value. You can know that object was deleted by special flag dict:is_key(<<"X-Riak-Deleted">>, riak_object:get_metadata(RiakObj)):

Third. To fix your error you should filter notfound keys from the list:

get_keys({error, notfound},_Keydata,_Arg) ->
    [];
get_keys(Value,_Keydata,_Arg) ->
    [[riak_object:bucket(Value),riak_object:key(Value)]].
danechkin
  • 1,306
  • 8
  • 15
  • I have a erlang map phase which is returning value till tombstone key only and exiting from the map phase. Can you please tell me what I am doing wrong? I can paste code here if you want. – RaviKiran Apr 12 '18 at 07:55