riak-client 2.4.1 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.document +5 -5
  3. data/.gitignore +3 -0
  4. data/Gemfile +17 -17
  5. data/Guardfile +20 -20
  6. data/LICENSE.md +16 -16
  7. data/RELNOTES.md +4 -0
  8. data/Rakefile +6 -1
  9. data/lib/riak/client/beefcake/crdt/counter_loader.rb +18 -18
  10. data/lib/riak/client/beefcake/crdt/hyper_log_log_loader.rb +18 -0
  11. data/lib/riak/client/beefcake/crdt/map_loader.rb +64 -64
  12. data/lib/riak/client/beefcake/crdt_loader.rb +4 -1
  13. data/lib/riak/client/beefcake/crdt_operator.rb +13 -0
  14. data/lib/riak/client/beefcake/footer +4 -4
  15. data/lib/riak/client/beefcake/header +6 -6
  16. data/lib/riak/client/beefcake/messages.rb +67 -10
  17. data/lib/riak/client/decaying.rb +36 -36
  18. data/lib/riak/client/feature_detection.rb +120 -120
  19. data/lib/riak/client/instrumentation.rb +19 -19
  20. data/lib/riak/client/node.rb +49 -49
  21. data/lib/riak/client/search.rb +27 -27
  22. data/lib/riak/conflict.rb +13 -13
  23. data/lib/riak/core_ext.rb +7 -7
  24. data/lib/riak/core_ext/blank.rb +53 -53
  25. data/lib/riak/core_ext/extract_options.rb +7 -7
  26. data/lib/riak/core_ext/json.rb +15 -15
  27. data/lib/riak/core_ext/slice.rb +18 -18
  28. data/lib/riak/core_ext/stringify_keys.rb +10 -10
  29. data/lib/riak/core_ext/symbolize_keys.rb +10 -10
  30. data/lib/riak/core_ext/to_param.rb +31 -31
  31. data/lib/riak/crdt.rb +23 -21
  32. data/lib/riak/crdt/base.rb +1 -1
  33. data/lib/riak/crdt/hyper_log_log.rb +97 -0
  34. data/lib/riak/crdt/operation.rb +19 -19
  35. data/lib/riak/encoding.rb +6 -6
  36. data/lib/riak/errors/backend_creation.rb +9 -9
  37. data/lib/riak/errors/connection_error.rb +50 -50
  38. data/lib/riak/errors/protobuffs_error.rb +11 -11
  39. data/lib/riak/i18n.rb +7 -7
  40. data/lib/riak/instrumentation.rb +6 -6
  41. data/lib/riak/json.rb +52 -52
  42. data/lib/riak/list_buckets.rb +28 -28
  43. data/lib/riak/locale/en.yml +1 -0
  44. data/lib/riak/locale/fr.yml +51 -51
  45. data/lib/riak/map_reduce/results.rb +49 -49
  46. data/lib/riak/map_reduce_error.rb +7 -7
  47. data/lib/riak/multiget.rb +122 -122
  48. data/lib/riak/robject.rb +17 -1
  49. data/lib/riak/search/result_document.rb +9 -0
  50. data/lib/riak/stamp.rb +77 -77
  51. data/lib/riak/tombstone.rb +13 -0
  52. data/lib/riak/util/tcp_socket_extensions.rb +58 -58
  53. data/lib/riak/version.rb +1 -1
  54. data/spec/failover/failover.rb +59 -59
  55. data/spec/fixtures/bitcask.txt +25 -25
  56. data/spec/fixtures/multipart-basic-conflict.txt +15 -15
  57. data/spec/fixtures/multipart-blank.txt +7 -7
  58. data/spec/fixtures/multipart-mapreduce.txt +10 -10
  59. data/spec/fixtures/multipart-with-body.txt +16 -16
  60. data/spec/fixtures/multipart-with-marked-tombstones.txt +17 -17
  61. data/spec/fixtures/multipart-with-unmarked-tombstone.txt +16 -16
  62. data/spec/fixtures/server.cert.crt +15 -15
  63. data/spec/fixtures/server.cert.key +15 -15
  64. data/spec/fixtures/test.pem +1 -1
  65. data/spec/integration/riak/bucket_types_spec.rb +38 -0
  66. data/spec/integration/riak/crdt/configuration_spec.rb +4 -3
  67. data/spec/integration/riak/crdt_spec.rb +70 -0
  68. data/spec/integration/riak/encodings/crdt_spec.rb +29 -3
  69. data/spec/integration/riak/encodings/yz_spec.rb +2 -1
  70. data/spec/integration/riak/preflist_spec.rb +15 -3
  71. data/spec/integration/riak/protobuffs/timeouts_spec.rb +1 -1
  72. data/spec/integration/riak/security_spec.rb +11 -6
  73. data/spec/integration/riak/threading_spec.rb +154 -150
  74. data/spec/integration/yokozuna/index_spec.rb +61 -61
  75. data/spec/integration/yokozuna/queries_spec.rb +1 -1
  76. data/spec/integration/yokozuna/schema_spec.rb +49 -49
  77. data/spec/riak/beefcake_protobuffs_backend/crdt_operator_spec.rb +22 -0
  78. data/spec/riak/core_ext/to_param_spec.rb +15 -15
  79. data/spec/riak/crdt/hyper_log_log_spec.rb +56 -0
  80. data/spec/riak/crdt/inner_counter_spec.rb +21 -21
  81. data/spec/riak/crdt/inner_set_spec.rb +33 -33
  82. data/spec/riak/crdt/set_spec.rb +61 -61
  83. data/spec/riak/crdt/shared_examples.rb +14 -0
  84. data/spec/riak/escape_spec.rb +72 -72
  85. data/spec/riak/feature_detection_spec.rb +77 -77
  86. data/spec/riak/index_collection_spec.rb +53 -53
  87. data/spec/riak/instrumentation_spec.rb +124 -124
  88. data/spec/riak/link_spec.rb +85 -85
  89. data/spec/riak/list_buckets_spec.rb +41 -41
  90. data/spec/riak/node_spec.rb +26 -26
  91. data/spec/riak/robject_spec.rb +45 -0
  92. data/spec/support/certs/README.md +12 -12
  93. data/spec/support/certs/ca.crt +21 -21
  94. data/spec/support/certs/client.crl +13 -13
  95. data/spec/support/certs/client.crt +94 -94
  96. data/spec/support/certs/client.csr +18 -18
  97. data/spec/support/certs/client.key +27 -27
  98. data/spec/support/certs/empty_ca.crt +21 -21
  99. data/spec/support/certs/server.crl +13 -13
  100. data/spec/support/certs/server.crt +94 -94
  101. data/spec/support/certs/server.key +27 -27
  102. data/spec/support/crdt_search_fixtures.rb +1 -1
  103. data/spec/support/integration_setup.rb +10 -10
  104. data/spec/support/test_client.rb +1 -1
  105. data/spec/support/test_client.yml.example +10 -10
  106. metadata +10 -3
