redis-cluster-client 0.3.9 → 0.3.11

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
  SHA256:
3
- metadata.gz: 9570ec36f046f18840242eb63ede8e5bdf710e4a9a2d738b244bed46ea53530c
4
- data.tar.gz: 5fd06dcf1f843e7f6151278400f33d45725c1ee1b8dcbf0afc6d72a00677c237
3
+ metadata.gz: 7eb062a2819ec74aebd03e23d7fd55281b8bf600bb5dd9bbcfb4cb36086070ef
4
+ data.tar.gz: 0bb82a71679f66948d09f07a8e5ccb6b31138e9c1fe7f9d6ab7d10abf35cf473
5
5
  SHA512:
6
- metadata.gz: 0c4b639bb180399c9d71bd054da5d10c03e93fafd4f595aa958dbec36d842a8b01da9449f5fe57f4c51a6088a99abc35fc2e6e5ec1605ba7058ecab8b05a9ebd
7
- data.tar.gz: 50b5b38b74b9b79b9526af4f76fdf7b3a5b54a51ccf2a641c78039610478087cbb0452239454580288a66c580cdacb0277f6aaf14f2eb44c5804ae6f86607b3d
6
+ metadata.gz: 87727a31dfd4278a353902f31b9bda5f99fe9e0651491f8b2af5bcab16bae819087adff8a8e7ecfdaf81bcd1f99b95e002d66bb4cc44ab690326bcca6c10dd4c
7
+ data.tar.gz: d4850893095a151cfe5f47a66642fcc311cd58e3466f46f5d8a1ce1e73374ac3f7faaf6b0bcb6ea1f3b18762c3198fad57af33614514280bcac85bfab2af8b08
@@ -21,7 +21,7 @@ class RedisClient
21
21
  @replications.each_value { |keys| keys.sort_by! { |k| latencies.fetch(k) } }
22
22
  @replica_clients = select_replica_clients(@replications, @clients)
23
23
  @clients_for_scanning = select_clients_for_scanning(@replications, @clients)
24
- @existed_replicas = @replications.reject { |_, v| v.empty? }.values
24
+ @existed_replicas = @replications.values.reject(&:empty?)
25
25
  end
26
26
 
27
27
  def clients_for_scanning(seed: nil) # rubocop:disable Lint/UnusedMethodArgument
@@ -43,7 +43,6 @@ class RedisClient
43
43
  clients.each_slice(::RedisClient::Cluster::Node::MAX_THREADS).each_with_object({}) do |chuncked_clients, acc|
44
44
  threads = chuncked_clients.map do |k, v|
45
45
  Thread.new(k, v) do |node_key, client|
46
- Thread.pass
47
46
  Thread.current.thread_variable_set(:node_key, node_key)
48
47
 
49
48
  min = DUMMY_LATENCY_NSEC
@@ -18,10 +18,12 @@ class RedisClient
18
18
  MAX_STARTUP_SAMPLE = 37
19
19
  MAX_THREADS = Integer(ENV.fetch('REDIS_CLIENT_MAX_THREADS', 5))
20
20
  IGNORE_GENERIC_CONFIG_KEYS = %i[url host port path].freeze
21
+ SLOT_OPTIMIZATION_STRING = '0' * SLOT_SIZE
21
22
 
22
23
  ReloadNeeded = Class.new(::RedisClient::Error)
