riakpb 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  == DESCRIPTION:
6
6
 
7
- This is a Ruby client for Riak, using protocol buffers instead of REST. It offers some benefit in terms of speed and it abstracts Buckets/Keys differently than does the REST client. Different != Better.
7
+ This is a Ruby client for Riakpb, using protocol buffers instead of REST. It offers some benefit in terms of speed and it abstracts Buckets/Keys differently than does the REST client. Different != Better.
8
8
 
9
9
  == FEATURES/PROBLEMS:
10
10
 
@@ -19,23 +19,23 @@ This is a work in progress and I am current improving the rspec and the document
19
19
 
20
20
  === Connect to riak and ping it:
21
21
 
22
- >> client = Riak::Client.new # Riak::Client.new({:host => "ubuntu01", :port => 1234})
23
- => #<Riak::Client:0x0000010328a040 @host="127.0.0.1", @port=8087, @w=nil, @dw=nil, @buckets=[], @bucket_cache={}>
22
+ >> client = Riakpb::Client.new # Riakpb::Client.new({:host => "ubuntu01", :port => 1234})
23
+ => #<Riakpb::Client:0x0000010328a040 @host="127.0.0.1", @port=8087, @w=nil, @dw=nil, @buckets=[], @bucket_cache={}>
24
24
  >> client.ping?
25
25
  => true
26
26
 
27
27
  === List Buckets within riak:
28
28
  <i>Not suggested for use in production</i>
29
29
 
30
- >> client = Riak::Client.new
31
- => #<Riak::Client:0x00000101439a78 @host="127.0.0.1", @port=8087, @w=nil, @dw=nil, @buckets=[], @bucket_cache={}>
30
+ >> client = Riakpb::Client.new
31
+ => #<Riakpb::Client:0x00000101439a78 @host="127.0.0.1", @port=8087, @w=nil, @dw=nil, @buckets=[], @bucket_cache={}>
32
32
  >> client.buckets
33
33
  => ["hb", "goog"]
34
34
 
35
35
  === Fetch a Bucket:
36
36
 
37
37
  >> bucket = client["goog"]
38
- => #<Riak::Bucket name=goog, props={n_val=>3, allow_mult=false}>
38
+ => #<Riakpb::Bucket name=goog, props={n_val=>3, allow_mult=false}>
39
39
 
40
40
  === Destroy a Bucket:
41
41
 
@@ -45,22 +45,22 @@ This is a work in progress and I am current improving the rspec and the document
45
45
  === List Keys within the Bucket:
46
46
 
47
47
  >> bucket = client["goog"]
48
- => #<Riak::Bucket name=goog, props={n_val=>3, allow_mult=false}>
48
+ => #<Riakpb::Bucket name=goog, props={n_val=>3, allow_mult=false}>
49
49
  >> bucket.keys
50
50
  => ["2010-05-03", "2010-03-24", "2010-03-05", "2010-02-25", <<SNIP>>, "2005-02-10", "2005-01-04"]
51
51
 
52
52
  === Fetch a Key:
53
53
 
54
54
  >> key = bucket["2010-04-12"]
55
- => #<Riak::Key name="2010-04-12", vclock="k\xCEa```\xCC`\xCA\x05R,\xCC\xF3{*2\x98\x12\x19\xF3X\x19N\xCF\xEB8\xCA\x97\x05\x00", contents=[#<#Riak::RiakContent value={"Date"=>Mon, 12 Apr 2010, "Open"=>"567.35", "High"=>"574.00", "Low"=>"566.22", "Close"=>"572.73", "Volume"=>"2352400", "Adj Close"=>"572.73"}, content_type="application/json", vtag="3pbhcnmUtPZvXBSCmo5ESs", links=[], last_mod=1276388043, last_mod_usecs=65345, usermeta={}>]>
55
+ => #<Riakpb::Key name="2010-04-12", vclock="k\xCEa```\xCC`\xCA\x05R,\xCC\xF3{*2\x98\x12\x19\xF3X\x19N\xCF\xEB8\xCA\x97\x05\x00", contents=[#<#Riakpb::Content value={"Date"=>Mon, 12 Apr 2010, "Open"=>"567.35", "High"=>"574.00", "Low"=>"566.22", "Close"=>"572.73", "Volume"=>"2352400", "Adj Close"=>"572.73"}, content_type="application/json", vtag="3pbhcnmUtPZvXBSCmo5ESs", links=[], last_mod=1276388043, last_mod_usecs=65345, usermeta={}>]>
56
56
 
57
57
  === Fetch a Key's Content:
58
- <i>Differs from the REST client. Key+RiakContent = ROjbect</i>
58
+ <i>Differs from the REST client. Key+Content = ROjbect</i>
59
59
 
60
60
  >> rcon = key.content
61
- => #<#Riak::RiakContent value={"Date"=>Mon, 12 Apr 2010, "Open"=>"567.35", "High"=>"574.00", "Low"=>"566.22", "Close"=>"572.73", "Volume"=>"2352400", "Adj Close"=>"572.73"}, content_type="application/json", vtag="3pbhcnmUtPZvXBSCmo5ESs", links=[], last_mod=1276388043, last_mod_usecs=65345, usermeta={}>
61
+ => #<#Riakpb::Content value={"Date"=>Mon, 12 Apr 2010, "Open"=>"567.35", "High"=>"574.00", "Low"=>"566.22", "Close"=>"572.73", "Volume"=>"2352400", "Adj Close"=>"572.73"}, content_type="application/json", vtag="3pbhcnmUtPZvXBSCmo5ESs", links=[], last_mod=1276388043, last_mod_usecs=65345, usermeta={}>
62
62
 
63
- === Play with the RiakContent's data and save it:
63
+ === Play with the Content's data and save it:
64
64
 
65
65
  >> rcon.value
66
66
  => {"Date"=>Mon, 12 Apr 2010, "Open"=>"567.35", "High"=>"574.00", "Low"=>"566.22", "Close"=>"572.73", "Volume"=>"2352400", "Adj Close"=>"572.73"}
@@ -71,29 +71,29 @@ This is a work in progress and I am current improving the rspec and the document
71
71
  >> rcon.value["Date"] += 1.day
72
72
  => Tue, 13 Apr 2010
73
73
  >> rcon
74
- => #<#Riak::RiakContent value={"Date"=>Tue, 13 Apr 2010, "Open"=>"567.35", "High"=>"574.00", "Low"=>"566.22", "Close"=>"572.73", "Volume"=>"2352400", "Adj Close"=>"572.73"}, content_type="application/json", vtag="3pbhcnmUtPZvXBSCmo5ESs", links=[], last_mod=1276388043, last_mod_usecs=65345, usermeta={}>
74
+ => #<#Riakpb::Content value={"Date"=>Tue, 13 Apr 2010, "Open"=>"567.35", "High"=>"574.00", "Low"=>"566.22", "Close"=>"572.73", "Volume"=>"2352400", "Adj Close"=>"572.73"}, content_type="application/json", vtag="3pbhcnmUtPZvXBSCmo5ESs", links=[], last_mod=1276388043, last_mod_usecs=65345, usermeta={}>
75
75
  >> rcon.save
76
76
  => true
77
77
  >> key = bucket["2010-04-12"]
78
- => #<Riak::Key name="2010-04-12", vclock="k\xCEa```\xCA`\xCA\x05R,\xCC\xF3{*2\x98\x12\x19\xF3X\x19N\xCF\xEB8\xCA\a\x13\xFE\x9A\xF3\x05*|x)P8\v\x00", contents=[#<#Riak::RiakContent value={"Date"=>Tue, 13 Apr 2010, "Open"=>"567.35", "High"=>"574.00", "Low"=>"566.22", "Close"=>"572.73", "Volume"=>"2352400", "Adj Close"=>"572.73"}, content_type="application/json", vtag="2wCEI09OVZEUcHozcm9XCX", links=[], last_mod=1276389827, last_mod_usecs=762316, usermeta={}>]>
78
+ => #<Riakpb::Key name="2010-04-12", vclock="k\xCEa```\xCA`\xCA\x05R,\xCC\xF3{*2\x98\x12\x19\xF3X\x19N\xCF\xEB8\xCA\a\x13\xFE\x9A\xF3\x05*|x)P8\v\x00", contents=[#<#Riakpb::Content value={"Date"=>Tue, 13 Apr 2010, "Open"=>"567.35", "High"=>"574.00", "Low"=>"566.22", "Close"=>"572.73", "Volume"=>"2352400", "Adj Close"=>"572.73"}, content_type="application/json", vtag="2wCEI09OVZEUcHozcm9XCX", links=[], last_mod=1276389827, last_mod_usecs=762316, usermeta={}>]>
79
79
  >> rcon = key.content
80
- => #<#Riak::RiakContent value={"Date"=>Tue, 13 Apr 2010, "Open"=>"567.35", "High"=>"574.00", "Low"=>"566.22", "Close"=>"572.73", "Volume"=>"2352400", "Adj Close"=>"572.73"}, content_type="application/json", vtag="2wCEI09OVZEUcHozcm9XCX", links=[], last_mod=1276389827, last_mod_usecs=762316, usermeta={}>
80
+ => #<#Riakpb::Content value={"Date"=>Tue, 13 Apr 2010, "Open"=>"567.35", "High"=>"574.00", "Low"=>"566.22", "Close"=>"572.73", "Volume"=>"2352400", "Adj Close"=>"572.73"}, content_type="application/json", vtag="2wCEI09OVZEUcHozcm9XCX", links=[], last_mod=1276389827, last_mod_usecs=762316, usermeta={}>
81
81
  >> rcon.value["Date"] -= 1.day
82
82
  => Mon, 12 Apr 2010
83
83
  >> rcon.save
84
84
  => true
85
85
  >> key = bucket["2010-04-12"]
