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
b044f855
Commit
b044f855
authored
Sep 10, 2019
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor mostly for readability
parent
ce9dc2b7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
19 deletions
+21
-19
ee/lib/gitlab/geo/log_cursor/daemon.rb
ee/lib/gitlab/geo/log_cursor/daemon.rb
+21
-19
No files found.
ee/lib/gitlab/geo/log_cursor/daemon.rb
View file @
b044f855
...
@@ -39,7 +39,7 @@ module Gitlab
...
@@ -39,7 +39,7 @@ module Gitlab
handle_error
(
lease
[:
error
])
handle_error
(
lease
[:
error
])
# When no new event is found sleep for a few moments
# When no new event is found sleep for a few moments
arbitrary_sleep
(
lease
[
:ttl
])
sleep_break
(
lease
[
:ttl
])
end
end
def
find_and_handle_events!
def
find_and_handle_events!
...
@@ -54,26 +54,26 @@ module Gitlab
...
@@ -54,26 +54,26 @@ module Gitlab
private
private
def
handle_error
(
did_
error
)
def
handle_error
(
error
)
track_failing_since
(
did_
error
)
track_failing_since
(
error
)
if
excessive_errors?
if
excessive_errors?
exit!
(
"Consecutive errors for over
#{
MAX_ERROR_DURATION
}
seconds"
)
exit!
(
"Consecutive errors for over
#{
MAX_ERROR_DURATION
}
seconds"
)
end
end
end
end
def
track_failing_since
(
did_
error
)
def
track_failing_since
(
error
)
if
did_
error
if
error
@failing_since
||=
Time
.
now
@failing_since
||=
Time
.
now
.
utc
else
else
@failing_since
=
nil
@failing_since
=
nil
end
end
end
end
def
excessive_errors?
def
excessive_errors?
return
if
@failing_since
.
nil?
return
unless
@failing_since
MAX_ERROR_DURATION
<
(
Time
.
now
-
@failing_since
)
(
Time
.
now
.
utc
-
@failing_since
)
>
MAX_ERROR_DURATION
end
end
def
handle_events
(
batch
,
previous_batch_last_id
)
def
handle_events
(
batch
,
previous_batch_last_id
)
...
@@ -152,25 +152,27 @@ module Gitlab
...
@@ -152,25 +152,27 @@ module Gitlab
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
# Sleeps for the
expired TTL that remains on the lease
plus some random seconds.
# Sleeps for the
specified duration
plus some random seconds.
#
#
# This allows multiple GeoLogCursors to randomly process a batch of events,
# This allows multiple GeoLogCursors to randomly process a batch of events,
# without favouring the shortest path (or latency).
# without favouring the shortest path (or latency).
def
arbitrary_sleep
(
delay
)
#
jitter
=
rand
(
1
..
20
)
*
0.1
# Exits early if needed.
sleep_break
(
delay
+
jitter
)
end
def
sleep_break
(
seconds
)
def
sleep_break
(
seconds
)
while
seconds
>
0.0
sleep
(
random_jitter_time
)
to_sleep
=
seconds
>
1.0
?
1.0
:
seconds
seconds
-=
to_sleep
seconds
.
to_i
.
times
do
sleep
(
to_sleep
)
break
if
exit
?
break
if
exit
?
sleep
(
1
)
end
end
end
end
# Returns a random float from 0.1 to 2.0
def
random_jitter_time
rand
(
1
..
20
)
*
0.1
end
def
gap_tracking
def
gap_tracking
@gap_tracking
||=
::
Gitlab
::
Geo
::
EventGapTracking
.
new
(
logger
)
@gap_tracking
||=
::
Gitlab
::
Geo
::
EventGapTracking
.
new
(
logger
)
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