Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
022c38e6
Commit
022c38e6
authored
Aug 03, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use `keys` instead of `scan_each`
parent
3899d07f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
21 deletions
+13
-21
lib/gitlab/git/storage/circuit_breaker.rb
lib/gitlab/git/storage/circuit_breaker.rb
+1
-1
lib/gitlab/git/storage/health.rb
lib/gitlab/git/storage/health.rb
+9
-19
spec/lib/gitlab/git/storage/health_spec.rb
spec/lib/gitlab/git/storage/health_spec.rb
+3
-1
No files found.
lib/gitlab/git/storage/circuit_breaker.rb
View file @
022c38e6
...
@@ -14,7 +14,7 @@ module Gitlab
...
@@ -14,7 +14,7 @@ module Gitlab
pattern
=
"
#{
Gitlab
::
Git
::
Storage
::
REDIS_KEY_PREFIX
}
*"
pattern
=
"
#{
Gitlab
::
Git
::
Storage
::
REDIS_KEY_PREFIX
}
*"
Gitlab
::
Git
::
Storage
.
redis
.
with
do
|
redis
|
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?
redis
.
del
(
*
all_storage_keys
)
unless
all_storage_keys
.
empty?
end
end
...
...
lib/gitlab/git/storage/health.rb
View file @
022c38e6
...
@@ -14,17 +14,7 @@ module Gitlab
...
@@ -14,17 +14,7 @@ module Gitlab
Gitlab
::
Git
::
Storage
.
redis
.
with
do
|
redis
|
Gitlab
::
Git
::
Storage
.
redis
.
with
do
|
redis
|
keys_per_storage
=
all_keys_for_storages
(
storage_names
,
redis
)
keys_per_storage
=
all_keys_for_storages
(
storage_names
,
redis
)
results_per_storage
=
load_for_keys
(
keys_per_storage
,
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
)
end
end
results_per_storage
.
map
do
|
name
,
info
|
results_per_storage
.
map
do
|
name
,
info
|
...
@@ -34,13 +24,13 @@ module Gitlab
...
@@ -34,13 +24,13 @@ module Gitlab
end
end
def
self
.
all_keys_for_storages
(
storage_names
,
redis
)
def
self
.
all_keys_for_storages
(
storage_names
,
redis
)
keys_per_storage
=
nil
keys_per_storage
=
{}
redis
.
pipelined
do
redis
.
pipelined
do
keys_per_storage
=
storage_names
.
inject
({})
do
|
result
,
storage_name
|
storage_names
.
each
do
|
storage_name
|
key
=
pattern_for_storage
(
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
end
end
...
@@ -48,15 +38,15 @@ module Gitlab
...
@@ -48,15 +38,15 @@ module Gitlab
end
end
def
self
.
load_for_keys
(
keys_per_storage
,
redis
)
def
self
.
load_for_keys
(
keys_per_storage
,
redis
)
info_for_keys
=
nil
info_for_keys
=
{}
redis
.
pipelined
do
redis
.
pipelined
do
info_for_keys
=
keys_per_storage
.
inject
({})
do
|
result
,
(
storage_name
,
keys
)
|
keys_per_storage
.
each
do
|
storage_name
,
keys_future
|
info_for_storage
=
keys
.
map
do
|
key
|
info_for_storage
=
keys
_future
.
value
.
map
do
|
key
|
{
name:
key
,
failure_count:
redis
.
hget
(
key
,
:failure_count
)
}
{
name:
key
,
failure_count:
redis
.
hget
(
key
,
:failure_count
)
}
end
end
result
.
merge
(
storage_name
=>
info_for_storage
)
info_for_keys
[
storage_name
]
=
info_for_storage
end
end
end
end
...
...
spec/lib/gitlab/git/storage/health_spec.rb
View file @
022c38e6
...
@@ -23,7 +23,9 @@ describe Gitlab::Git::Storage::Health, clean_gitlab_redis_shared_state: true, br
...
@@ -23,7 +23,9 @@ describe Gitlab::Git::Storage::Health, clean_gitlab_redis_shared_state: true, br
describe
'.load_for_keys'
do
describe
'.load_for_keys'
do
let
(
:subject
)
do
let
(
:subject
)
do
results
=
Gitlab
::
Git
::
Storage
.
redis
.
with
do
|
redis
|
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
end
# Make sure the `Redis#future is loaded
# Make sure the `Redis#future is loaded
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment