diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-08-03 13:28:43 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-08-04 15:38:49 +0200 |
commit | 022c38e63e202e9da2608d020face6c108e47313 (patch) | |
tree | 07c0604ae1212637c41c5af6cbc4f52b6e252671 | |
parent | 3899d07f9eb5ffa2369195c800be18e297f67613 (diff) | |
download | gitlab-ce-022c38e63e202e9da2608d020face6c108e47313.tar.gz |
Use `keys` instead of `scan_each`
-rw-r--r-- | lib/gitlab/git/storage/circuit_breaker.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/git/storage/health.rb | 28 | ||||
-rw-r--r-- | spec/lib/gitlab/git/storage/health_spec.rb | 4 |
3 files changed, 13 insertions, 21 deletions
diff --git a/lib/gitlab/git/storage/circuit_breaker.rb b/lib/gitlab/git/storage/circuit_breaker.rb index 7b040a05c42..237b4598730 100644 --- a/lib/gitlab/git/storage/circuit_breaker.rb +++ b/lib/gitlab/git/storage/circuit_breaker.rb @@ -14,7 +14,7 @@ module Gitlab pattern = "#{Gitlab::Git::Storage::REDIS_KEY_PREFIX}*" Gitlab::Git::Storage.redis.with do |redis| - all_storage_keys = redis.scan_each(match: pattern).to_a + all_storage_keys = redis.keys(pattern) redis.del(*all_storage_keys) unless all_storage_keys.empty? end diff --git a/lib/gitlab/git/storage/health.rb b/lib/gitlab/git/storage/health.rb index 0a28052fd81..2d723147f4f 100644 --- a/lib/gitlab/git/storage/health.rb +++ b/lib/gitlab/git/storage/health.rb @@ -14,17 +14,7 @@ module Gitlab Gitlab::Git::Storage.redis.with do |redis| keys_per_storage = all_keys_for_storages(storage_names, redis) - - # We need to make sure all keys are actually loaded as an array. - # Otherwise when using the enumerator of the `scan_each` within a - # second pipeline, it will be assumed unloaded, wich would make the - # result unusable inside the pipeline. - loaded_keys_per_storage = keys_per_storage.inject({}) do |loaded_keys, (storage_name, keys)| - loaded_keys[storage_name] = keys.to_a - loaded_keys - end - - results_per_storage = load_for_keys(loaded_keys_per_storage, redis) + results_per_storage = load_for_keys(keys_per_storage, redis) end results_per_storage.map do |name, info| @@ -34,13 +24,13 @@ module Gitlab end def self.all_keys_for_storages(storage_names, redis) - keys_per_storage = nil + keys_per_storage = {} redis.pipelined do - keys_per_storage = storage_names.inject({}) do |result, storage_name| - key = pattern_for_storage(storage_name) + storage_names.each do |storage_name| + pattern = pattern_for_storage(storage_name) - result.merge(storage_name => redis.scan_each(match: key)) + keys_per_storage[storage_name] = redis.keys(pattern) end end @@ -48,15 +38,15 @@ module Gitlab end def self.load_for_keys(keys_per_storage, redis) - info_for_keys = nil + info_for_keys = {} redis.pipelined do - info_for_keys = keys_per_storage.inject({}) do |result, (storage_name, keys)| - info_for_storage = keys.map do |key| + keys_per_storage.each do |storage_name, keys_future| + info_for_storage = keys_future.value.map do |key| { name: key, failure_count: redis.hget(key, :failure_count) } end - result.merge(storage_name => info_for_storage) + info_for_keys[storage_name] = info_for_storage end end diff --git a/spec/lib/gitlab/git/storage/health_spec.rb b/spec/lib/gitlab/git/storage/health_spec.rb index 28b74a0581f..2d3af387971 100644 --- a/spec/lib/gitlab/git/storage/health_spec.rb +++ b/spec/lib/gitlab/git/storage/health_spec.rb @@ -23,7 +23,9 @@ describe Gitlab::Git::Storage::Health, clean_gitlab_redis_shared_state: true, br describe '.load_for_keys' do let(:subject) do results = Gitlab::Git::Storage.redis.with do |redis| - described_class.load_for_keys({ 'broken' => [host1_key] }, redis) + fake_future = double + allow(fake_future).to receive(:value).and_return([host1_key]) + described_class.load_for_keys({ 'broken' => fake_future }, redis) end # Make sure the `Redis#future is loaded |