86
- => #<Riak::Key name="2010-04-12", vclock="k\xCEa```\xCA`\xCA\x05R,\xCC\xF3{*2\x98\x12\x19\xF3X\x19N\xCF\xEB8\xCA\a\x13\xFE\x9A\xF3\x05(\xCC\x04\x14~\xBC\x14(\x9C\x05\x00", contents=[#<#Riak::RiakContent value={"Date"=>Mon, 12 Apr 2010, "Open"=>"567.35", "High"=>"574.00", "Low"=>"566.22", "Close"=>"572.73", "Volume"=>"2352400", "Adj Close"=>"572.73"}, content_type="application/json", vtag="264RmLHrCK89zvhtq4n6Fj", links=[], last_mod=1276389859, last_mod_usecs=810556, usermeta={}>]>
86
+ => #<Riakpb::Key name="2010-04-12", vclock="k\xCEa```\xCA`\xCA\x05R,\xCC\xF3{*2\x98\x12\x19\xF3X\x19N\xCF\xEB8\xCA\a\x13\xFE\x9A\xF3\x05(\xCC\x04\x14~\xBC\x14(\x9C\x05\x00", contents=[#<#Riakpb::Content value={"Date"=>Mon, 12 Apr 2010, "Open"=>"567.35", "High"=>"574.00", "Low"=>"566.22", "Close"=>"572.73", "Volume"=>"2352400", "Adj Close"=>"572.73"}, content_type="application/json", vtag="264RmLHrCK89zvhtq4n6Fj", links=[], last_mod=1276389859, last_mod_usecs=810556, usermeta={}>]>
87
87
  >> rcon = key.content
88
- => #<#Riak::RiakContent value={"Date"=>Mon, 12 Apr 2010, "Open"=>"567.35", "High"=>"574.00", "Low"=>"566.22", "Close"=>"572.73", "Volume"=>"2352400", "Adj Close"=>"572.73"}, content_type="application/json", vtag="264RmLHrCK89zvhtq4n6Fj", links=[], last_mod=1276389859, last_mod_usecs=810556, usermeta={}>
88
+ => #<#Riakpb::Content value={"Date"=>Mon, 12 Apr 2010, "Open"=>"567.35", "High"=>"574.00", "Low"=>"566.22", "Close"=>"572.73", "Volume"=>"2352400", "Adj Close"=>"572.73"}, content_type="application/json", vtag="264RmLHrCK89zvhtq4n6Fj", links=[], last_mod=1276389859, last_mod_usecs=810556, usermeta={}>
89
89
  >>
90
90
 
91
91
  === Junkshot: (Siblings)
92
92
 
93
- >> client = Riak::Client.new
94
- => #<Riak::Client:0x00000100d2b998 @host="127.0.0.1", @port=8087, @w=nil, @dw=nil, @buckets=[], @bucket_cache={}>
93
+ >> client = Riakpb::Client.new
94
+ => #<Riakpb::Client:0x00000100d2b998 @host="127.0.0.1", @port=8087, @w=nil, @dw=nil, @buckets=[], @bucket_cache={}>
95
95
  >> bucket = client["goog2"]
96
- => #<Riak::Bucket name=goog2, props={n_val=>3, allow_mult=false}>
96
+ => #<Riakpb::Bucket name=goog2, props={n_val=>3, allow_mult=false}>
97
97
  >> bucket.allow_mult = true
98
98
  => true
99
99
  >> client.junkshot "goog2", "2010-04-12", {:links => {"tomorrow" => ["goog2", "2010-04-13"]}}
@@ -129,7 +129,7 @@ I'm working on ways to simplify M/R requests. It works the same as in ripple.
129
129
  require 'riak'
130
130
  require 'csv'
131
131
 
132
- client = Riak::Client.new
132
+ client = Riakpb::Client.new
133
133
  bucket = client["goog"]
134
134
 
135
135
  CSV.foreach('goog.csv', :headers => true) do |row|
@@ -158,9 +158,9 @@ From Github:
158
158
 
159
159
  == LINKS:
160
160
 
161
- * Riak Fast Track: https://wiki.basho.com/display/RIAK/The+Riak+Fast+Track
162
- * Riak Fast Track GOOG data: https://wiki.basho.com/display/RIAK/Loading+Data+and+Running+MapReduce+Queries
163
- * Ruby Client for Riak's REST Interface: http://github.com/seancribbs/ripple
161
+ * Riakpb Fast Track: https://wiki.basho.com/display/RIAK/The+Riakpb+Fast+Track
162
+ * Riakpb Fast Track GOOG data: https://wiki.basho.com/display/RIAK/Loading+Data+and+Running+MapReduce+Queries
163
+ * Ruby Client for Riakpb's REST Interface: http://github.com/seancribbs/ripple
164
164
 
165
165
  == THANKS:
166
166
 
data/Rakefile CHANGED
@@ -5,9 +5,9 @@ require './lib/riak'
5
5
 
6
6
  gemspec = Gem::Specification.new do |gem|
7
7
  gem.name = "riakpb"
8
- gem.summary = %Q{riakpb is a protocol buffer client for Riak--the distributed database by Basho.}
9
- gem.description = %Q{riakpb is a protocol buffer client for Riak--the distributed database by Basho.}
10
- gem.version = Riak::VERSION
8
+ gem.summary = %Q{riakpb is a protocol buffer client for Riakpb--the distributed database by Basho.}
9
+ gem.description = %Q{riakpb is a protocol buffer client for Riakpb--the distributed database by Basho.}
10
+ gem.version = Riakpb::VERSION
11
11
  gem.email = "me@inherentlylame.com"
