riak-client 1.4.5 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/Gemfile +0 -1
- data/{LICENSE → LICENSE.md} +0 -0
- data/README.markdown +211 -66
- data/RELEASE_NOTES.md +22 -47
- data/Rakefile +45 -0
- data/lib/riak.rb +1 -1
- data/lib/riak/bucket.rb +2 -2
- data/lib/riak/client.rb +22 -195
- data/lib/riak/client/beefcake/crdt_loader.rb +127 -0
- data/lib/riak/client/beefcake/crdt_operator.rb +222 -0
- data/lib/riak/client/beefcake/footer +4 -0
- data/lib/riak/client/beefcake/header +6 -0
- data/lib/riak/client/beefcake/message_codes.rb +29 -0
- data/lib/riak/client/beefcake/message_overlay.rb +61 -0
- data/lib/riak/client/beefcake/messages.rb +733 -371
- data/lib/riak/client/beefcake/object_methods.rb +1 -1
- data/lib/riak/client/beefcake/protocol.rb +105 -0
- data/lib/riak/client/beefcake/socket.rb +243 -0
- data/lib/riak/client/beefcake_protobuffs_backend.rb +262 -122
- data/lib/riak/client/node.rb +4 -75
- data/lib/riak/client/protobuffs_backend.rb +6 -14
- data/lib/riak/client/search.rb +0 -64
- data/lib/riak/client/yokozuna.rb +52 -0
- data/lib/riak/counter.rb +1 -1
- data/lib/riak/crdt.rb +21 -0
- data/lib/riak/crdt/base.rb +97 -0
- data/lib/riak/crdt/batch_counter.rb +19 -0
- data/lib/riak/crdt/batch_map.rb +41 -0
- data/lib/riak/crdt/counter.rb +71 -0
- data/lib/riak/crdt/inner_counter.rb +74 -0
- data/lib/riak/crdt/inner_flag.rb +42 -0
- data/lib/riak/crdt/inner_map.rb +53 -0
- data/lib/riak/crdt/inner_register.rb +26 -0
- data/lib/riak/crdt/inner_set.rb +95 -0
- data/lib/riak/crdt/map.rb +88 -0
- data/lib/riak/crdt/operation.rb +19 -0
- data/lib/riak/crdt/set.rb +156 -0
- data/lib/riak/crdt/typed_collection.rb +131 -0
- data/lib/riak/errors/base.rb +9 -0
- data/lib/riak/errors/connection_error.rb +44 -0
- data/lib/riak/errors/crdt_error.rb +18 -0
- data/lib/riak/errors/failed_request.rb +56 -0
- data/lib/riak/errors/protobuffs_error.rb +11 -0
- data/lib/riak/i18n.rb +2 -0
- data/lib/riak/json.rb +1 -1
- data/lib/riak/locale/en.yml +26 -1
- data/lib/riak/locale/fr.yml +0 -1
- data/lib/riak/map_reduce.rb +1 -1
- data/lib/riak/map_reduce/results.rb +1 -1
- data/lib/riak/multiget.rb +1 -2
- data/lib/riak/rcontent.rb +8 -3
- data/lib/riak/robject.rb +2 -8
- data/lib/riak/secondary_index.rb +4 -4
- data/lib/riak/serializers.rb +1 -1
- data/lib/riak/util/escape.rb +3 -5
- data/lib/riak/version.rb +1 -1
- data/lib/riak/walk_spec.rb +7 -3
- data/riak-client.gemspec +10 -8
- data/spec/fixtures/bitcask.txt +25 -0
- data/spec/integration/riak/bucket_types_spec.rb +61 -0
- data/spec/integration/riak/counters_spec.rb +17 -32
- data/spec/integration/riak/crdt_spec.rb +181 -0
- data/spec/integration/riak/crdt_validation/map_spec.rb +63 -0
- data/spec/integration/riak/crdt_validation/set_spec.rb +122 -0
- data/spec/integration/riak/protobuffs_backends_spec.rb +9 -26
- data/spec/integration/riak/security_spec.rb +94 -0
- data/spec/integration/riak/threading_spec.rb +24 -67
- data/spec/integration/yokozuna/index_spec.rb +61 -0
- data/spec/integration/yokozuna/queries_spec.rb +116 -0
- data/spec/integration/yokozuna/schema_spec.rb +49 -0
- data/spec/riak/beefcake_protobuffs_backend/crdt_operator_spec.rb +222 -0
- data/spec/riak/beefcake_protobuffs_backend/object_methods_spec.rb +4 -4
- data/spec/riak/beefcake_protobuffs_backend/protocol_spec.rb +189 -0
- data/spec/riak/beefcake_protobuffs_backend/socket_spec.rb +151 -0
- data/spec/riak/beefcake_protobuffs_backend_spec.rb +68 -106
- data/spec/riak/bucket_spec.rb +81 -77
- data/spec/riak/client_spec.rb +43 -340
- data/spec/riak/core_ext/to_param_spec.rb +2 -2
- data/spec/riak/counter_spec.rb +20 -20
- data/spec/riak/crdt/counter_spec.rb +52 -0
- data/spec/riak/crdt/inner_counter_spec.rb +21 -0
- data/spec/riak/crdt/inner_flag_spec.rb +39 -0
- data/spec/riak/crdt/inner_map_spec.rb +47 -0
- data/spec/riak/crdt/inner_register_spec.rb +40 -0
- data/spec/riak/crdt/inner_set_spec.rb +33 -0
- data/spec/riak/crdt/map_spec.rb +77 -0
- data/spec/riak/crdt/set_spec.rb +58 -0
- data/spec/riak/crdt/shared_examples.rb +74 -0
- data/spec/riak/crdt/typed_collection_spec.rb +231 -0
- data/spec/riak/escape_spec.rb +33 -37
- data/spec/riak/feature_detection_spec.rb +45 -45
- data/spec/riak/index_collection_spec.rb +12 -12
- data/spec/riak/link_spec.rb +34 -34
- data/spec/riak/list_buckets_spec.rb +7 -7
- data/spec/riak/map_reduce/filter_builder_spec.rb +6 -6
- data/spec/riak/map_reduce/phase_spec.rb +35 -35
- data/spec/riak/map_reduce_spec.rb +89 -87
- data/spec/riak/multiget_spec.rb +20 -15
- data/spec/riak/node_spec.rb +5 -152
- data/spec/riak/robject_spec.rb +95 -108
- data/spec/riak/search_spec.rb +17 -139
- data/spec/riak/secondary_index_spec.rb +49 -49
- data/spec/riak/serializers_spec.rb +9 -9
- data/spec/riak/stamp_spec.rb +9 -9
- data/spec/riak/walk_spec_spec.rb +46 -46
- data/spec/spec_helper.rb +14 -22
- data/spec/support/certs/README.md +13 -0
- data/spec/support/certs/ca.crt +22 -0
- data/spec/support/certs/client.crt +95 -0
- data/spec/support/certs/client.key +27 -0
- data/spec/support/certs/empty_ca.crt +21 -0
- data/spec/support/certs/server.crl +13 -0
- data/spec/support/certs/server.crt +95 -0
- data/spec/support/certs/server.key +27 -0
- data/spec/support/integration_setup.rb +1 -1
- data/spec/support/search_corpus_setup.rb +29 -8
- data/spec/support/test_client.rb +46 -0
- data/spec/support/test_client.yml.example +10 -0
- data/spec/support/unified_backend_examples.rb +104 -83
- data/spec/support/version_filter.rb +2 -2
- data/spec/support/wait_until.rb +14 -0
- metadata +134 -132
- data/erl_src/riak_kv_test014_backend.beam +0 -0
- data/erl_src/riak_kv_test014_backend.erl +0 -189
- data/erl_src/riak_kv_test_backend.beam +0 -0
- data/erl_src/riak_kv_test_backend.erl +0 -731
- data/erl_src/riak_search_test_backend.beam +0 -0
- data/erl_src/riak_search_test_backend.erl +0 -175
- data/lib/riak/client/excon_backend.rb +0 -172
- data/lib/riak/client/http_backend.rb +0 -413
- data/lib/riak/client/http_backend/bucket_streamer.rb +0 -15
- data/lib/riak/client/http_backend/chunked_json_streamer.rb +0 -42
- data/lib/riak/client/http_backend/configuration.rb +0 -227
- data/lib/riak/client/http_backend/key_streamer.rb +0 -15
- data/lib/riak/client/http_backend/object_methods.rb +0 -114
- data/lib/riak/client/http_backend/request_headers.rb +0 -34
- data/lib/riak/client/http_backend/transport_methods.rb +0 -201
- data/lib/riak/client/instrumentation.rb +0 -25
- data/lib/riak/client/net_http_backend.rb +0 -82
- data/lib/riak/cluster.rb +0 -151
- data/lib/riak/failed_request.rb +0 -81
- data/lib/riak/instrumentation.rb +0 -6
- data/lib/riak/node.rb +0 -40
- data/lib/riak/node/configuration.rb +0 -304
- data/lib/riak/node/console.rb +0 -133
- data/lib/riak/node/control.rb +0 -207
- data/lib/riak/node/defaults.rb +0 -85
- data/lib/riak/node/generation.rb +0 -127
- data/lib/riak/node/log.rb +0 -34
- data/lib/riak/node/version.rb +0 -29
- data/lib/riak/search.rb +0 -3
- data/lib/riak/test_server.rb +0 -89
- data/lib/riak/util/headers.rb +0 -32
- data/lib/riak/util/multipart.rb +0 -52
- data/lib/riak/util/multipart/stream_parser.rb +0 -62
- data/spec/fixtures/munchausen.txt +0 -1033
- data/spec/integration/riak/cluster_spec.rb +0 -88
- data/spec/integration/riak/http_backends_spec.rb +0 -180
- data/spec/integration/riak/node_spec.rb +0 -170
- data/spec/integration/riak/test_server_spec.rb +0 -57
- data/spec/riak/excon_backend_spec.rb +0 -102
- data/spec/riak/headers_spec.rb +0 -21
- data/spec/riak/http_backend/configuration_spec.rb +0 -273
- data/spec/riak/http_backend/object_methods_spec.rb +0 -243
- data/spec/riak/http_backend/transport_methods_spec.rb +0 -97
- data/spec/riak/http_backend_spec.rb +0 -367
- data/spec/riak/instrumentation_spec.rb +0 -167
- data/spec/riak/multipart_spec.rb +0 -23
- data/spec/riak/net_http_backend_spec.rb +0 -15
- data/spec/riak/stream_parser_spec.rb +0 -53
- data/spec/support/drb_mock_server.rb +0 -39
- data/spec/support/http_backend_implementation_examples.rb +0 -253
- data/spec/support/mock_server.rb +0 -81
- data/spec/support/mocks.rb +0 -4
- data/spec/support/riak_test.rb +0 -77
- data/spec/support/sometimes.rb +0 -46
- data/spec/support/test_server.rb +0 -61
- data/spec/support/test_server.yml.example +0 -14
@@ -0,0 +1,19 @@
|
|
1
|
+
module Riak
|
2
|
+
module Crdt
|
3
|
+
# @api private
|
4
|
+
module Operation
|
5
|
+
class Update
|
6
|
+
attr_accessor :parent
|
7
|
+
attr_accessor :name
|
8
|
+
attr_accessor :type
|
9
|
+
attr_accessor :value
|
10
|
+
end
|
11
|
+
|
12
|
+
class Delete
|
13
|
+
attr_accessor :parent
|
14
|
+
attr_accessor :name
|
15
|
+
attr_accessor :type
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
module Riak
|
2
|
+
module Crdt
|
3
|
+
|
4
|
+
# A distributed set containing strings, using the Riak 2 Data Types feature.
|
5
|
+
#
|
6
|
+
# Uses the Ruby standard library `::Set` frequently, so the full class names will
|
7
|
+
# be used frequently.
|
8
|
+
class Set < Base
|
9
|
+
|
10
|
+
# Create a set instance. If not provided, the default bucket type from
|
11
|
+
# {Riak::Crdt} will be used.
|
12
|
+
#
|
13
|
+
# @param bucket [Bucket] the {Riak::Bucket} for this set
|
14
|
+
# @param [String, nil] key The name of the set. A nil key makes
|
15
|
+
# Riak assign a key.
|
16
|
+
# @param [String] bucket_type The optional bucket type for this set.
|
17
|
+
# The default is in `Crdt::Base::DEFAULT_BUCKET_TYPES[:set]`.
|
18
|
+
# @param options [Hash]
|
19
|
+
def initialize(bucket, key, bucket_type=nil, options={})
|
20
|
+
super(bucket, key, bucket_type || DEFAULT_BUCKET_TYPES[:set], options)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Yields a `BatchSet` to proxy multiple set operations into a single
|
24
|
+
# Riak update. The `BatchSet` has the same methods as this
|
25
|
+
# {Riak::Crdt::Set}.
|
26
|
+
#
|
27
|
+
# @yieldparam batch_set [BatchSet] collects set operations
|
28
|
+
def vivify(value)
|
29
|
+
value.each(&:freeze)
|
30
|
+
@members = ::Set.new(value)
|
31
|
+
@members.freeze
|
32
|
+
end
|
33
|
+
|
34
|
+
def batch
|
35
|
+
batcher = BatchSet.new self
|
36
|
+
|
37
|
+
yield batcher
|
38
|
+
|
39
|
+
operate batcher.operations
|
40
|
+
end
|
41
|
+
|
42
|
+
# Gets the current set members from Riak if necessary, and return the
|
43
|
+
# stdlib `::Set` of them.
|
44
|
+
#
|
45
|
+
# @return [::Set] a Ruby standard library {::Set} of the members
|
46
|
+
# of this {Riak::Crdt::Set}
|
47
|
+
def members
|
48
|
+
reload if dirty?
|
49
|
+
@members
|
50
|
+
end
|
51
|
+
|
52
|
+
alias :value :members
|
53
|
+
|
54
|
+
# Cast this {Riak::Crdt::Set} to a Ruby {Array}.
|
55
|
+
#
|
56
|
+
# @return [Array] array of set members
|
57
|
+
def to_a
|
58
|
+
members.to_a
|
59
|
+
end
|
60
|
+
|
61
|
+
# Check to see if this structure has any members.
|
62
|
+
#
|
63
|
+
# @return [Boolean] if the structure is empty
|
64
|
+
def empty?
|
65
|
+
members.empty?
|
66
|
+
end
|
67
|
+
|
68
|
+
# Check to see if a given string is present in this data structure.
|
69
|
+
#
|
70
|
+
# @param [String] candidate string to check for inclusion in this structure
|
71
|
+
# @return [Boolean] if the structure includes
|
72
|
+
def include?(candidate)
|
73
|
+
members.include?(candidate)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Add a {String} to the {Riak::Crdt::Set}
|
77
|
+
#
|
78
|
+
# @param [String] element the element to add to the set
|
79
|
+
# @param [Hash] options
|
80
|
+
def add(element, options={})
|
81
|
+
operate operation(:add, element), options
|
82
|
+
end
|
83
|
+
|
84
|
+
# Remove a {String} from the {Riak::Crdt::Set}
|
85
|
+
#
|
86
|
+
# @param [String] element to remove from the set
|
87
|
+
# @param [Hash] options
|
88
|
+
def remove(element, options={})
|
89
|
+
raise CrdtError::SetRemovalWithoutContextError unless context?
|
90
|
+
operate operation(:remove, element), options
|
91
|
+
end
|
92
|
+
|
93
|
+
alias :delete :remove
|
94
|
+
|
95
|
+
private
|
96
|
+
def vivify(value)
|
97
|
+
@members = value
|
98
|
+
end
|
99
|
+
|
100
|
+
def operation(direction, element)
|
101
|
+
Operation::Update.new.tap do |op|
|
102
|
+
op.type = :set
|
103
|
+
op.value = { direction => element }
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
class BatchSet
|
108
|
+
def initialize(base)
|
109
|
+
@base = base
|
110
|
+
@adds = ::Set.new
|
111
|
+
@removes = ::Set.new
|
112
|
+
end
|
113
|
+
|
114
|
+
def add(element)
|
115
|
+
@adds.add element
|
116
|
+
end
|
117
|
+
|
118
|
+
def remove(element)
|
119
|
+
raise CrdtError::SetRemovalWithoutContextError.new unless context?
|
120
|
+
@removes.add element
|
121
|
+
end
|
122
|
+
|
123
|
+
alias :delete :remove
|
124
|
+
|
125
|
+
def include?(element)
|
126
|
+
members.include? element
|
127
|
+
end
|
128
|
+
|
129
|
+
def empty?
|
130
|
+
members.empty?
|
131
|
+
end
|
132
|
+
|
133
|
+
def context?
|
134
|
+
@base.context?
|
135
|
+
end
|
136
|
+
|
137
|
+
def to_a
|
138
|
+
members.to_a
|
139
|
+
end
|
140
|
+
|
141
|
+
def members
|
142
|
+
(@base + @adds).subtract @removes
|
143
|
+
end
|
144
|
+
|
145
|
+
alias :value :members
|
146
|
+
|
147
|
+
def operations
|
148
|
+
Operation::Update.new.tap do |op|
|
149
|
+
op.type = :set
|
150
|
+
op.value = {add: @adds.to_a, remove: @removes.to_a}
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
module Riak
|
2
|
+
module Crdt
|
3
|
+
# A collection of elements of a given type inside a {Map}.
|
4
|
+
class TypedCollection
|
5
|
+
|
6
|
+
ALREADY_WRAPPED = ::Set.new [InnerCounter, InnerFlag, InnerMap]
|
7
|
+
NEEDS_NAME = ::Set.new [InnerCounter, InnerSet, InnerMap]
|
8
|
+
INITIALIZE_NIL = ::Set.new [InnerRegister]
|
9
|
+
|
10
|
+
# @api private
|
11
|
+
def initialize(type, parent, contents={})
|
12
|
+
@type = type
|
13
|
+
@parent = parent
|
14
|
+
contents = {} if contents.nil?
|
15
|
+
stringified_contents = contents.stringify_keys
|
16
|
+
@contents = stringified_contents.keys.inject(Hash.new) do |contents, key|
|
17
|
+
contents.tap do |c|
|
18
|
+
content = stringified_contents[key]
|
19
|
+
if ALREADY_WRAPPED.include? content.class
|
20
|
+
c[key] = content
|
21
|
+
else
|
22
|
+
c[key] = @type.new self, content
|
23
|
+
end
|
24
|
+
c[key].name = key if needs_name?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# @api private
|
30
|
+
def reparent(new_parent)
|
31
|
+
reparented = self.class.new(@type,
|
32
|
+
new_parent,
|
33
|
+
@contents)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Check if a value for a given key exists in this map.
|
37
|
+
#
|
38
|
+
# @param [String] key the key to check for
|
39
|
+
# @return [Boolean] if the key is inside this collection
|
40
|
+
def include?(key)
|
41
|
+
@contents.include? normalize_key(key)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Get the value for a given key
|
45
|
+
#
|
46
|
+
# @param [String] key the key to get the value for
|
47
|
+
# @return the value for the given key
|
48
|
+
def [](key)
|
49
|
+
key = normalize_key key
|
50
|
+
if include? key
|
51
|
+
candidate = @contents[key]
|
52
|
+
return candidate unless candidate.respond_to? :parent
|
53
|
+
return candidate if candidate.parent == self
|
54
|
+
end
|
55
|
+
|
56
|
+
return nil if initialize_nil?
|
57
|
+
|
58
|
+
new_instance = @type.new self
|
59
|
+
new_instance.name = key if needs_name?
|
60
|
+
|
61
|
+
return new_instance
|
62
|
+
end
|
63
|
+
|
64
|
+
# Set the value for a given key. Operation of this method
|
65
|
+
# is only defined for {InnerCounter}, {InnerRegister}, and
|
66
|
+
# {InnerFlag} types.
|
67
|
+
#
|
68
|
+
# @param [String] key the key to set a new value for
|
69
|
+
# @param [Boolean, String, Integer] value the value to set at the key,
|
70
|
+
# or in the case of counters, the amount to increment
|
71
|
+
def []=(key, value)
|
72
|
+
key = normalize_key key
|
73
|
+
|
74
|
+
operation = @type.update value
|
75
|
+
operation.name = key
|
76
|
+
|
77
|
+
result = @parent.operate operation
|
78
|
+
|
79
|
+
@contents[key] = @type.new self, value
|
80
|
+
@contents[key].name = key if needs_name?
|
81
|
+
|
82
|
+
result
|
83
|
+
end
|
84
|
+
|
85
|
+
alias :increment :[]=
|
86
|
+
|
87
|
+
# Remove the entry from the map.
|
88
|
+
#
|
89
|
+
# @param [String] key the key to remove from the map
|
90
|
+
def delete(key)
|
91
|
+
key = normalize_key key
|
92
|
+
operation = @type.delete
|
93
|
+
operation.name = key
|
94
|
+
|
95
|
+
@parent.operate operation
|
96
|
+
|
97
|
+
@contents.delete key
|
98
|
+
end
|
99
|
+
|
100
|
+
# @api private
|
101
|
+
def operate(key, inner_operation)
|
102
|
+
key = normalize_key key
|
103
|
+
|
104
|
+
inner_operation.name = key
|
105
|
+
|
106
|
+
@parent.operate inner_operation
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
# Does this set have the context necessary to remove elements?
|
111
|
+
#
|
112
|
+
# @return [Boolean] if the set has a defined context
|
113
|
+
def context?
|
114
|
+
!!@parent.context?
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
def normalize_key(unnormalized_key)
|
119
|
+
unnormalized_key.to_s
|
120
|
+
end
|
121
|
+
|
122
|
+
def initialize_nil?
|
123
|
+
INITIALIZE_NIL.include? @type
|
124
|
+
end
|
125
|
+
|
126
|
+
def needs_name?
|
127
|
+
NEEDS_NAME.include? @type
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'riak/errors/base'
|
2
|
+
|
3
|
+
module Riak
|
4
|
+
class ConnectionError < Error
|
5
|
+
end
|
6
|
+
|
7
|
+
class TlsError < ConnectionError
|
8
|
+
class CertHostMismatchError < TlsError
|
9
|
+
def initialize
|
10
|
+
super t('ssl.cert_host_mismatch')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class CertNotValidError < TlsError
|
15
|
+
def initialize
|
16
|
+
super t('ssl.cert_not_valid')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class CertRevokedError < TlsError
|
21
|
+
def initialize
|
22
|
+
super t('ssl.cert_revoked')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class ReadDataError < TlsError
|
27
|
+
def initialize(actual, candidate)
|
28
|
+
super t('ssl.read_data_error', actual: actual, candidate: candidate)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class UnknownKeyTypeError < TlsError
|
33
|
+
def initialize
|
34
|
+
super t('ssl.unknown_key_type')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class UserConfigurationError < ConnectionError
|
40
|
+
def initialize
|
41
|
+
super t('pbc.user_not_username')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'riak/errors/base'
|
2
|
+
|
3
|
+
module Riak
|
4
|
+
class CrdtError < Error
|
5
|
+
|
6
|
+
class SetRemovalWithoutContextError < CrdtError
|
7
|
+
def initialize
|
8
|
+
super t('crdt.set_removal_without_context')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class PreconditionError < CrdtError
|
13
|
+
def initialize(message)
|
14
|
+
super t('crdt.precondition', message: message)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'riak/errors/base'
|
2
|
+
|
3
|
+
module Riak
|
4
|
+
class FailedRequest < Error
|
5
|
+
def initialize(message)
|
6
|
+
super(message || t('failed_request'))
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
# Exception raised when receiving an unexpected Protocol Buffers response from Riak
|
11
|
+
class ProtobuffsFailedRequest < FailedRequest
|
12
|
+
def initialize(code, message)
|
13
|
+
super t('protobuffs_failed_request', :code => code, :body => message)
|
14
|
+
@original_message = message
|
15
|
+
@not_found = code == :not_found
|
16
|
+
@server_error = code == :server_error
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [true, false] whether the error response is in JSON
|
20
|
+
def is_json?
|
21
|
+
begin
|
22
|
+
JSON.parse(@original_message)
|
23
|
+
true
|
24
|
+
rescue
|
25
|
+
false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [true,false] whether the error represents a "not found" response
|
30
|
+
def not_found?
|
31
|
+
@not_found
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [true,false] whether the error represents an internal
|
35
|
+
# server error
|
36
|
+
def server_error?
|
37
|
+
@server_error
|
38
|
+
end
|
39
|
+
|
40
|
+
def body
|
41
|
+
@original_message
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class ProtobuffsUnexpectedResponse < ProtobuffsFailedRequest
|
46
|
+
def initialize(code, expected)
|
47
|
+
super code, t('pbc.unexpected_response', expected: expected, actual: code)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class ProtobuffsErrorResponse < ProtobuffsFailedRequest
|
52
|
+
def initialize(payload)
|
53
|
+
super payload.errcode, payload.errmsg
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|