aerospike 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee7d4805db6b56945a1f5112c62272f3371c79f8
4
- data.tar.gz: ab922b1acac8a4aa5b09d5605886127c12af60cf
3
+ metadata.gz: c3befa3762779a41284c82d7d1c91071b2d808ba
4
+ data.tar.gz: e68d7474c1cc4f87b2b4e1ae2dc1f9cf6ce5363b
5
5
  SHA512:
6
- metadata.gz: 6879a1edd54bcdb9ad82e5cc3f484cbe5f56034eed1058c9aeb556b2d7b1ca93f663f2260a7d1818b311d5ab65f11a5ab2b8fbae1b85bbaaf277fc5c01234df0
7
- data.tar.gz: 911f4c56dfe6e1d6eb801e560f87732db0309dd5e80bec9969bd5f1af17f0ec3ecfdb249ea865178b619afa6eccbaaa956bc199eba2b9b2bce7d3bdafffe22a9
6
+ metadata.gz: 0670ec0132babe9a91821511c0303c866dd058d35c9e7e6dada688c20ce3d85ae44af4d29734200f8879d95530d94e8d2feff203ddce8f45f034ece463457d0f
7
+ data.tar.gz: 6a7ec991acdee8ae19227a33ec72f73bf11a845533032e9555cd3538c362f2398c4e09c2ff0ad5fe55cb60bfcdcbc33a3ace4ab72c93e7c43464f42174772d48
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## Dec 28 2014 (0.1.6)
2
+
3
+ Minor features added, minor fixes and improvements.
4
+
5
+ * **New Features**:
6
+
7
+ * Added `Policy.consistency_level`
8
+ * Added `WritePolicy.commit_level`
9
+
10
+ * **Fixes**
11
+
12
+ * Fixed setting timeout on connection
13
+ * Fixed exception handling typo for Connection#write
14
+
1
15
  ## Dec 8 2014 (0.1.5)
2
16
 
3
17
  Major features added, minor fixes and improvements.
data/lib/aerospike.rb CHANGED
@@ -46,6 +46,8 @@ require 'aerospike/policy/policy'
46
46
  require 'aerospike/policy/write_policy'
47
47
  require 'aerospike/policy/scan_policy'
48
48
  require 'aerospike/policy/query_policy'
49
+ require 'aerospike/policy/consistency_level'
50
+ require 'aerospike/policy/commit_level'
49
51
 
50
52
  require 'aerospike/cluster/connection'
51
53
  require 'aerospike/cluster/cluster'
@@ -669,9 +669,6 @@ module Aerospike
669
669
  policy = opt_to_query_policy(options)
670
670
  new_policy = policy.clone
671
671
 
672
- # Always set a taskId
673
- statement.task_id = Time.now.to_i if statement.task_id == 0
674
-
675
672
  nodes = @cluster.nodes
676
673
  if nodes.length == 0
677
674
  raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::SERVER_NOT_AVAILABLE, "Scan failed because cluster is empty.")
@@ -726,7 +723,7 @@ module Aerospike
726
723
  ClientPolicy.new(
727
724
  options[:timeout],
728
725
  options[:connection_queue_size],
729
- options[:fail_if_not_connected],
726
+ options[:fail_if_not_connected]
730
727
  )
731
728
  end
732
729
  end
@@ -742,6 +739,7 @@ module Aerospike
742
739
  options[:timeout],
743
740
  options[:max_retiries],
744
741
  options[:sleep_between_retries],
742
+ options[:consistency_level]
745
743
  )
746
744
  end
747
745
  end
@@ -757,7 +755,8 @@ module Aerospike
757
755
  options[:gen_policy],
758
756
  options[:generation],
759
757
  options[:expiration],
760
- options[:send_key]
758
+ options[:send_key],
759
+ options[:commit_level]
761
760
  )
762
761
  end
763
762
  end
@@ -51,7 +51,7 @@ module Aerospike
51
51
  begin
52
52
  written = @socket.write_nonblock(buffer.read(total, length - total))
53
53
  total += written
54
- rescue IO::WaitWriteable, Errno::EAGAIN
54
+ rescue IO::WaitWritable, Errno::EAGAIN
55
55
  IO.select(nil, [@socket])
56
56
  retry
57
57
  rescue => e
@@ -92,8 +92,7 @@ module Aerospike
92
92
  def timeout=(timeout)
93
93
  if timeout > 0 && timeout != @timeout
94
94
  @timeout = timeout
