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
Show 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
handle_error
(
lease
[:
error
])
# When no new event is found sleep for a few moments
arbitrary_sleep
(
lease
[
:ttl
])
sleep_break
(
lease
[
:ttl
])
end
def
find_and_handle_events!
...
...
@@ -54,26 +54,26 @@ module Gitlab
private
def
handle_error
(
did_
error
)
track_failing_since
(
did_
error
)
def
handle_error
(
error
)
track_failing_since
(
error
)
if
excessive_errors?
exit!
(
"Consecutive errors for over
#{
MAX_ERROR_DURATION
}
seconds"
)
end
end
def
track_failing_since
(
did_
error
)
if
did_
error
@failing_since
||=
Time
.
now
def
track_failing_since
(
error
)
if
error
@failing_since
||=
Time
.
now
.
utc
else
@failing_since
=
nil
end
end
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
def
handle_events
(
batch
,
previous_batch_last_id
)
...
...
@@ -152,25 +152,27 @@ module Gitlab
end
# 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,
# without favouring the shortest path (or latency).
def
arbitrary_sleep
(
delay
)
jitter
=
rand
(
1
..
20
)
*
0.1
sleep_break
(
delay
+
jitter
)
end
#
# Exits early if needed.
def
sleep_break
(
seconds
)
while
seconds
>
0.0
to_sleep
=
seconds
>
1.0
?
1.0
:
seconds
seconds
-=
to_sleep
sleep
(
to_sleep
)
sleep
(
random_jitter_time
)
seconds
.
to_i
.
times
do
break
if
exit
?
sleep
(
1
)
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
@gap_tracking
||=
::
Gitlab
::
Geo
::
EventGapTracking
.
new
(
logger
)
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