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.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/Gemfile +0 -1
  4. data/{LICENSE → LICENSE.md} +0 -0
  5. data/README.markdown +211 -66
  6. data/RELEASE_NOTES.md +22 -47
  7. data/Rakefile +45 -0
  8. data/lib/riak.rb +1 -1
  9. data/lib/riak/bucket.rb +2 -2
  10. data/lib/riak/client.rb +22 -195
  11. data/lib/riak/client/beefcake/crdt_loader.rb +127 -0
  12. data/lib/riak/client/beefcake/crdt_operator.rb +222 -0
  13. data/lib/riak/client/beefcake/footer +4 -0
  14. data/lib/riak/client/beefcake/header +6 -0
  15. data/lib/riak/client/beefcake/message_codes.rb +29 -0
  16. data/lib/riak/client/beefcake/message_overlay.rb +61 -0
  17. data/lib/riak/client/beefcake/messages.rb +733 -371
  18. data/lib/riak/client/beefcake/object_methods.rb +1 -1
  19. data/lib/riak/client/beefcake/protocol.rb +105 -0
  20. data/lib/riak/client/beefcake/socket.rb +243 -0
  21. data/lib/riak/client/beefcake_protobuffs_backend.rb +262 -122
  22. data/lib/riak/client/node.rb +4 -75
  23. data/lib/riak/client/protobuffs_backend.rb +6 -14
  24. data/lib/riak/client/search.rb +0 -64
  25. data/lib/riak/client/yokozuna.rb +52 -0
  26. data/lib/riak/counter.rb +1 -1
  27. data/lib/riak/crdt.rb +21 -0
  28. data/lib/riak/crdt/base.rb +97 -0
  29. data/lib/riak/crdt/batch_counter.rb +19 -0
  30. data/lib/riak/crdt/batch_map.rb +41 -0
  31. data/lib/riak/crdt/counter.rb +71 -0
  32. data/lib/riak/crdt/inner_counter.rb +74 -0
  33. data/lib/riak/crdt/inner_flag.rb +42 -0
  34. data/lib/riak/crdt/inner_map.rb +53 -0
  35. data/lib/riak/crdt/inner_register.rb +26 -0
  36. data/lib/riak/crdt/inner_set.rb +95 -0
  37. data/lib/riak/crdt/map.rb +88 -0
  38. data/lib/riak/crdt/operation.rb +19 -0
  39. data/lib/riak/crdt/set.rb +156 -0
  40. data/lib/riak/crdt/typed_collection.rb +131 -0
  41. data/lib/riak/errors/base.rb +9 -0
  42. data/lib/riak/errors/connection_error.rb +44 -0
  43. data/lib/riak/errors/crdt_error.rb +18 -0
  44. data/lib/riak/errors/failed_request.rb +56 -0
  45. data/lib/riak/errors/protobuffs_error.rb +11 -0
  46. data/lib/riak/i18n.rb +2 -0
  47. data/lib/riak/json.rb +1 -1
  48. data/lib/riak/locale/en.yml +26 -1
  49. data/lib/riak/locale/fr.yml +0 -1
  50. data/lib/riak/map_reduce.rb +1 -1
  51. data/lib/riak/map_reduce/results.rb +1 -1
  52. data/lib/riak/multiget.rb +1 -2
  53. data/lib/riak/rcontent.rb +8 -3
  54. data/lib/riak/robject.rb +2 -8
  55. data/lib/riak/secondary_index.rb +4 -4
  56. data/lib/riak/serializers.rb +1 -1
  57. data/lib/riak/util/escape.rb +3 -5
  58. data/lib/riak/version.rb +1 -1
  59. data/lib/riak/walk_spec.rb +7 -3
  60. data/riak-client.gemspec +10 -8
  61. data/spec/fixtures/bitcask.txt +25 -0
  62. data/spec/integration/riak/bucket_types_spec.rb +61 -0
  63. data/spec/integration/riak/counters_spec.rb +17 -32
  64. data/spec/integration/riak/crdt_spec.rb +181 -0
  65. data/spec/integration/riak/crdt_validation/map_spec.rb +63 -0
  66. data/spec/integration/riak/crdt_validation/set_spec.rb +122 -0
  67. data/spec/integration/riak/protobuffs_backends_spec.rb +9 -26
  68. data/spec/integration/riak/security_spec.rb +94 -0
  69. data/spec/integration/riak/threading_spec.rb +24 -67
  70. data/spec/integration/yokozuna/index_spec.rb +61 -0
  71. data/spec/integration/yokozuna/queries_spec.rb +116 -0
  72. data/spec/integration/yokozuna/schema_spec.rb +49 -0
  73. data/spec/riak/beefcake_protobuffs_backend/crdt_operator_spec.rb +222 -0
  74. data/spec/riak/beefcake_protobuffs_backend/object_methods_spec.rb +4 -4
  75. data/spec/riak/beefcake_protobuffs_backend/protocol_spec.rb +189 -0
  76. data/spec/riak/beefcake_protobuffs_backend/socket_spec.rb +151 -0
  77. data/spec/riak/beefcake_protobuffs_backend_spec.rb +68 -106
  78. data/spec/riak/bucket_spec.rb +81 -77
  79. data/spec/riak/client_spec.rb +43 -340
  80. data/spec/riak/core_ext/to_param_spec.rb +2 -2
  81. data/spec/riak/counter_spec.rb +20 -20
  82. data/spec/riak/crdt/counter_spec.rb +52 -0
  83. data/spec/riak/crdt/inner_counter_spec.rb +21 -0
  84. data/spec/riak/crdt/inner_flag_spec.rb +39 -0
  85. data/spec/riak/crdt/inner_map_spec.rb +47 -0
  86. data/spec/riak/crdt/inner_register_spec.rb +40 -0
  87. data/spec/riak/crdt/inner_set_spec.rb +33 -0
  88. data/spec/riak/crdt/map_spec.rb +77 -0
  89. data/spec/riak/crdt/set_spec.rb +58 -0
  90. data/spec/riak/crdt/shared_examples.rb +74 -0
  91. data/spec/riak/crdt/typed_collection_spec.rb +231 -0
  92. data/spec/riak/escape_spec.rb +33 -37
  93. data/spec/riak/feature_detection_spec.rb +45 -45
  94. data/spec/riak/index_collection_spec.rb +12 -12
  95. data/spec/riak/link_spec.rb +34 -34
  96. data/spec/riak/list_buckets_spec.rb +7 -7
  97. data/spec/riak/map_reduce/filter_builder_spec.rb +6 -6
  98. data/spec/riak/map_reduce/phase_spec.rb +35 -35
  99. data/spec/riak/map_reduce_spec.rb +89 -87
  100. data/spec/riak/multiget_spec.rb +20 -15
  101. data/spec/riak/node_spec.rb +5 -152
  102. data/spec/riak/robject_spec.rb +95 -108
  103. data/spec/riak/search_spec.rb +17 -139
  104. data/spec/riak/secondary_index_spec.rb +49 -49
  105. data/spec/riak/serializers_spec.rb +9 -9
  106. data/spec/riak/stamp_spec.rb +9 -9
  107. data/spec/riak/walk_spec_spec.rb +46 -46
  108. data/spec/spec_helper.rb +14 -22
  109. data/spec/support/certs/README.md +13 -0
  110. data/spec/support/certs/ca.crt +22 -0
  111. data/spec/support/certs/client.crt +95 -0
  112. data/spec/support/certs/client.key +27 -0
  113. data/spec/support/certs/empty_ca.crt +21 -0
  114. data/spec/support/certs/server.crl +13 -0
  115. data/spec/support/certs/server.crt +95 -0
  116. data/spec/support/certs/server.key +27 -0
  117. data/spec/support/integration_setup.rb +1 -1
  118. data/spec/support/search_corpus_setup.rb +29 -8
  119. data/spec/support/test_client.rb +46 -0
  120. data/spec/support/test_client.yml.example +10 -0
  121. data/spec/support/unified_backend_examples.rb +104 -83
  122. data/spec/support/version_filter.rb +2 -2
  123. data/spec/support/wait_until.rb +14 -0
  124. metadata +134 -132
  125. data/erl_src/riak_kv_test014_backend.beam +0 -0
  126. data/erl_src/riak_kv_test014_backend.erl +0 -189
  127. data/erl_src/riak_kv_test_backend.beam +0 -0
  128. data/erl_src/riak_kv_test_backend.erl +0 -731
  129. data/erl_src/riak_search_test_backend.beam +0 -0
  130. data/erl_src/riak_search_test_backend.erl +0 -175
  131. data/lib/riak/client/excon_backend.rb +0 -172
  132. data/lib/riak/client/http_backend.rb +0 -413
  133. data/lib/riak/client/http_backend/bucket_streamer.rb +0 -15
  134. data/lib/riak/client/http_backend/chunked_json_streamer.rb +0 -42
  135. data/lib/riak/client/http_backend/configuration.rb +0 -227
  136. data/lib/riak/client/http_backend/key_streamer.rb +0 -15
  137. data/lib/riak/client/http_backend/object_methods.rb +0 -114
  138. data/lib/riak/client/http_backend/request_headers.rb +0 -34
  139. data/lib/riak/client/http_backend/transport_methods.rb +0 -201
  140. data/lib/riak/client/instrumentation.rb +0 -25
  141. data/lib/riak/client/net_http_backend.rb +0 -82
  142. data/lib/riak/cluster.rb +0 -151
  143. data/lib/riak/failed_request.rb +0 -81
  144. data/lib/riak/instrumentation.rb +0 -6
  145. data/lib/riak/node.rb +0 -40
  146. data/lib/riak/node/configuration.rb +0 -304
  147. data/lib/riak/node/console.rb +0 -133
  148. data/lib/riak/node/control.rb +0 -207
  149. data/lib/riak/node/defaults.rb +0 -85
  150. data/lib/riak/node/generation.rb +0 -127
  151. data/lib/riak/node/log.rb +0 -34
  152. data/lib/riak/node/version.rb +0 -29
  153. data/lib/riak/search.rb +0 -3
  154. data/lib/riak/test_server.rb +0 -89
  155. data/lib/riak/util/headers.rb +0 -32
  156. data/lib/riak/util/multipart.rb +0 -52
  157. data/lib/riak/util/multipart/stream_parser.rb +0 -62
  158. data/spec/fixtures/munchausen.txt +0 -1033
  159. data/spec/integration/riak/cluster_spec.rb +0 -88
  160. data/spec/integration/riak/http_backends_spec.rb +0 -180
  161. data/spec/integration/riak/node_spec.rb +0 -170
  162. data/spec/integration/riak/test_server_spec.rb +0 -57
  163. data/spec/riak/excon_backend_spec.rb +0 -102
  164. data/spec/riak/headers_spec.rb +0 -21
  165. data/spec/riak/http_backend/configuration_spec.rb +0 -273
  166. data/spec/riak/http_backend/object_methods_spec.rb +0 -243
  167. data/spec/riak/http_backend/transport_methods_spec.rb +0 -97
  168. data/spec/riak/http_backend_spec.rb +0 -367
  169. data/spec/riak/instrumentation_spec.rb +0 -167
  170. data/spec/riak/multipart_spec.rb +0 -23
  171. data/spec/riak/net_http_backend_spec.rb +0 -15
  172. data/spec/riak/stream_parser_spec.rb +0 -53
  173. data/spec/support/drb_mock_server.rb +0 -39
  174. data/spec/support/http_backend_implementation_examples.rb +0 -253
  175. data/spec/support/mock_server.rb +0 -81
  176. data/spec/support/mocks.rb +0 -4
  177. data/spec/support/riak_test.rb +0 -77
  178. data/spec/support/sometimes.rb +0 -46
  179. data/spec/support/test_server.rb +0 -61
  180. data/spec/support/test_server.yml.example +0 -14
