28. function(v) {
var m = v.values[0].data.
match('w*','g');
var r = [];
for(var i in m)
if (m[i] != '') {
var o = {};
o[m[i]] = 1;
r.push(o);
}
return r;
}
basho
29. map()
function(v) {
var m = v.values[0].data.
match('w*','g');
var r = [];
for(var i in m)
if (m[i] != '') {
var o = {};
o[m[i]] = 1;
r.push(o);
}
return r;
}
basho
32. R2
reduce()
6
5
8
7
4
3
1
function(v) {
var r = {};
for (var i in v) {
for(var w in v[i]) {
if (w in r)
r[w] += v[i][w];
else
r[w] = v[i][w];
}
}
return [r];
}
basho
35. he r
m ot
ch ild
father people/dean
child mo
the
r
chi
ld
people/bob people/alice
people/claire
basho
36. he r
hild m ot
gra ndc
ch ild
father so n people/dean
child mo
the
daughter r
chi
dau ld
people/bob people/alice ght
grandc er
hild
people/claire
basho
37. he r
m ot
ch ild
father so n people/dean
child mo
the
daughter r
chi
dau ld
people/bob people/alice ght
er
GET /riak/person/bob/people,child,_
key link link
bucket tag
people/claire
basho
38. he r
m ot
ch ild
father so n people/dean
child mo
the
daughter r
chi
dau ld
people/bob people/alice ght
er
GET /riak/person/bob/people,child,_/_,child,_
key link1 link1 link2 link2
bucket tag bucket tag
people/claire
basho
39. he r
m ot
ch ild
father so n people/dean
child mo
the
daughter r
chi
dau ld
people/bob people/alice ght
er
GET /riak/person/bob/people,child,1/people,child,_
people/claire
basho
41. http://wiki.basho.com
follow twitter.com/basho/team
riak-users@lists.basho.com
#riak on Freenode
basho
Editor's Notes
Inspired by the paper Amazon wrote about developing their Dynamo system.
One common encoding is JSON, but you can use what you’d like.
Applications can use the content type to decide how to decode the value.
We call the combination of key/bucket/value/metadata a Riak Object.
One of the things we use the metadata for is to make a nice restful HTTP interface.
Here’s an example - if we stored an HTML fragment under they key greeting, in the bucket gluecon
The additional metadata lets us generate a nice HTTP response.
Riak plays very well with the web.
The additional metadata lets us generate a nice HTTP response.
Riak plays very well with the web.
Riak is a decentralized key/value store.
It uses distributed hashing to spread the data across all available machines.
All nodes are the same and we have no single points of failure.
From an operations point of view, adding a node is as simple as configuring the base operating system,
installing riak and joining the new node to the cluster.
There are no replication topologies to update.
Data is automatically migrated to new nodes.
Add more nodes for extra capacity or lowering latency.
And when your spike is over, Riak scales back down again.
Once you have multiple nodes, you get reliability.
Riak can store multiple copies of your data.
get/put/delete operations request each of the replicas and make sure they are all up to date.
The N value stores how many replicas of each key are stored.
As nodes may come and go, there is a chance of the cluster containing stale data or conflicts.
Riak handles this by versioning objects with vector clocks and requesting all N objects.
Using the vector clock we can tell if the data is just stale or in conflict.
Riak can handle this with a last timestamp wins strategy or provide the conflicts back to the application.
Dealing with clusters increases your chance of something failing.
In Riak when a node becomes unavailable, another node takes over for it.
If the failure is temporary and the node comes back, the data it missed is returned to it.
Or it can be removed from the cluster and the other nodes will take over for it permanently.
If the failure is temporary and the node comes back, the data it missed is returned to it.
Or it can be removed from the cluster and the other nodes will take over for it permanently.
The get/put/delete operations in Riak access data by primary key.
Most applications need more.
Riak has an implementation of map/reduce that allows you to visit each key in a bucket
in a map phase extract any information you’d like from it (possibly none) and then combine the results
in a reduce phase.
map and reduce functions can be written in Javascript or Erlang.
The work of mapping is distributed to all nodes in the cluster.
The results of the map are streamed to one node for the reduce().
map and reduce functions can be written in Javascript or Erlang.
The work of mapping is distributed to all nodes in the cluster.
The results of the map are streamed to one node for the reduce().
map and reduce functions can be written in Javascript or Erlang.
The work of mapping is distributed to all nodes in the cluster.
The results of the map are streamed to one node for the reduce().
map and reduce functions can be written in Javascript or Erlang.
The work of mapping is distributed to all nodes in the cluster.
The results of the map are streamed to one node for the reduce().
map and reduce functions can be written in Javascript or Erlang.
The work of mapping is distributed to all nodes in the cluster.
The results of the map are streamed to one node for the reduce().
map and reduce functions can be written in Javascript or Erlang.
The work of mapping is distributed to all nodes in the cluster.
The results of the map are streamed to one node for the reduce().
map and reduce functions can be written in Javascript or Erlang.
The work of mapping is distributed to all nodes in the cluster.
The results of the map are streamed to one node for the reduce().
map and reduce functions can be written in Javascript or Erlang.
The work of mapping is distributed to all nodes in the cluster.
The results of the map are streamed to one node for the reduce().
map and reduce functions can be written in Javascript or Erlang.
The work of mapping is distributed to all nodes in the cluster.
The results of the map are streamed to one node for the reduce().
As they say, no riak object is an island. Application care about relationships in their data.
Riak can store one way ‘links’ in the object metadata, pointing to another bucket/key.
Each link has a tag and there can be many objects.
Riak can combine map/reduce with object metadata to handle relationships between them and we have a special link walking interface included in our HTTP interace.
Here’s an example using biological relationships.
The first set of links store children.
but links are one way, so if you want to get back you have to add more links.
and more links - however it makes sense to use them
We expose links through map/reduce
and directly over our HTTP interface
We can
You can also return intermediate steps - after the trailing comma for the observant of you.
Riak has clients in many languages that are supported by the Basho team and there are also
community provided ones springing up too.
That’s about all I could show you in 10 minutes - please visit our website and check us out.
We have a FastTrack section on our wiki to go through all you need to get started.
Thank you for listening.