Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add instructions and load script for Riak.

  • Loading branch information...
commit 7808661af0a058ec5895bc594545845963be2e28 1 parent fbd0c88
Sean Cribbs authored
Showing with 152 additions and 0 deletions.
  1. +88 −0 riak/README.txt
  2. +64 −0 riak/load_data.rb
88 riak/README.txt
View
@@ -0,0 +1,88 @@
+-------------------------------
+ WindyCityDB Lab Info for Riak
+-------------------------------
+
+--------------
+ INSTALLATION
+--------------
+
+Installation for OS/X is simple using the prebuilt packages here:
+
+(64-bit) http://downloads.basho.com/riak/riak-0.11/riak-0.11.0-osx-x86_64.tar.gz
+(32-bit) http://downloads.basho.com/riak/riak-0.11/riak-0.11.0-osx-i386.tar.gz
+
+1. Download and unpack the tarball.
+
+2. Edit the etc/app.config file, changing references to "127.0.0.1" to
+ "0.0.0.0". This will force Riak to bind to all network interfaces.
+
+3. Run "bin/riak start" to start up the Riak node.
+
+Riak shines best when run in a clustered environment on multiple
+physical hosts. If this configuration is possible, follow these
+instructions:
+
+1. If you started the Riak node in the previous steps, stop it with
+ "bin/riak stop".
+
+2. Edit the etc/vm.args file, changing the name of "riak@127.0.0.1"
+ to include the IP of the public interface on the machine. This name
+ must be unique across the cluster. Example:
+
+ -name riak@10.1.5.37
+
+3. Configure other nodes similarly from the tarball, using their
+ public IP addresses in etc/vm.args.
+
+4. Join the other nodes to the first one using the "bin/riak-admin
+ join" command. Example:
+
+ $ bin/riak-admin join riak@10.1.5.37
+ Sent join request to 'riak@10.1.5.37'.
+
+More detailed information is available on the wiki:
+http://wiki.basho.com/
+
+------------------
+ CLIENT LIBRARIES
+------------------
+
+Riak has an HTTP interface that is well-documented on this wiki page:
+http://wiki.basho.com/display/RIAK/REST+API -- As a result, any
+language with an HTTP client can access Riak and perform operations on
+it.
+
+Many of our new users favor dynamic languages, so the Ruby, Python,
+and Javascript libraries are popular. Installation instructions are below:
+
+Ruby (http://github.com/seancribbs/ripple)
+
+ $ gem install riak-client
+
+Python (http://bitbucket.org/basho/riak-python-client)
+
+ $ python setup.py install
+
+Javascript (http://bitbucket.org/basho/riak-javascript-client)
+[no installation]
+
+For other client libraries see:
+
+ http://wiki.basho.com/display/RIAK/Client+Libraries
+ http://wiki.basho.com/display/RIAK/Community-Developed+Libraries+and+Projects
+
+--------------
+ LOADING DATA
+--------------
+
+After installing the `riak-client`, `yajl`, and `curb` RubyGems, run
+the included Ruby script. It assumes that you will be connecting to
+Riak on the same host (localhost/127.0.0.1). For best performance,
+use Ruby 1.9.
+
+ $ ruby load_data.rb
+
+This will be followed by a lot of output about what's being written
+into Riak.
+
+(Tested on Ruby 1.9.1 / Mac OS/X 10.6)
64 riak/load_data.rb
View
@@ -0,0 +1,64 @@
+require 'rubygems'
+require 'yajl'
+require 'riak'
+
+ActiveSupport::JSON.backend = 'Yajl'
+
+client = Riak::Client.new
+
+types = [:answers,:comments,:posts,:users]
+@buckets = {}
+links = {}
+types.each do |type|
+ @buckets[type] = client.bucket(type.to_s, :keys => false)
+ links[type] = Hash.new {|h,k| h[k] = [] }
+end
+@buckets[:answers] = @buckets[:posts]
+
+# Load the most dependent stuff first so you can link back later:
+# 1) comments
+# 2) answers
+# 3) posts
+# 4) users
+def load_data_for(type)
+ puts "Loading the #{type} from #{type}.json. This may take a while!"
+ raw_data = Yajl::Parser.parse(File.read(File.join("..","data","#{type}.json")))
+ bucket = @buckets[type]
+ raw_data[type.to_s].each do |item|
+ id = item['Id']
+ object = bucket.new(id)
+ object.data = item
+ yield object, item if block_given?
+ object.store(:w => 1, :returnbody => false)
+ print "."; $stdout.flush
+ end
+ puts
+end
+
+load_data_for(:comments) do |obj, json|
+ user, post = json['UserId'], json['PostId']
+ obj.links << Riak::Link.new("/riak/users/#{user}","user")
+ obj.links << Riak::Link.new("/riak/posts/#{post}","post")
+ links[:users][user] << obj.to_link('comment')
+ links[:posts][post] << obj.to_link('comment')
+end
+
+load_data_for(:answers) do |obj, json|
+ user, post = json['OwnerUserId'], json['ParentId']
+ obj.links << Riak::Link.new("/riak/users/#{user}","owner") unless user.blank?
+ obj.links << Riak::Link.new("/riak/posts/#{post}","parent")
+ obj.links.merge(links[:posts][obj.key])
+ links[:users][user] << obj.to_link('answer')
+ links[:posts][post] << obj.to_link('answer')
+end
+
+load_data_for(:posts) do |obj, json|
+ user = json['UserId']
+ obj.links << Riak::Link.new("/riak/users/#{user}","owner") unless user.blank?
+ obj.links.merge(links[:posts][obj.key])
+ links[:users][user] << obj.to_link('question')
+end
+
+load_data_for(:users) do |obj, json|
+ obj.links.merge(links[:users][obj.key])
+end
Please sign in to comment.
Something went wrong with that request. Please try again.