95
- # if IO.select([@socket], [@socket], [@socket], timeout.to_f)
96
- if IO.select(nil, nil, nil, timeout.to_f)
95
+ if IO.select([@socket], [@socket], [@socket], timeout.to_f)
97
96
  begin
98
97
  # Verify there is now a good connection
99
98
  @socket.connect_nonblock(@sockaddr)
@@ -34,7 +34,7 @@ module Aerospike
34
34
  end
35
35
 
36
36
  def write_buffer
37
- set_batch_exists(@batch_namespace)
37
+ set_batch_exists(@policy, @batch_namespace)
38
38
  end
39
39
 
40
40
  # Parse all results in the batch. Add records to shared list.
@@ -34,7 +34,7 @@ module Aerospike
34
34
  end
35
35
 
36
36
  def write_buffer
37
- set_batch_get(@batch_namespace, @bin_names, @read_attr)
37
+ set_batch_get(@policy, @batch_namespace, @bin_names, @read_attr)
38
38
  end
39
39
 
40
40
  # Parse all results in the batch. Add records to shared list.
@@ -21,6 +21,9 @@ require 'msgpack'
21
21
  require 'aerospike/result_code'
22
22
  require 'aerospike/command/field_type'
23
23
 
24
+ require 'aerospike/policy/consistency_level'
25
+ require 'aerospike/policy/commit_level'
26
+
24
27
  module Aerospike
25
28
 
26
29
  private
@@ -34,6 +37,9 @@ module Aerospike
34
37
  # Do not read the bins
35
38
  INFO1_NOBINDATA = Integer(1 << 5)
36
39
 
40
+ # Involve all replicas in read operation.
41
+ INFO1_CONSISTENCY_ALL = Integer(1 << 6)
42
+
37
43
  # Create or update record
38
44
  INFO2_WRITE = Integer(1 << 0)
39
45
  # Fling a record into the belly of Moloch.
@@ -49,6 +55,8 @@ module Aerospike
49
55
 
50
56
  # This is the last of a multi-part message.
51
57
  INFO3_LAST = Integer(1 << 0)
58
+ # Commit to master only before declaring success.
59
+ INFO3_COMMIT_MASTER = Integer(1 << 1)
52
60
  # Update only. Merge bins.
53
61
  INFO3_UPDATE_ONLY = Integer(1 << 3)
54
62
 
@@ -127,27 +135,27 @@ module Aerospike
127
135
  end
128
136
 
129
137
  # Writes the command for exist operations
130
- def set_exists(key)
138
+ def set_exists(policy, key)
131
139
  begin_cmd
132
140
  field_count = estimate_key_size(key)
133
141
  size_buffer
134
- write_header(INFO1_READ|INFO1_NOBINDATA, 0, field_count, 0)
142
+ write_header(policy, INFO1_READ|INFO1_NOBINDATA, 0, field_count, 0)
135
143
  write_key(key)
136
144
  end_cmd
137
145
  end
138
146
 
139
147
  # Writes the command for get operations (all bins)
140
- def set_read_for_key_only(key)
148
+ def set_read_for_key_only(policy, key)
141
149
  begin_cmd
142
150
  field_count = estimate_key_size(key)
143
151
  size_buffer
144
- write_header(INFO1_READ|INFO1_GET_ALL, 0, field_count, 0)
152
+ write_header(policy, INFO1_READ|INFO1_GET_ALL, 0, field_count, 0)
145
153
  write_key(key)
146
154
  end_cmd
147
155
  end
148
156
 
149
157
  # Writes the command for get operations (specified bins)
150
- def set_read(key, bin_names)
158
+ def set_read(policy, key, bin_names)
151
159
  if bin_names && bin_names.length > 0
152
160
  begin_cmd
153
161
  field_count = estimate_key_size(key)
@@ -157,7 +165,7 @@ module Aerospike
157
165
  end
158
166
 
159
167
  size_buffer
160
- write_header(INFO1_READ, 0, field_count, bin_names.length)
168
+ write_header(policy, INFO1_READ, 0, field_count, bin_names.length)
161
169
  write_key(key)
162
170
 
163
171
  bin_names.each do |bin_name|
@@ -166,12 +174,12 @@ module Aerospike
166
174
 
167
175
  end_cmd
168
176
  else
169
- set_read_for_key_only(key)
177
+ set_read_for_key_only(policy, key)
170
178
  end
171
179
  end
172
180
 
173
181
  # Writes the command for getting metadata operations
