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
@@ -0,0 +1,97 @@
1
+ require 'riak/util/string'
2
+
3
+ module Riak
4
+ module Crdt
5
+
6
+ # A distributed set containing strings, using the Riak 2 Data Types feature and Hyper Log Log algorithm
7
+ class HyperLogLog < Base
8
+ include Util::String
9
+
10
+ # Create a HLL instance. The bucket type is determined by the first of
11
+ # these sources:
12
+ #
13
+ # 1. The `bucket_type` String argument
14
+ # 2. A {BucketTyped::Bucket} as the `bucket` argument
15
+ # 3. The `Crdt::Base::DEFAULT_BUCKET_TYPES[:hll]` entry
16
+ #
17
+ # @param bucket [Bucket] the {Riak::Bucket} for this set
18
+ # @param [String, nil] key The name of the set. A nil key makes
19
+ # Riak assign a key.
20
+ # @param [String] bucket_type The bucket type for this HLL datatype
21
+ # @param options [Hash]
22
+ def initialize(bucket, key, bucket_type = nil, options = {})
23
+ super(bucket, key, bucket_type || :hll, options)
24
+ end
25
+
26
+ # Gets the current HLL value from Riak
27
+ #
28
+ # @return [Integer]
29
+ def value
30
+ reload if dirty?
31
+ @value
32
+ end
33
+ alias :cardinality :value
34
+
35
+ def batch
36
+ batcher = BatchHyperLogLog.new self
37
+
38
+ yield batcher
39
+
40
+ operate batcher.operations
41
+ end
42
+
43
+ # Add a {String} to the {Riak::Crdt::HyperLogLog}
44
+ #
45
+ # @param [String] element the element to add to the set
46
+ # @param [Hash] options
47
+ def add(element, options = {})
48
+ operate operation(:add, element), options
49
+ end
50
+
51
+ def pretty_print(pp)
52
+ super pp do
53
+ pp.comma_breakable
54
+ pp.pp to_a
55
+ end
56
+ end
57
+
58
+ private
59
+ def vivify(value)
60
+ @value = value
61
+ end
62
+
63
+ def operation(direction, element)
64
+ Operation::Update.new.tap do |op|
65
+ op.type = :hll
66
+ op.value = { direction => element }
67
+ end
68
+ end
69
+
70
+ class BatchHyperLogLog
71
+ def initialize(base)
72
+ @base = base
73
+ @adds = ::Set.new
74
+ end
75
+
76
+ def add(element)
77
+ @adds.add element
78
+ end
79
+
80
+ def to_a
81
+ @adds.to_a
82
+ end
83
+
84
+ def value
85
+ @adds
86
+ end
87
+
88
+ def operations
89
+ Operation::Update.new.tap do |op|
90
+ op.type = :hll
91
+ op.value = {add: @adds.to_a}
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -1,19 +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
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
@@ -1,6 +1,6 @@
1
- if defined? Encoding
2
- Encoding.default_internal = "UTF-8" if Encoding.default_internal.nil? ||
3
- !Encoding.default_internal.ascii_compatible?
4
- else
5
- $KCODE = "U"
6
- end
1
+ if defined? Encoding
2
+ Encoding.default_internal = "UTF-8" if Encoding.default_internal.nil? ||
3
+ !Encoding.default_internal.ascii_compatible?
4
+ else
5
+ $KCODE = "U"
6
+ end
@@ -1,9 +1,9 @@
1
- require 'riak/errors/base'
2
-
3
- module Riak
4
- class BackendCreationError < Error
5
- def initialize(backend)
6
- super t('protobuffs_configuration', backend: backend)
7
- end
8
- end
9
- end
1
+ require 'riak/errors/base'
2
+
3
+ module Riak
4
+ class BackendCreationError < Error
5
+ def initialize(backend)
6
+ super t('protobuffs_configuration', backend: backend)
7
+ end
8
+ end
9
+ end
@@ -1,50 +1,50 @@
1
- require 'riak/errors/base'
2
-
3
- module Riak
4
- class ConnectionError < Error
5
- end
6
-
7
- class TlsError < ConnectionError
8
- class SslVersionConfigurationError < TlsError
9
- def initialize
10
- super t('ssl.version_configuration_error')
11
- end
12
- end
13
-
14
- class CertHostMismatchError < TlsError
15
- def initialize
16
- super t('ssl.cert_host_mismatch')
17
- end
18
- end
19
-
20
- class CertNotValidError < TlsError
21
- def initialize
22
- super t('ssl.cert_not_valid')
23
- end
24
- end
25
-
26
- class CertRevokedError < TlsError
27
- def initialize
28
- super t('ssl.cert_revoked')
29
- end
30
- end
31
-
32
- class ReadDataError < TlsError
33
- def initialize(actual, candidate)
34
- super t('ssl.read_data_error', actual: actual, candidate: candidate)
35
- end
36
- end
37
-
38
- class UnknownKeyTypeError < TlsError
39
- def initialize
40
- super t('ssl.unknown_key_type')
41
- end
42
- end
43
- end
44
-
45
- class UserConfigurationError < ConnectionError
46
- def initialize
47
- super t('pbc.user_not_username')
48
- end
49
- end
50
- end
1
+ require 'riak/errors/base'
2
+
3
+ module Riak
4
+ class ConnectionError < Error
5
+ end
6
+
7
+ class TlsError < ConnectionError
8
+ class SslVersionConfigurationError < TlsError
9
+ def initialize
10
+ super t('ssl.version_configuration_error')
11
+ end
12
+ end
13
+
14
+ class CertHostMismatchError < TlsError
15
+ def initialize
16
+ super t('ssl.cert_host_mismatch')
17
+ end
18
+ end
19
+
20
+ class CertNotValidError < TlsError
21
+ def initialize
22
+ super t('ssl.cert_not_valid')
23
+ end
24
+ end
25
+
26
+ class CertRevokedError < TlsError
27
+ def initialize
28
+ super t('ssl.cert_revoked')
29
+ end
30
+ end
31
+
32
+ class ReadDataError < TlsError
33
+ def initialize(actual, candidate)
34
+ super t('ssl.read_data_error', actual: actual, candidate: candidate)
35
+ end
36
+ end
37
+
38
+ class UnknownKeyTypeError < TlsError
39
+ def initialize
40
+ super t('ssl.unknown_key_type')
41
+ end
42
+ end
43
+ end
44
+
45
+ class UserConfigurationError < ConnectionError
46
+ def initialize
47
+ super t('pbc.user_not_username')
48
+ end
49
+ end
50
+ end
@@ -1,11 +1,11 @@
1
- require 'riak/errors/base'
2
- module Riak
3
- class ProtobuffsError < Error
4
- end
5
-
6
- class ProtobuffsFailedHeader < ProtobuffsError
7
- def initialize
8
- super t('pbc.failed_header')
9
- end
10
- end
11
- end
1
+ require 'riak/errors/base'
2
+ module Riak
3
+ class ProtobuffsError < Error
4
+ end
5
+
6
+ class ProtobuffsFailedHeader < ProtobuffsError
7
+ def initialize
8
+ super t('pbc.failed_header')
9
+ end
10
+ end
11
+ end
@@ -1,7 +1,7 @@
1
- require 'i18n'
2
-
3
- I18n.config.enforce_available_locales = true unless I18n.config.enforce_available_locales == false
4
-
5
- Dir.glob(File.expand_path("../locale/*.yml", __FILE__)).each do |locale_file|
6
- I18n.load_path << locale_file
7
- end
1
+ require 'i18n'
2
+
3
+ I18n.config.enforce_available_locales = true unless I18n.config.enforce_available_locales == false
4
+
5
+ Dir.glob(File.expand_path("../locale/*.yml", __FILE__)).each do |locale_file|
6
+ I18n.load_path << locale_file
7
+ end
@@ -1,6 +1,6 @@
1
- begin
2
- require 'instrumentable'
3
- require 'riak/client/instrumentation'
4
- rescue LoadError => e
5
- # Go quietly into the night...(?)
6
- end
1
+ begin
2
+ require 'instrumentable'
3
+ require 'riak/client/instrumentation'
4
+ rescue LoadError => e
5
+ # Go quietly into the night...(?)
6
+ end
@@ -1,52 +1,52 @@
1
- require 'multi_json'
2
- if MultiJson.respond_to?(:adapter)
3
- MultiJson.adapter
4
- else
5
- MultiJson.engine # Force loading of an engine
6
- end
7
- require 'riak/core_ext/json'
8
-
9
- module Riak
10
- class << self
11
- # Options that will be passed to the JSON parser and encoder.
12
- # Defaults to `{:max_nesting => 20}`
13
- attr_accessor :json_options
14
- end
15
- self.json_options = {:max_nesting => 20}
16
-
17
- # JSON module for internal use inside riak-client
18
- module JSON
19
- class << self
20
- if MultiJson.respond_to?(:dump) # MultiJson 1.2 or later
21
- # Parse a JSON string
22
- # @param [String] str a JSON payload
23
- # @return [Array,Hash] a Ruby object decoded from the JSON payload
24
- def parse(str)
25
- MultiJson.load(str, Riak.json_options)
26
- end
27
-
28
- # Generate a JSON string
29
- # @param [Array, Hash] obj an object to JSON-encode
30
- # @return [String] a JSON payload
31
- def encode(obj)
32
- MultiJson.dump(obj)
33
- end
34
- else
35
- # Parse a JSON string
36
- # @param [String] str a JSON payload
37
- # @return [Array,Hash] a Ruby object decoded from the JSON payload
38
- def parse(str)
39
- MultiJson.decode(str, Riak.json_options)
40
- end
41
-
42
- # Generate a JSON string
43
- # @param [Array, Hash] obj an object to JSON-encode
44
- # @return [String] a JSON payload
45
- def encode(obj)
46
- MultiJson.encode(obj)
47
- end
48
- end
49
- alias :dump :encode
50
- end
51
- end
52
- end
1
+ require 'multi_json'
2
+ if MultiJson.respond_to?(:adapter)
3
+ MultiJson.adapter
4
+ else
5
+ MultiJson.engine # Force loading of an engine
6
+ end
7
+ require 'riak/core_ext/json'
8
+
9
+ module Riak
10
+ class << self
11
+ # Options that will be passed to the JSON parser and encoder.
12
+ # Defaults to `{:max_nesting => 20}`
13
+ attr_accessor :json_options
14
+ end
15
+ self.json_options = {:max_nesting => 20}
16
+
17
+ # JSON module for internal use inside riak-client
18
+ module JSON
19
+ class << self
20
+ if MultiJson.respond_to?(:dump) # MultiJson 1.2 or later
21
+ # Parse a JSON string
22
+ # @param [String] str a JSON payload
23
+ # @return [Array,Hash] a Ruby object decoded from the JSON payload
24
+ def parse(str)
25
+ MultiJson.load(str, Riak.json_options)
26
+ end
27
+
28
+ # Generate a JSON string
29
+ # @param [Array, Hash] obj an object to JSON-encode
30
+ # @return [String] a JSON payload
31
+ def encode(obj)
32
+ MultiJson.dump(obj)
33
+ end
34
+ else
35
+ # Parse a JSON string
36
+ # @param [String] str a JSON payload
37
+ # @return [Array,Hash] a Ruby object decoded from the JSON payload
38
+ def parse(str)
39
+ MultiJson.decode(str, Riak.json_options)
40
+ end
41
+
42
+ # Generate a JSON string
43
+ # @param [Array, Hash] obj an object to JSON-encode
44
+ # @return [String] a JSON payload
45
+ def encode(obj)
46
+ MultiJson.encode(obj)
47
+ end
48
+ end
49
+ alias :dump :encode
50
+ end
51
+ end
52
+ end
@@ -1,28 +1,28 @@
1
- module Riak
2
- class ListBuckets
3
- def initialize(client, options, block)
4
- @client = client
5
- @block = block
6
- @options = options
7
- perform_request
8
- end
9
-
10
- def perform_request
11
- @client.backend do |be|
12
- be.list_buckets @options, &wrapped_block
13
- end
14
- end
15
-
16
- private
17
-
18
- def wrapped_block
19
- proc do |bucket_names|
20
- next if bucket_names.nil?
21
- bucket_names.each do |bucket_name|
22
- bucket = @client.bucket bucket_name
23
- @block.call bucket
24
- end
25
- end
26
- end
27
- end
28
- end
1
+ module Riak
2
+ class ListBuckets
3
+ def initialize(client, options, block)
4
+ @client = client
5
+ @block = block
6
+ @options = options
7
+ perform_request
8
+ end
9
+
10
+ def perform_request
11
+ @client.backend do |be|
12
+ be.list_buckets @options, &wrapped_block
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def wrapped_block
19
+ proc do |bucket_names|
20
+ next if bucket_names.nil?
21
+ bucket_names.each do |bucket_name|
22
+ bucket = @client.bucket bucket_name
23
+ @block.call bucket
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end