loading erlang terms

Scott Lystig Fritchie fritchie at snookles.com
Thu Nov 11 21:01:33 EST 2010

Catching up(*) on a thread from the end of October (nothing like being
prompt, is there?)...

Charles Blair <chas at uchicago.edu> wrote:

cb> Thanks for spotting the "brainos". But even without those, here is a
cb> repeat of the experiment.

Assuming that these code snippets demonstrate what you're trying to do,
then I have a "Doctor, it hurts when I do this" answer.

    OaiTerm = {oai_dc,"AEP-WYS97",{{2004,10,28},{17,21,25}},["aep"],"/storage/aep2003/metadata/oai_dc/oai_dc-AEP-WYS97.xml"}.
    {ok, C} = riak:local_client(). 
    C:put(riak_object:new(<<"oai_test">>, <<"SLF">>, <<"Here is a binary value">>)).
    C:put(riak_object:new(<<"oai_test">>, <<"AEP-WYS97">>, OaiTerm)).
    C:get(<<"oai_test">>, <<"SLF">>).                          
    C:get(<<"oai_test">>, <<"AEP-WYS97">>).

Both of the puts via the Erlang client will work, and both of the gets
work just fine.

    {ok,Pid} = riakc_pb_socket:start_link("localhost", 8087).
    riakc_pb_socket:get(Pid, <<"oai_test">>, <<"SLF">>).

... and that works, ...

    riakc_pb_socket:get(Pid, <<"oai_test">>,<<"AEP-WYS97">>).

... and that fails with a closed TCP connection.

The value associated with the <<"AEP-WYS97">> key is an Erlang term,
specifially a tuple.  The Protocol Buffers interface doesn't know how to
encode Erlang tuples, so it crashes the process on the server side
that's responsible for decoding & encoding traffic on the socket.

If the value that you put() is converted to a binary via
term_to_binary(), you'll have no problem retrieving it via the Protocol
Buffers interface ... but you'll have to use binary_to_term() to get
your original record back.


(*) So much time has gone by that you're probably already figured this
out.  I figured the list's archives ought to have an answer.  And if
Charles didn't have an answer from someplace else, hopefully he returns
tomorrow from holiday in Tahiti to read this very-prompt-seeming

More information about the riak-users mailing list