174
- def set_read_header(key)
182
+ def set_read_header(policy, key)
175
183
  begin_cmd
176
184
  field_count = estimate_key_size(key)
177
185
  estimate_operation_size_for_bin_name('')
@@ -181,7 +189,7 @@ module Aerospike
181
189
  # The workaround is to request a non-existent bin.
182
190
  # TODO: Fix this on server.
183
191
  #command.set_read(INFO1_READ | _INFO1_NOBINDATA);
184
- write_header(INFO1_READ, 0, field_count, 1)
192
+ write_header(policy, INFO1_READ, 0, field_count, 1)
185
193
 
186
194
  write_key(key)
187
195
  write_operation_for_bin_name('', Aerospike::Operation::READ)
@@ -223,7 +231,7 @@ module Aerospike
223
231
  if write_attr != 0
224
232
  write_header_with_policy(policy, read_attr, write_attr, field_count, operations.length)
225
233
  else
226
- write_header(read_attr, write_attr, field_count, operations.length)
234
+ write_header(policy, read_attr, write_attr, field_count, operations.length)
227
235
  end
228
236
  write_key(key)
229
237
 
@@ -236,7 +244,7 @@ module Aerospike
236
244
  end_cmd
237
245
  end
238
246
 
239
- def set_udf(key, package_name, function_name, args)
247
+ def set_udf(policy, key, package_name, function_name, args)
240
248
  begin_cmd
241
249
  field_count = estimate_key_size(key)
242
250
  arg_bytes = args.to_bytes
@@ -244,7 +252,7 @@ module Aerospike
244
252
  field_count += estimate_udf_size(package_name, function_name, arg_bytes)
245
253
  size_buffer
246
254
 
247
- write_header(0, INFO2_WRITE, field_count, 0)
255
+ write_header(policy, 0, INFO2_WRITE, field_count, 0)
248
256
  write_key(key)
249
257
  write_field_string(package_name, Aerospike::FieldType::UDF_PACKAGE_NAME)
250
258
  write_field_string(function_name, Aerospike::FieldType::UDF_FUNCTION)
@@ -253,7 +261,7 @@ module Aerospike
253
261
  end_cmd
254
262
  end
255
263
 
256
- def set_batch_exists(batch_namespace)
264
+ def set_batch_exists(policy, batch_namespace)
257
265
  # Estimate buffer size
258
266
  begin_cmd
259
267
  keys = batch_namespace.keys
@@ -264,7 +272,7 @@ module Aerospike
264
272
 
265
273
  size_buffer
266
274
 
267
- write_header(INFO1_READ|INFO1_NOBINDATA, 0, 2, 0)
275
+ write_header(policy, INFO1_READ|INFO1_NOBINDATA, 0, 2, 0)
268
276
  write_field_string(batch_namespace.namespace, Aerospike::FieldType::NAMESPACE)
269
277
  write_field_header(byte_size, Aerospike::FieldType::DIGEST_RIPE_ARRAY)
270
278
 
@@ -275,7 +283,7 @@ module Aerospike
275
283
  end_cmd
276
284
  end
277
285
 
278
- def set_batch_get(batch_namespace, bin_names, read_attr)
286
+ def set_batch_get(policy, batch_namespace, bin_names, read_attr)
279
287
  # Estimate buffer size
280
288
  begin_cmd
281
289
  byte_size = batch_namespace.keys.length * DIGEST_SIZE
@@ -296,7 +304,7 @@ module Aerospike
296
304
  operation_count = bin_names.length
297
305
  end
298
306
 
299
- write_header(read_attr, 0, 2, operation_count)
307
+ write_header(policy, read_attr, 0, 2, operation_count)
300
308
  write_field_string(batch_namespace.namespace, Aerospike::FieldType::NAMESPACE)
301
309
  write_field_header(byte_size, Aerospike::FieldType::DIGEST_RIPE_ARRAY)
302
310
 
@@ -351,7 +359,7 @@ module Aerospike
351
359
  operation_count = bin_names.length
352
360
  end
353
361
 
354
- write_header(read_attr, 0, field_count, operation_count)
362
+ write_header(policy, read_attr, 0, field_count, operation_count)
355
363
 
356
364
  if namespace
357
365
  write_field_string(namespace, Aerospike::FieldType::NAMESPACE)
@@ -534,7 +542,9 @@ module Aerospike
534
542
  end
535
543
 
536
544
  # Generic header write.