@@ -1,36 +1,36 @@
1
- module Riak
2
- class Client
3
- # A float value which decays exponentially toward 0 over time.
4
- # @private
5
- class Decaying
6
- attr_accessor :e
7
- attr_accessor :p
8
-
9
- # @param [Hash] opts options
10
- # @option options [Float] :p (0.0) The initial value
11
- # @option options [Float] :e (Math::E) Exponent base
12
- # @option options [Float] :r (Math.log(0.5) / 10) Timescale
13
- # factor - defaulting to decay 50% every 10 seconds
14
- def initialize(opts = {})
15
- @p = opts[:p] || 0.0
16
- @e = opts[:e] || Math::E
17
- @r = opts[:r] || Math.log(0.5) / 10
18
- @t0 = Time.now
19
- end
20
-
21
- # Add to current value.
22
- # @param [Float] d the value to add
23
- def <<(d)
24
- @p = value + d
25
- end
26
-
27
- # @return [Float] the current value (adjusted for the time decay)
28
- def value
29
- now = Time.now
30
- dt = now - @t0
31
- @t0 = now
32
- @p = @p * (@e ** (@r * dt))
33
- end
34
- end
35
- end
36
- end
1
+ module Riak
2
+ class Client
3
+ # A float value which decays exponentially toward 0 over time.
4
+ # @private
5
+ class Decaying
6
+ attr_accessor :e
7
+ attr_accessor :p
8
+
9
+ # @param [Hash] opts options
10
+ # @option options [Float] :p (0.0) The initial value
11
+ # @option options [Float] :e (Math::E) Exponent base
12
+ # @option options [Float] :r (Math.log(0.5) / 10) Timescale
13
+ # factor - defaulting to decay 50% every 10 seconds
14
+ def initialize(opts = {})
15
+ @p = opts[:p] || 0.0
16
+ @e = opts[:e] || Math::E
17
+ @r = opts[:r] || Math.log(0.5) / 10
18
+ @t0 = Time.now
19
+ end
20
+
21
+ # Add to current value.
22
+ # @param [Float] d the value to add
23
+ def <<(d)
24
+ @p = value + d
25
+ end
26
+
27
+ # @return [Float] the current value (adjusted for the time decay)
28
+ def value
29
+ now = Time.now
30
+ dt = now - @t0
31
+ @t0 = now
32
+ @p = @p * (@e ** (@r * dt))
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,120 +1,120 @@
1
- module Riak
2
- class Client
3
- # Methods that can be used to determine whether certain features
4
- # are supported by the Riak node to which the client backend is
5
- # connected.
6
- #
7
- # Backends must implement the "get_server_version" method,
8
- # returning a string representing the Riak node's version. This is
9
- # implemented on HTTP using the stats resource, and on Protocol
10
- # Buffers using the RpbGetServerInfoReq message.
11
- module FeatureDetection
12
- # Constants representing Riak versions
13
- VERSION = {
14
- 1 => Gem::Version.new("1.0.0"),
15
- 1.1 => Gem::Version.new("1.1.0"),
16
- 1.2 => Gem::Version.new("1.2.0"),
17
- 1.3 => Gem::Version.new("1.3.0"),
18
- 1.4 => Gem::Version.new("1.4.0")
19
- }.freeze
20
-
21
- # @return [String] the version of the Riak node
22
- # @abstract
23
- def get_server_version
24
- raise NotImplementedError
25
- end
26
-
27
- # @return [Gem::Version] the version of the Riak node to which
28
- # this backend is connected
29
- def server_version
30
- @server_version ||= Gem::Version.new(get_server_version.split("-").first)
31
- end
32
-
33
- # @return [true,false] whether MapReduce requests can be submitted without
34
- # phases.
35
- def mapred_phaseless?
36
- at_least? VERSION[1.1]
37
- end
38
-
39
- # @return [true,false] whether secondary index queries are
40
- # supported over Protocol Buffers
41
- def pb_indexes?
42
- at_least? VERSION[1.2]
43
- end
44
-
45
- # @return [true,false] whether search queries are supported over
46
- # Protocol Buffers
47
- def pb_search?
48
- at_least? VERSION[1.2]
49
- end
50
-
51
- # @return [true,false] whether conditional fetch/store semantics
52
- # are supported over Protocol Buffers
53
- def pb_conditionals?
54
- at_least? VERSION[1]
55
- end
56
-
57
- # @return [true,false] whether additional quorums and FSM
58
- # controls are available, e.g. primary quorums, basic_quorum,
59
- # notfound_ok
60
- def quorum_controls?
61
- at_least? VERSION[1]
62
- end
63
-
64
- # @return [true,false] whether "not found" responses might
65
- # include vclocks
66
- def tombstone_vclocks?
67
- at_least? VERSION[1]
68
- end
69
-
70
- # @return [true,false] whether partial-fetches (vclock and
71
- # metadata only) are supported over Protocol Buffers
72
- def pb_head?
73
- at_least? VERSION[1]
74
- end
75
-
76
- # @return [true,false] whether bucket properties can be cleared
77
- # (reset to defaults) over HTTP
78
- def http_props_clearable?
79
- at_least? VERSION[1.3]
80
- end
81
-
82
- # @return [true,false] whether secondary indexes support
83
- # pagination
84
- def index_pagination?
85
- at_least? VERSION[1.4]
86
- end
87
-
88
- # @return [true,false] whether secondary indexes support
89
- # return_terms
90
- def index_return_terms?
91
- at_least? VERSION[1.4]
92
- end
93
-
94
- # @return [true,false] whether secondary indexes support
95
- # streaming
96
- def index_streaming?
97
- at_least? VERSION[1.4]
98
- end
99
-
100
- # @return [true,false] whether timeouts are accepted for
101
- # object CRUD, key listing, and bucket listing
102
- def key_object_bucket_timeouts?
103
- at_least? VERSION[1.4]
104
- end
105
-
106
- protected
107
- # @return [true,false] whether the server version is the same or
108
- # newer than the requested version
109
- def at_least?(version)
110
- server_version >= version
111
- end
112
-
113
- # Backends should call this when their connection is interrupted
114
- # or reset so as to facilitate rolling upgrades
115
- def reset_server_version
116
- @server_version = nil
117
- end
118
- end
119
- end
120
- end
1
+ module Riak
2
+ class Client
3
+ # Methods that can be used to determine whether certain features
4
+ # are supported by the Riak node to which the client backend is
5
+ # connected.
6
+ #
7
+ # Backends must implement the "get_server_version" method,
8
+ # returning a string representing the Riak node's version. This is
9
+ # implemented on HTTP using the stats resource, and on Protocol
10
+ # Buffers using the RpbGetServerInfoReq message.
11
+ module FeatureDetection
12
+ # Constants representing Riak versions
13
+ VERSION = {
14
+ 1 => Gem::Version.new("1.0.0"),
15
+ 1.1 => Gem::Version.new("1.1.0"),
16
+ 1.2 => Gem::Version.new("1.2.0"),
17
+ 1.3 => Gem::Version.new("1.3.0"),
18
+ 1.4 => Gem::Version.new("1.4.0")
19
+ }.freeze
20
+
21
+ # @return [String] the version of the Riak node
22
+ # @abstract
23
+ def get_server_version
24
+ raise NotImplementedError
25
+ end
26
+
27
+ # @return [Gem::Version] the version of the Riak node to which
28
+ # this backend is connected
29
+ def server_version
30
+ @server_version ||= Gem::Version.new(get_server_version.split("-").first)
31
+ end
32
+
33
+ # @return [true,false] whether MapReduce requests can be submitted without
34
+ # phases.
35
+ def mapred_phaseless?
36
+ at_least? VERSION[1.1]
37
+ end
38
+
39
+ # @return [true,false] whether secondary index queries are
40
+ # supported over Protocol Buffers
41
+ def pb_indexes?
42
+ at_least? VERSION[1.2]
43
+ end
44
+
45
+ # @return [true,false] whether search queries are supported over
46
+ # Protocol Buffers
47
+ def pb_search?
48
+ at_least? VERSION[1.2]
49
+ end
50
+
51
+ # @return [true,false] whether conditional fetch/store semantics
52
+ # are supported over Protocol Buffers
53
+ def pb_conditionals?
54
+ at_least? VERSION[1]
55
+ end
56
+
57
+ # @return [true,false] whether additional quorums and FSM
58
+ # controls are available, e.g. primary quorums, basic_quorum,
59
+ # notfound_ok
60
+ def quorum_controls?
61
+ at_least? VERSION[1]
62
+ end
63
+
64
+ # @return [true,false] whether "not found" responses might
65
+ # include vclocks
66
+ def tombstone_vclocks?
67
+ at_least? VERSION[1]
68
+ end
69
+
70
+ # @return [true,false] whether partial-fetches (vclock and
71
+ # metadata only) are supported over Protocol Buffers
72
+ def pb_head?
73
+ at_least? VERSION[1]
74
+ end
75
+
76
+ # @return [true,false] whether bucket properties can be cleared
77
+ # (reset to defaults) over HTTP
78
+ def http_props_clearable?
79
+ at_least? VERSION[1.3]
80
+ end
81
+
82
+ # @return [true,false] whether secondary indexes support
83
+ # pagination
84
+ def index_pagination?
85
+ at_least? VERSION[1.4]
86
+ end
87
+
88
+ # @return [true,false] whether secondary indexes support
89
+ # return_terms
90
+ def index_return_terms?
91
+ at_least? VERSION[1.4]
92
+ end
93
+
94
+ # @return [true,false] whether secondary indexes support
95
+ # streaming
96
+ def index_streaming?
97
+ at_least? VERSION[1.4]
98
+ end
99
+
100
+ # @return [true,false] whether timeouts are accepted for
101
+ # object CRUD, key listing, and bucket listing
102
+ def key_object_bucket_timeouts?
103
+ at_least? VERSION[1.4]
104
+ end
105
+
106
+ protected
107
+ # @return [true,false] whether the server version is the same or
108
+ # newer than the requested version
109
+ def at_least?(version)
110
+ server_version >= version
111
+ end
112
+
113
+ # Backends should call this when their connection is interrupted
114
+ # or reset so as to facilitate rolling upgrades
115
+ def reset_server_version
116
+ @server_version = nil
117
+ end
118
+ end
119
+ end
120
+ end
@@ -1,19 +1,19 @@
1
- class Riak::Client
2
- include Instrumentable
3
-
4
- client_payload = {client_id: :client_id}
5
-
6
- instrument_method :buckets, 'riak.list_buckets', client_payload
7
- instrument_method :list_buckets, 'riak.list_buckets', client_payload
8
- instrument_method :list_keys, 'riak.list_keys', client_payload
9
- instrument_method :set_bucket_props, 'riak.set_bucket_props', client_payload
10
- instrument_method :get_bucket_props, 'riak.get_bucket_props', client_payload
11
- instrument_method :clear_bucket_props, 'riak.clear_bucket_props', client_payload
12
- instrument_method :get_index, 'riak.get_index', client_payload
13
- instrument_method :store_object, 'riak.store_object', client_payload
14
- instrument_method :get_object, 'riak.get_object', client_payload
15
- instrument_method :reload_object, 'riak.reload_object', client_payload
16
- instrument_method :delete_object, 'riak.delete_object', client_payload
17
- instrument_method :mapred, 'riak.map_reduce', client_payload
18
- instrument_method :ping, 'riak.ping', client_payload
19
- end
1
+ class Riak::Client
2
+ include Instrumentable
3
+
4
+ client_payload = {client_id: :client_id}
5
+
6
+ instrument_method :buckets, 'riak.list_buckets', client_payload
7
+ instrument_method :list_buckets, 'riak.list_buckets', client_payload
8
+ instrument_method :list_keys, 'riak.list_keys', client_payload
9
+ instrument_method :set_bucket_props, 'riak.set_bucket_props', client_payload
10
+ instrument_method :get_bucket_props, 'riak.get_bucket_props', client_payload
11
+ instrument_method :clear_bucket_props, 'riak.clear_bucket_props', client_payload
12
+ instrument_method :get_index, 'riak.get_index', client_payload
13
+ instrument_method :store_object, 'riak.store_object', client_payload
14
+ instrument_method :get_object, 'riak.get_object', client_payload
15
+ instrument_method :reload_object, 'riak.reload_object', client_payload
16
+ instrument_method :delete_object, 'riak.delete_object', client_payload
17
+ instrument_method :mapred, 'riak.map_reduce', client_payload
18
+ instrument_method :ping, 'riak.ping', client_payload
19
+ end
@@ -1,49 +1,49 @@
1
- module Riak
2
- class Client
3
- class Node
4
- # Represents a single riak node in a cluster.
5
-
6
- include Util::Translation
7
- include Util::Escape
8
-
9
- VALID_OPTIONS = [:host, :pb_port]
10
-
11
- # For a score which halves in 10 seconds, choose
12
- # ln(1/2)/10
13
- ERRORS_DECAY_RATE = Math.log(0.5)/10
14
-
15
- # What IP address or hostname does this node listen on?
16
- attr_accessor :host
17
-
18
- # Which port does the protocol buffers interface listen on?
19
- attr_accessor :pb_port
20
-
21
- # A Decaying rate of errors.
22
- attr_reader :error_rate
23
-
24
- def initialize(client, opts = {})
25
- @client = client
26
- @host = opts[:host] || "127.0.0.1"
27
- @pb_port = opts[:pb_port] || 8087
28
-
29
- @error_rate = Decaying.new
30
- end
31
-
32
- def ==(o)
33
- o.kind_of? Node and
34
- @host == o.host and
35
- @pb_port == o.pb_port
36
- end
37
-
38
- # Can this node be used for protocol buffers requests?
39
- def protobuffs?
40
- # TODO: Need to sort out capabilities
41
- true
42
- end
43
-
44
- def inspect
45
- "#<Node #{@host}:#{@pb_port}>"
46
- end
47
- end
48
- end
49
- end
1
+ module Riak
2
+ class Client
3
+ class Node
4
+ # Represents a single riak node in a cluster.
5
+
6
+ include Util::Translation
7
+ include Util::Escape
8
+
9
+ VALID_OPTIONS = [:host, :pb_port]
10
+
11
+ # For a score which halves in 10 seconds, choose
12
+ # ln(1/2)/10
13
+ ERRORS_DECAY_RATE = Math.log(0.5)/10
14
+
15
+ # What IP address or hostname does this node listen on?
16
+ attr_accessor :host
17
+
18
+ # Which port does the protocol buffers interface listen on?
19
+ attr_accessor :pb_port
20
+
21
+ # A Decaying rate of errors.
22
+ attr_reader :error_rate
23
+
24
+ def initialize(client, opts = {})
25
+ @client = client
26
+ @host = opts[:host] || "127.0.0.1"
27
+ @pb_port = opts[:pb_port] || 8087
28
+
29
+ @error_rate = Decaying.new
30
+ end
31
+
32
+ def ==(o)
33
+ o.kind_of? Node and
34
+ @host == o.host and
35
+ @pb_port == o.pb_port
36
+ end
37
+
38
+ # Can this node be used for protocol buffers requests?
39
+ def protobuffs?
40
+ # TODO: Need to sort out capabilities
41
+ true
42
+ end
43
+
44
+ def inspect
45
+ "#<Node #{@host}:#{@pb_port}>"
46
+ end
47
+ end
48
+ end
49
+ end