riak_kv_multi_backend + custom backend

Todd t.greenwoodgeer at gmail.com
Sun May 8 17:38:32 EDT 2011


---------------------------
1. Minor doc suggestion
---------------------------

http://wiki.basho.com/Configuration-Files.html

"""
# riak_kv_fs_backend
Data is stored in binary files on the filesystem

     * riak_kv_fs_backendroot
       Root directory where the files are stored (ex: /var/lib/riak/data)
"""

"riak_kv_fs_backendroot" should be "riak_kv_fs_backend_root"


Note: these docs correctly point that out:
http://doc.erlagner.org/riak_kv/riak_kv_fs_backend.html

-----------------------------------
2. Working example of multi backend
-----------------------------------

Following the previous thread on this, I was able to noodle out how to 
make this work:

a) edit the app.config
++++++++++++++++++++++

user at erlang32:~/projects/riak/riak/rel/riak$ vim etc/app.config

  42  %% Riak KV config
  43  {riak_kv, [
  44             %% Storage_backend specifies the Erlang module defining 
the storage
  45             %% mechanism that will be used on this node.
  46             {storage_backend, riak_kv_multi_backend},
  47             {multi_backend_default, <<"cache">>},
  48             {multi_backend, [
  49                {<<"bitcask">>, riak_kv_bitcask_backend, [
  50                   {data_root, "/var/riak/data/bitcask"}
  51                ]},
  52                {<<"filesystem">>, riak_kv_fs_backend, [
  53                   {riak_kv_fs_backend_root, 
"/var/riak/data/filesystem"}
  54                ]},
  55                {<<"cache">>, riak_kv_cache_backend, [
  56                   {riak_kv_cache_backend_memory, 1024},
  57                   {riak_kv_cache_backend_ttl, 600},
  58                   {riak_kv_cache_backend_max_ttl, 3600}
  59                ]}
  60             ]},


b) try to persist data into the filestore backend
+++++++++++++++++++++++++++++++++++++++++++++++++

user at erlang32:~/projects/riak/riak/rel/riak$ ./erts-5.8.3/bin/erl -name 
'riaktest at 127.0.0.1' -setcookie riak

Erlang R14B02 (erts-5.8.3) [source] [rq:1] [async-threads:0] 
[kernel-poll:false]

Eshell V5.8.3  (abort with ^G)

(riaktest at 127.0.0.1)1> RiakNode = 'riak at 127.0.0.1'.
'riak at 127.0.0.1'
(riaktest at 127.0.0.1)2> net_adm:ping(RiakNode).
pong
(riaktest at 127.0.0.1)3>  {ok, C} = riak:client_connect(RiakNode).
{ok,{riak_client,'riak at 127.0.0.1',<<3,169,233,111>>}}
(riaktest at 127.0.0.1)4> C:set_bucket(<<"Blobs">>, [{backend, 
<<"filesystem">>}]).
ok
(riaktest at 127.0.0.1)5> Blob=riak_object:new(<<"Blobs">>, <<"file1">>, 
[<<"data blob 1">>]).
{r_object,<<"Blobs">>,<<"file1">>,
           [{r_content,{dict,0,16,16,8,80,48,
 
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],...},
                             {{[],[],[],[],[],[],[],[],[],[],[],[],...}}},
                       [<<"data blob 1">>]}],
           [],
           {dict,1,16,16,8,80,48,
                 {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],...},
                 {{[],[],[],[],[],[],[],[],[],[],[],[],[],...}}},
           undefined}
(riaktest at 127.0.0.1)6> C:put(Blob, 1).
ok

c) retrieve the persisted data
++++++++++++++++++++++++++++++


(riaktest at 127.0.0.1)7> {ok, Retrieved} = C:get(<<"Blobs">>, <<"file1">>, 1).
{ok,{r_object,<<"Blobs">>,<<"file1">>,
               [{r_content,{dict,2,16,16,8,80,48,
                                 {[],[],[],[],[],[],[],[],[],[],[],[],...},
                                 {{[],[],[],[],[],[],[],[],[],[],...}}},
                           [<<"data blob 1">>]}],
               [{<<3,169,233,111>>,{1,63472109206}}],
               {dict,1,16,16,8,80,48,
                     {[],[],[],[],[],[],[],[],[],[],[],[],[],...},
                     {{[],[],[],[],[],[],[],[],[],[],[],...}}},
               undefined}}
(riaktest at 127.0.0.1)9> riak_object:get_value(Retrieved).
[<<"data blob 1">>]

Hope that helps.

-Todd




More information about the riak-users mailing list