12
12
  gem.homepage = "http://github.com/aitrus/riak-pbclient"
13
13
  gem.authors = ["Scott Gonyea"]
data/lib/riak/bucket.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  require 'riak'
2
2
 
3
- module Riak
4
- # Represents and encapsulates operations on a Riak bucket. You may retrieve a bucket
3
+ module Riakpb
4
+ # Represents and encapsulates operations on a Riakpb bucket. You may retrieve a bucket
5
5
  # using {Client#bucket}, or create it manually and retrieve its meta-information later.
6
6
  class Bucket
7
7
  include Util::Translation
8
8
  include Util::MessageCode
9
9
 
10
- # @return [Riak::Client] the associated client
10
+ # @return [Riakpb::Client] the associated client
11
11
  attr_reader :client
12
12
 
13
13
  # @return [String] the bucket name
@@ -21,11 +21,11 @@ module Riak
21
21
 
22
22
  attr_reader :key_cache
23
23
 
24
- # Create a Riak bucket manually.
25
- # @param [Client] client the {Riak::Client} for this bucket
24
+ # Create a Riakpb bucket manually.
25
+ # @param [Client] client the {Riakpb::Client} for this bucket
26
26
  # @param [String] name the name of the bucket
27
27
  def initialize(client, name, options={})
28
- options.assert_valid_keys(:n_val, :allow_mult)
28
+ options.assert_valid_keys(:n_val, :allow_mult, :return_body)
29
29
  raise ArgumentError, t("client_type", :client => client.inspect) unless client.is_a?(Client)
30
30
  raise ArgumentError, t("string_type", :string => name.inspect) unless name.is_a?(String)
31
31
 
@@ -33,16 +33,16 @@ module Riak
33
33
  @name = name
34
34
  self.n_val ||= options[:n_val]
35
35
  self.allow_mult ||= options[:allow_mult]
36
- @key_cache = Hash.new{|k,v| k[v] = Riak::Key.new(self, v)}
36
+ @key_cache = Hash.new{|k,v| k[v] = Riakpb::Key.new(self, v)}
37
37
  end
38
38
 
39
- # Load information for the bucket from a response given by the {Riak::Client::HTTPBackend}.
40
- # Used mostly internally - use {Riak::Client#bucket} to get a {Bucket} instance.
41
- # @param [RpbHash] response a response from {Riak::Client::HTTPBackend}
39
+ # Load information for the bucket from a response given by the {Riakpb::Client::HTTPBackend}.
40
+ # Used mostly internally - use {Riakpb::Client#bucket} to get a {Bucket} instance.
41
+ # @param [RpbHash] response a response from {Riakpb::Client::HTTPBackend}
42
42
  # @return [Bucket] self
43
43
  # @see Client#bucket
44
44
  def load(response)
45
- if response.is_a?(Riak::RpbGetBucketResp)
45
+ if response.is_a?(Riakpb::RpbGetBucketResp)
46
46
  @n_val = response.props.n_val
47
47
  @allow_mult = response.props.allow_mult
48
48
 
@@ -66,7 +66,7 @@ module Riak
66
66
  # Retrieve an object from within the bucket.
67
67
  # @param [String] key the key of the object to retrieve
68
68
  # @param [Fixnum] r - the read quorum for the request - how many nodes should concur on the read
69
- # @return [Riak::Key] the object
69
+ # @return [Riakpb::Key] the object
70
70
  def key(key, options={})
71
71
  raise ArgumentError, t("fixnum_invalid", :num => options[:r]) unless options[:r].is_a?(NilClass) or options[:r].is_a?(Fixnum)
72
72
  raise ArgumentError, t("string_invalid", :string => key) unless key.is_a?(String)
@@ -84,21 +84,21 @@ module Riak
84
84
  # Retrieve an object from within the bucket. Will raise an error message if key does not exist.
85
85
  # @param [String] key the key of the object to retrieve
86
86
  # @param [Fixnum] quorum - the read quorum for the request - how many nodes should concur on the read
87
- # @return [Riak::Key] the object
87
+ # @return [Riakpb::Key] the object
88
88
  def key!(key, r=nil)
89
89
  raise ArgumentError, t("string_invalid", :string => key) unless key.is_a?(String)
90
90
  raise ArgumentError, t("fixnum_invalid", :num => r) unless r.is_a?(Fixnum) or r.nil?
91
91
 
92
92
  response = @client.get_request @name, key, r
93
93
 
94
- Riak::Key.new(self, key).load!(response)
94
+ Riakpb::Key.new(self, key).load!(response)
95
95
  end
96
96
 
97
97
  # Retrieves a Key from the given Bucket. Originally written for link retrieval.
98
98
  # @param [String] bucket the name of the bucket, in which the Key is contained
99
99
  # @param [String] key the name of the key to retrieve
100
100
  # @option options [Fixnum] :quorum read quorum- num of replicas need to agree when retrieving the object
101
- # @return [Riak::Key] the object
101
+ # @return [Riakpb::Key] the object
102
102
  def get_linked(bucket, key, options=nil)
