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 +23 -23
- data/Rakefile +3 -3
- data/lib/riak/bucket.rb +23 -23
- data/lib/riak/client/rpc.rb +14 -12
- data/lib/riak/client.rb +59 -73
- data/lib/riak/client_pb.rb +1 -1
- data/lib/riak/{riak_content.rb → content.rb} +125 -70
- data/lib/riak/failed_exchange.rb +2 -2
- data/lib/riak/failed_request.rb +3 -3
- data/lib/riak/key.rb +38 -38
- data/lib/riak/locale/en.yml +3 -3
- data/lib/riak/map_reduce.rb +6 -6
- data/lib/riak/sibling_error.rb +3 -3
- data/lib/riak/util/decode.rb +1 -1
- data/lib/riak/util/encode.rb +2 -2
- data/lib/riak/util/message_code.rb +9 -9
- data/lib/riak/util/translation.rb +1 -1
- data/lib/riak.rb +3 -3
- data/load_stocks.rb +1 -1
- data/spec/riak/bucket_spec.rb +22 -22
- data/spec/riak/client_spec.rb +31 -31
- data/spec/riak/{riak_content_spec.rb → content_spec.rb} +17 -18
- data/spec/riak/key_spec.rb +16 -16
- data/spec/riak/map_reduce_spec.rb +30 -30
- data/spec/riak/rpc_spec.rb +2 -2
- metadata +9 -10
- data/riakpb.gemspec +0 -37
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'riak'
|
2
2
|
require 'set'
|
3
3
|
|
4
|
-
module
|
5
|
-
# Parent class of all object types supported by ripple. {
|
6
|
-
# the data and metadata stored in a bucket/key pair in the
|
7
|
-
class
|
4
|
+
module Riakpb
|
5
|
+
# Parent class of all object types supported by ripple. {Riakpb::RObject} represents
|
6
|
+
# the data and metadata stored in a bucket/key pair in the Riakpb database.
|
7
|
+
class Content
|
8
8
|
include Util::Translation
|
9
9
|
include Util::MessageCode
|
10
10
|
|
11
|
-
# @return [Key] the key in which this
|
11
|
+
# @return [Key] the key in which this Content is stored.
|
12
12
|
attr_accessor :key
|
13
13
|
|
14
|
-
# @return [String] the data stored in
|
14
|
+
# @return [String] the data stored in Riakpb at this object's key. Varies in format by content-type.
|
15
15
|
attr_accessor :value
|
16
16
|
alias_attribute :data, :value
|
17
17
|
|
@@ -27,7 +27,7 @@ module Riak
|
|
27
27
|
# @return [String] the vtag of the object
|
28
28
|
attr_accessor :vtag
|
29
29
|
|
30
|
-
# @return [Set<Link>] an Set of {
|
30
|
+
# @return [Set<Link>] an Set of {Riakpb::Link} objects for relationships between this object and other resources
|
31
31
|
attr_accessor :links
|
32
32
|
|
33
33
|
# @return [Time] the Last-Modified header from the most recent HTTP response, useful for caching and reloading
|
@@ -42,95 +42,127 @@ module Riak
|
|
42
42
|
attr_accessor :usermeta
|
43
43
|
alias_attribute :meta, :usermeta
|
44
44
|
|
45
|
-
|
46
|
-
|
45
|
+
attr_accessor :options
|
46
|
+
|
47
|
+
# Create a new riak_content object manually
|
48
|
+
# @param [Riakpb::Key] key Key instance that owns this Content (really, you should use the Key to get this)
|
47
49
|
# @param [Hash] contents Any contents to initialize this instance with
|
48
50
|
# @see Key#content
|
49
|
-
# @see
|
50
|
-
def initialize(key,
|
51
|
+
# @see Content#load
|
52
|
+
def initialize(key, options={})
|
51
53
|
@key = key unless key.nil?
|
52
54
|
@links = Hash.new{|k,v| k[v] = []}
|
53
|
-
@_links = []
|
54
55
|
@usermeta = {}
|
56
|
+
@options = options
|
55
57
|
|
56
|
-
|
58
|
+
self.last_mod = Time.now
|
57
59
|
|
58
60
|
yield self if block_given?
|
59
61
|
end
|
60
62
|
|
61
|
-
|
62
|
-
|
63
|
+
def [](attribute)
|
64
|
+
instance_variable_get "@#{attribute}"
|
65
|
+
end
|
66
|
+
|
67
|
+
# Load information for the content from the response object, Riakpb::RpbContent.
|
63
68
|
# @param [RpbContent/Hash] contents an RpbContent object or a Hash.
|
64
|
-
# @return [
|
65
|
-
def load(
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
unless
|
69
|
+
# @return [Content] self
|
70
|
+
def load(content)
|
71
|
+
case content
|
72
|
+
when Riakpb::RpbContent, Hash, Riakpb::Content
|
73
|
+
last_mod = content[:last_mod]
|
74
|
+
last_mod_usecs = content[:last_mod_usecs]
|
75
|
+
|
76
|
+
if not (last_mod.blank? or last_mod_usecs.blank?)
|
77
|
+
self.last_mod = Time.at "#{last_mod}.#{last_mod_usecs}".to_f
|
78
|
+
end
|
79
|
+
|
80
|
+
@content_type = content[:content_type] unless content[:content_type].blank?
|
81
|
+
@charset = content[:charset] unless content[:charset].blank?
|
82
|
+
@content_encoding = content[:content_encoding] unless content[:content_encoding].blank?
|
83
|
+
@vtag = content[:vtag] unless content[:vtag].blank?
|
84
|
+
self.links = content[:links] unless content[:links].blank?
|
85
|
+
self.usermeta = content[:usermeta] unless content[:usermeta].blank?
|
86
|
+
|
87
|
+
unless content[:value].blank?
|
77
88
|
case @content_type
|
78
89
|
when /json/
|
79
|
-
@value = ActiveSupport::JSON.decode(
|
90
|
+
@value = ActiveSupport::JSON.decode(content[:value])
|
80
91
|
when /octet/
|
81
|
-
@value = Marshal.load(
|
92
|
+
@value = Marshal.load(content[:value])
|
82
93
|
else
|
83
|
-
@value =
|
94
|
+
@value = content[:value]
|
84
95
|
end
|
85
96
|
end
|
86
|
-
|
87
|
-
return(self)
|
97
|
+
else raise ArgumentError, t("riak_content_type")
|
88
98
|
end
|
89
99
|
|
90
|
-
|
100
|
+
return(self)
|
91
101
|
end
|
92
102
|
|
93
|
-
|
103
|
+
def merge(content)
|
104
|
+
@links.merge(
|
105
|
+
self.links = content[:links]
|
106
|
+
) unless content[:links].blank?
|
107
|
+
|
108
|
+
@usermega.merge(
|
109
|
+
self.usermeta = content[:usermeta]
|
110
|
+
) unless content[:usermeta].blank?
|
111
|
+
|
112
|
+
@content_type = content[:content_type] unless content[:content_type].blank?
|
113
|
+
@value = content[:value]
|
114
|
+
@charset = content[:charset] unless content[:charset].blank?
|
115
|
+
@content_encoding = content[:content_encoding] unless content[:content_encoding].blank?
|
116
|
+
@vtag = content[:vtag] unless content[:vtag].blank?
|
117
|
+
@last_mod = content[:last_mod]
|
118
|
+
@last_mod_usecs = content[:last_mod_usecs]
|
119
|
+
|
120
|
+
return(self)
|
121
|
+
end
|
122
|
+
|
123
|
+
# Save the Content instance in riak.
|
94
124
|
# @option options [Fixnum] w (write quorum) how many replicas to write to before returning a successful response
|
95
125
|
# @option options [Fixnum] dw how many replicas to commit to durable storage before returning a successful response
|
96
126
|
# @option options [true/false] return_body whether or not to have riak return the key, once saved. default = true
|
97
127
|
def save(options={})
|
98
128
|
begin
|
99
|
-
save!(options)
|
129
|
+
self.save!(options)
|
100
130
|
rescue FailedRequest
|
101
131
|
return(false)
|
102
132
|
end
|
103
133
|
return(true)
|
104
134
|
end
|
105
135
|
|
106
|
-
# Save the
|
136
|
+
# Save the Content instance in riak. Raise/do not rescue on failure.
|
107
137
|
# @option options [Fixnum] w (write quorum) how many replicas to write to before returning a successful response
|
108
138
|
# @option options [Fixnum] dw how many replicas to commit to durable storage before returning a successful response
|
109
139
|
# @option options [true/false] return_body whether or not to have riak return the key, once saved. default = true
|
110
140
|
def save!(options={})
|
111
141
|
options[:content] = self
|
142
|
+
options = @options.merge(options)
|
143
|
+
|
112
144
|
return(true) if @key.save(options)
|
113
145
|
return(false) # Create and raise Error message for this? Extend "Failed Request"?
|
114
146
|
end
|
115
147
|
|
148
|
+
|
116
149
|
# Internalizes a link to a Key, which will be saved on next call to... uh, save
|
117
150
|
# @param [Hash] tags name of the tag, pointing to a Key instance, or an array ["bucket", "key"]
|
118
|
-
# @return [Hash] links that this
|
151
|
+
# @return [Hash] links that this Content points to
|
119
152
|
def link_key(tags)
|
120
|
-
raise TypeError.new t('invalid_tag') unless
|
153
|
+
raise TypeError.new t('invalid_tag') unless tags.is_a?(Hash) or tags.is_a?(Array)
|
154
|
+
|
121
155
|
tags.each do |tag, link|
|
122
156
|
case link
|
123
157
|
when Array
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
get_link ||= @key.get_linked(bucket, key, {:safely => true})
|
129
|
-
raise RuntimeError.new t('invalid_key') if get_link.nil?
|
158
|
+
newlink = Riakpb::RpbLink.new
|
159
|
+
newlink[:bucket] = link[0]
|
160
|
+
newlink[:key] = link[1]
|
161
|
+
raise ArgumentError.new t('invalid_tag') if link[0].nil? or link[1].nil?
|
130
162
|
|
131
|
-
@links[tag.to_s] <<
|
163
|
+
@links[tag.to_s] << newlink
|
132
164
|
|
133
|
-
when
|
165
|
+
when Riakpb::Key
|
134
166
|
@links[tag.to_s] << link
|
135
167
|
|
136
168
|
else
|
@@ -142,35 +174,59 @@ module Riak
|
|
142
174
|
|
143
175
|
# Set the links to other Key in riak.
|
144
176
|
# @param [RpbGetResp, RpbPutResp] contains the tag/bucket/key of a given link
|
145
|
-
# @return [Set] links that this
|
177
|
+
# @return [Set] links that this Content points to
|
146
178
|
def links=(pb_links)
|
147
179
|
@links.clear
|
148
180
|
|
149
|
-
pb_links
|
150
|
-
|
181
|
+
case pb_links
|
182
|
+
when Hash
|
183
|
+
pb_links.each do |k, v|
|
184
|
+
raise TypeError.new unless k.is_a?(String)
|
185
|
+
|
186
|
+
if v.is_a?(Array)
|
187
|
+
@links[k] += v
|
188
|
+
else
|
189
|
+
@links[k] << v
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
when Array, Protobuf::Field::FieldArray
|
194
|
+
pb_links.each do |pb_link|
|
195
|
+
@links[pb_link.tag] << @key.get_linked(pb_link.bucket, pb_link.key, {:safely => true})
|
196
|
+
end
|
197
|
+
else
|
198
|
+
raise TypeError.new
|
151
199
|
end
|
152
200
|
|
153
201
|
return(@links)
|
154
202
|
end
|
155
203
|
|
156
|
-
# @return [Riak::RpbContent] An instance of a RpbContent, suitable for protobuf exchange
|
157
|
-
def to_pb
|
158
|
-
raise TypeError.new t('value_empty') if @value.nil?
|
159
204
|
|
160
|
-
|
205
|
+
def last_mod=(time_mod)
|
206
|
+
@last_mod = Time.at time_mod
|
207
|
+
end
|
208
|
+
|
209
|
+
# @return [Riakpb::RpbContent] An instance of a RpbContent, suitable for protobuf exchange
|
210
|
+
def to_pb
|
211
|
+
rpb_content = Riakpb::RpbContent.new
|
161
212
|
rpb_links = []
|
162
213
|
|
163
214
|
@links.each do |tag, links|
|
164
215
|
links.each do |link|
|
165
|
-
|
166
|
-
|
167
|
-
|
216
|
+
case link
|
217
|
+
when Riakpb::RpbLink
|
218
|
+
rpb_links << hlink
|
219
|
+
when Riakpb::Key
|
220
|
+
pb_link = link.to_pb_link
|
221
|
+
pb_link.tag = tag
|
222
|
+
rpb_links << pb_link
|
223
|
+
end
|
168
224
|
end
|
169
225
|
end
|
170
226
|
|
171
227
|
usermeta = []
|
172
228
|
@usermeta.each do |key,value|
|
173
|
-
pb_pair =
|
229
|
+
pb_pair = Riakpb::RpbPair.new
|
174
230
|
pb_pair[:key] = key
|
175
231
|
pb_pair[:value] = value
|
176
232
|
usermeta << pb_pair
|
@@ -179,30 +235,29 @@ module Riak
|
|
179
235
|
catch(:redo) do
|
180
236
|
case @content_type
|
181
237
|
when /octet/
|
182
|
-
rpb_content.value = Marshal.dump(@value)
|
238
|
+
rpb_content.value = Marshal.dump(@value) unless @value.blank?
|
183
239
|
when /json/
|
184
|
-
rpb_content.value = ActiveSupport::JSON.encode(@value)
|
240
|
+
rpb_content.value = ActiveSupport::JSON.encode(@value) unless @value.blank?
|
185
241
|
when "", nil
|
186
242
|
@content_type = "application/json"
|
187
243
|
redo
|
188
244
|
else
|
189
|
-
rpb_content.value = @value.to_s
|
245
|
+
rpb_content.value = @value.to_s unless @value.blank?
|
190
246
|
end
|
191
247
|
end
|
192
248
|
|
193
|
-
rpb_content.content_type = @content_type unless @content_type.
|
194
|
-
rpb_content.charset = @charset unless @charset.
|
195
|
-
rpb_content.content_encoding = @content_encoding unless @content_encoding.
|
196
|
-
rpb_content.
|
197
|
-
rpb_content.
|
198
|
-
rpb_content.usermeta = usermeta unless usermeta.nil?
|
249
|
+
rpb_content.content_type = @content_type unless @content_type.blank?
|
250
|
+
rpb_content.charset = @charset unless @charset.blank? # || @charset.empty?
|
251
|
+
rpb_content.content_encoding = @content_encoding unless @content_encoding.blank? # || @content_encoding.empty?
|
252
|
+
rpb_content.links = rpb_links unless rpb_links.blank?
|
253
|
+
rpb_content.usermeta = usermeta unless usermeta.blank?
|
199
254
|
|
200
255
|
return(rpb_content)
|
201
256
|
end
|
202
257
|
|
203
258
|
# @return [String] A representation suitable for IRB and debugging output
|
204
259
|
def inspect
|
205
|
-
"#<#
|
260
|
+
"#<#Riakpb::Content " + [
|
206
261
|
(@value.nil?) ? nil : "value=#{@value.inspect}",
|
207
262
|
(@content_type.nil?) ? nil : "content_type=#{@content_type.inspect}",
|
208
263
|
(@charset.nil?) ? nil : "charset=#{@charset.inspect}",
|
@@ -218,5 +273,5 @@ module Riak
|
|
218
273
|
|
219
274
|
private
|
220
275
|
|
221
|
-
end # class
|
222
|
-
end # module
|
276
|
+
end # class Content
|
277
|
+
end # module Riakpb
|
data/lib/riak/failed_exchange.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'riak'
|
2
2
|
|
3
|
-
module
|
4
|
-
# Exception raised when the expected response code from
|
3
|
+
module Riakpb
|
4
|
+
# Exception raised when the expected response code from Riakpb
|
5
5
|
# fails to match the actual response code.
|
6
6
|
class FailedExchange < StandardError
|
7
7
|
include Util::Translation
|
data/lib/riak/failed_request.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'riak'
|
2
2
|
|
3
|
-
module
|
4
|
-
# Exception raised when the expected response code from
|
3
|
+
module Riakpb
|
4
|
+
# Exception raised when the expected response code from Riakpb
|
5
5
|
# fails to match the actual response code.
|
6
6
|
class FailedRequest < StandardError
|
7
|
-
include
|
7
|
+
include Riakpb::Util::Translation
|
8
8
|
|
9
9
|
attr_reader :expected
|
10
10
|
attr_reader :actual
|
data/lib/riak/key.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'riak'
|
2
2
|
|
3
|
-
module
|
4
|
-
# Represents and encapsulates operations on a
|
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 Key
|
7
7
|
include Util::Translation
|
8
8
|
include Util::MessageCode
|
9
9
|
|
10
|
-
# @return [
|
10
|
+
# @return [Riakpb::Client] the associated client
|
11
11
|
attr_reader :bucket
|
12
12
|
|
13
13
|
# @return [String] the bucket name
|
@@ -16,25 +16,25 @@ module Riak
|
|
16
16
|
# @return [String] the bucket name
|
17
17
|
attr_reader :vclock
|
18
18
|
|
19
|
-
# Create a
|
19
|
+
# Create a Riakpb bucket manually.
|
20
20
|
# @param [Bucket] bucket the Bucket object within which this Key exists
|
21
21
|
# @option options [String] name the name assigned to this Key entity
|
22
22
|
# @option options [Fixnum] vclock Careful! Do not set this unless you have a reason to
|
23
|
-
# @option options [
|
23
|
+
# @option options [Content] content a content object, that's to be inserted in this Key
|
24
24
|
def initialize(bucket, key, get_response=nil)
|
25
25
|
# options.assert_valid_keys(:name, :vclock, :content)
|
26
26
|
|
27
27
|
self.bucket = bucket
|
28
28
|
self.name = key
|
29
29
|
|
30
|
-
@contents = Hash.new{|k,v| k[v] =
|
30
|
+
@contents = Hash.new{|k,v| k[v] = Riakpb::Content.new(self)}
|
31
31
|
|
32
32
|
# @contents[:new]
|
33
33
|
|
34
34
|
load(get_response) unless get_response.nil?
|
35
35
|
end
|
36
36
|
|
37
|
-
# Load information for the key from the response object,
|
37
|
+
# Load information for the key from the response object, Riakpb::RpbGetResp.
|
38
38
|
#
|
39
39
|
# @param [RpbGetResp/Hash] response an RpbGetResp/RpbPutResp object or a Hash.
|
40
40
|
# @return [Key] self
|
@@ -53,12 +53,12 @@ module Riak
|
|
53
53
|
return(self)
|
54
54
|
end
|
55
55
|
|
56
|
-
# Load information for the key from
|
56
|
+
# Load information for the key from Riakpb::RpbGetResp object.
|
57
57
|
#
|
58
58
|
# @param [RpbGetResp/Hash] response an RpbGetResp/RpbPutResp object or a Hash.
|
59
59
|
# @return [Key] self
|
60
60
|
def load!(response)
|
61
|
-
raise ArgumentError, t("response_type") unless response.is_a?(
|
61
|
+
raise ArgumentError, t("response_type") unless response.is_a?(Riakpb::RpbGetResp)
|
62
62
|
|
63
63
|
if response.has_field?(:vclock) and response.has_field?(:content)
|
64
64
|
|
@@ -89,8 +89,8 @@ module Riak
|
|
89
89
|
|
90
90
|
end
|
91
91
|
|
92
|
-
# Retrieves any Keys that are linked to, inside
|
93
|
-
# @return [Key] the Key to which the
|
92
|
+
# Retrieves any Keys that are linked to, inside Content elements.
|
93
|
+
# @return [Key] the Key to which the Content is linked (may be empty if it does not exist)
|
94
94
|
def get_linked(bucket, key, options={})
|
95
95
|
@bucket.get_linked(bucket, key, options)
|
96
96
|
end
|
@@ -98,7 +98,7 @@ module Riak
|
|
98
98
|
# Sets the name attribute for this Key object
|
99
99
|
# @param [String] key_name sets the name of the Key
|
100
100
|
# @return [Hash] the properties that were accepted
|
101
|
-
# @raise [FailedRequest] if the new properties were not accepted by the
|
101
|
+
# @raise [FailedRequest] if the new properties were not accepted by the Riakpb server
|
102
102
|
def name=(key_name)
|
103
103
|
raise ArgumentError, t("key_name_type") unless key_name.is_a?(String)
|
104
104
|
|
@@ -107,9 +107,9 @@ module Riak
|
|
107
107
|
|
108
108
|
# Sets the content object for this Key. I do not yet support siblings in this method and, therefore,
|
109
109
|
# you may or may not destroy them if you use this and are not careful.
|
110
|
-
# @param [
|
111
|
-
# @return [
|
112
|
-
# @raise [ArgumentError] will yell at you if the supplied riak_content is not of the
|
110
|
+
# @param [Riakpb::Content] content a Content instance that should be contained within this Key
|
111
|
+
# @return [Riakpb::Content] the Content instance that was just set
|
112
|
+
# @raise [ArgumentError] will yell at you if the supplied riak_content is not of the Content class
|
113
113
|
def content=(riak_contents)
|
114
114
|
|
115
115
|
if riak_contents.is_a?(Protobuf::Field::FieldArray)
|
@@ -122,7 +122,7 @@ module Riak
|
|
122
122
|
end
|
123
123
|
|
124
124
|
return(true)
|
125
|
-
elsif riak_contents.is_a?(
|
125
|
+
elsif riak_contents.is_a?(Riakpb::Content)
|
126
126
|
|
127
127
|
@contents.clear
|
128
128
|
|
@@ -137,9 +137,9 @@ module Riak
|
|
137
137
|
|
138
138
|
end # def content=
|
139
139
|
|
140
|
-
# "@contents" is an array of
|
140
|
+
# "@contents" is an array of Content objects, though only contains more than one in the event that
|
141
141
|
# there are siblings.
|
142
|
-
# @return [
|
142
|
+
# @return [Riakpb::Content] the content of this Key instance's value (ie, key/value)
|
143
143
|
def content
|
144
144
|
case @contents.size
|
145
145
|
when 0 then @contents[:new]
|
@@ -148,8 +148,8 @@ module Riak
|
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
151
|
-
# "@contents" is an array of
|
152
|
-
# @return [Array<
|
151
|
+
# "@contents" is an array of Content objects. This gives you that entire array.
|
152
|
+
# @return [Array<Riakpb::Content>] the contents of this Key instance's value and its siblings, if any
|
153
153
|
def contents
|
154
154
|
retr_c = []
|
155
155
|
|
@@ -158,8 +158,8 @@ module Riak
|
|
158
158
|
return(retr_c)
|
159
159
|
end
|
160
160
|
|
161
|
-
# Save the Key+
|
162
|
-
# @option options [
|
161
|
+
# Save the Key+Content instance in riak.
|
162
|
+
# @option options [Content] content Content instance to be saved in this Key. Must be specified if there are siblings.
|
163
163
|
# @option options [Fixnum] w (write quorum) how many replicas to write to before returning a successful response
|
164
164
|
# @option options [Fixnum] dw how many replicas to commit to durable storage before returning a successful response
|
165
165
|
# @option options [Boolean] return_body whether or not to have riak return the key, once saved. default = true
|
@@ -175,8 +175,8 @@ module Riak
|
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
178
|
-
options[:content] = rcontent.to_pb if rcontent.is_a?(
|
179
|
-
options[:content] = rcontent if rcontent.is_a?(
|
178
|
+
options[:content] = rcontent.to_pb if rcontent.is_a?(Riakpb::Content)
|
179
|
+
options[:content] = rcontent if rcontent.is_a?(Riakpb::RpbContent)
|
180
180
|
options[:key] = @name
|
181
181
|
options[:vclock] = @vclock unless @vclock.nil?
|
182
182
|
|
@@ -190,7 +190,7 @@ module Riak
|
|
190
190
|
end
|
191
191
|
end
|
192
192
|
|
193
|
-
# Save the
|
193
|
+
# Save the Content instance in riak. Raise/do not rescue on failure.
|
194
194
|
# @option options [Fixnum] w (write quorum) how many replicas to write to before returning a successful response
|
195
195
|
# @option options [Fixnum] dw how many replicas to commit to durable storage before returning a successful response
|
196
196
|
# @option options [Boolean] return_body whether or not to have riak return the key, once saved. default = true
|
@@ -208,7 +208,7 @@ module Riak
|
|
208
208
|
# @option options [Fixnum] w (write quorum) how many replicas to write to before returning a successful response
|
209
209
|
# @option options [Fixnum] dw how many replicas to commit to durable storage before returning a successful response
|
210
210
|
# @option options [Boolean] return_body whether or not to have riak return the key, once saved. default = true
|
211
|
-
# @return [
|
211
|
+
# @return [Riakpb::RpbPutReq]
|
212
212
|
def to_pb_put(options={})
|
213
213
|
rcontent = options[:content]
|
214
214
|
|
@@ -220,26 +220,26 @@ module Riak
|
|
220
220
|
end
|
221
221
|
end
|
222
222
|
|
223
|
-
pb_put_req =
|
223
|
+
pb_put_req = Riakpb::RpbPutReq.new
|
224
224
|
pb_put_req.key = @name
|
225
|
-
pb_put_req.content = rcontent.to_pb if rcontent.is_a?(
|
226
|
-
pb_put_req.content = rcontent if rcontent.is_a?(
|
225
|
+
pb_put_req.content = rcontent.to_pb if rcontent.is_a?(Riakpb::Content)
|
226
|
+
pb_put_req.content = rcontent if rcontent.is_a?(Riakpb::RpbContent)
|
227
227
|
pb_put_req.vclock = @vclock unless @vclock.nil?
|
228
228
|
|
229
229
|
return(pb_put_req)
|
230
230
|
end
|
231
231
|
|
232
|
-
# "@contents" is an array of
|
233
|
-
# @return [
|
232
|
+
# "@contents" is an array of Content objects. This gives you that entire array.
|
233
|
+
# @return [Riakpb::RpbLink]
|
234
234
|
def to_pb_link
|
235
|
-
pb_link =
|
235
|
+
pb_link = Riakpb::RpbLink.new
|
236
236
|
pb_link[:bucket] = @bucket.name
|
237
237
|
pb_link[:key] = @name
|
238
238
|
|
239
239
|
return(pb_link)
|
240
240
|
end
|
241
241
|
|
242
|
-
# Converts this Key into an array, that can be used by a
|
242
|
+
# Converts this Key into an array, that can be used by a Content, if desired.
|
243
243
|
# @return [Array] contains the name of the bucket and the name of the key
|
244
244
|
def to_link
|
245
245
|
[@bucket.name, @name]
|
@@ -255,7 +255,7 @@ module Riak
|
|
255
255
|
|
256
256
|
# @return [String] a representation suitable for IRB and debugging output
|
257
257
|
def inspect
|
258
|
-
"#<
|
258
|
+
"#<Riakpb::Key name=#{@name.inspect}, vclock=#{@vclock.inspect}, contents=#{contents.inspect}>"
|
259
259
|
end
|
260
260
|
|
261
261
|
private
|
@@ -263,14 +263,14 @@ module Riak
|
|
263
263
|
# Sets the name attribute for this Key object
|
264
264
|
# @param [String] key_name sets the name of the Key
|
265
265
|
# @return [Hash] the properties that were accepted
|
266
|
-
# @raise [FailedRequest] if the new properties were not accepted by the
|
266
|
+
# @raise [FailedRequest] if the new properties were not accepted by the Riakpb server
|
267
267
|
def bucket=(bucket)
|
268
|
-
raise ArgumentError, t("invalid_bucket") unless bucket.is_a?(
|
268
|
+
raise ArgumentError, t("invalid_bucket") unless bucket.is_a?(Riakpb::Bucket)
|
269
269
|
|
270
270
|
@bucket ||= bucket
|
271
271
|
end
|
272
272
|
|
273
|
-
# Sets the vclock attribute for this Key, which was supplied by the
|
273
|
+
# Sets the vclock attribute for this Key, which was supplied by the Riakpb node (if you're doing it right)
|
274
274
|
# @param [Fixnum] vclock the vector clock
|
275
275
|
# @return [Fixnum] the vector clock
|
276
276
|
# @raise [ArgumentError] if you failed at this task, you'll be instructed to place your head on the keyboard
|
@@ -281,4 +281,4 @@ module Riak
|
|
281
281
|
end
|
282
282
|
|
283
283
|
end # class Key
|
284
|
-
end # module
|
284
|
+
end # module Riakpb
|
data/lib/riak/locale/en.yml
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
en:
|
2
2
|
riak:
|
3
|
-
client_type: "invalid argument {{client}} is not a
|
3
|
+
client_type: "invalid argument {{client}} is not a Riakpb::Client"
|
4
4
|
string_type: "invalid_argument {{string}} is not a String"
|
5
5
|
loading_bucket: "while loading bucket '{{name}}'"
|
6
6
|
invalid_bucket: "the specified bucket is invalid"
|
7
7
|
invalid_key: "the specified key is invalid or does not exist"
|
8
8
|
siblings_disallowed: "the specified bucket does not allow siblings. Set allow_mult in props to do this."
|
9
9
|
value_empty: "a value must be set in order to serialize into a protocol buffer"
|
10
|
-
failed_request: "Expected message code {{expected}} from
|
11
|
-
decode_error: "
|
10
|
+
failed_request: "Expected message code {{expected}} from Riakpb but received {{actual}}. {{output}}"
|
11
|
+
decode_error: "Riakpb reported a message length of {{expected}} but length was {{actual}}. {{output}}"
|
12
12
|
save_resp_siblings: "The save operation has resulted in unresolved siblings. {{output}}"
|
13
13
|
save_resp_err: "The attempted save operation resulted in an error response from riak."
|
14
14
|
failed_rx: "You might have discovered a bug. {{failure}}"
|
data/lib/riak/map_reduce.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'riak'
|
2
2
|
|
3
|
-
module
|
3
|
+
module Riakpb
|
4
4
|
# Class for invoking map-reduce jobs using the HTTP interface.
|
5
5
|
class MapReduce
|
6
6
|
include Util::Translation
|
@@ -15,7 +15,7 @@ module Riak
|
|
15
15
|
attr_accessor :query
|
16
16
|
|
17
17
|
# Creates a new map-reduce job.
|
18
|
-
# @param [Client] client the
|
18
|
+
# @param [Client] client the Riakpb::Client interface
|
19
19
|
# @yield [self] helpful for initializing the job
|
20
20
|
def initialize(client)
|
21
21
|
@client, @inputs, @query = client, [], []
|
@@ -44,16 +44,16 @@ module Riak
|
|
44
44
|
when 1
|
45
45
|
p = params.first
|
46
46
|
case p
|
47
|
-
when
|
47
|
+
when Riakpb::Bucket
|
48
48
|
@inputs = p.name
|
49
|
-
when
|
49
|
+
when Riakpb::Key
|
50
50
|
@inputs << p.to_input
|
51
51
|
when String
|
52
52
|
@inputs = p
|
53
53
|
end
|
54
54
|
when 2..3
|
55
55
|
bucket = params.shift
|
56
|
-
bucket = bucket.name if
|
56
|
+
bucket = bucket.name if Riakpb::Bucket === bucket
|
57
57
|
@inputs << params.unshift(bucket)
|
58
58
|
end
|
59
59
|
self
|
@@ -135,7 +135,7 @@ module Riak
|
|
135
135
|
# @return [Symbol] the type of phase - :map, :reduce, or :link
|
136
136
|
attr_accessor :type
|
137
137
|
|
138
|
-
# @return [String, Array<String, String>, Hash, WalkSpec] For :map and :reduce types, the Javascript function to run (as a string or hash with bucket/key), or the module + function in Erlang to run. For a :link type, a {
|
138
|
+
# @return [String, Array<String, String>, Hash, WalkSpec] For :map and :reduce types, the Javascript function to run (as a string or hash with bucket/key), or the module + function in Erlang to run. For a :link type, a {Riakpb::WalkSpec} or an equivalent hash.
|
139
139
|
attr_accessor :function
|
140
140
|
|
141
141
|
# @return [String] the language of the phase's function - "javascript" or "erlang". Meaningless for :link type phases.
|
data/lib/riak/sibling_error.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'riak'
|
2
2
|
|
3
|
-
module
|
4
|
-
# Exception raised when the expected response code from
|
3
|
+
module Riakpb
|
4
|
+
# Exception raised when the expected response code from Riakpb
|
5
5
|
# fails to match the actual response code.
|
6
6
|
class SiblingError < StandardError
|
7
|
-
include
|
7
|
+
include Riakpb::Util::Translation
|
8
8
|
|
9
9
|
attr_reader :key
|
10
10
|
|