aerospike 2.9.0 → 2.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +51 -4
  3. data/README.md +1 -1
  4. data/lib/aerospike.rb +12 -4
  5. data/lib/aerospike/aerospike_exception.rb +7 -1
  6. data/lib/aerospike/atomic/atomic.rb +1 -1
  7. data/lib/aerospike/bin.rb +1 -1
  8. data/lib/aerospike/cdt/list_operation.rb +1 -1
  9. data/lib/aerospike/cdt/map_operation.rb +1 -1
  10. data/lib/aerospike/cdt/map_order.rb +1 -1
  11. data/lib/aerospike/cdt/map_policy.rb +1 -1
  12. data/lib/aerospike/cdt/map_return_type.rb +1 -1
  13. data/lib/aerospike/cdt/map_write_mode.rb +1 -1
  14. data/lib/aerospike/client.rb +10 -11
  15. data/lib/aerospike/cluster.rb +92 -17
  16. data/lib/aerospike/cluster/partition.rb +1 -1
  17. data/lib/aerospike/cluster/partition_parser.rb +169 -0
  18. data/lib/aerospike/command/admin_command.rb +2 -3
  19. data/lib/aerospike/command/batch_direct_command.rb +1 -1
  20. data/lib/aerospike/command/batch_direct_exists_command.rb +1 -1
  21. data/lib/aerospike/command/batch_direct_node.rb +3 -3
  22. data/lib/aerospike/command/batch_index_command.rb +10 -2
  23. data/lib/aerospike/command/batch_index_node.rb +2 -2
  24. data/lib/aerospike/command/batch_item.rb +1 -1
  25. data/lib/aerospike/command/command.rb +102 -11
  26. data/lib/aerospike/command/delete_command.rb +21 -5
  27. data/lib/aerospike/command/execute_command.rb +1 -1
  28. data/lib/aerospike/command/exists_command.rb +21 -5
  29. data/lib/aerospike/command/field_type.rb +3 -1
  30. data/lib/aerospike/command/multi_command.rb +11 -4
  31. data/lib/aerospike/command/operate_command.rb +6 -1
  32. data/lib/aerospike/command/read_command.rb +29 -18
  33. data/lib/aerospike/command/read_header_command.rb +18 -6
  34. data/lib/aerospike/command/roles.rb +1 -1
  35. data/lib/aerospike/command/single_command.rb +9 -3
  36. data/lib/aerospike/command/touch_command.rb +14 -3
  37. data/lib/aerospike/command/unsupported_particle_type_validator.rb +1 -1
  38. data/lib/aerospike/command/write_command.rb +13 -4
  39. data/lib/aerospike/connection/create.rb +1 -1
  40. data/lib/aerospike/features.rb +1 -1
  41. data/lib/aerospike/geo_json.rb +70 -1
  42. data/lib/aerospike/host.rb +1 -1
  43. data/lib/aerospike/info.rb +1 -1
  44. data/lib/aerospike/key.rb +1 -1
  45. data/lib/aerospike/language.rb +1 -1
  46. data/lib/aerospike/node.rb +3 -6
  47. data/lib/aerospike/node/refresh/partitions.rb +6 -15
  48. data/lib/aerospike/node_validator.rb +45 -40
  49. data/lib/aerospike/operation.rb +6 -1
  50. data/lib/aerospike/policy/admin_policy.rb +1 -1
  51. data/lib/aerospike/policy/batch_policy.rb +1 -1
  52. data/lib/aerospike/policy/client_policy.rb +1 -1
  53. data/lib/aerospike/policy/commit_level.rb +1 -1
  54. data/lib/aerospike/policy/consistency_level.rb +1 -1
  55. data/lib/aerospike/policy/generation_policy.rb +1 -1
  56. data/lib/aerospike/policy/operate_policy.rb +1 -1
  57. data/lib/aerospike/policy/policy.rb +57 -3
  58. data/lib/aerospike/policy/priority.rb +1 -1
  59. data/lib/aerospike/policy/query_policy.rb +8 -1
  60. data/lib/aerospike/policy/record_bin_multiplicity.rb +1 -1
  61. data/lib/aerospike/policy/record_exists_action.rb +1 -1
  62. data/lib/aerospike/policy/replica.rb +38 -0
  63. data/lib/aerospike/policy/scan_policy.rb +8 -1
  64. data/lib/aerospike/policy/write_policy.rb +1 -1
  65. data/lib/aerospike/query/filter.rb +1 -1
  66. data/lib/aerospike/query/pred_exp.rb +192 -0
  67. data/lib/aerospike/query/pred_exp/and_or.rb +32 -0
  68. data/lib/aerospike/query/pred_exp/geo_json_value.rb +41 -0
  69. data/lib/aerospike/query/pred_exp/integer_value.rb +32 -0
  70. data/lib/aerospike/query/pred_exp/op.rb +27 -0
  71. data/lib/aerospike/query/pred_exp/regex.rb +32 -0
  72. data/lib/aerospike/query/pred_exp/regex_flags.rb +23 -0
  73. data/lib/aerospike/query/pred_exp/string_value.rb +29 -0
  74. data/lib/aerospike/query/query_command.rb +27 -1
  75. data/lib/aerospike/query/recordset.rb +5 -5
  76. data/lib/aerospike/query/scan_command.rb +1 -1
  77. data/lib/aerospike/query/statement.rb +12 -3
  78. data/lib/aerospike/query/stream_command.rb +9 -10
  79. data/lib/aerospike/record.rb +1 -1
  80. data/lib/aerospike/result_code.rb +13 -20
  81. data/lib/aerospike/socket/base.rb +1 -1
  82. data/lib/aerospike/task/execute_task.rb +1 -1
  83. data/lib/aerospike/task/index_task.rb +1 -1
  84. data/lib/aerospike/task/task.rb +1 -1
  85. data/lib/aerospike/task/udf_register_task.rb +1 -1
  86. data/lib/aerospike/task/udf_remove_task.rb +1 -1
  87. data/lib/aerospike/ttl.rb +1 -1
  88. data/lib/aerospike/udf.rb +1 -1
  89. data/lib/aerospike/user_role.rb +1 -1
  90. data/lib/aerospike/utils/buffer.rb +1 -1
  91. data/lib/aerospike/utils/packer.rb +1 -1
  92. data/lib/aerospike/utils/pool.rb +1 -1
  93. data/lib/aerospike/utils/unpacker.rb +7 -2
  94. data/lib/aerospike/value/particle_type.rb +1 -1
  95. data/lib/aerospike/value/value.rb +59 -29
  96. data/lib/aerospike/version.rb +1 -1
  97. metadata +15 -8
  98. data/lib/aerospike/cluster/partition_tokenizer_new.rb +0 -130
  99. data/lib/aerospike/cluster/partition_tokenizer_old.rb +0 -135
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b4a6204e2eedbfcbd9a755abdc89da26d978ec5cddbc401b9085863e953c9a5a
4
- data.tar.gz: 9ef1ad5e358a98a30da46cf6aded8bc8958f62e16f239523f313a7c2ddd169b2
3
+ metadata.gz: 7bef523a7e7500d8e39cb80f3b9ee6831a5ddc0bd6d782685181cae6a6c6ada5
4
+ data.tar.gz: 760d626bffac6ed69bcdda048daf39b07a12a85264b67be0677ad5d552c5473c
5
5
  SHA512:
6
- metadata.gz: 6ca26471e04a8999b081699e2b68f51eaa00e28cc1e8e8fc4d7e0f1fa2830de9dbb5725b888420cab85dbd5f34af2dae675b81963a9b7c88320e3393e2b0c1a1
7
- data.tar.gz: c854595481004116f1c0fd90600dcf0ba94dfe9b371a8a310a21afae601dd491ecd960658cfe7fe3f08859259af421b19453aeec2cfda68484af328f7c98657c
6
+ metadata.gz: df19a0c2900463a35b73ba52bfae3bdb2c5f6cbdaba3ab17172219e96ad3de3878bbc1ff57403fbbffe0fb48cc147ee642297e2fe47c829d768e76b1e4dee0fa
7
+ data.tar.gz: 528ade6f9abfb9b9e266439fefa6606f2623aec2503ec6c5466a5c3f9ffd9656debea49ff434f715f042c3ae319546e80352aa36cdc925ed351cab2633c75c4b
@@ -2,7 +2,54 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
- ## [Unreleased]
5
+ ## [2.13.0] - 2019-07-17
6
+
7
+ * **New Features**
8
+ * Adds support for replica policies.
9
+
10
+ * **Improvements**
11
+ * Remove support for "old" partition tokenizer.
12
+ * Refactor how partition parser is initialized and called.
13
+ * Adds support for 'replicas' and remove the old partition table queries from the server.
14
+
15
+ ## [2.12.0] - 2019-04-21
16
+
17
+ * **New Features**
18
+ * Support for predicate expressions in all transaction.
19
+ * Support for `operation.delete` in `client#operate`.
20
+
21
+ * **Improvements**
22
+ * Optimize serialization for nested structures. Thanks to [@Kacper Madej](https://github.com/madejejej)! [[#94](https://github.com/aerospike/aerospike-client-ruby/pull/94)]
23
+ * Remove `Thread#abort_on_exception` from `batch_index_command`. Thanks to [@Kacper Madej](https://github.com/madejejej)! [[#94](https://github.com/aerospike/aerospike-client-ruby/pull/92)]
24
+ * Does not allow values other than Integer, Float, String, Symbol and nil to be used as keys in Maps.
25
+
26
+ * **Bug Fixes**
27
+ * Fixes tests that weren't using ENV variables for connections. This will allow the tests to be run on any server.
28
+
29
+
30
+ ## [2.11.0] - 2019-05-17
31
+
32
+ * **New Features**
33
+ * Support for predicate expressions in queries. Thanks to [@Minus10Degrees](https://github.com/Minus10Degrees)! [[#78](https://github.com/aerospike/aerospike-client-ruby/issues/78)]
34
+
35
+ * **Bug Fixes**
36
+ * Client#execute\_udf\_on\_query should not modify the statement argument. [[#79](https://github.com/aerospike/aerospike-client-ruby/issues/79)]
37
+ * Encoding::UndefinedConversionError when reading blob data from CDT list/map bin. [[#84](https://github.com/aerospike/aerospike-client-ruby/issues/84)]
38
+
39
+ ## [2.10.0] - 2019-05-10
40
+
41
+ * **New Features**
42
+ * Add support for LB discovery / seeding. Thanks to [@filiptepper](https://github.com/filiptepper)! [[#80](https://github.com/aerospike/aerospike-client-ruby/issues/80)]
43
+
44
+ ## [2.9.1] - 2019-04-03
45
+
46
+ * **Bug Fixes**
47
+ * Query fails if one or more cluster nodes do not have records in the set [[#77](https://github.com/aerospike/aerospike-client-ruby/issues/77)]
48
+
49
+ * **Updates**
50
+ * Change admin message version to 2 (from 0)
51
+ * Remove unused BIN_EXISTS_ERROR (6) and BIN_NOT_FOUND (17) error codes
52
+ * Tests: Support setting user/password when running specs
6
53
 
7
54
  ## [2.9.0] - 2018-11-09
8
55
 
@@ -10,10 +57,10 @@ All notable changes to this project will be documented in this file.
10
57
  * Add INFINITY and WILDCARD values for use in CDT map/list comparators. [AER-5945]
11
58
 
12
59
  * **Bug Fixes**
13
- * Default policies set on Client instance do not get applied [[#74](https://github.com/aerospike/aerospike-client-ruby/issue/74)]
60
+ * Default policies set on Client instance do not get applied [[#74](https://github.com/aerospike/aerospike-client-ruby/issues/74)]
14
61
 
15
62
  * **Updates**
16
- * *BREAKING CHANGE*: Change default for send_key write policy to false [[#73](https://github.com/aerospike/aerospike-client-ruby/issue/73)]
63
+ * *BREAKING CHANGE*: Change default for send_key write policy to false [[#73](https://github.com/aerospike/aerospike-client-ruby/issues/73)]
17
64
  * Support truncate info command argument "lut=now" for servers that require it. [AER-5955]
18
65
 
19
66
  ## [2.8.0] - 2018-08-06
@@ -140,7 +187,7 @@ All notable changes to this project will be documented in this file.
140
187
 
141
188
  ## [2.0.0] - 2016-05-27
142
189
 
143
- * **Breaking Changes** - Please refer to detailed list of [API changes](docs/api-changes.md#v2.0.0) for further details.
190
+ * **Breaking Changes** - Please refer to detailed list of [API changes](https://www.aerospike.com/docs/client/ruby/usage/incompatible.html#version-2-0-0) for further details.
144
191
  * Incompatible integer key digests: digests for integer keys computed by v2 and v1 are different; the Aerospike server uses the key digest to retrieve records. This will impact your ability to read records with integer keys that were created by a v1 client version.
145
192
  * Backward incompatible changes to the `Aerospike::Client.new` initializer.
146
193
  * The `Aerospike::Client.new_many` initializer has been removed; use `Aerospike::Client.new` instead.
data/README.md CHANGED
@@ -97,7 +97,7 @@ This library is packaged with a number of tests.
97
97
 
98
98
  To run all the test cases:
99
99
 
100
- $ bundle exec rspec
100
+ $ AEROSPIKE_HOSTS="<host:port>[,<hoist:port>]" AEROSPIKE_USER="<user>" AEROSPIKE_PASSWORD="<pass>" bundle exec rspec
101
101
 
102
102
  <a name="Examples"></a>
103
103
  ## Examples
@@ -1,4 +1,4 @@
1
- # Copyright 2014-2018 Aerospike, Inc.
1
+ # Copyright 2014-2020 Aerospike, Inc.
2
2
  #
3
3
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
4
4
  # license agreements.
@@ -101,11 +101,10 @@ require 'aerospike/connection/create'
101
101
 
102
102
  require 'aerospike/cluster'
103
103
  require 'aerospike/cluster/create_connection'
104
- require 'aerospike/cluster/partition'
105
104
  require 'aerospike/cluster/find_nodes_to_remove'
106
105
  require 'aerospike/cluster/find_node'
107
- require 'aerospike/cluster/partition_tokenizer_new'
108
- require 'aerospike/cluster/partition_tokenizer_old'
106
+ require 'aerospike/cluster/partition'
107
+ require 'aerospike/cluster/partition_parser'
109
108
  require 'aerospike/node'
110
109
  require 'aerospike/node/generation'
111
110
  require 'aerospike/node/refresh/failed'
@@ -142,6 +141,15 @@ require 'aerospike/query/stream_command'
142
141
  require 'aerospike/query/query_command'
143
142
  require 'aerospike/query/scan_command'
144
143
  require 'aerospike/query/statement'
144
+ require 'aerospike/query/pred_exp'
145
+
146
+ require 'aerospike/query/pred_exp/and_or'
147
+ require 'aerospike/query/pred_exp/geo_json_value'
148
+ require 'aerospike/query/pred_exp/integer_value'
149
+ require 'aerospike/query/pred_exp/op'
150
+ require 'aerospike/query/pred_exp/regex'
151
+ require 'aerospike/query/pred_exp/regex_flags'
152
+ require 'aerospike/query/pred_exp/string_value'
145
153
 
146
154
  module Aerospike
147
155
  extend Loggable
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Copyright 2014-2018 Aerospike, Inc.
2
+ # Copyright 2014-2020 Aerospike, Inc.
3
3
  #
4
4
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
5
  # license agreements.
@@ -90,5 +90,11 @@ module Aerospike
90
90
  super(ResultCode::COMMAND_REJECTED, msg)
91
91
  end
92
92
  end
93
+
94
+ class InvalidNamespace < Aerospike
95
+ def initialize(msg=nil)
96
+ super(ResultCode::INVALID_NAMESPACE, msg)
97
+ end
98
+ end
93
99
  end
94
100
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Copyright 2014-2017 Aerospike, Inc.
2
+ # Copyright 2014-2020 Aerospike, Inc.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Copyright 2014-2017 Aerospike, Inc.
2
+ # Copyright 2014-2020 Aerospike, Inc.
3
3
  #
4
4
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
5
  # license agreements.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2016-2018 Aerospike, Inc.
3
+ # Copyright 2016-2020 Aerospike, Inc.
4
4
  #
5
5
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
6
6
  # license agreements.
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Copyright 2016-2018 Aerospike, Inc.
2
+ # Copyright 2016-2020 Aerospike, Inc.
3
3
  #
4
4
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
5
  # license agreements.
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Copyright 2016-2017 Aerospike, Inc.
2
+ # Copyright 2016-2020 Aerospike, Inc.
3
3
  #
4
4
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
5
  # license agreements.
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Copyright 2016-2018 Aerospike, Inc.
2
+ # Copyright 2016-2020 Aerospike, Inc.
3
3
  #
4
4
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
5
  # license agreements.
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Copyright 2016-2017 Aerospike, Inc.
2
+ # Copyright 2016-2020 Aerospike, Inc.
3
3
  #
4
4
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
5
  # license agreements.
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Copyright 2016-2018 Aerospike, Inc.
2
+ # Copyright 2016-2020 Aerospike, Inc.
3
3
  #
4
4
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
5
  # license agreements.
@@ -1,4 +1,4 @@
1
- # Copyright 2014-2018 Aerospike, Inc.
1
+ # Copyright 2014-2020 Aerospike, Inc.
2
2
  #
3
3
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
4
4
  # license agreements.
@@ -322,11 +322,11 @@ module Aerospike
322
322
 
323
323
  if policy.use_batch_direct
324
324
  key_map = BatchItem.generate_map(keys)
325
- execute_batch_direct_commands(keys) do |node, batch|
325
+ execute_batch_direct_commands(policy, keys) do |node, batch|
326
326
  BatchDirectCommand.new(node, batch, policy, key_map, bin_names, results, info_flags)
327
327
  end
328
328
  else
329
- execute_batch_index_commands(keys) do |node, batch|
329
+ execute_batch_index_commands(policy, keys) do |node, batch|
330
330
  BatchIndexCommand.new(node, batch, policy, bin_names, results, info_flags)
331
331
  end
332
332
  end
@@ -351,11 +351,11 @@ module Aerospike
351
351
 
352
352
  if policy.use_batch_direct
353
353
  key_map = BatchItem.generate_map(keys)
354
- execute_batch_direct_commands(keys) do |node, batch|
354
+ execute_batch_direct_commands(policy, keys) do |node, batch|
355
355
  BatchDirectExistsCommand.new(node, batch, policy, key_map, results)
356
356
  end
357
357
  else
358
- execute_batch_index_commands(keys) do |node, batch|
358
+ execute_batch_index_commands(policy, keys) do |node, batch|
359
359
  BatchIndexExistsCommand.new(node, batch, policy, results)
360
360
  end
361
361
  end
@@ -526,7 +526,7 @@ module Aerospike
526
526
  raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::SERVER_NOT_AVAILABLE, "Executing UDF failed because cluster is empty.")
527
527
  end
528
528
 
529
- # TODO: wait until all migrations are finished
529
+ statement = statement.clone
530
530
  statement.set_aggregate_function(package_name, function_name, function_args, false)
531
531
 
532
532
  # Use a thread per node
@@ -884,17 +884,16 @@ module Aerospike
884
884
  command.execute
885
885
  end
886
886
 
887
- def execute_batch_index_commands(keys)
887
+ def execute_batch_index_commands(policy, keys)
888
888
  if @cluster.nodes.empty?
889
889
  raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::SERVER_NOT_AVAILABLE, "Executing Batch Index command failed because cluster is empty.")
890
890
  end
891
891
 
892
- batch_nodes = BatchIndexNode.generate_list(@cluster, keys)
892
+ batch_nodes = BatchIndexNode.generate_list(@cluster, policy.replica, keys)
893
893
  threads = []
894
894
 
895
895
  batch_nodes.each do |batch|
896
896
  threads << Thread.new do
897
- Thread.current.abort_on_exception = true
898
897
  command = yield batch.node, batch
899
898
  execute_command(command)
900
899
  end
@@ -903,12 +902,12 @@ module Aerospike
903
902
  threads.each(&:join)
904
903
  end
905
904
 
906
- def execute_batch_direct_commands(keys)
905
+ def execute_batch_direct_commands(policy, keys)
907
906
  if @cluster.nodes.empty?
908
907
  raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::SERVER_NOT_AVAILABLE, "Executing Batch Direct command failed because cluster is empty.")
909
908
  end
910
909
 
911
- batch_nodes = BatchDirectNode.generate_list(@cluster, keys)
910
+ batch_nodes = BatchDirectNode.generate_list(@cluster, policy.replica, keys)
912
911
  threads = []
913
912
 
914
913
  # Use a thread per namespace per node
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2014-2018 Aerospike, Inc.
3
+ # Copyright 2014-2020 Aerospike, Inc.
4
4
  #
5
5
  # Portions may be licensed to Aerospike, Inc. under one or more contributor
6
6
  # license agreements.
@@ -38,6 +38,8 @@ module Aerospike
38
38
  @cluster_name = policy.cluster_name
39
39
  @tls_options = policy.tls
40
40
 
41
+ @replica_index = Atomic.new(0)
42
+
41
43
  @aliases = {}
42
44
  @cluster_nodes = []
43
45
  @partition_write_map = {}
@@ -102,18 +104,92 @@ module Aerospike
102
104
  (node_array.length > 0) && !@closed.value
103
105
  end
104
106
 
105
- def get_node_for_key(key)
106
- partition = Partition.new_by_key(key)
107
+ # Returns a node on the cluster for read operations
108
+ def batch_read_node(partition, replica_policy)
109
+ case replica_policy
110
+ when Aerospike::Replica::MASTER, Aerospike::Replica::SEQUENCE
111
+ return master_node(partition)
112
+ when Aerospike::Replica::MASTER_PROLES
113
+ return master_proles_node(partition)
114
+ when Aerospike::Replica::RANDOM
115
+ return random_node
116
+ else
117
+ raise Aerospike::Exceptions::InvalidNode("invalid policy.replica value")
118
+ end
119
+ end
120
+
121
+ # Returns a node on the cluster for read operations
122
+ def read_node(partition, replica_policy, seq)
123
+ case replica_policy
124
+ when Aerospike::Replica::MASTER
125
+ return master_node(partition)
126
+ when Aerospike::Replica::MASTER_PROLES
127
+ return master_proles_node(partition)
128
+ when Aerospike::Replica::SEQUENCE
129
+ return sequence_node(partition, seq)
130
+ when Aerospike::Replica::RANDOM
131
+ return random_node
132
+ else
133
+ raise Aerospike::Exceptions::InvalidNode("invalid policy.replica value")
134
+ end
135
+ end
136
+
137
+ # Returns a node on the cluster for read operations
138
+ def master_node(partition)
139
+ partition_map = partitions
140
+ replica_array = partition_map[partition.namespace]
141
+ raise Aerospike::Exceptions::InvalidNamespace("namespace not found in the partition map") if !replica_array
142
+
143
+ node_array = (replica_array.get)[0]
144
+ raise Aerospike::Exceptions::InvalidNamespace("namespace not found in the partition map") if !node_array
145
+
146
+ node = (node_array.get)[partition.partition_id]
147
+ raise Aerospike::Exceptions::InvalidNode if !node || !node.active?
148
+
149
+ node
150
+ end
151
+
152
+ # Returns a node on the cluster for read operations
153
+ def master_proles_node(partition)
154
+ partition_map = partitions
155
+ replica_array = partition_map[partition.namespace]
156
+ raise Aerospike::Exceptions::InvalidNamespace("namespace not found in the partition map") if !replica_array
157
+
158
+ replica_array = replica_array.get
107
159
 
108
- # Must copy hashmap reference for copy on write semantics to work.
109
- nmap = partitions
110
- if node_array = nmap[partition.namespace]
111
- node = node_array.value[partition.partition_id]
160
+ node = nil
161
+ for replica in replica_array
162
+ idx = (@replica_index.update{|v| v.succ} % replica_array.size).abs
163
+ node = (replica_array[idx].get)[partition.partition_id]
112
164
 
113
165
  return node if node && node.active?
114
166
  end
115
167
 
116
- random_node
168
+ raise Aerospike::Exceptions::InvalidNode
169
+ end
170
+
171
+ # Returns a random node on the cluster
172
+ def sequence_node(partition, seq)
173
+ partition_map = partitions
174
+ replica_array = partition_map[partition.namespace]
175
+ raise Aerospike::Exceptions::InvalidNamespace("namespace not found in the partition map") if !replica_array
176
+
177
+ replica_array = replica_array.get
178
+
179
+ node = nil
180
+ for replica in replica_array
181
+ idx = (seq.update{|v| v.succ} % replica_array.size).abs
182
+ node = (replica_array[idx].get)[partition.partition_id]
183
+
184
+ return node if node && node.active?
185
+ end
186
+
187
+ raise Aerospike::Exceptions::InvalidNode
188
+ end
189
+
190
+ def get_node_for_key(replica_policy, key)
191
+ partition = Partition.new_by_key(key)
192
+ batch_read_node(partition, replica_policy)
117
193
  end
118
194
 
119
195
  # Returns a random node on the cluster
@@ -124,8 +200,8 @@ module Aerospike
124
200
  i = 0
125
201
  while i < length
126
202
  # Must handle concurrency with other non-tending threads, so node_index is consistent.
127
- index = (@node_index.update{ |v| v+1 } % node_array.length).abs
128
- node = node_array[index]
203
+ idx = (@node_index.update{ |v| v.succ } % node_array.length).abs
204
+ node = node_array[idx]
129
205
 
130
206
  return node if node.active?
131
207
 
@@ -167,12 +243,9 @@ module Aerospike
167
243
  end
168
244
  end
169
245
 
170
- def update_partitions(tokens, node)
171
- nmap = tokens.update_partition(partitions, node)
172
- # update partition write map
246
+ def update_partitions(parser)
247
+ nmap = parser.update_partitions(partitions)
173
248
  set_partitions(nmap) if nmap
174
-
175
- Aerospike.logger.info("Partitions for node #{node.name} updated")
176
249
  end
177
250
 
178
251
  def request_info(policy, *commands)
@@ -441,8 +514,10 @@ module Aerospike
441
514
  def find_node_in_partition_map(filter)
442
515
  partitions_list = partitions
443
516
 
444
- partitions_list.values.each do |node_array|
445
- return true if node_array.value.any? { |node| node == filter }
517
+ partitions_list.values.each do |replica_array|
518
+ replica_array.get.each do |node_array|
519
+ return true if node_array.value.any? { |node| node == filter }
520
+ end
446
521
  end
447
522
  false
448
523
  end