537
- def write_header(read_attr, write_attr, field_count, operation_count)
545
+ def write_header(policy, read_attr, write_attr, field_count, operation_count)
546
+ read_attr |= INFO1_CONSISTENCY_ALL if policy.consistency_level == Aerospike::ConsistencyLevel::CONSISTENCY_ALL
547
+
538
548
  # Write all header data except total size which must be written last.
539
549
  @data_buffer.write_byte(MSG_REMAINING_HEADER_SIZE, 8) # Message heade.length.
540
550
  @data_buffer.write_byte(read_attr, 9)
@@ -581,6 +591,9 @@ module Aerospike
581
591
  write_attr |= INFO2_GENERATION_DUP
582
592
  end
583
593
 
594
+ info_attr |= INFO3_COMMIT_MASTER if policy.commit_level == Aerospike::CommitLevel::COMMIT_MASTER
595
+ read_attr |= INFO1_CONSISTENCY_ALL if policy.consistency_level == Aerospike::ConsistencyLevel::CONSISTENCY_ALL
596
+
584
597
  # Write all header data except total size which must be written last.
585
598
  @data_buffer.write_byte(MSG_REMAINING_HEADER_SIZE, 8) # Message heade.length.
586
599
  @data_buffer.write_byte(read_attr, 9)
@@ -34,7 +34,7 @@ module Aerospike
34
34
  end
35
35
 
36
36
  def write_buffer
37
- set_udf(@key, @package_name, @function_name, @args)
37
+ set_udf(@policy, @key, @package_name, @function_name, @args)
38
38
  end
39
39
 
40
40
  end # class
@@ -34,7 +34,7 @@ module Aerospike
34
34
  end
35
35
 
36
36
  def write_buffer
37
- set_exists(@key)
37
+ set_exists(@policy, @key)
38
38
  end
39
39
 
40
40
  def parse_result
@@ -38,7 +38,7 @@ module Aerospike
38
38
  end
39
39
 
40
40
  def write_buffer
41
- set_read(@key, @bin_names)
41
+ set_read(@policy, @key, @bin_names)
42
42
  end
43
43
 
44
44
  def parse_result
@@ -34,7 +34,7 @@ module Aerospike
34
34
  end
35
35
 
36
36
  def write_buffer
37
- set_read_header(@key)
37
+ set_read_header(@policy, @key)
38
38
  end
39
39
 
40
40
  def parse_result
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ # Copyright 2014 Aerospike, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http:#www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ module Aerospike
17
+
18
+ module CommitLevel
19
+
20
+ # Server should wait until successfully committing master and all replicas.
21
+ COMMIT_ALL = 0
22
+
23
+ # Server should wait until successfully committing master only.
24
+ COMMIT_MASTER = 1
25
+
26
+ end # module
27
+
28
+ end # module
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ # Copyright 2014 Aerospike, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http:#www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ module Aerospike
17
+
18
+ module ConsistencyLevel
19
+
20
+ # Involve a single replica in the operation.
21
+ CONSISTENCY_ONE = 0
22
+
23
+ # Involve all replicas in the operation.
24
+ CONSISTENCY_ALL = 1
25
+
26
+ end # module
27
+
28
+ end # module
@@ -14,6 +14,7 @@
14
14
  # limitations under the License.
15
15
 
16
16
  require 'aerospike/policy/priority'
17
+ require 'aerospike/policy/consistency_level'
17
18
 
18
19
 
19
20
  module Aerospike
@@ -21,9 +22,9 @@ module Aerospike
21
22
  # Container object for client policy command.
22
23
  class Policy
23
24
 
24
- attr_accessor :priority, :timeout, :max_retries, :sleep_between_retries
25
+ attr_accessor :priority, :timeout, :max_retries, :sleep_between_retries, :consistency_level
25
26
 
26
- def initialize(priority=nil, timeout=nil, max_retiries=nil, sleep_between_retries=nil)
27
+ def initialize(priority=nil, timeout=nil, max_retiries=nil, sleep_between_retries=nil, consistency_level=nil)
27
28
  # Container object for transaction policy attributes used in all database
28
29
  # operation calls.
29
30
 
@@ -31,6 +32,11 @@ module Aerospike
31
32
  # Currently, only used for scans.
32
33
  @priority = priority || Priority::DEFAULT
33
34
 
