7. An entry
arbitrary name
• lives in a bucket
bucket
• has a key
• has a value
8. An entry
arbitrary name
• lives in a bucket
bucket
• has a key arbitrary name
key
• has a value
9. An entry
arbitrary name
forms the path
• lives in a bucket
bucket to the value
• has a key arbitrary name
key
• has a value
10. An entry
arbitrary name
forms the path
• lives in a bucket
bucket to the value
• has a key arbitrary name
key
• has a value
value
a binary blob
and mime type
11. An entry
arbitrary name
forms the path
• lives in a bucket
bucket to the value
• has a key arbitrary name
key
• has a value
value
a binary blob
and mime type
= Store anything, yay!
59. The N to the R to the W to the DW and the RW
Number of copies
ie. distribute to N nodes
60. Read
ie. have R nodes agree
The N to the R to the W to the DW and the RW
Number of copies
ie. distribute to N nodes
61. Read
ie. have R nodes agree
The N to the R to the W to the DW and the RW
Write
Number of copies ie. ack’d by
ie. distribute to N nodes W nodes
62. Durable write
Read ie. persistently written by
ie. have R nodes agree DW nodes
The N to the R to the W to the DW and the RW
Write
Number of copies ie. ack’d by
ie. distribute to N nodes W nodes
63. Durable write
Read ie. persistently written by
ie. have R nodes agree DW nodes
The N to the R to the W to the DW and the RW
Write Read-write
Number of copies ie. ack’d by
ie. persistently deleted by
ie. distribute to N nodes W nodes
RW nodes
70. I do care!
• Resolve conflicts in application logic
• Conflicts exposed as siblings beneath a key
• Response is HTTP 300 Multiple Choice
• Served as mime/multipart
72. What is Riak
and what’s the agenda?
Decentralized key-value store
A database ideally suited for web applications
A flexible map/reduce engine
73. Map / Reduce
• Javascript or Erlang
• Exposed in the HTTP API
74. Map / Reduce count words
function(v) {
var words = v.values[0].data.toLowerCase().match('w*','g');
var counts = [];
for(var word in words)
if (words[word] != '') {
var count = {};
count[words[word]] = 1;
counts.push(count);
}
return counts;
}
75. Map / Reduce count words
function(values) {
var result = {};
for (var value in values) {
for(var word in values[value]) {
if (word in result)
result[word] += values[value][word];
else
result[word] = values[value][word];
}
}
return [result];
}
76. Map & Reduce count words
Put this in your POST request and let Riak smoke it
{"inputs":"bucket", "query":[{"map":{"language":"javascript",
"source":"function(v) { var words = v.values[0].data.toLowerCase().match(/
w*/g); var counts = []; for(var word in words) if (words[word] != '')
{ var count = {}; count[words[word]] = 1; counts.push(count); } return
counts; }"}},{"reduce":{"language":"javascript", "source":"function(values)
{ var result = {}; for (var value in values) { for(var word in
values[value]) { if (word in result) result[word] += values[value][word];
else result[word] = values[value][word]; } } return [result]; }"}}]}
77. Map & Reduce count words
function(v) {
var words = v.values[0].data.toLowerCase().match('w*','g');
var counts = [];
for(var word in words)
if (words[word] != '') {
var count = {};
count[words[word]] = 1;
counts.push(count);
}
return counts;
}
{"inputs":"bucket", "query":[{"map":{"language":"javascript",
"source":"function(v) { var words = v.values[0].data.toLowerCase().match(/
w*/g); var counts = []; for(var word in words) if (words[word] != '')
{ var count = {}; count[words[word]] = 1; counts.push(count); } return
counts; }"}},{"reduce":{"language":"javascript", "source":"function(values)
{ var result = {}; for (var value in values) { for(var word in
values[value]) { if (word in result) result[word] += values[value][word];
else result[word] = values[value][word]; } } return [result]; }"}}]}
78. Map & Reduce count words
function(values) {
var result = {};
for (var value in values) {
for(var word in values[value]) {
if (word in result)
result[word] += values[value][word];
else
result[word] = values[value][word];
}
}
return [result];
}
{"inputs":"bucket", "query":[{"map":{"language":"javascript",
"source":"function(v) { var words = v.values[0].data.toLowerCase().match(/
w*/g); var counts = []; for(var word in words) if (words[word] != '')
{ var count = {}; count[words[word]] = 1; counts.push(count); } return
counts; }"}},{"reduce":{"language":"javascript", "source":"function(values)
{ var result = {}; for (var value in values) { for(var word in
values[value]) { if (word in result) result[word] += values[value][word];
else result[word] = values[value][word]; } } return [result]; }"}}]}
82. The whole enchilada
HTTP API Riak Search Luwak
Riak Key/Value Store
Bitcask InnoDB DETS File system Balanced trees LRU ETS
Riak Core
Membership management Work distribution
leave/join
Cluster state Partitioning
gossip protocol (consistent hashing, hinted handoff)
Erlang / OTP
83. Try it
downloads.basho.com
brew install riak
Web admin @ github.com/gmaurice/Riaktive