Here's an example of how to code with Riak using cURL and ruby to do a basic PUT, GET and more. We then index the data using Apache Solr integration.
No matter what platform we’re discussing, we’re beyond the view of rows and columns. Data is more diverse than ever. More difficult to parse. Here is some of that story.
5. ➜ (riak-dev-cluster) rake bootstrap
➜ (riak-dev-cluster) rake member_status
---- Cluster Status ----
Ring ready: true
5
Starting the riak-dev-cluster
for a local dev environment
13. • Keys – simply binary values
used to identify Objects.*
• Values – can be numbers,
strings, objects, binaries, etc.
• Buckets – used to define a
virtual namespace for storing
Riak objects.
Data Model
Riak stores data as a combination of keys and values in buckets
13
14. curl http://127.0.0.1:8098/types/places/buckets/country/keys/US
{
"Alpha2_s": "US”,
"Alpha3_s": "USA”,
"EnglishName_s": "United States”,
"NumericCode_i": 840
}
Riak offers both HTTP and Protocol Buffers APIs. The following HTTP
API example uses curl to retrieve a value by key:
Note: Protocol buffers are Google's language-neutral, platform-neutral,
extensible mechanism for serializing structured data – think XML, but
smaller, faster, and simpler.
Data Model
14
15. There are a diverse group of client libraries for Riak that support both the
HTTP and Protocol Buffer APIs:
Basho Supported Libraries:
• Java
• Ruby
• Python
• PHP
• Erlang
• .NET
• Node.js
Community Libraries:
• C
• Clojure
• Go
• Perl
• Scala
• R
Polylingual
16. ➜ export RIAK_HOST=http://localhost:8098
➜ curl -v $RIAK_HOST/buckets/capitals/keys/usa
-X PUT
-H "content-type: text/plain”
-d "Washington D.C.”
* Trying 127.0.0.1... connected
> PUT /buckets/capitals/keys/usa HTTP/1.1
> Content-Type: text/plain
>
< HTTP/1.1 204 No Content
16
Storing data
Through HTTP
24. ➜ riak-2.1.0 cat etc/riak.conf | grep -i search
## this to be set to 'active', including search.
## To enable Search set this 'on'.
search = on
24
Solr will index any field that it recognizes, based
on the index's schema. The default schema
(_yz_default) uses the suffix to decide the field
type (_s represents a string, _i is an integer, _b is
binary and so on).
A Simple Search
Enabling search in Riak
26. Riak stores data as a combination of keys and values in buckets
A SIMPLE SEARCH
Key Value Bucket
ruby {
"name_s" : "Ruby Client",
"maintainer_s" : “Basho",
"popular_b" : true
}
coding-with-riak
go {
"name_s" : "Go Client",
"popular_b" : true,
"maintainer_s" : “Community"
}
coding-with-riak
26
A Simple Search
Using Apache Solr
31. 31
• Apache Solr full-
text search
• Support for Solr’s
client query APIs
• Tag objects with
one or more query
values
• Index integers or
strings
• Exact matches or
ranges of values
• Filter documents
by tag
• Count words in
documents
• Extract links to
related data
Riak Search
Secondary
Indexes
MapReduce
Search in Riak
42. A multitude of stats is available through riak-admin or HTTP
Calculations
Basic Stats:
• CPU (user/system/wait/idle)
• Processor Load
• Available Memory
• Available disk space
• Used file descriptors
• Swap Usage
• IOWait
• Read operations
• Write operations
• Network throughput
• Network errors
Exploring Latency:
• FSM Time Stats represent
the amount of time in
microseconds required to
traverse the GET or PUT
Finite State Machine code,
offering a picture of general
node health.
43. The most common way to analyze Riak is through your favorite interface
Tools
Basho Tested:
• Zabbix
• Nagios
• New Relic
Community Libraries:
• OpenTSDB
• Ganglia
• collectd
51. What you will gain
51
More flexible, fluid designs
More natural data representations
Scaling without pain
Reduced operational complexity
52. Application Type Key Value
Session User/Session ID Session Data
Advertising Campaign ID Ad Content
Logs Date Log File
Sensor Date, Date/Time Sensor Updates
User Data Login, email, UUID User Attributes
Content Title, Integer Text,
JSON/XML/HTTP
document, images,
Riak Use Cases