Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Riak 2.0: A Cookbook

Jordan West
January 22, 2014

Riak 2.0: A Cookbook

Jordan West

January 22, 2014
Tweet

More Decks by Jordan West

Other Decks in Technology

Transcript

  1. $ git clone git://github.com/basho/riak.git $ git checkout riak-2.0.0pre10 $ make

    locked-deps $ make devrel $ dev/dev1/bin/riak start slides: http://bit.ly/1ee4Cq8
  2. Riak is operator friendly...except configuring it makes me pull my

    hair out and don’t even get me started on scripting changes PROBLEM: Configuration
  3. [{lager_console_backend,info}, {lager_file_backend, [{file,"./log/console.log"}, {level,info}, {size,10485760}, {date,"$D0"}, {count,5}]}, {lager_file_backend, [{file,"./log/error.log"}, {level,error},

    {size,10485760}, {date,"$D0"}, {count,5}]}]} Riak 1.x Configuration ,dmu DQK^L@W^DSR^S@AKDR 145/// ,dmu DQK^BQ@RG^CTLO -.knf.dqk^bq‘rg-ctlp ,dmu DQK^ETKKRVDDO^@ESDQ / ,dmu DQK^L@W^ONQSR 53///
  4. erlang.async_threads = 64 erlang.max_ports = 64000 erlang.max_ets_tables = 256000 erlang.process_limit

    = 256000 knf-bnmrnkd < ansg knf-bnmrnkd-kdudk < hmen knf-rxrknf < nee knf-bq‘rg < nm knf-bq‘rg-l‘whltl^ldrr‘fd^rhyd < 53JA knf-bq‘rg-rhyd < 0/LA knf-bq‘rg-qns‘shnm < #C/ knf-bq‘rg-qns‘shnm-jddp < 4 Riak 2.0: riak.conf Configuration
  5. $ grep “log.console.* =” riak.conf log.console.level = debug ... $

    sed -i -r "s/console\.level = .*/console\.level = info/" riak.conf $ grep log.console.level riak.conf log.console.level = info Riak 2.0: riak.conf Configuration
  6. $ riak config effective | grep console.level log.console.level = info

    $ echo "log.console.level = debug" >> riak.conf $ riak config effective | grep console.level log.console.level = debug $ cat riak.conf | grep log.console.level log.console.level = info log.console.level = debug Riak 2.0: riak.conf Configuration
  7. $ riak config describe log.console.level Documentation for log.console.level The severity

    level of the console log, default is 'info'. Datatype : [{enum,[debug,info,warning,error]}] Default Value: info Set Value : info app.config : lager.handlers Riak 2.0: riak.conf Configuration
  8. How do I use the multi-backend when I have thousands

    of buckets half of which don’t use the default backend? PROBLEM: Bucket Types
  9. $ riak-admin bucket-type create ads '{"props": {"backend": "ads_bitcask"}}' ads created

    $ riak-admin bucket-type activate ads ads has been activated $ riak-admin bucket-type create users '{"props": {"backend": "users_level"}}' users created $ riak-admin bucket-type activate users users has been activated Riak 2.0: Bucket Types Configuration
  10. $ riak-admin bucket-type list users (active) fileblocks (not active) ads

    (active) Riak 2.0: Bucket Types Configuration
  11. $ riak-admin bucket-type status ads ads is active ... w:

    quorum r: quorum n_val: 3 allow_mult: true $ riak-admin bucket-type status fileblocks | grep fileblocks fileblocks has been created and may be activated Riak 2.0: Bucket Types Configuration
  12. $ curl -X PUT -d "bucket types" http://r.c/types/ads/buckets/client1/keys/anid $ curl

    http://r.c/types/ads/buckets/client1/keys/anid bucket types Riak 2.0: Bucket Types Configuration
  13. logical grouping of buckets bucket/key > type/bucket/key buckets inherit and

    can override properties of the type “default” bucket type for existing data Bucket Types Riak 2.0: Bucket Types
  14. A subset of my key/value data requires single-key strong consistency

    but I don’t want to use another data store PROBLEM: Strong Consistency
  15. You’re out of luck or perhaps you don’t need this

    model of consistency Riak 1.x Strong Consistency
  16. $ echo "strong_consistency = on" >> riak.conf $ grep strong_consistency

    riak.conf ## strong_consistency = on strong_consistency = on $ riak stop && riak start Riak 2.0: Strong Consistency Strong Consistency
  17. $ riak-admin bucket-type create inodes '{"props": {"consistent": true}}' inodes created

    $ riak-admin bucket-type activate inodes inodes has been activated $ riak-admin bucket-type status inodes | grep consistent consistent: true Riak 2.0: Strong Consistency Strong Consistency
  18. $ curl -v -X PUT -d "own=0777,..." http://r.c/types/inodes/buckets/fs1/keys/f1 ... <

    HTTP/1.1 204 No Content ... $ curl -v http://r.c/types/inodes/buckets/fs1/keys/f1 ... < HTTP/1.1 200 OK < X-Riak-Vclock: somebytes own=0777,... Riak 2.0: Strong Consistency Strong Consistency
  19. $ curl -v -X PUT -d "own=0775,..." http://r.c/types/inodes/buckets/fs1/keys/f1 ... <

    HTTP/1.1 412 Precondition Failed ... $ curl -v -X PUT -d "own=0775,..." -H “X-Riak-Vclock: somebytes” http://r.c/ types/inodes/buckets/fs1/keys/f1 ... < HTTP/1.1 204 No Content Riak 2.0: Strong Consistency Strong Consistency
  20. Single key Property of the data not the operation Strong

    Consistency Riak 2.0: Strong Consistency
  21. I want to build a shopping cart that properly handles

    concurrent removes and it would be great if Riak could resolve the conflicts for me while we’re at it PROBLEM: Data Types
  22. Maybe you’ve heard of CRDTs and decided to build your

    own on the client-side Riak 1.x Data Types
  23. $ riak-admin bucket-type create carts '{"props": {"datatype": "set"}}' carts created

    $ riak-admin bucket-type activate carts carts has been activated $ riak-admin bucket-type status carts | grep datatype datatype: set Riak 2.0: Data Types Data Types
  24. 6> {ok, C} = riakc_pb_socket:start_link("host", Port). {ok,<0.46.0>} 7> riakc_pb_socket:fetch_type(C, {<<"carts">>,

    <<"user1">>}, <<"cart1">>). {error,{notfound,set}} Riak 2.0: Data Types Data Types