PUT Knowledge BUCKET Brain KEY Riak

1,305 views
1,180 views

Published on

Introduction to Riak, and Riak-CS at "Munich Rubyshift The big Ruby & Database shootout!" 9/2013 http://www.meetup.com/Munich-Rubyshift-Ruby-User-Group/

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,305
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

PUT Knowledge BUCKET Brain KEY Riak

  1. 1. PUT Knowledge BUCKET Brain KEY Riak An intro to Riak by Phil github.com/sideshowcoder twitter.com/ischi
  2. 2. Code The slides contain code, this is how it works a_string = "I am a string" a_string
  3. 3. Ok so Riak, eh? client = Riak::Client.new bucket = client.bucket("brain") object = bucket.get_or_new("riak") object.content_type = "application/json" object.data = { message: "Know stuff on riak!", level: "awesome" } object.store object.reload.data
  4. 4. What is Riak? Key / Value Store Distributed Dynamo based
  5. 5. Buckets client.bucket("brain").name
  6. 6. Keys bucket.keys
  7. 7. Values bucket.get("riak").data
  8. 8. Distributed Keyspace is spread across the members of a cluster via Consistent Hashing
  9. 9. Hashing Key => Hash(key) => Result => 2ˆn -1 possible outcomes Digest.hexencode Digest::MD5.digest("my-key")
  10. 10. Consistent Hashing Source littleriakbook
  11. 11. Replication Source littleriakbook
  12. 12. CAP Theorem Consistency Availability Partition tolerance
  13. 13. Trade-offs Riak chooses adjustable AP, which means it never reaches full Consistency but can be tuned to the needs
  14. 14. N/R/W Values N: Replication count R: Min number of nodes to read from W: Min number of nodes to write to
  15. 15. More on the basics behind this? Littleriakbook by Eric Redmond dynamo paper
  16. 16. Ring members $ riak-admin member-status =========================== Membership ============================ Status Ring Pending Node ------------------------------------------------------------------- valid 100.0% -- 'riak@127.0.0.1' ------------------------------------------------------------------- Valid:1 / Leaving:0 / Exiting:0 / Joining:0 / Down:0
  17. 17. Ring Status $ riak-admin ring-status ============================ Claimant ============================= Claimant: 'riak@127.0.0.1' Status: up Ring Ready: true ======================== Ownership Handoff ======================== No pending changes. ======================== Unreachable Nodes ======================== All nodes are up and reachable
  18. 18. Just Key / Value store? ... mehh! Tags Map and Reduce S3...
  19. 19. 2i aka Secondary Indexes aka Tags object = bucket.get("riak") object.indexes["level_bin"] = ["awesome"] object.store bucket.get_index("level_bin", "awesome")
  20. 20. Map and Reduce js_func = "function(v){ return [Riak.mapValuesJson(v)[0].message]; }" Riak::MapReduce.new(client) .add("brain", "riak") .map(js_func, :keep => true) .run
  21. 21. Let's talk S3 Wait what?
  22. 22. Run your own S3 (compatible) backed by Riak
  23. 23. Features Same API as S3 (use aws-sdk in ruby) Great reporting facilities It's your own S3!
  24. 24. Setup Install Riak Install RiakCS Install Stanchion It's detailed here
  25. 25. ... or just setup via Vagrant! $ vagrant plugin install vagrant-berkshelf $ vagrant plugin install vagrant-omnibus $ git clone https://github.com/basho/vagrant-riak-cs-cluster $ cd vagrant-riak-cs-cluster $ RIAK_CS_CREATE_ADMIN_USER=1 vagrant up Virtual setup using vagrant
  26. 26. Create a user curl -H 'Content-Type: application/json' -X POST http://127.0.0.1:8080/riak-cs/user --data '{"email":"admin@admin.com", "name":"admin"}'
  27. 27. OK let's try it! AWS::S3.new({ :access_key_id => "8AA5UQR3EACDS_TIAXLV", :secret_access_key => "M5eG0q1pN9y6hlc4-JbiCHXLt1YXCY2n7Sb5Yg==", :use_ssl => false, :proxy_uri => "http://localhost:8080" })
  28. 28. Create a bucket s3bucket = s3.buckets.create("my-bucket", :acl => :public_read) s3.buckets.map(&:name)
  29. 29. Write something! obj = s3bucket.objects["riak.jpg"] obj.write File.read('./images/riak.jpg') obj.acl = :public_read s3bucket.objects.map(&:key)
  30. 30. OK lets read it back This is loaded from local Riak CS
  31. 31. Recap Distributes Key / Value Store Easy to interface with Clients are build of HTTP Use RiakCS to replace or augment S3
  32. 32. Questions?
  33. 33. Resources Littleriakbook by Eric Redmond Basho docs on Racks

×