@@ -0,0 +1,71 @@
1
+ module Riak
2
+ module Crdt
3
+
4
+ # A distributed counter that supports incrementing and decrementing. This
5
+ # `Counter` uses the Riak 2 Data Types feature. If you're interested in
6
+ # Riak 1.4 Counters, see {Riak::Counter}.
7
+ class Counter < Base
8
+
9
+ # Create a counter instance. If not provided, the default bucket type
10
+ # from {Riak::Crdt} will be used.
11
+ #
12
+ # @param [Bucket] bucket the {Riak::Bucket} for this counter
13
+ # @param [String, nil] key The name of the counter. A nil key makes
14
+ # Riak assign a key.
15
+ # @param [String] bucket_type The optional bucket type for this counter.
16
+ # The default is in `Crdt::Base::DEFAULT_BUCKET_TYPES[:counter]`.
17
+ # @param [Hash] options
18
+ def initialize(bucket, key, bucket_type=nil, options={})
19
+ super(bucket, key, bucket_type || DEFAULT_BUCKET_TYPES[:counter], options)
20
+ end
21
+
22
+ # The current value of the counter; hits the server if the value has
23
+ # not been fetched or if the counter has been incremented.
24
+ def value
25
+ reload if dirty?
26
+ return @value
27
+ end
28
+
29
+ # Increment the counter.
30
+ #
31
+ # @param [Integer] amount
32
+ # @param [Hash] options
33
+ def increment(amount=1, options={})
34
+ operate operation(amount), options
35
+ end
36
+
37
+ # Yields a {BatchCounter} to turn multiple increments into a single
38
+ # Riak hit.
39
+ #
40
+ # @yieldparam [BatchCounter] batch_counter collects multiple increments
41
+ def batch
42
+ batcher = BatchCounter.new
43
+
44
+ yield batcher
45
+
46
+ increment batcher.accumulator
47
+ end
48
+
49
+ alias :to_i :value
50
+
51
+ # Decrement the counter.
52
+ #
53
+ # @param [Integer] amount
54
+ def decrement(amount=1)
55
+ increment -amount
56
+ end
57
+
58
+ private
59
+ def vivify(value)
60
+ @value = value
61
+ end
62
+
63
+ def operation(amount)
64
+ Operation::Update.new.tap do |op|
65
+ op.type = :counter
66
+ op.value = amount
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,74 @@
1
+ module Riak
2
+ module Crdt
3
+ # The {InnerCounter} lives inside a {Map}, or an {InnerMap} inside of a
4
+ # {Map}, and is accessed through a {TypedCollection}.
5
+ #
6
+ # Much like the {Riak::Crdt::Counter}, it provides an integer value that can
7
+ # be incremented and decremented.
8
+ class InnerCounter
9
+ # The name of this counter inside a map.
10
+ #
11
+ # @api private
12
+ attr_accessor :name
13
+
14
+ # The value of this counter.
15
+ #
16
+ # @return [Integer] counter value
17
+ attr_reader :value
18
+ alias :to_i :value
19
+
20
+ # The parent of this counter.
21
+ #
22
+ # @api private
23
+ attr_reader :parent
24
+
25
+ # @api private
26
+ def initialize(parent, value=0)
27
+ @parent = parent
28
+ @value = value
29
+ end
30
+
31
+ # Increment the counter.
32
+ #
33
+ # @param [Integer] amount How much to increment the counter by.
34
+ def increment(amount = 1)
35
+ @parent.increment name, amount
36
+ end
37
+
38
+ # Decrement the counter. Opposite of increment.
39
+ #
40
+ # @param [Integer] amount How much to decrement from the counter.
41
+ def decrement(amount = 1)
42
+ increment -amount
43
+ end
44
+
45
+ # Perform multiple increments against this counter, and collapse
46
+ # them into a single operation.
47
+ #
48
+ # @yieldparam [BatchCounter] batch_counter actually collects the
49
+ # operations.
50
+ def batch
51
+ batcher = BatchCounter.new
52
+
53
+ yield batcher
54
+
55
+ increment batcher.accumulator
56
+ end
57
+
58
+ # @api private
59
+ def self.update(increment)
60
+ Operation::Update.new.tap do |op|
61
+ op.value = increment
62
+ op.type = :counter
63
+ end
64
+ end
65
+
66
+ # @api private
67
+ def self.delete
68
+ Operation::Delete.new.tap do |op|
69
+ op.type = :counter
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,42 @@
1
+ module Riak
2
+ module Crdt
3
+ # The {InnerFlag} is a boolean member of a {Map}. Since flag operations are
4
+ # extremely simple, this object simply provides internal API methods for
5
+ # {TypedCollection} to use.
6
+ #
7
+ # @api private
8
+ class InnerFlag
9
+ def self.new(parent, value)
10
+ ensure_boolean value
11
+
12
+ return value
13
+ end
14
+
15
+ def self.update(value)
16
+ ensure_boolean value
17
+
18
+ Operation::Update.new.tap do |op|
19
+ op.value = value
20
+ op.type = :flag
21
+ end
22
+ end
23
+
24
+ def self.delete
25
+ Operation::Delete.new.tap do |op|
26
+ op.type = :flag
27
+ end
28
+ end
29
+
30
+ private
31
+ def self.ensure_boolean(value)
32
+ return if value.is_a? TrueClass
33
+ return if value.is_a? FalseClass
34
+
35
+ raise FlagError, t('crdt.flag.not_boolean')
36
+ end
37
+
38
+ class FlagError < ArgumentError
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,53 @@
1
+ module Riak
2
+ module Crdt
3
+ # A map that exists inside a {TypedCollection} inside another map.
4
+ class InnerMap
5
+ attr_reader :counters, :flags, :maps, :registers, :sets
6
+
7
+ attr_accessor :name
8
+
9
+ # The parent of this counter.
10
+ #
11
+ # @api private
12
+ attr_reader :parent
13
+
14
+ # @api private
15
+ def initialize(parent, value={})
16
+ @parent = parent
17
+ @value = value.symbolize_keys
18
+
19
+ initialize_collections
20
+ end
21
+
22
+ # @api private
23
+ def operate(inner_operation)
24
+ wrapped_operation = Operation::Update.new.tap do |op|
25
+ op.value = inner_operation
26
+ op.type = :map
27
+ end
28
+
29
+ @parent.operate(name, wrapped_operation)
30
+ end
31
+
32
+ # @api private
33
+ def self.delete
34
+ Operation::Delete.new.tap do |op|
35
+ op.type = :map
36
+ end
37
+ end
38
+
39
+ def context?
40
+ @parent.context?
41
+ end
42
+
43
+ private
44
+ def initialize_collections
45
+ @counters = TypedCollection.new InnerCounter, self, @value[:counters]
46
+ @flags = TypedCollection.new InnerFlag, self, @value[:flags]
47
+ @maps = TypedCollection.new InnerMap, self, @value[:maps]
48
+ @registers = TypedCollection.new InnerRegister, self, @value[:registers]
49
+ @sets = TypedCollection.new InnerSet, self, @value[:sets]
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,26 @@
1
+ module Riak
2
+ module Crdt
3
+ class InnerRegister < String
4
+ attr_reader :parent
5
+
6
+ def initialize(parent, *args, &block)
7
+ @parent = parent
8
+ super(*args, &block)
9
+ freeze
10
+ end
11
+
12
+ def self.update(value)
13
+ Operation::Update.new.tap do |op|
14
+ op.value = value
15
+ op.type = :register
16
+ end
17
+ end
18
+
19
+ def self.delete
20
+ Operation::Delete.new.tap do |op|
21
+ op.type = :register
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,95 @@
1
+ module Riak
2
+ module Crdt
3
+ # The {InnerSet} is similar to a {Riak::Crdt::Set}, except it is part of
4
+ # a {Map} (or an {InnerMap} inside of a {Map}). It is usually accessed
5
+ # through a {TypedCollection}.
6
+ #
7
+ # Just like a {Riak::Crdt::Set}, it's a set of {String Strings} that can
8
+ # be added to or removed from.
9
+ class InnerSet
10
+ # The name of this set inside a map.
11
+ #
12
+ # @api private
13
+ attr_accessor :name
14
+
15
+ # The {::Set} value of this {InnerSet}.
16
+ #
17
+ # @return [::Set] set value
18
+ attr_reader :value
19
+ alias :members :value
20
+
21
+ # The parent of this counter.
22
+ #
23
+ # @api private
24
+ attr_reader :parent
25
+
26
+ # @api private
27
+ def initialize(parent, value=[])
28
+ @parent = parent
29
+ frozen_value = value.to_a.tap{ |v| v.each(&:freeze) }
30
+ @value = ::Set.new frozen_value
31
+ @value.freeze
32
+ end
33
+
34
+ # Casts this {InnerSet} to an {Array}.
35
+ #
36
+ # @return [Array] an array of all the members of this set
37
+ def to_a
38
+ value.to_a
39
+ end
40
+
41
+ # Check if this {InnerSet} is empty.
42
+ #
43
+ # @return [Boolean} whether this structure is empty or not
44
+ def empty?
45
+ value.empty?
46
+ end
47
+
48
+ # Check if a given string is in this structure.
49
+ #
50
+ # @param [String] element candidate string to check for inclusion
51
+ # @return [Boolean] whether the candidate is in this set or not
52
+ def include?(element)
53
+ value.include? element
54
+ end
55
+
56
+ # Add a {String} to the {InnerSet}
57
+ #
58
+ # @param [String] element the element to add
59
+ def add(element)
60
+ @parent.operate name, update(add: element)
61
+ end
62
+
63
+ # Remove a {String} from this set
64
+ #
65
+ # @param [String] element the element to remove
66
+ def remove(element)
67
+ raise CrdtError::SetRemovalWithoutContextError unless context?
68
+ @parent.operate name, update(remove: element)
69
+ end
70
+
71
+
72
+ # Does the map containing this set have the context necessary to remove elements?
73
+ #
74
+ # @return [Boolean] if the set has a defined context
75
+ def context?
76
+ @parent.context?
77
+ end
78
+
79
+ # @api private
80
+ def update(changes)
81
+ Operation::Update.new.tap do |op|
82
+ op.value = changes.symbolize_keys
83
+ op.type = :set
84
+ end
85
+ end
86
+
87
+ # @api private
88
+ def self.delete
89
+ Operation::Delete.new.tap do |op|
90
+ op.type = :set
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,88 @@
1
+ module Riak
2
+ module Crdt
3
+
4
+ # A distributed map of multiple fields, such as counters, flags, registers,
5
+ # sets, and, recursively, other maps, using the Riak 2 Data Types feature.
6
+ #
7
+ # Maps are complex, and the implementation is spread across many classes.
8
+ # You're looking at the top-level {Map} class, but there are also others
9
+ # that are also responsible for how maps work:
10
+ #
11
+ # * {InnerMap}: used for maps that live inside other maps
12
+ # * {BatchMap}: proxies multiple operations into a single Riak update request
13
+ # * {TypedCollection}: a collection of members of a single map, similar
14
+ # to a Ruby {Hash}
15
+ # * {InnerFlag}: a boolean value inside a map
16
+ # * {InnerRegister}: a {String} value inside a map
17
+ # * {InnerCounter}: a {Riak::Crdt::Counter}, but inside a map
18
+ # * {InnerSet}: a {Riak::Crdt::Set}, but inside a map
19
+ #
20
+ class Map < Base
21
+ attr_reader :counters, :flags, :maps, :registers, :sets
22
+
23
+ # Create a map instance. If not provided, the default bucket type
24
+ # from {Riak::Crdt} will be used.
25
+ #
26
+ # @param bucket [Bucket] the {Riak::Bucket} for this map
27
+ # @param [String, nil] key The name of the map. A nil key makes
28
+ # Riak assign a key.
29
+ # @param [String] bucket_type The optional bucket type for this map.
30
+ # The default is in `Crdt::Base::DEFAULT_BUCKET_TYPES[:map]`.
31
+ # @param options [Hash]
32
+ def initialize(bucket, key, bucket_type=nil, options={})
33
+ super(bucket, key, bucket_type || DEFAULT_BUCKET_TYPES[:map], options)
34
+
35
+ initialize_collections
36
+ end
37
+
38
+ # Maps are frequently updated in batches. Use this method to get a
39
+ # {BatchMap} to turn multiple operations into a single Riak update
40
+ # request.
41
+ #
42
+ # @yieldparam batch_map [BatchMap] collects updates and other operations
43
+ def batch(*args)
44
+ batch_map = BatchMap.new self
45
+
46
+ yield batch_map
47
+
48
+ write_operations batch_map.operations, *args
49
+ end
50
+
51
+ # This method *for internal use only* is used to collect oprations from
52
+ # disparate sources to provide a user-friendly API.
53
+ #
54
+ # @api private
55
+ def operate(operation, *args)
56
+ batch *args do |m|
57
+ m.operate operation
58
+ end
59
+ end
60
+
61
+ private
62
+ def vivify(data)
63
+ @counters = TypedCollection.new InnerCounter, self, data[:counters]
64
+ @flags = TypedCollection.new InnerFlag, self, data[:flags]
65
+ @maps = TypedCollection.new InnerMap, self, data[:maps]
66
+ @registers = TypedCollection.new InnerRegister, self, data[:registers]
67
+ @sets = TypedCollection.new InnerSet, self, data[:sets]
68
+ end
69
+
70
+ def initialize_collections(data={})
71
+ reload if dirty?
72
+ end
73
+
74
+ def write_operations(operations, *args)
75
+ operator do |op|
76
+ op.operate(bucket.name,
77
+ key,
78
+ bucket_type,
79
+ operations,
80
+ *args
81
+ )
82
+ end
83
+ # collections break dirty tracking
84
+ reload
85
+ end
86
+ end
87
+ end
88
+ end