Search code examples
erlangriak

Error with riak erlang protobuffs


I'm Following this guide http://docs.basho.com/riak/latest/dev/advanced/mapreduce/

After following this guide to setup 5 nodes http://docs.basho.com/riak/latest/quickstart/

start() ->
  {ok, Client} = riakc_pb_socket:start("127.0.0.1", 10018),
  Mine = riakc_obj:new(<<"groceries">>, <<"mine">>,
                     term_to_binary(["eggs", "bacon"])),
  Yours = riakc_obj:new(<<"groceries">>, <<"yours">>,
                      term_to_binary(["bread", "bacon"])),
  riakc_pb_socket:put(Client, Yours, [{w, 1}]),
  riakc_pb_socket:put(Client, Mine, [{w, 1}]).

I run this query and it gives this error

** Reason for termination == 
** {{badrecord,rpbputreq},
[{riak_kv_pb,iolist,2,[{file,"src/riak_kv_pb.erl"},{line,48}]},
 {riak_kv_pb,encode,2,[{file,"src/riak_kv_pb.erl"},{line,40}]},
 {riak_pb_codec,encode,1,[{file,"src/riak_pb_codec.erl"},{line,77}]},
 {riakc_pb_socket,send_request,2,
                  [{file,"src/riakc_pb_socket.erl"},{line,2066}]},
 {riakc_pb_socket,handle_call,3,
                  [{file,"src/riakc_pb_socket.erl"},{line,1252}]},
 {gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,588}]},
 {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,227}]}]}
** Last message in was {req,
                       {rpbputreq,<<"groceries">>,<<"yours">>,undefined,
                           {rpbcontent,
                               <<131,108,0,0,0,2,107,0,5,98,114,101,97,100,
                                 107,0,5,98,97,99,111,110,106>>,
                               undefined,undefined,undefined,undefined,[],
                               undefined,undefined,[],[],undefined},
                           1,undefined,undefined,undefined,undefined,
                           undefined,undefined,undefined,undefined,
                           undefined,undefined,undefined},
                       60000}
 ** When Server state == {state,"127.0.0.1",10018,false,false,#Port<0.3496>,
                           gen_tcp,undefined,
                           {[],[]},
                           1,[],infinity,undefined,undefined,undefined,
                           undefined,100}

The commit causes it

riakc_pb_socket:put(Client, Yours, [{w, 1}]),

I'm not connecting to a running node's console. I run erlang this command

erl -sname foo -pa ~/e/riak-erlang-client/ebin -pa /usr/lib/riak/lib/riak_kv-1.4.2-0-g61ac9d8/ebin -pa /usr/lib/riak/lib/riak_core-1.4.2/ebin -pa /usr/lib/riak/lib/riak_pb-1.4.1.1/ebin/

The bad record is defined in

/usr/lib/riak/lib/riak_pb-1.4.1.1/include/riak_kv_pb.hrl
-record(rpbputreq, {
bucket = erlang:error({required, bucket}),
key,
vclock,
content = erlang:error({required, content}),
w,
dw,
return_body,
pw,
if_not_modified,
if_none_match,
return_head,
timeout,
asis,
sloppy_quorum,
n_val
}).

Solution

  • the latest version of riak_pb in riak-erlang-client deps has an additional 'type' field at the end

      -record(rpbputreq, {
          bucket = erlang:error({required, bucket}),
          key,
          vclock,
          content = erlang:error({required, content}),
          w,
          dw,
          return_body,
          pw,
          if_not_modified,
          if_none_match,
          return_head,
          timeout,
          asis,
          sloppy_quorum,
          n_val,
          type
         }).