103
103
  @client[bucket].key(key, options)
104
104
  end
@@ -123,9 +123,9 @@ module Riak
123
123
  options = params.slice :return_body, :w, :dw
124
124
  content = params.slice :value, :content_type, :charset, :content_encoding, :links, :usermeta
125
125
 
126
- key = key.name if key.is_a?(Riak::Key)
126
+ key = key.name if key.is_a?(Riakpb::Key)
127
127
  options[:key] = key
128
- options[:content] = Riak::RpbContent.new(content)
128
+ options[:content] = Riakpb::RpbContent.new(content)
129
129
 
130
130
  self.store(options)
131
131
  end
@@ -135,7 +135,7 @@ module Riak
135
135
  # @param [Hash] options quorum options
136
136
  # @option options [Fixnum] :rw - the read/write quorum for the delete
137
137
  def delete(key, rw=nil)
138
- key = key.name if key.is_a?(Riak::Key)
138
+ key = key.name if key.is_a?(Riakpb::Key)
139
139
 
140
140
  @client.del_request(@name, key, rw)
141
141
  end
@@ -158,7 +158,7 @@ module Riak
158
158
  @allow_mult
159
159
  end
160
160
 
161
- # Set the allow_mult property. *NOTE* This will result in a PUT request to Riak.
161
+ # Set the allow_mult property. *NOTE* This will result in a PUT request to Riakpb.
162
162
  # @param [true, false] value whether the bucket should allow siblings
163
163
  def allow_mult=(value)
164
164
  case value
@@ -194,12 +194,12 @@ module Riak
194
194
 
195
195
  # @return [String] a representation suitable for IRB and debugging output
196
196
  def inspect
197
- "#<Riak::Bucket name=#{@name}, props={n_val=>#{@n_val}, allow_mult=#{@allow_mult}}>"
197
+ "#<Riakpb::Bucket name=#{@name}, props={n_val=>#{@n_val}, allow_mult=#{@allow_mult}}>"
198
198
  end
199
199
 
200
200
  # @return [String] a representation suitable for IRB and debugging output, including keys within this bucket
201
201
  def inspect!
202
- "#<Riak::Bucket name=#{@name}, props={n_val=>#{@n_val}, allow_mult=#{@allow_mult}}, keys=#{keys.inspect}>"
202
+ "#<Riakpb::Bucket name=#{@name}, props={n_val=>#{@n_val}, allow_mult=#{@allow_mult}}, keys=#{keys.inspect}>"
203
203
  end
204
204
 
205
205
  private
@@ -207,7 +207,7 @@ module Riak
207
207
  rpb_links = []
208
208
 
209
209
  link_params.each do |tag, links|
210
- pb_link = Riak::RpbLink.new
210
+ pb_link = Riakpb::RpbLink.new
211
211
  pb_link.tag = tag
212
212
  pb_link.bucket = links[0]
213
213
  pb_link.key = links[1]
@@ -220,7 +220,7 @@ module Riak
220
220
  rpb_meta = []
221
221
 
222
222
  meta_params.each do |k,v|
223
- pb_meta = Riak::RpbPair.new
223
+ pb_meta = Riakpb::RpbPair.new
224
224
  pb_meta.key = k
225
225
  pb_meta.value = v
226
226
  rpb_meta << pb_meta
@@ -6,27 +6,27 @@
6
6
  #
7
7
  require 'socket'
8
8
 
9
- module Riak
9
+ module Riakpb
10
10
  class Client
11
11
  class Rpc
12
- include Riak::Util::MessageCode
13
- include Riak::Util::Translation
14
- include Riak::Util::Encode
15
- include Riak::Util::Decode
12
+ include Riakpb::Util::MessageCode
13
+ include Riakpb::Util::Translation
14
+ include Riakpb::Util::Encode
15
+ include Riakpb::Util::Decode
16
16
 
17
17
  RECV_LIMIT=1073741824
18
18
 
19
19
  attr_reader :req_message, :response, :resp_message_codes, :resp_message, :status
20
20
 
21
- # Establishes a Client ID with the Riak node, for the life of the RPC connection.
22
- # @param [Client] client the Riak::Client object in which this Rpc instance lives
21
+ # Establishes a Client ID with the Riakpb node, for the life of the RPC connection.
22
+ # @param [Client] client the Riakpb::Client object in which this Rpc instance lives
23
23
  # @param [Fixnum] limit the max size of an individual TCPSocket receive call. Need to fix, later.
24
24
  def initialize(client, limit=RECV_LIMIT)
25
25
  @status = false
26
26
  @client = client
27
27
  @limit = limit
28
28
  @client_id = request(Util::MessageCode::GET_CLIENT_ID_REQUEST).client_id
29
- @set_client_id = Riak::RpbSetClientIdReq.new(:client_id => @client_id)
29
+ @set_client_id = Riakpb::RpbSetClientIdReq.new(:client_id => @client_id)
30
30
 
31
31
  # Request / Response Data
32
32
  @resp_message_codes = -1
@@ -97,14 +97,16 @@ module Riak
97
97
  self.parse_response socket.recv(@limit)
98
98
 
99
99
  end while(false == (@response[:done] rescue true))
