Hello Christian - I believe this is an inconsistency in the HTTP vs PB custom metadata APIs. We'll be revisiting this code at some point to clean things up. In the meantime, would you mind filing an issue at [1] so we don't lose track of this?
Cheers - Dave [1] https://github.com/basho/riak-erlang-client On Tue, Oct 23, 2012 at 12:48 AM, Christian Dahlqvist <christ...@whitenode.com> wrote: > On 22/10/2012 22:25, David Parfitt wrote: > > Hello Metin - > > I'm trying to get that into the docs right now. Will italics do? :-) > https://github.com/basho/riak-erlang-client/pull/74 > > Cheers - > Dave > > On Mon, Oct 22, 2012 at 5:22 PM, Metin Akat <akat.me...@gmail.com> wrote: > > Oh, I see, thanks for this clarification, much appreciated. > I think this should be written somewhere in bold, as 3 days later, I still > wasn't able to find anything on google. > > > On Tue, Oct 23, 2012 at 12:08 AM, David Parfitt <dparf...@basho.com> wrote: > > Hello Metin - > > Sorry for the delay. At the moment, all metadata needs to be stored > under the <<"X-Riak-Meta">> dict key. The following example > illustrates how this works: > > %% To store metadata: > Object = riakc_obj:new(<<"groceries">>, <<"mine">>, <<"eggs & bacon">>). > MetaData = dict:from_list([{<<"X-Riak-Meta">>, [{"Foo", "Bar"}]}]), > Object2 = riakc_obj:update_metadata(Object, MetaData). > riakc_pb_socket:put(Pid, Object2). > > %% To retrieve metadata: > {ok, O} = riakc_pb_socket:get(Pid, <<"groceries">>, <<"mine">>). > {ok, MD} = dict:find(<<"X-Riak-Meta">>, riakc_obj:get_metadata(O)). > > We're kicking around ways to improve this in the future. > > Cheers - > Dave > > On Fri, Oct 19, 2012 at 8:31 AM, Metin Akat <akat.me...@gmail.com> wrote: > > I am trying to do something like: > > Meta1 = dict:store(<<"ver">>, Ver, Meta0), > Obj1 = riakc_obj:update_metadata(Obj, Meta1), > > and then save the object. But on a subsequent read, the metadata k/v > pair is > not there. > > Is there anything special that needs to be done for this to work, or is > this > illegal way to use Riak? > > _______________________________________________ > riak-users mailing list > riak-users@lists.basho.com > http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com > > _______________________________________________ > riak-users mailing list > riak-users@lists.basho.com > http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com > > > Hi, > > As far as I can see there seems to be an inconsistency between the Erlang > and HTTP APIs with respect to how metadata is handled. > > When I query the record created in the example through the Erlang API > (attached to console) I, as expected, get the following: > > {ok, RO} = C:get(<<"groceries">>, <<"mine">>). > {ok, MD} = dict:find(<<"X-Riak-Meta">>, riak_object:get_metadata(RO)). > {ok,[{"Foo","Bar"}]} > > The metadata parameter is stored in the dictionary exactly as created, which > is expected. > > When I query this record through the HTTP interface the same metadata is > returned as a header: > > curl -v -X HEAD http://localhost:8098/riak/groceries/mine > > HEAD /riak/groceries/mine HTTP/1.1 > > User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 > OpenSSL/0.9.8r zlib/1.2.5 > > Host: localhost:8098 > > Accept: */* > > > < HTTP/1.1 200 OK > < X-Riak-Vclock: a85hYGBgzGDKBVIcypz/fga0yrzJYEpkzGNlEG36dZIvCwA= > < Vary: Accept-Encoding > < Server: MochiWeb/1.1 WebMachine/1.9.2 (someone had painted it blue) > < Link: </riak/groceries>; rel="up" > < Foo: Bar > < ETag: "5hdCr8ayy5j9orqA6nDJfs" > < Content-Type: application/octet-stream > < Content-Length: 12 > < > > When I tried to create another record with the same metadata as the first > one through the HTTP interface, I had to prefix the metadata with > "X-Riak-Meta-" in order for it to be saved on the record. When I did this > the interface did however not seem to strip the "X-Riak-Meta-" prefix from > the parameter, and when I query the record through the Erlang API, the > parameter is stored in the metadata dict as "X-Riak-Meta-Foo" instead of > just "Foo". > > I was expecting the parameter to be stored as "Foo" internally in Riak and > represented as "X-Riak-Meta-Foo" when getting or setting through the HTTP > API, but that does not seem to be the case. > > Is this an inconsistency or is there something I am doing wrong or have > missed here? > > Best regards, > > Christian > > > > > _______________________________________________ > riak-users mailing list > riak-users@lists.basho.com > http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com > _______________________________________________ riak-users mailing list riak-users@lists.basho.com http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com