Skip to content

Commit

Permalink
Updated docs
Browse files Browse the repository at this point in the history
Added bucket properties information
Added building section
Included deps in Starting section
Added Content-Type section
Add MapReduce
Added Link Walking
  • Loading branch information
Daniel Reverri committed Jul 15, 2010
1 parent 5a72639 commit 481c0f1
Showing 1 changed file with 97 additions and 17 deletions.
114 changes: 97 additions & 17 deletions docs/pb-client.txt
Expand Up @@ -4,13 +4,22 @@ Riak Protocol Buffers Client Usage Introduction
This document assumes that you have already started your Riak cluster.
For instructions on that prerequisite, refer to riak/doc/basic-setup.txt.

Overview
Building
---

To talk to riak, all you need is an Erlang node with the riak-erlang-client
Assuming you have a working Erlang (R13B04 or later) installation,
building Riak Protocol Buffers Client should be as simple as:

$ cd $PATH_TO_RIAKC
$ make

Starting
---

To talk to Riak, all you need is an Erlang node with the riak-erlang-client
library (riakc) in its code path.

$ erl -pa $PATH_TO_RIAKC/ebin
$ erl -pa $PATH_TO_RIAKC/ebin $PATH_TO_RIAKC/deps/*/ebin

You'll know you've done this correctly if you can execute the
following commands and get a path to a beam file, instead of the atom
Expand All @@ -19,17 +28,18 @@ following commands and get a path to a beam file, instead of the atom
1> code:which(riakc_pb_socket).
".../riak-erlang-client/ebin/riakc_pb_socket.beam"

Or you can install the library into your code path using rebar
Optionally, you can install the library into your code path using rebar

$ cd riak-erlang-client
$ cd $PATH_TO_RIAKC
$ ./rebar install

Connecting
---

Once you have your node running, pass your Riak server nodename
to riak:client_connect/1 to connect and get a client. This can
be as simple as:
Once you have your node running, pass your Riak server's connection
information to riakc_pb_socket:start_link/2. The arguments to this
function correspond to 'pd_ip' and 'pb_port' from the 'app.config'
file on your Riak server.

1> {ok, Pid} = riakc_pb_socket:start_link("127.0.0.1", 8087).
{ok,<0.56.0>}
Expand All @@ -39,6 +49,24 @@ Verify connectivity with the server using ping/1.
2> riakc_pb_socket:ping(Pid).
pong

Bucket Properties
---

At this time, the Protocol Buffers interface only supports two
bucket properties:
n_val
allow_mult

The property 'last_write_wins' is not yet supported. A feature
request has been filed:
https://issues.basho.com/370

Retrieving the properties of a bucket is as simple as:
3> riakc_pb_socket:get_bucket(Pid, <<"groceries">>).
{ok,[{n_val,3},{allow_mult,false}]}

Setting bucket properties is also simple:
4> riakc_pb_socket:set_bucket(Pid, <<"groceries">>, [{n_val, 2}]).

Storing New Data
---
Expand Down Expand Up @@ -105,6 +133,14 @@ is returned.
See riak/doc/architecture.txt for more information about W and DW
values.

Content-Type
---

If you will be fetching data created with the riak-erlang-client through
the REST interface you must set a Content-Type. To set the Content-Type:

7> riakc_obj:update_content_type(Object, "application/x-erlang-term").


Fetching Data
---
Expand All @@ -126,7 +162,7 @@ key you used before:
{{[],[],[],[],[],[],[],[],[],[],[],...}}},
undefined}}

Like 'put', there is a 'get' functions that takes options, get/3.
Like 'put', there is a 'get' function that takes options, get/3.

Options

Expand Down Expand Up @@ -175,7 +211,7 @@ As with get and put, delete can also take options

{rw, RW}: the number of nodes to wait for responses from

Issuing a delete for an object that does not exist returns just returns ok.
Issuing a delete for an object that does not exist returns ok.

Encoding
---
Expand All @@ -188,7 +224,7 @@ example

decode_term(Object) ->
case riakc_obj:get_content_type(Object) of
<<"application/x-erlang-term">> ->
"application/x-erlang-term" ->
try
{ok, binary_to_term(riakc_obj:get_value(Object))}
catch
Expand All @@ -201,7 +237,7 @@ decode_term(Object) ->

encode_term(Object, Term) ->
riakc_obj:update_value(Object, term_to_binary(Term, [compressed]),
<<"application/x-erlang-term">>).
"application/x-erlang-term").


Siblings
Expand All @@ -222,7 +258,7 @@ The values can be listed with
And the content types as

3> riakc_obj:get_content_types(Obj).
[<<"application/json">>,<<"application/json">>]
["application/json","application/json"]

Siblings are resolved by calling riakc_obj:update_value with
the winning value on an object returned by get or put with
Expand All @@ -242,7 +278,9 @@ for example). For that, there is list_keys:

Note that keylist updates are asynchronous to the object storage
primitives, and may not be updated immediately after a put or delete.
This function is primarily intended as a debugging aid.
Also note that listing keys requires traversing the entire key space.
This function should not be used in production and is primarily
intended as a development/debugging aid.

list_keys/2 is just a convenience function around the streaming
version of the call stream_list_keys(Pid, Bucket).
Expand All @@ -256,11 +294,53 @@ version of the call stream_list_keys(Pid, Bucket).

See riakc_pb_socket:wait_for_listkeys for an example of receiving.

To be completed
MapReduce
---

Bucket properties and map/reduce support were not ready for the 0.10
release. They will be implemented in the near future.
This section will only show an example of running a MapReduce query.
Please refer to riak/doc/basic-mapreduce.txt for the specifics on
MapReduce in Riak.

MapReduce queries can be run using the following functions in the
riakc_pb_socket module:
mapred/3
mapred/4
mapred_stream/4
mapred_stream/5

There are also functions for running MapReduce queries against an
entire bucket but these should only be used in development/debugging.
Running a MapReduce query against a bucket has the same performance
penalty as running list_keys/2.

Example query:
3> riakc_pb_socket:mapred(Pid, [{<<"groceries">>, <<"mine">>}],
[{map, {modfun, riak_kv_mapreduce, map_object_value}, none, true}]).
{ok,[{0,[<<"eggs & bacon">>]}]}

Link Walking
---

If you've setup links in your objects with the "Link" header you can
walk these links using a link phase. The following example creates an
object with links and walks the links via a MapReduce query.

4> riakc_pb_socket:put(Pid, riakc_obj:new(<<"items">>, <<"eggs">>, <<"stuff about eggs">>, "application/x-erlang-term")).
ok
5> riakc_pb_socket:put(Pid, riakc_obj:new(<<"items">>, <<"bacon">>, <<"stuff about bacon">>, "application/x-erlang-term")).
ok
6> List = riakc_obj:new(<<"lists">>, <<"mine">>, <<"">>, "application/x-erlang-term").
...
7> List1 = riakc_obj:update_metadata(List, dict:store(<<"Links">>, [{{<<"items">>, <<"eggs">>}, <<"tag">>}, {{<<"items">>, <<"bacon">>}, <<"tag">>}], dict:new())).
...
8> riakc_pb_socket:put(Pid, List1).
ok
9> riakc_pb_socket:mapred(Pid, [{<<"lists">>, <<"mine">>}],
[{link, <<"items">>, '_', true}]).
{ok,[{0,
[[<<"items">>,<<"bacon">>,<<"tag">>],
[<<"items">>,<<"eggs">>,<<"tag">>]]}]}


Troubleshooting
---
Expand Down

0 comments on commit 481c0f1

Please sign in to comment.