100
+
101
+ socket.flush
100
102
  end # with_socket
101
103
 
102
104
  return(@response)
103
105
  end # stream_request
104
106
 
105
- # Handles the response from the Riak node
106
- # @param [String] value The message returned from the Riak node over the TCP Socket
107
- # @return [Protobuf::Message] @response the processed response (if any) from the Riak node
107
+ # Handles the response from the Riakpb node
108
+ # @param [String] value The message returned from the Riakpb node over the TCP Socket
109
+ # @return [Protobuf::Message] @response the processed response (if any) from the Riakpb node
108
110
  def parse_response(value)
109
111
  @resp_message << value
110
112
 
@@ -135,4 +137,4 @@ module Riak
135
137
 
136
138
  end # class Client
137
139
  end # module Rpc
138
- end # module RiakPbclient
140
+ end # module RiakpbPbclient
data/lib/riak/client.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'riak'
2
2
 
3
- module Riak
4
- # A client connection to Riak.
3
+ module Riakpb
4
+ # A client connection to Riakpb.
5
5
  class Client
6
6
  include Util::Translation
7
7
  include Util::MessageCode
@@ -22,23 +22,31 @@ module Riak
22
22
  attr_reader :node
23
23
  attr_reader :server_version
24
24
  attr_reader :client_id
25
-
26
- # Creates a client connection to Riak's Protobuf Listener
27
- # @param [String] options configuration options for the client
28
- # @param [String] host ('127.0.0.1') The host or IP address for the Riak endpoint
29
- # @param [Fixnum] port (8087) The port of the Riak protobuf listener endpoint
25
+ attr_reader :options
26
+
27
+ # Creates a client connection to Riakpb's Protobuf Listener
28
+ # @options [Hash] options configuration options for the client
30
29
  def initialize(options={})
31
30
  self.host = options[:host] || "127.0.0.1"
32
31
  self.port = options[:port] || 8087
33
- self.client_id = options[:client_id] unless options[:client_id].nil?
34
- @w = options[:w]
35
- @dw = options[:dw]
32
+ self.client_id = options[:client_id] unless options[:client_id].blank?
33
+
34
+ read_quorum = options[:r] || options[:read_quorum]
35
+ write_quorum = options[:w] || options[:write_quorum]
36
+ replica_commit = options[:dw] || options[:replica_commit]
37
+ return_body = options[:rb] || options[:return_body] || true
38
+
39
+ @options = options.slice!(:host, :port, :client_id, :r, :read_quorum, :w, :write_quorum, :dw, :replica_commit, :rb, :return_body)
40
+ @options[:r] = read_quorum unless read_quorum.blank?
41
+ @options[:w] = write_quorum unless write_quorum.blank?
42
+ @options[:dw] = replica_commit unless replica_commit.blank?
43
+ @options[:return_body] = return_body unless return_body.blank?
44
+
36
45
  @buckets = []
37
- @bucket_cache = Hash.new{|k,v| k[v] = Riak::Bucket.new(self, v)}
46
+ @bucket_cache = Hash.new{|k,v| k[v] = Riakpb::Bucket.new(self, v, @options)}
38
47
  end
39
-
40
- # Set the hostname of the Riak endpoint. Must be an IPv4, IPv6, or valid hostname
41
- # @param [String] value The host or IP address for the Riak endpoint
48
+ # Set the hostname of the Riakpb endpoint. Must be an IPv4, IPv6, or valid hostname
49
+ # @param [String] value The host or IP address for the Riakpb endpoint
42
50
  # @raise [ArgumentError] if an invalid hostname is given
43
51
  # @return [String] the assigned hostname
44
52
  def host=(value)
@@ -46,8 +54,8 @@ module Riak
46
54
  @host = value
47
55
  end
48
56
 
49
- # Set the port number of the Riak endpoint. This must be an integer between 0 and 65535.
50
- # @param [Fixnum] value The port number of the Riak endpoint
57
+ # Set the port number of the Riakpb endpoint. This must be an integer between 0 and 65535.
58
+ # @param [Fixnum] value The port number of the Riakpb endpoint
51
59
  # @raise [ArgumentError] if an invalid port number is given
52
60
  # @return [Fixnum] the assigned port number
53
61
  def port=(value)
@@ -56,7 +64,7 @@ module Riak
56
64
  end
57
65
 
58
66
  # Set the client ID for this client. Must be a string or Fixnum value 0 =< value < MAX_CLIENT_ID.
59
- # @param [String, Fixnum] value The internal client ID used by Riak to route responses
67
+ # @param [String, Fixnum] value The internal client ID used by Riakpb to route responses
60
68
  # @raise [ArgumentError] when an invalid client ID is given
61
69
  # @return [String] the assigned client ID
62
70
  def client_id=(value)
@@ -71,13 +79,13 @@ module Riak
71
79
  end
72
80
 
73
81
  # Establish a connection to the riak node, and store the Rpc instance
74
- # @return [Riak::Client::Rpc] the Rpc instance that handles connections to the riak node
82
+ # @return [Riakpb::Client::Rpc] the Rpc instance that handles connections to the riak node
75
83
  def rpc(options={})
