riak-client 2.2.0.pre1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +0 -2
- data/README.markdown +11 -7
- data/RELEASE_NOTES.md +29 -2
- data/Rakefile +5 -3
- data/lib/riak/bucket.rb +55 -23
- data/lib/riak/bucket_properties.rb +8 -1
- data/lib/riak/bucket_type.rb +29 -0
- data/lib/riak/bucket_typed/bucket.rb +15 -7
- data/lib/riak/client.rb +24 -8
- data/lib/riak/client/beefcake/bucket_properties_operator.rb +8 -8
- data/lib/riak/client/beefcake/crdt/set_loader.rb +1 -1
- data/lib/riak/client/beefcake/crdt_loader.rb +1 -1
- data/lib/riak/client/beefcake/crdt_operator.rb +9 -9
- data/lib/riak/client/beefcake/message_codes.rb +4 -0
- data/lib/riak/client/beefcake/message_overlay.rb +4 -0
- data/lib/riak/client/beefcake/messages.rb +35 -5
- data/lib/riak/client/beefcake/object_methods.rb +21 -13
- data/lib/riak/client/beefcake/protocol.rb +7 -7
- data/lib/riak/client/beefcake/socket.rb +2 -2
- data/lib/riak/client/beefcake_protobuffs_backend.rb +58 -33
- data/lib/riak/client/protobuffs_backend.rb +5 -5
- data/lib/riak/client/yokozuna.rb +3 -3
- data/lib/riak/core_ext/deep_dup.rb +1 -1
- data/lib/riak/counter.rb +10 -10
- data/lib/riak/crdt/base.rb +39 -21
- data/lib/riak/crdt/batch_counter.rb +5 -5
- data/lib/riak/crdt/batch_map.rb +2 -2
- data/lib/riak/crdt/counter.rb +7 -7
- data/lib/riak/crdt/inner_counter.rb +4 -4
- data/lib/riak/crdt/inner_flag.rb +3 -3
- data/lib/riak/crdt/inner_map.rb +1 -1
- data/lib/riak/crdt/inner_register.rb +1 -1
- data/lib/riak/crdt/inner_set.rb +5 -5
- data/lib/riak/crdt/map.rb +9 -9
- data/lib/riak/crdt/set.rb +10 -10
- data/lib/riak/crdt/typed_collection.rb +39 -36
- data/lib/riak/errors/base.rb +1 -1
- data/lib/riak/errors/crdt_error.rb +20 -0
- data/lib/riak/errors/search_error.rb +6 -0
- data/lib/riak/index_collection.rb +1 -1
- data/lib/riak/link.rb +5 -3
- data/lib/riak/locale/en.yml +5 -1
- data/lib/riak/map_reduce.rb +7 -7
- data/lib/riak/map_reduce/filter_builder.rb +2 -2
- data/lib/riak/map_reduce/phase.rb +2 -2
- data/lib/riak/preflist_item.rb +7 -0
- data/lib/riak/rcontent.rb +8 -8
- data/lib/riak/robject.rb +27 -14
- data/lib/riak/search.rb +1 -0
- data/lib/riak/search/index.rb +17 -3
- data/lib/riak/search/query.rb +14 -6
- data/lib/riak/search/result_collection.rb +56 -3
- data/lib/riak/search/result_document.rb +71 -1
- data/lib/riak/search/schema.rb +6 -6
- data/lib/riak/secondary_index.rb +20 -12
- data/lib/riak/serializers.rb +0 -1
- data/lib/riak/util/escape.rb +2 -2
- data/lib/riak/util/translation.rb +1 -2
- data/lib/riak/version.rb +1 -1
- data/lib/riak/walk_spec.rb +67 -32
- data/riak-client.gemspec +5 -4
- data/spec/integration/riak/bucket_types_spec.rb +35 -5
- data/spec/integration/riak/conflict_resolution_spec.rb +1 -1
- data/spec/integration/riak/counters_spec.rb +1 -1
- data/spec/integration/riak/crdt/configuration_spec.rb +37 -0
- data/spec/integration/riak/crdt_search_spec.rb +176 -0
- data/spec/integration/riak/crdt_spec.rb +9 -33
- data/spec/integration/riak/crdt_validation/map_spec.rb +4 -4
- data/spec/integration/riak/crdt_validation/set_spec.rb +13 -13
- data/spec/integration/riak/preflist_spec.rb +31 -0
- data/spec/integration/riak/protobuffs/interrupted_request_spec.rb +2 -2
- data/spec/integration/riak/protobuffs_backends_spec.rb +9 -2
- data/spec/integration/riak/search_spec.rb +3 -3
- data/spec/integration/riak/secondary_index_spec.rb +3 -3
- data/spec/integration/riak/security_spec.rb +7 -7
- data/spec/integration/yokozuna/queries_spec.rb +1 -1
- data/spec/riak/beefcake_protobuffs_backend/bucket_properties_operator_spec.rb +9 -9
- data/spec/riak/beefcake_protobuffs_backend/crdt_operator_spec.rb +9 -9
- data/spec/riak/beefcake_protobuffs_backend/protocol_spec.rb +5 -5
- data/spec/riak/beefcake_protobuffs_backend_spec.rb +8 -8
- data/spec/riak/bucket_properties_spec.rb +27 -6
- data/spec/riak/bucket_spec.rb +5 -5
- data/spec/riak/bucket_type_spec.rb +21 -5
- data/spec/riak/bucket_typed/bucket_spec.rb +62 -0
- data/spec/riak/client_spec.rb +36 -18
- data/spec/riak/counter_spec.rb +4 -4
- data/spec/riak/crdt/counter_spec.rb +2 -2
- data/spec/riak/crdt/inner_flag_spec.rb +2 -2
- data/spec/riak/crdt/inner_map_spec.rb +4 -4
- data/spec/riak/crdt/inner_register_spec.rb +1 -1
- data/spec/riak/crdt/map_spec.rb +4 -4
- data/spec/riak/crdt/shared_examples.rb +5 -5
- data/spec/riak/crdt/typed_collection_spec.rb +21 -21
- data/spec/riak/map_reduce/filter_builder_spec.rb +2 -2
- data/spec/riak/map_reduce/phase_spec.rb +4 -4
- data/spec/riak/map_reduce_spec.rb +60 -42
- data/spec/riak/multiget_spec.rb +2 -2
- data/spec/riak/robject_spec.rb +55 -14
- data/spec/riak/search/index_spec.rb +12 -2
- data/spec/riak/search/query_spec.rb +4 -4
- data/spec/riak/search/result_collection_spec.rb +6 -4
- data/spec/riak/search/result_document_spec.rb +52 -9
- data/spec/riak/search/schema_spec.rb +2 -2
- data/spec/riak/secondary_index_spec.rb +6 -6
- data/spec/riak/serializers_spec.rb +27 -10
- data/spec/riak/walk_spec_spec.rb +10 -6
- data/spec/spec_helper.rb +11 -2
- data/spec/support/crdt_search_config.rb +112 -0
- data/spec/support/crdt_search_fixtures.rb +42 -0
- data/spec/support/search_config.rb +7 -5
- data/spec/support/search_corpus_setup.rb +2 -2
- data/spec/support/test_client.rb +2 -2
- data/spec/support/unified_backend_examples.rb +5 -5
- data/spec/support/version_filter.rb +5 -3
- data/spec/support/wait_until.rb +9 -3
- metadata +36 -13
- data/spec/riak/bucket_typed/bucket.rb +0 -43
data/lib/riak/errors/base.rb
CHANGED
|
@@ -14,5 +14,25 @@ module Riak
|
|
|
14
14
|
super t('crdt.precondition', message: message)
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
|
+
|
|
18
|
+
class UnrecognizedDataType < CrdtError
|
|
19
|
+
def initialize(given_type)
|
|
20
|
+
super t('crdt.unrecognized_type', type: given_type)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class UnexpectedDataType < CrdtError
|
|
25
|
+
def initialize(given_type, expected_type)
|
|
26
|
+
super t('crdt.unexpected_type',
|
|
27
|
+
given: given_type,
|
|
28
|
+
expected: expected_type)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
class NotACrdt < CrdtError
|
|
33
|
+
def initialize
|
|
34
|
+
super t('crdt.not_a_crdt')
|
|
35
|
+
end
|
|
36
|
+
end
|
|
17
37
|
end
|
|
18
38
|
end
|
|
@@ -25,5 +25,11 @@ module Riak
|
|
|
25
25
|
super t('search.index_non_exist', index: index)
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
|
+
|
|
29
|
+
class UnexpectedResultError < SearchError
|
|
30
|
+
def initialize(expected, actual)
|
|
31
|
+
super t('search.unexpected_result', expected: expected, actual: actual)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
28
34
|
end
|
|
29
35
|
end
|
data/lib/riak/link.rb
CHANGED
|
@@ -52,7 +52,7 @@ module Riak
|
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
# @return [String] the URL (relative or absolute) of the related resource
|
|
55
|
-
def url(new_scheme=false)
|
|
55
|
+
def url(new_scheme = false)
|
|
56
56
|
return @url unless @bucket
|
|
57
57
|
|
|
58
58
|
if new_scheme
|
|
@@ -68,9 +68,11 @@ module Riak
|
|
|
68
68
|
@key = unescape($1) if value =~ %r{^/buckets/[^/]+/keys/([^/]+)/?} || value =~ %r{^/[^/]+/[^/]+/([^/]+)/?}
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
-
def inspect
|
|
71
|
+
def inspect
|
|
72
|
+
to_s
|
|
73
|
+
end
|
|
72
74
|
|
|
73
|
-
def to_s(new_scheme=false)
|
|
75
|
+
def to_s(new_scheme = false)
|
|
74
76
|
%Q[<#{url(new_scheme)}>; riaktag="#{tag}"]
|
|
75
77
|
end
|
|
76
78
|
|
data/lib/riak/locale/en.yml
CHANGED
|
@@ -13,9 +13,12 @@ en:
|
|
|
13
13
|
increment_by_integer: "Counters can only be incremented or decremented by integers."
|
|
14
14
|
crdt:
|
|
15
15
|
precondition_error: "Riak server returned precondition error: %{message}"
|
|
16
|
+
not_a_crdt: "Expected to find a CRDT, but failed."
|
|
16
17
|
set_removal_without_context: "CRDT Sets do not support removal without context. Store and reload the set before removing members."
|
|
17
18
|
unknown_field: "Unknown field type %{symbol}, expected one of :counter, :map, or :set."
|
|
18
19
|
unknown_inner_field: "Unknown field type %{symbol}, expected one of :counter, :flag, :map, :register, or :set."
|
|
20
|
+
unexpected_type: "Tried to initialize %{expected}, found unexpected %{given}."
|
|
21
|
+
unrecognized_type: "Couldn't determine CRDT class for datatype %{type}"
|
|
19
22
|
serialize_no_ops: "Can't serialize an empty list of CRDT operations."
|
|
20
23
|
flag:
|
|
21
24
|
not_boolean: "Flags can only be true or false."
|
|
@@ -49,7 +52,7 @@ en:
|
|
|
49
52
|
invalid_ssl_verify_mode: "%{invalid} is not a valid :verify_mode option for SSL. Valid options are 'peer' and 'none'."
|
|
50
53
|
invalid_index_query: "%{value} is not a valid index query term, only Strings, Integers, and Ranges of those are allowed."
|
|
51
54
|
indexes_unsupported: "Riak server does not support secondary indexes."
|
|
52
|
-
loading_bucket: "while loading bucket '%{name}'"
|
|
55
|
+
loading_bucket: "while loading bucket '%{name}'"
|
|
53
56
|
list_buckets: "Riak::Client#buckets is an expensive operation that should not be used in production.\n %{backtrace}"
|
|
54
57
|
list_keys: "Riak::Bucket#keys is an expensive operation that should not be used in production.\n %{backtrace}"
|
|
55
58
|
missing_block: "A block must be given."
|
|
@@ -75,6 +78,7 @@ en:
|
|
|
75
78
|
index_non_exist: "The index %{index} doesn't exist."
|
|
76
79
|
index_argument_error: "invalid argument %{index} is not a Riak::Search::Index or a String"
|
|
77
80
|
schema_exists: "The schema %{name} already exists."
|
|
81
|
+
unexpected_result: "Expected %{expected} but got %{actual} from search result."
|
|
78
82
|
search_unsupported: "Riak server does not support search."
|
|
79
83
|
search_docs_require_id: "Search index documents must include the 'id' field."
|
|
80
84
|
search_remove_requires_id_or_query: "Search index documents to be removed must have 'id' or 'query' keys."
|
data/lib/riak/map_reduce.rb
CHANGED
|
@@ -85,7 +85,7 @@ module Riak
|
|
|
85
85
|
else
|
|
86
86
|
bucket = maybe_escape(bucket)
|
|
87
87
|
end
|
|
88
|
-
|
|
88
|
+
|
|
89
89
|
warn(t('full_bucket_mapred', :backtrace => caller.join("\n "))) unless Riak.disable_list_keys_warnings
|
|
90
90
|
@inputs = {:bucket => bucket, :key_filters => params.first }
|
|
91
91
|
else
|
|
@@ -246,13 +246,13 @@ module Riak
|
|
|
246
246
|
|
|
247
247
|
# Processes a {RObject} into a single-object {MapReduce} input, whether it
|
|
248
248
|
# has a bucket type or not.
|
|
249
|
-
def robject_input(obj, key_data='')
|
|
249
|
+
def robject_input(obj, key_data = '')
|
|
250
250
|
bucket = obj.bucket
|
|
251
251
|
if bucket.needs_type?
|
|
252
252
|
return [
|
|
253
|
-
maybe_escape(bucket.name),
|
|
254
|
-
maybe_escape(obj.key),
|
|
255
|
-
key_data,
|
|
253
|
+
maybe_escape(bucket.name),
|
|
254
|
+
maybe_escape(obj.key),
|
|
255
|
+
key_data,
|
|
256
256
|
maybe_escape(bucket.type.name)
|
|
257
257
|
]
|
|
258
258
|
end
|
|
@@ -263,13 +263,13 @@ module Riak
|
|
|
263
263
|
# Processes a key into a single-object {MapReduce} input, doing the correct
|
|
264
264
|
# thing if the bucket argument is a {String}, {Bucket}, or a
|
|
265
265
|
# {BucketTyped::Bucket}.
|
|
266
|
-
def key_input(key, bucket, key_data='')
|
|
266
|
+
def key_input(key, bucket, key_data = '')
|
|
267
267
|
kd = []
|
|
268
268
|
kd << key_data unless key_data.blank?
|
|
269
269
|
|
|
270
270
|
if bucket.is_a? String
|
|
271
271
|
return [
|
|
272
|
-
maybe_escape(bucket),
|
|
272
|
+
maybe_escape(bucket),
|
|
273
273
|
maybe_escape(key)
|
|
274
274
|
] + kd
|
|
275
275
|
elsif bucket.needs_type?
|
|
@@ -28,7 +28,7 @@ module Riak
|
|
|
28
28
|
:less_than => 1,
|
|
29
29
|
:greater_than_eq => 1,
|
|
30
30
|
:less_than_eq => 1,
|
|
31
|
-
:between => [2,3],
|
|
31
|
+
:between => [2, 3],
|
|
32
32
|
:matches => 1,
|
|
33
33
|
:neq => 1,
|
|
34
34
|
:eq => 1,
|
|
@@ -52,7 +52,7 @@ module Riak
|
|
|
52
52
|
# end
|
|
53
53
|
LOGICAL_OPERATIONS = %w{and or not}
|
|
54
54
|
|
|
55
|
-
FILTERS.each do |f,arity|
|
|
55
|
+
FILTERS.each do |f, arity|
|
|
56
56
|
arities = [arity].flatten
|
|
57
57
|
|
|
58
58
|
define_method(f) { |*args|
|
|
@@ -31,7 +31,7 @@ module Riak
|
|
|
31
31
|
# @option options [String, Array, Hash] :function In the case of Javascript, a literal function in a string, or a hash with :bucket and :key. In the case of Erlang, an Array of [module, function]. For a :link phase, a hash including any of :bucket, :tag or a WalkSpec.
|
|
32
32
|
# @option options [Boolean] :keep (false) whether to return the results of this phase
|
|
33
33
|
# @option options [Array] :arg (nil) any extra static arguments to pass to the phase
|
|
34
|
-
def initialize(options={})
|
|
34
|
+
def initialize(options = {})
|
|
35
35
|
self.type = options[:type]
|
|
36
36
|
self.language = options[:language] || "javascript"
|
|
37
37
|
self.function = options[:function]
|
|
@@ -70,7 +70,7 @@ module Riak
|
|
|
70
70
|
|
|
71
71
|
# Converts the phase to its JSON-compatible representation for job invocation.
|
|
72
72
|
# @return [Hash] a Hash-equivalent of the phase
|
|
73
|
-
def as_json(options=nil)
|
|
73
|
+
def as_json(options = nil)
|
|
74
74
|
obj = case type
|
|
75
75
|
when :map, :reduce
|
|
76
76
|
defaults = {"language" => language, "keep" => keep}
|
data/lib/riak/rcontent.rb
CHANGED
|
@@ -52,7 +52,7 @@ module Riak
|
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
def indexes=(hash)
|
|
55
|
-
@indexes = hash.inject(new_index_hash) do |h, (k,v)|
|
|
55
|
+
@indexes = hash.inject(new_index_hash) do |h, (k, v)|
|
|
56
56
|
h[k].merge([*v])
|
|
57
57
|
h
|
|
58
58
|
end
|
|
@@ -68,9 +68,9 @@ module Riak
|
|
|
68
68
|
@data
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
-
# @param [Object] new_data unmarshaled form of the data to be stored in
|
|
72
|
-
# Riak. Object will be serialized using {#serialize} if a known
|
|
73
|
-
# content_type is used. Setting this overrides values stored with
|
|
71
|
+
# @param [Object] new_data unmarshaled form of the data to be stored in
|
|
72
|
+
# Riak. Object will be serialized using {#serialize} if a known
|
|
73
|
+
# content_type is used. Setting this overrides values stored with
|
|
74
74
|
# {#raw_data=}
|
|
75
75
|
# @return [Object] the object stored
|
|
76
76
|
def data=(new_data)
|
|
@@ -142,14 +142,14 @@ module Riak
|
|
|
142
142
|
extract_if_present(metadata, 'content-type', :content_type)
|
|
143
143
|
extract_if_present(metadata, 'X-Riak-Last-Modified', :last_modified) { |v| Time.httpdate( v ) }
|
|
144
144
|
extract_if_present(metadata, 'index', :indexes) do |entries|
|
|
145
|
-
Hash[ entries.map {|k,v| [k, Set.new(Array(v))] } ]
|
|
145
|
+
Hash[ entries.map {|k, v| [k, Set.new(Array(v))] } ]
|
|
146
146
|
end
|
|
147
147
|
extract_if_present(metadata, 'Links', :links) do |links|
|
|
148
148
|
Set.new( links.map { |l| Link.new(*l) } )
|
|
149
149
|
end
|
|
150
150
|
extract_if_present(metadata, 'X-Riak-Meta', :meta) do |meta|
|
|
151
151
|
Hash[
|
|
152
|
-
meta.map do |k,v|
|
|
152
|
+
meta.map do |k, v|
|
|
153
153
|
[k.sub(%r{^x-riak-meta-}i, ''), [v]]
|
|
154
154
|
end
|
|
155
155
|
]
|
|
@@ -158,7 +158,7 @@ module Riak
|
|
|
158
158
|
end
|
|
159
159
|
|
|
160
160
|
private
|
|
161
|
-
def extract_if_present(hash, key, attribute=nil)
|
|
161
|
+
def extract_if_present(hash, key, attribute = nil)
|
|
162
162
|
if hash[key].present?
|
|
163
163
|
attribute ||= key
|
|
164
164
|
value = block_given? ? yield(hash[key]) : hash[key]
|
|
@@ -167,7 +167,7 @@ module Riak
|
|
|
167
167
|
end
|
|
168
168
|
|
|
169
169
|
def new_index_hash
|
|
170
|
-
Hash.new {|h,k| h[k] = Set.new }
|
|
170
|
+
Hash.new {|h, k| h[k] = Set.new }
|
|
171
171
|
end
|
|
172
172
|
end
|
|
173
173
|
end
|
data/lib/riak/robject.rb
CHANGED
|
@@ -12,7 +12,7 @@ module Riak
|
|
|
12
12
|
# the Riak database, the base unit of data manipulation.
|
|
13
13
|
class RObject
|
|
14
14
|
include Util::Translation
|
|
15
|
-
extend
|
|
15
|
+
extend Util::Translation
|
|
16
16
|
include Util::Escape
|
|
17
17
|
extend Util::Escape
|
|
18
18
|
extend Forwardable
|
|
@@ -23,13 +23,15 @@ module Riak
|
|
|
23
23
|
# @return [String] the key of this object within its bucket
|
|
24
24
|
attr_accessor :key
|
|
25
25
|
|
|
26
|
-
# @return [String] the Riak vector clock for the object
|
|
26
|
+
# @return [String] the Riak causal context/vector clock for the object
|
|
27
27
|
attr_accessor :vclock
|
|
28
28
|
|
|
29
|
+
alias :causal_context :vclock
|
|
30
|
+
alias :causal_context= :vclock=
|
|
29
31
|
alias :vector_clock :vclock
|
|
30
32
|
alias :vector_clock= :vclock=
|
|
31
33
|
|
|
32
|
-
# @return [Boolean] whether to attempt to prevent stale writes using
|
|
34
|
+
# @return [Boolean] whether to attempt to prevent stale writes using
|
|
33
35
|
# conditional PUT semantics, If-None-Match: * or If-Match: etag
|
|
34
36
|
# @see http://wiki.basho.com/display/RIAK/REST+API#RESTAPI-Storeaneworexistingobjectwithakey Riak Rest API Docs
|
|
35
37
|
attr_accessor :prevent_stale_writes
|
|
@@ -94,7 +96,7 @@ module Riak
|
|
|
94
96
|
# @param [String] key the key at which the object resides. If nil, a key will be assigned when the object is saved.
|
|
95
97
|
# @yield self the new RObject
|
|
96
98
|
# @see Bucket#get
|
|
97
|
-
def initialize(bucket, key=nil)
|
|
99
|
+
def initialize(bucket, key = nil)
|
|
98
100
|
@bucket, @key = bucket, key
|
|
99
101
|
|
|
100
102
|
# fix a require-loop
|
|
@@ -108,8 +110,8 @@ module Riak
|
|
|
108
110
|
end
|
|
109
111
|
|
|
110
112
|
# Load object data from a map/reduce response item.
|
|
111
|
-
# This method is used by RObject::load_from_mapreduce to instantiate the
|
|
112
|
-
# objects.
|
|
113
|
+
# This method is used by RObject::load_from_mapreduce to instantiate the
|
|
114
|
+
# necessary objects.
|
|
113
115
|
# @param [Hash] response a response from {Riak::MapReduce}
|
|
114
116
|
# @return [RObject] self
|
|
115
117
|
def load_from_mapreduce(response)
|
|
@@ -124,17 +126,21 @@ module Riak
|
|
|
124
126
|
|
|
125
127
|
# Store the object in Riak
|
|
126
128
|
# @param [Hash] options query parameters
|
|
127
|
-
# @option options [Fixnum] :r the "r" parameter (Read quorum for the
|
|
129
|
+
# @option options [Fixnum] :r the "r" parameter (Read quorum for the
|
|
130
|
+
# implicit read performed when validating the store operation)
|
|
128
131
|
# @option options [Fixnum] :w the "w" parameter (Write quorum)
|
|
129
132
|
# @option options [Fixnum] :dw the "dw" parameter (Durable-write quorum)
|
|
130
|
-
# @option options [Boolean] :returnbody (true) whether to return the result
|
|
133
|
+
# @option options [Boolean] :returnbody (true) whether to return the result
|
|
134
|
+
# of a successful write in the body of the response. Set to false for
|
|
135
|
+
# fire-and-forget updates, set to true to immediately have access to the
|
|
136
|
+
# object's stored representation.
|
|
131
137
|
# @return [Riak::RObject] self
|
|
132
138
|
# @raise [ArgumentError] if the content_type is not defined
|
|
133
139
|
# @raise [Conflict] if the object has siblings
|
|
134
|
-
def store(options={})
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
140
|
+
def store(options = {})
|
|
141
|
+
fail Conflict, self if conflict?
|
|
142
|
+
fail ArgumentError, t('content_type_undefined') unless content_type.present?
|
|
143
|
+
fail ArgumentError, t('zero_length_key') if key == ''
|
|
138
144
|
@bucket.client.store_object(self, default(options))
|
|
139
145
|
self
|
|
140
146
|
end
|
|
@@ -146,7 +152,7 @@ module Riak
|
|
|
146
152
|
# the vclock is not present, useful for reloading the object after
|
|
147
153
|
# a store (not passed in the query params)
|
|
148
154
|
# @return [Riak::RObject] self
|
|
149
|
-
def reload(options={})
|
|
155
|
+
def reload(options = {})
|
|
150
156
|
force = options.delete(:force)
|
|
151
157
|
return self unless @key && (@vclock || force)
|
|
152
158
|
self.etag = self.last_modified = nil if force
|
|
@@ -158,7 +164,7 @@ module Riak
|
|
|
158
164
|
# Delete the object from Riak and freeze this instance. Will work whether or not the object actually
|
|
159
165
|
# exists in the Riak database.
|
|
160
166
|
# @see Bucket#delete
|
|
161
|
-
def delete(options={})
|
|
167
|
+
def delete(options = {})
|
|
162
168
|
return if key.blank?
|
|
163
169
|
options[:vclock] = vclock if vclock
|
|
164
170
|
@bucket.delete(key, default(options))
|
|
@@ -197,6 +203,13 @@ module Riak
|
|
|
197
203
|
Link.new(@bucket.name, @key, tag)
|
|
198
204
|
end
|
|
199
205
|
|
|
206
|
+
# Retrieves a preflist for this RObject; useful for
|
|
207
|
+
# figuring out where in the cluster it is stored.
|
|
208
|
+
# @return [Array<PreflistItem>] an array of preflist entries
|
|
209
|
+
def preflist(options = {})
|
|
210
|
+
bucket.get_preflist key, options
|
|
211
|
+
end
|
|
212
|
+
|
|
200
213
|
private
|
|
201
214
|
|
|
202
215
|
def default(options)
|
data/lib/riak/search.rb
CHANGED
data/lib/riak/search/index.rb
CHANGED
|
@@ -6,9 +6,14 @@ module Riak::Search
|
|
|
6
6
|
# bucket or bucket type property must be configured to use the index in order
|
|
7
7
|
# for new and updated documents to be indexed and searchable.
|
|
8
8
|
class Index
|
|
9
|
+
# @!attribute [r] name
|
|
9
10
|
# @return [String] the name of the index
|
|
10
11
|
attr_reader :name
|
|
11
12
|
|
|
13
|
+
# @!attribute [r] client
|
|
14
|
+
# @return [Riak::Client] the client to operate on the index with
|
|
15
|
+
attr_reader :client
|
|
16
|
+
|
|
12
17
|
# Initializes an index object, that may or may not exist.
|
|
13
18
|
#
|
|
14
19
|
# @param [Riak::Client] client the client connected to the Riak cluster
|
|
@@ -36,13 +41,13 @@ module Riak::Search
|
|
|
36
41
|
|
|
37
42
|
# Attempt to create this index
|
|
38
43
|
#
|
|
39
|
-
# @raise [Riak::SearchError::IndexExistsError] if an index with the given
|
|
44
|
+
# @raise [Riak::SearchError::IndexExistsError] if an index with the given
|
|
40
45
|
# name already exists
|
|
41
|
-
def create!(schema = nil, n_val = nil)
|
|
46
|
+
def create!(schema = nil, n_val = nil, timeout = nil)
|
|
42
47
|
raise Riak::SearchError::IndexExistsError.new name if exists?
|
|
43
48
|
|
|
44
49
|
@client.backend do |b|
|
|
45
|
-
b.create_search_index name, schema, n_val
|
|
50
|
+
b.create_search_index name, schema, n_val, timeout
|
|
46
51
|
end
|
|
47
52
|
|
|
48
53
|
@index_data = nil
|
|
@@ -50,6 +55,15 @@ module Riak::Search
|
|
|
50
55
|
true
|
|
51
56
|
end
|
|
52
57
|
|
|
58
|
+
# Create a {Riak::Search::Query} using this index and client
|
|
59
|
+
#
|
|
60
|
+
# @param [String] term the query term
|
|
61
|
+
# @param [Hash] options a hash of options to set attributes on the query
|
|
62
|
+
# @return [Riak::Search::Query] a query using this index
|
|
63
|
+
def query(term, options = { })
|
|
64
|
+
Riak::Search::Query.new(@client, self, term, options)
|
|
65
|
+
end
|
|
66
|
+
|
|
53
67
|
private
|
|
54
68
|
def index_data
|
|
55
69
|
return @index_data if defined?(@index_data) && @index_data
|
data/lib/riak/search/query.rb
CHANGED
|
@@ -3,7 +3,7 @@ require 'riak/search'
|
|
|
3
3
|
module Riak::Search
|
|
4
4
|
# A {Riak::Search::Query} wraps a Solr query for Riak Search 2.
|
|
5
5
|
class Query
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
# @!attribute rows
|
|
8
8
|
# @return [Numeric] the number of rows to return from the query
|
|
9
9
|
attr_accessor :rows
|
|
@@ -36,6 +36,14 @@ module Riak::Search
|
|
|
36
36
|
# @return [String] the term to query
|
|
37
37
|
attr_reader :term
|
|
38
38
|
|
|
39
|
+
# @!attribute [r] index
|
|
40
|
+
# @return [Riak::Search::Index] the index to query against
|
|
41
|
+
attr_reader :index
|
|
42
|
+
|
|
43
|
+
# @!attribute [r] client
|
|
44
|
+
# @return [Riak::Client] the client to query against
|
|
45
|
+
attr_reader :client
|
|
46
|
+
|
|
39
47
|
# Initializes a query object.
|
|
40
48
|
#
|
|
41
49
|
# @param [Riak::Client] client the client connected to the Riak cluster
|
|
@@ -43,7 +51,7 @@ module Riak::Search
|
|
|
43
51
|
# {Riak::Search::Index} instance or a {String}
|
|
44
52
|
# @param [String] term the query term
|
|
45
53
|
# @param [Hash] options a hash of options to quickly set attributes
|
|
46
|
-
def initialize(client, index, term, options={ })
|
|
54
|
+
def initialize(client, index, term, options = { })
|
|
47
55
|
@client = client
|
|
48
56
|
validate_index index
|
|
49
57
|
@term = term
|
|
@@ -63,7 +71,7 @@ module Riak::Search
|
|
|
63
71
|
end
|
|
64
72
|
|
|
65
73
|
private
|
|
66
|
-
|
|
74
|
+
|
|
67
75
|
def index_name
|
|
68
76
|
return @index if @index.is_a? String
|
|
69
77
|
return @index.name
|
|
@@ -95,14 +103,14 @@ module Riak::Search
|
|
|
95
103
|
@df = %w{text}
|
|
96
104
|
@op = nil
|
|
97
105
|
@fl = %w{_yz_rb _yz_rk _yz_rt score}
|
|
98
|
-
|
|
106
|
+
|
|
99
107
|
@presort = nil
|
|
100
108
|
end
|
|
101
109
|
|
|
102
110
|
def consume_options
|
|
103
111
|
@rows = @options[:rows] if @options[:rows]
|
|
104
112
|
@start = @options[:start] if @options[:start]
|
|
105
|
-
|
|
113
|
+
|
|
106
114
|
@sort = @options[:sort] if @options[:sort]
|
|
107
115
|
@filter = @options[:filter] if @options[:filter]
|
|
108
116
|
|
|
@@ -112,7 +120,7 @@ module Riak::Search
|
|
|
112
120
|
end
|
|
113
121
|
|
|
114
122
|
def prepare_options
|
|
115
|
-
configured_options = {
|
|
123
|
+
configured_options = {
|
|
116
124
|
rows: @rows,
|
|
117
125
|
start: @start,
|
|
118
126
|
sort: @sort,
|