35
+ # How replicas should be consulted in a read operation to provide the desired
36
+ # consistency guarantee. Default to allowing one replica to be used in the
37
+ # read operation.
38
+ @consistency_level = consistency_level || Aerospike::ConsistencyLevel::CONSISTENCY_ONE
39
+
34
40
  # Transaction timeout.
35
41
  # This timeout is used to set the socket timeout and is also sent to the
36
42
  # server along with the transaction in the wire protocol.
@@ -14,6 +14,7 @@
14
14
  # limitations under the License.
15
15
 
16
16
  require 'aerospike/policy/policy'
17
+ require 'aerospike/policy/commit_level'
17
18
  require 'aerospike/policy/generation_policy'
18
19
  require 'aerospike/policy/record_exists_action'
19
20
 
@@ -23,9 +24,9 @@ module Aerospike
23
24
  class WritePolicy < Policy
24
25
 
25
26
  attr_accessor :record_exists_action, :generation_policy,
26
- :generation, :expiration, :send_key
27
+ :generation, :expiration, :send_key, :commit_level
27
28
 
28
- def initialize(record_exists_action=nil, gen_policy=nil, generation=nil, expiration=nil, send_key=nil)
29
+ def initialize(record_exists_action=nil, gen_policy=nil, generation=nil, expiration=nil, send_key=nil, commit_level=nil)
29
30
  super()
30
31
 
31
32
  # Qualify how to handle writes where the record already exists.
@@ -35,6 +36,11 @@ module Aerospike
35
36
  # indicates that the generation is not used to restrict writes.
36
37
  @generation_policy = gen_policy || GenerationPolicy::NONE
37
38
 
39
+ # Desired consistency guarantee when committing a transaction on the server. The default
40
+ # (COMMIT_ALL) indicates that the server should wait for master and all replica commits to
41
+ # be successful before returning success to the client.
42
+ @commit_level = commit_level || Aerospike::CommitLevel::COMMIT_ALL
43
+
38
44
  # Expected generation. Generation is the number of times a record has been modified
39
45
  # (including creation) on the server. If a write operation is creating a record,
40
46
  # the expected generation would be 0
@@ -81,7 +81,7 @@ module Aerospike
81
81
  fieldCount+=1
82
82
  end
83
83
 
84
- @statement.task_id = Time.now.to_i + Time.usec if @statement.task_id == 0
84
+ @statement.set_task_id
85
85
 
86
86
  @data_offset += 8 + FIELD_HEADER_SIZE
87
87
  fieldCount+=1
@@ -113,7 +113,7 @@ module Aerospike
113
113
  readAttr = INFO1_READ
114
114
  operation_count = (@statement.filters.to_a.length == 0 && @statement.bin_names.to_a.length == 0) ? @statement.bin_names.length : 0
115
115
 
116
- write_header(readAttr, 0, fieldCount, operation_count)
116
+ write_header(@policy, readAttr, 0, fieldCount, operation_count)
117
117
 
118
118
  if @statement.namespace
119
119
  write_field_string(@statement.namespace, Aerospike::FieldType::NAMESPACE)
@@ -48,7 +48,7 @@ module Aerospike
48
48
  @function_args = nil
49
49
 
50
50
  # TaskId determines query task id. (Optional)
51
- @task_id = 0
51
+ @task_id = rand(RAND_MAX)
52
52
 
53
53
  # determines if the query should return data
54
54
  @return_data = true
@@ -65,6 +65,16 @@ module Aerospike
65
65
  return (filters.nil? || (filters.empty?))
66
66
  end
67
67
 
68
+ def set_task_id
69
+ while @task_id == 0
70
+ @task_id = rand(RAND_MAX)
71
+ end
72
+ end
73
+
74
+ private
75
+
76
+ RAND_MAX = 2**63
77
+
68
78
  end # class
69
79
 
70
80
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Aerospike
3
- VERSION = "0.1.5"
3
+ VERSION = "0.1.6"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aerospike
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Khosrow Afroozeh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-08 00:00:00.000000000 Z
11
+ date: 2014-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: atomic
@@ -90,6 +90,8 @@ files:
90
90
  - lib/aerospike/operation.rb
91
91
  - lib/aerospike/policy/batch_policy.rb
92
92
  - lib/aerospike/policy/client_policy.rb
93
+ - lib/aerospike/policy/commit_level.rb
94
+ - lib/aerospike/policy/consistency_level.rb
93
95
  - lib/aerospike/policy/generation_policy.rb
94
96
  - lib/aerospike/policy/policy.rb
95
97
  - lib/aerospike/policy/priority.rb