76
84
  options[:client_id] ||= @client_id if @client_id
77
85
  @rpc ||= Rpc.new(self)
78
86
  end
79
87
 
80
- # Tests connectivity with the Riak host.
88
+ # Tests connectivity with the Riakpb host.
81
89
  # @return [Boolean] Successful returned as 'true', failed connection returned as 'false'
82
90
  def ping?
83
91
  rpc.request Util::MessageCode::PING_REQUEST
@@ -88,7 +96,7 @@ module Riak
88
96
  # Retrieves basic information from the riak node.
89
97
  # @return [Hash] Returns the name of the node and its software release number
90
98
  def info
91
- response = rpc.request Riak::Util::MessageCode::GET_SERVER_INFO_REQUEST
99
+ response = rpc.request Riakpb::Util::MessageCode::GET_SERVER_INFO_REQUEST
92
100
 
93
101
  @node = response.node
94
102
  @server_version = response.server_version
@@ -96,21 +104,21 @@ module Riak
96
104
  {:node => @node, :server_version => @server_version}
97
105
  end
98
106
 
99
- # I need bucket! Bring me bucket! (Retrieves a bucket from Riak. Eating disorder not included.)
107
+ # I need bucket! Bring me bucket! (Retrieves a bucket from Riakpb. Eating disorder not included.)
100
108
  # @param [String] bucket the bucket to retrieve
101
109
  # @return [Bucket] the requested bucket
102
110
  def bucket(bucket)
103
111
  return(@bucket_cache[bucket]) if @bucket_cache.has_key?(bucket)
104
- bring_me_bucket!(bucket)
112
+ self.bucket!(bucket)
105
113
  end
106
114
  alias :[] :bucket
107
115
  alias :bring_me_bucket :bucket
108
116
 
109
- # I need bucket! Bring me bucket! (Retrieves a bucket from Riak, even if it's already been retrieved.)
117
+ # I need bucket! Bring me bucket! (Retrieves a bucket from Riakpb, even if it's already been retrieved.)
110
118
  # @param [String] bucket the bucket to retrieve
111
119
  # @return [Bucket] the requested bucket
112
120
  def bucket!(bucket)
