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
63879f57
Commit
63879f57
authored
Jan 23, 2020
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Document reference counter with YARD tags
parent
f6616247
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
2 deletions
+26
-2
lib/gitlab/reference_counter.rb
lib/gitlab/reference_counter.rb
+26
-2
No files found.
lib/gitlab/reference_counter.rb
View file @
63879f57
# frozen_string_literal: true
module
Gitlab
# Reference Counter
#
# A reference counter is used as a mechanism to identify when
# a repository is being accessed by a writable operation.
#
# Maintenance operations would use this as a clue to when it should
# execute significant changes in order to avoid disrupting running traffic
class
ReferenceCounter
REFERENCE_EXPIRE_TIME
=
600
attr_reader
:gl_repository
,
:key
# Reference Counter instance
#
# @example
# Gitlab::ReferenceCounter.new('project-1')
#
# @see Gitlab::GlRepository::RepoType.identifier_for_repositorable
# @param [String] gl_repository repository identifier
def
initialize
(
gl_repository
)
@gl_repository
=
gl_repository
@key
=
"git-receive-pack-reference-counter:
#{
gl_repository
}
"
end
# Return the actual counter value
#
# @return [Integer] value
def
value
Gitlab
::
Redis
::
SharedState
.
with
{
|
redis
|
(
redis
.
get
(
key
)
||
0
).
to_i
}
end
# Increase the counter
#
# @return [Boolean] whether operation was a success
def
increase
redis_cmd
do
|
redis
|
redis
.
incr
(
key
)
...
...
@@ -22,13 +42,17 @@ module Gitlab
end
end
# rubocop:disable Gitlab/RailsLogger
# Decrease the counter
#
# @return [Boolean] whether operation was a success
def
decrease
redis_cmd
do
|
redis
|
current_value
=
redis
.
decr
(
key
)
if
current_value
<
0
# rubocop:disable Gitlab/RailsLogger
Rails
.
logger
.
warn
(
"Reference counter for
#{
gl_repository
}
decreased"
\
" when its value was less than 1. Reseting the counter."
)
" when its value was less than 1. Resetting the counter."
)
# rubocop:enable Gitlab/RailsLogger
redis
.
del
(
key
)
end
end
...
...
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