24
+
23
25
  Info = Struct.new(
24
- 'RedisNode',
26
+ 'RedisClusterNode',
25
27
  :id, :node_key, :role, :primary_id, :ping_sent,
26
28
  :pong_recv, :config_epoch, :link_state, :slots,
27
29
  keyword_init: true
@@ -35,23 +37,27 @@ class RedisClient
35
37
  end
36
38
  end
37
39
 
38
- SLOT_OPTIMIZATION_MAX_SHARD_SIZE = 256
39
- SLOT_OPTIMIZATION_STRING = '0' * SLOT_SIZE
40
- Slot = Struct.new('RedisSlot', :slots, :primary_node_keys, keyword_init: true) do
41
- def [](slot)
42
- primary_node_keys[slots.getbyte(slot)]
40
+ Slot = Struct.new('StringArray', :string, :elements, keyword_init: true) do
41
+ def [](index)
42
+ raise IndexError if index < 0
43
+ return if index >= string.bytesize
44
+
45
+ elements[string.getbyte(index)]
43
46
  end
44
47
 
45
- def []=(slot, primary_node_key)
46
- index = primary_node_keys.find_index(primary_node_key)
47
- if index.nil?
48
- raise(::RedisClient::Cluster::Node::ReloadNeeded, primary_node_key) if primary_node_keys.size >= SLOT_OPTIMIZATION_MAX_SHARD_SIZE
48
+ def []=(index, element)
49
+ raise IndexError if index < 0
50
+ return if index >= string.bytesize
51
+
52
+ pos = elements.find_index(element) # O(N)
53
+ if pos.nil?
54
+ raise(RangeError, 'full of elements') if elements.size >= 256
49
55
 
50
- index = primary_node_keys.size
51
- primary_node_keys << primary_node_key
56
+ pos = elements.size
57
+ elements << element
52
58
  end
53
59
 
54
- slots.setbyte(slot, index)
60
+ string.setbyte(index, pos)
55
61
  end
56
62
  end
57
63
 
@@ -79,7 +85,6 @@ class RedisClient
79
85
  startup_nodes.each_slice(MAX_THREADS).with_index do |chuncked_startup_nodes, chuncked_idx|
80
86
  threads = chuncked_startup_nodes.each_with_index.map do |raw_client, idx|
81
87
  Thread.new(raw_client, (MAX_THREADS * chuncked_idx) + idx) do |cli, i|
82
- Thread.pass
83
88
  Thread.current.thread_variable_set(:index, i)
84
89
  reply = cli.call('CLUSTER', 'NODES')
85
90
  Thread.current.thread_variable_set(:info, parse_cluster_node_reply(reply))
@@ -229,7 +234,12 @@ class RedisClient
229
234
  def update_slot(slot, node_key)
230
235
  return if @mutex.locked?
231
236
 
232
- @mutex.synchronize { @slots[slot] = node_key }
237
+ @mutex.synchronize do
238
+ @slots[slot] = node_key
239
+ rescue RangeError
240
+ @slots = Array.new(SLOT_SIZE) { |i| @slots[i] }
241
+ @slots[slot] = node_key
242
+ end
233
243
  end
234
244
 
235
245
  private
@@ -256,11 +266,11 @@ class RedisClient
256
266
  end
257
267
 
258
268
  def make_array_for_slot_node_mappings(node_info_list)
259
- return Array.new(SLOT_SIZE) if node_info_list.count(&:primary?) > SLOT_OPTIMIZATION_MAX_SHARD_SIZE
269
+ return Array.new(SLOT_SIZE) if node_info_list.count(&:primary?) > 256
260
270
 
261
271
  ::RedisClient::Cluster::Node::Slot.new(
262
- slots: String.new(SLOT_OPTIMIZATION_STRING, encoding: Encoding::BINARY, capacity: SLOT_SIZE),
263
- primary_node_keys: node_info_list.select(&:primary?).map(&:node_key)
272
+ string: String.new(SLOT_OPTIMIZATION_STRING, encoding: Encoding::BINARY, capacity: SLOT_SIZE),
273
+ elements: node_info_list.select(&:primary?).map(&:node_key)
264
274
  )
265
275
  end
266
276
 
@@ -293,7 +303,6 @@ class RedisClient
293
303
  clients.each_slice(MAX_THREADS) do |chuncked_clients|
294
304
  threads = chuncked_clients.map do |k, v|
295
305
  Thread.new(k, v) do |node_key, client|
296
- Thread.pass
297
306
  Thread.current.thread_variable_set(:node_key, node_key)
298
307
  reply = yield(node_key, client)
299
308
  Thread.current.thread_variable_set(:result, reply)
@@ -142,7 +142,6 @@ class RedisClient
142
142
  @pipelines&.each_slice(MAX_THREADS) do |chuncked_pipelines|
143
143
  threads = chuncked_pipelines.map do |node_key, pipeline|
144
144
  Thread.new(node_key, pipeline) do |nk, pl|
145
- Thread.pass
146
145
  Thread.current.thread_variable_set(:node_key, nk)
147
146
  replies = do_pipelining(@router.find_node(nk), pl)
148
147
  raise ReplySizeError, "commands: #{pl._size}, replies: #{replies.size}" if pl._size != replies.size
@@ -12,6 +12,7 @@ class RedisClient
12
12
  class Cluster
13
13
  class Router
14
14
  ZERO_CURSOR_FOR_SCAN = '0'
15
+ METHODS_FOR_BLOCKING_CMD = %i[blocking_call_v blocking_call].freeze
15
16
 
16
17
  attr_reader :node
17
18
 
@@ -91,7 +92,7 @@ class RedisClient
91
92
  raise
92
93
  end
93
94
  rescue ::RedisClient::ConnectionError => e
94
- raise if method == :blocking_call_v || (method == :blocking_call && e.is_a?(RedisClient::ReadTimeoutError))
95
+ raise if METHODS_FOR_BLOCKING_CMD.include?(method) && e.is_a?(RedisClient::ReadTimeoutError)
95
96
  raise if retry_count <= 0
96
97
 
97
98
  update_cluster_info!
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-cluster-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.3.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taishi Kasuga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-24 00:00:00.000000000 Z
11
+ date: 2022-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis-client