113
- request = Riak::RpbGetBucketReq.new(:bucket => bucket)
121
+ request = Riakpb::RpbGetBucketReq.new(:bucket => bucket)
114
122
  response = rpc.request(
115
123
  Util::MessageCode::GET_BUCKET_REQUEST,
116
124
  request
@@ -124,12 +132,12 @@ module Riak
124
132
  # @param [RpbBucketProps, Hash] props the properties to be set within the given bucket
125
133
  # @return [TrueClass, FalseClass] whether or not the operation was successful
126
134
  def set_bucket(bucket, props)
127
- props = Riak::RpbBucketProps.new(props) if props.is_a?(Hash)
135
+ props = Riakpb::RpbBucketProps.new(props) if props.is_a?(Hash)
128
136
 
129
- raise TypeError.new t('invalid_props') unless props.is_a?(Riak::RpbBucketProps)
137
+ raise TypeError.new t('invalid_props') unless props.is_a?(Riakpb::RpbBucketProps)
130
138
 
131
139
  begin
132
- request = Riak::RpbSetBucketReq.new(:bucket => bucket, :props => props)
140
+ request = Riakpb::RpbSetBucketReq.new(:bucket => bucket, :props => props)
133
141
  response = rpc.request(
134
142
  Util::MessageCode::SET_BUCKET_REQUEST,
135
143
  request
@@ -142,14 +150,20 @@ module Riak
142
150
  end
143
151
  end
144
152
 
145
- # Retrieves a key, using RpbGetReq, from within a given bucket, from Riak.
153
+ # Retrieves a key, using RpbGetReq, from within a given bucket, from Riakpb.
146
154
  # @param [String] bucket the bucket from which to retrieve the key
147
155
  # @param [String] key the name of the key to be received
148
156
  # @param [Fixnum] quorum read quorum- num of replicas need to agree when retrieving the object
149
157
  # @return [RpbGetResp] the response in which the given Key is stored
150
158
  def get_request(bucket, key, quorum=nil)
151
- request = Riak::RpbGetReq.new({:bucket => bucket, :key => key})
152
- request.r = quorum if quorum.is_a?(Fixnum)
159
+ request = Riakpb::RpbGetReq.new({:bucket => bucket, :key => key})
160
+
161
+ quorum ||= @read_quorum
162
+ unless quorum.blank?
163
+ quorum = quorum.to_i
164
+ request.r = quorum
165
+ end
166
+
153
167
 
154
168
  response = rpc.request(
155
169
  Util::MessageCode::GET_REQUEST,
@@ -169,27 +183,27 @@ module Riak
169
183
  def put_request(options)
170
184
  raise ArgumentError, t('invalid_bucket') if options[:bucket].empty?
171
185
  raise ArgumentError, t('empty_content') if options[:content].nil?
186
+ options[:w] ||= @write_quorum unless @write_quorum.nil?
187
+ options[:dw] ||= @replica_commit unless @replica_commit.nil?
188
+ options[:return_body] = @return_body unless options.has_key?(:return_body)
172
189
 
173
- options[:w] ||= @w unless @w.nil?
174
- options[:dw] ||= @dw unless @dw.nil?
175
- options[:return_body] ||= true
176
-
177
- request = Riak::RpbPutReq.new(options)
190
+ request = Riakpb::RpbPutReq.new(options.slice :bucket, :key, :vclock, :content, :w, :dw, :return_body)
178
191
  response = rpc.request(
179
192
  Util::MessageCode::PUT_REQUEST,
180
193
  request
181
194
  )
182
195
 
196
+ return(true) if response == ""
183
197
  return(response)
184
198
  end
185
199
 
186
- # Deletes a key, using RpbDelReq, from within a given bucket, from Riak.
200
+ # Deletes a key, using RpbDelReq, from within a given bucket, from Riakpb.
187
201
  # @param [String] bucket the bucket from which to delete the key
188
202
  # @param [String] key the name of the key to be deleted
189
203
  # @param [Fixnum] rw how many replicas to delete before returning a successful response
190
204
  # @return [RpbGetResp] the response confirming deletion
191
205
  def del_request(bucket, key, rw=nil)
192
- request = Riak::RpbDelReq.new
206
+ request = Riakpb::RpbDelReq.new
193
207
  request.bucket = bucket
194
208
  request.key = key
195
209
  request.rw ||= rw
@@ -198,6 +212,9 @@ module Riak
198
212
  Util::MessageCode::DEL_REQUEST,
199
213
  request
200
214
  )
215
+
216
+ return(true) if response == ""
217
+ return(response)
201
218
  end
202
219
 
203
220
  # Sends a MapReduce operation to riak, using RpbMapRedReq, and returns the Response/phases.
@@ -205,7 +222,7 @@ module Riak
205
222
  # @param [String] content_type encoding for map/reduce job
206
223
  # @return [RpbMapRedResp] the response, encoded in the same format that was sent
207
224
  def map_reduce_request(mr_request, content_type)
208
- request = Riak::RpbMapRedReq.new
225
+ request = Riakpb::RpbMapRedReq.new
209
226
  request.request = mr_request
210
227
  request.content_type = content_type
211
228
 
@@ -214,12 +231,12 @@ module Riak
214
231
  request
215
232
  )
216
233
 
217
- return(response)
234
+ return(response)
218
235
  end
219
236
  alias :mapred :map_reduce_request
220
237
  alias :mr :map_reduce_request
221
238
 
222
- # Lists the buckets found in the Riak database
239
+ # Lists the buckets found in the Riakpb database
223
240
  # @raise [ReturnRespError] if the message response does not correlate with the message requested
224
241
  # @return [Array] list of buckets (String)
225
242
  def buckets
@@ -229,7 +246,7 @@ module Riak
229
246
  @buckets = response.buckets.each{|b| b}
230
247
  end
231
248
 
232
- # Lists the keys within their respective buckets, that are found in the Riak database
249
+ # Lists the keys within their respective buckets, that are found in the Riakpb database
233
250
  # @param [String] bucket the bucket from which to retrieve the list of keys
234
251
  # @raise [ReturnRespError] if the message response does not correlate with the message requested
235
252
  # @return [Hash] Mapping of the buckets (String) to their keys (Array of Strings)
@@ -246,42 +263,11 @@ module Riak
246
263
  # "#<Client >"
247
264
  # end
248
265
 
249
- # Junkshot lets you throw a lot of data at riak, which will then need to be reconciled later
250
- # @overload junkshot(bucket, key, params)
251
- # @param [String] bucket the name of the bucket
252
- # @param [String] key the name of the key
253
- # @param [Hash] params the parameters that are to be updated (Needs fixin')
254
- # @overload junkshot(key, params)
255
- # @param [Key] key the Key instance to be junkshotted
256
- # @param [Hash] params the parameters that are to be updated (Needs fixin')
257
- # @return [String, Key] dependent upon whether :return_body is set to true or false
258
- def junkshot(*params)
259
- params = params.dup.flatten
260
- case params.size
261
- when 3
262
- bucket = params[0]
263
- key = params[1]
264
- params = params[2]
265
- when 2
266
- begin
267
- key = params[0]
268
- bucket = key.bucket
269
- key = key.name
270
- rescue NoMethodError
271
- raise TypeError.new t('invalid_key')
272
- end
273
- params = params[1]
274
- end
275
- self.bucket!(bucket).junkshot(key, params)
276
- end
277
- alias :stuff :junkshot
278
- alias :jk :junkshot
279
-
280
266
  private
281
267
  def b64encode(n)
282
268
  Base64.encode64([n].pack("N")).chomp
283
269
  end
284
270
 
285
271
  end # class Client
286
- end # module Riak
272
+ end # module Riakpb
287
273
 
@@ -253,7 +253,7 @@ require 'protobuf/message/enum'
253
253
  require 'protobuf/message/service'
254
254
  require 'protobuf/message/extend'
255
255
 
256
- module Riak
256
+ module Riakpb
257
257
  class RpbErrorResp < ::Protobuf::Message
258
258
  defined_in __FILE__
259
259
  required :bytes, :errmsg, 1