PUT Knowledge BUCKET
Brain KEY Riak
An intro to Riak
by Phil
github.com/sideshowcoder
twitter.com/ischi
Code
The slides contain code, this is how it works
a_string = "I am a string"
a_string
Ok so Riak, eh?
client = Riak::Client.new
bucket = client.bucket("brain")
object = bucket.get_or_new("riak")
object.conten...
What is Riak?
Key / Value Store
Distributed
Dynamo based
Buckets
client.bucket("brain").name
Keys
bucket.keys
Values
bucket.get("riak").data
Distributed
Keyspace is spread across the members of a cluster via Consistent
Hashing
Hashing
Key => Hash(key) => Result => 2ˆn -1 possible outcomes
Digest.hexencode Digest::MD5.digest("my-key")
Consistent Hashing
Source littleriakbook
Replication
Source littleriakbook
CAP Theorem
Consistency
Availability
Partition tolerance
Trade-offs
Riak chooses adjustable AP, which means it never reaches full
Consistency but can be tuned to the needs
N/R/W Values
N: Replication count
R: Min number of nodes to read from
W: Min number of nodes to write to
More on the basics behind
this?
Littleriakbook by Eric Redmond
dynamo paper
Ring members
$ riak-admin member-status
=========================== Membership ============================
Status Ring Pe...
Ring Status
$ riak-admin ring-status
============================ Claimant =============================
Claimant: 'riak@1...
Just Key / Value store? ...
mehh!
Tags
Map and Reduce
S3...
2i aka Secondary Indexes
aka Tags
object = bucket.get("riak")
object.indexes["level_bin"] = ["awesome"]
object.store
bucke...
Map and Reduce
js_func = "function(v){ return [Riak.mapValuesJson(v)[0].message]; }"
Riak::MapReduce.new(client)
.add("bra...
Let's talk S3
Wait what?
Run your own S3 (compatible) backed by Riak
Features
Same API as S3 (use aws-sdk in ruby)
Great reporting facilities
It's your own S3!
Setup
Install Riak
Install RiakCS
Install Stanchion
It's detailed here
... or just setup via Vagrant!
$ vagrant plugin install vagrant-berkshelf
$ vagrant plugin install vagrant-omnibus
$ git c...
Create a user
curl -H 'Content-Type: application/json' -X POST 
http://127.0.0.1:8080/riak-cs/user 
--data '{"email":"admi...
OK let's try it!
AWS::S3.new({
:access_key_id => "8AA5UQR3EACDS_TIAXLV",
:secret_access_key => "M5eG0q1pN9y6hlc4-JbiCHXLt1...
Create a bucket
s3bucket = s3.buckets.create("my-bucket", :acl => :public_read)
s3.buckets.map(&:name)
Write something!
obj = s3bucket.objects["riak.jpg"]
obj.write File.read('./images/riak.jpg')
obj.acl = :public_read
s3buck...
OK lets read it back
This is loaded from local Riak CS
Recap
Distributes Key / Value Store
Easy to interface with
Clients are build of HTTP
Use RiakCS to replace or augment S3
Questions?
Resources
Littleriakbook by Eric Redmond
Basho docs on Racks
Upcoming SlideShare
Loading in...5
×

PUT Knowledge BUCKET Brain KEY Riak

1,056

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,056
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
6
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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×