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
72e58df6
Commit
72e58df6
authored
Aug 01, 2018
by
Toon Claes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make methods private as much as possible
parent
01ce3d7d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
27 deletions
+29
-27
ee/lib/gitlab/geo/event_gap_tracking.rb
ee/lib/gitlab/geo/event_gap_tracking.rb
+2
-2
ee/lib/gitlab/geo/log_cursor/daemon.rb
ee/lib/gitlab/geo/log_cursor/daemon.rb
+2
-0
ee/spec/lib/gitlab/geo/event_gap_tracking_spec.rb
ee/spec/lib/gitlab/geo/event_gap_tracking_spec.rb
+14
-14
ee/spec/lib/gitlab/geo/log_cursor/daemon_spec.rb
ee/spec/lib/gitlab/geo/log_cursor/daemon_spec.rb
+11
-11
No files found.
ee/lib/gitlab/geo/event_gap_tracking.rb
View file @
72e58df6
...
@@ -60,6 +60,8 @@ module Gitlab
...
@@ -60,6 +60,8 @@ module Gitlab
end
end
end
end
private
def
track_gaps
(
current_id
)
def
track_gaps
(
current_id
)
log_info
(
"Event log gap detected"
,
previous_event_id:
previous_id
,
current_event_id:
current_id
)
log_info
(
"Event log gap detected"
,
previous_event_id:
previous_id
,
current_event_id:
current_id
)
...
@@ -78,8 +80,6 @@ module Gitlab
...
@@ -78,8 +80,6 @@ module Gitlab
current_id
>
(
previous_id
+
1
)
current_id
>
(
previous_id
+
1
)
end
end
private
def
grace_timestamp
def
grace_timestamp
(
Time
.
now
-
GAP_GRACE_PERIOD
).
to_i
(
Time
.
now
-
GAP_GRACE_PERIOD
).
to_i
end
end
...
...
ee/lib/gitlab/geo/log_cursor/daemon.rb
View file @
72e58df6
...
@@ -43,6 +43,8 @@ module Gitlab
...
@@ -43,6 +43,8 @@ module Gitlab
end
end
end
end
private
def
handle_events
(
batch
,
previous_batch_last_id
)
def
handle_events
(
batch
,
previous_batch_last_id
)
logger
.
info
(
"Handling events"
,
first_id:
batch
.
first
.
id
,
last_id:
batch
.
last
.
id
)
logger
.
info
(
"Handling events"
,
first_id:
batch
.
first
.
id
,
last_id:
batch
.
last
.
id
)
...
...
ee/spec/lib/gitlab/geo/event_gap_tracking_spec.rb
View file @
72e58df6
...
@@ -18,12 +18,12 @@ describe Gitlab::Geo::EventGapTracking, :clean_gitlab_redis_cache do
...
@@ -18,12 +18,12 @@ describe Gitlab::Geo::EventGapTracking, :clean_gitlab_redis_cache do
it
'returns the lowest gap id'
do
it
'returns the lowest gap id'
do
Timecop
.
travel
(
50
.
minutes
.
ago
)
do
Timecop
.
travel
(
50
.
minutes
.
ago
)
do
gap_tracking
.
previous_id
=
18
gap_tracking
.
previous_id
=
18
gap_tracking
.
track_gaps
(
20
)
gap_tracking
.
send
(
:track_gaps
,
20
)
end
end
Timecop
.
travel
(
40
.
minutes
.
ago
)
do
Timecop
.
travel
(
40
.
minutes
.
ago
)
do
gap_tracking
.
previous_id
=
12
gap_tracking
.
previous_id
=
12
gap_tracking
.
track_gaps
(
14
)
gap_tracking
.
send
(
:track_gaps
,
14
)
end
end
expect
(
described_class
.
min_gap_id
).
to
eq
(
13
)
expect
(
described_class
.
min_gap_id
).
to
eq
(
13
)
...
@@ -37,10 +37,10 @@ describe Gitlab::Geo::EventGapTracking, :clean_gitlab_redis_cache do
...
@@ -37,10 +37,10 @@ describe Gitlab::Geo::EventGapTracking, :clean_gitlab_redis_cache do
it
'returns the number of gaps'
do
it
'returns the number of gaps'
do
gap_tracking
.
previous_id
=
18
gap_tracking
.
previous_id
=
18
gap_tracking
.
track_gaps
(
20
)
gap_tracking
.
send
(
:track_gaps
,
20
)
gap_tracking
.
previous_id
=
12
gap_tracking
.
previous_id
=
12
gap_tracking
.
track_gaps
(
14
)
gap_tracking
.
send
(
:track_gaps
,
14
)
expect
(
described_class
.
gap_count
).
to
eq
(
2
)
expect
(
described_class
.
gap_count
).
to
eq
(
2
)
end
end
...
@@ -106,12 +106,12 @@ describe Gitlab::Geo::EventGapTracking, :clean_gitlab_redis_cache do
...
@@ -106,12 +106,12 @@ describe Gitlab::Geo::EventGapTracking, :clean_gitlab_redis_cache do
it
'logs a message'
do
it
'logs a message'
do
expect
(
gap_tracking
).
to
receive
(
:log_info
).
with
(
/gap detected/
,
hash_including
(
previous_event_id:
previous_event_id
,
current_event_id:
event_id_with_gap
))
expect
(
gap_tracking
).
to
receive
(
:log_info
).
with
(
/gap detected/
,
hash_including
(
previous_event_id:
previous_event_id
,
current_event_id:
event_id_with_gap
))
gap_tracking
.
track_gaps
(
event_id_with_gap
)
gap_tracking
.
send
(
:track_gaps
,
event_id_with_gap
)
end
end
it
'saves the gap id in redis'
do
it
'saves the gap id in redis'
do
Timecop
.
freeze
do
Timecop
.
freeze
do
gap_tracking
.
track_gaps
(
event_id_with_gap
)
gap_tracking
.
send
(
:track_gaps
,
event_id_with_gap
)
expect
(
read_gaps
).
to
contain_exactly
([
gap_id
.
to_s
,
Time
.
now
.
to_i
])
expect
(
read_gaps
).
to
contain_exactly
([
gap_id
.
to_s
,
Time
.
now
.
to_i
])
end
end
...
@@ -119,7 +119,7 @@ describe Gitlab::Geo::EventGapTracking, :clean_gitlab_redis_cache do
...
@@ -119,7 +119,7 @@ describe Gitlab::Geo::EventGapTracking, :clean_gitlab_redis_cache do
it
'saves a range of gaps id in redis'
do
it
'saves a range of gaps id in redis'
do
Timecop
.
freeze
do
Timecop
.
freeze
do
gap_tracking
.
track_gaps
(
event_id_with_gap
+
3
)
gap_tracking
.
send
(
:track_gaps
,
event_id_with_gap
+
3
)
expected_gaps
=
((
previous_event_id
+
1
)
..
(
event_id_with_gap
+
2
)).
collect
{
|
id
|
[
id
.
to_s
,
Time
.
now
.
to_i
]
}
expected_gaps
=
((
previous_event_id
+
1
)
..
(
event_id_with_gap
+
2
)).
collect
{
|
id
|
[
id
.
to_s
,
Time
.
now
.
to_i
]
}
...
@@ -131,13 +131,13 @@ describe Gitlab::Geo::EventGapTracking, :clean_gitlab_redis_cache do
...
@@ -131,13 +131,13 @@ describe Gitlab::Geo::EventGapTracking, :clean_gitlab_redis_cache do
expected_gaps
=
[]
expected_gaps
=
[]
Timecop
.
freeze
do
Timecop
.
freeze
do
gap_tracking
.
track_gaps
(
event_id_with_gap
)
gap_tracking
.
send
(
:track_gaps
,
event_id_with_gap
)
expected_gaps
<<
[
gap_id
.
to_s
,
Time
.
now
.
to_i
]
expected_gaps
<<
[
gap_id
.
to_s
,
Time
.
now
.
to_i
]
end
end
Timecop
.
travel
(
2
.
minutes
)
do
Timecop
.
travel
(
2
.
minutes
)
do
gap_tracking
.
previous_id
=
17
gap_tracking
.
previous_id
=
17
gap_tracking
.
track_gaps
(
19
)
gap_tracking
.
send
(
:track_gaps
,
19
)
expected_gaps
<<
[
18
.
to_s
,
Time
.
now
.
to_i
]
expected_gaps
<<
[
18
.
to_s
,
Time
.
now
.
to_i
]
end
end
...
@@ -147,25 +147,25 @@ describe Gitlab::Geo::EventGapTracking, :clean_gitlab_redis_cache do
...
@@ -147,25 +147,25 @@ describe Gitlab::Geo::EventGapTracking, :clean_gitlab_redis_cache do
describe
'#gap?'
do
describe
'#gap?'
do
it
'returns false when current_id is the previous +1'
do
it
'returns false when current_id is the previous +1'
do
expect
(
gap_tracking
.
gap?
(
previous_event_id
+
1
)).
to
be_falsy
expect
(
gap_tracking
.
send
(
:gap?
,
previous_event_id
+
1
)).
to
be_falsy
end
end
it
'returns true when current_id is the previous +2'
do
it
'returns true when current_id is the previous +2'
do
expect
(
gap_tracking
.
gap?
(
previous_event_id
+
2
)).
to
be_truthy
expect
(
gap_tracking
.
send
(
:gap?
,
previous_event_id
+
2
)).
to
be_truthy
end
end
it
'returns false when current_id is equal to the previous'
do
it
'returns false when current_id is equal to the previous'
do
expect
(
gap_tracking
.
gap?
(
previous_event_id
)).
to
be_falsy
expect
(
gap_tracking
.
send
(
:gap?
,
previous_event_id
)).
to
be_falsy
end
end
it
'returns false when current_id less than the previous'
do
it
'returns false when current_id less than the previous'
do
expect
(
gap_tracking
.
gap?
(
previous_event_id
-
1
)).
to
be_falsy
expect
(
gap_tracking
.
send
(
:gap?
,
previous_event_id
-
1
)).
to
be_falsy
end
end
it
'returns false when previous id is 0'
do
it
'returns false when previous id is 0'
do
gap_tracking
.
previous_id
=
0
gap_tracking
.
previous_id
=
0
expect
(
gap_tracking
.
gap?
(
100
)).
to
be_falsy
expect
(
gap_tracking
.
send
(
:gap?
,
100
)).
to
be_falsy
end
end
end
end
...
...
ee/spec/lib/gitlab/geo/log_cursor/daemon_spec.rb
View file @
72e58df6
...
@@ -86,7 +86,7 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql, :clean_gitlab_redis_shared
...
@@ -86,7 +86,7 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql, :clean_gitlab_redis_shared
end
end
it
'calls #handle_gap_event for each gap the gap tracking finds'
do
it
'calls #handle_gap_event for each gap the gap tracking finds'
do
allow
(
daemon
.
gap_tracking
).
to
receive
(
:fill_gaps
).
and_yield
(
1
).
and_yield
(
5
)
allow
(
daemon
.
send
(
:gap_tracking
)
).
to
receive
(
:fill_gaps
).
and_yield
(
1
).
and_yield
(
5
)
expect
(
daemon
).
to
receive
(
:handle_gap_event
).
with
(
1
)
expect
(
daemon
).
to
receive
(
:handle_gap_event
).
with
(
1
)
expect
(
daemon
).
to
receive
(
:handle_gap_event
).
with
(
5
)
expect
(
daemon
).
to
receive
(
:handle_gap_event
).
with
(
5
)
...
@@ -193,20 +193,20 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql, :clean_gitlab_redis_shared
...
@@ -193,20 +193,20 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql, :clean_gitlab_redis_shared
let
(
:batch
)
{
create_list
(
:geo_event_log
,
2
)
}
let
(
:batch
)
{
create_list
(
:geo_event_log
,
2
)
}
it
'passes the previous batch id on to gap tracking'
do
it
'passes the previous batch id on to gap tracking'
do
expect
(
daemon
.
gap_tracking
).
to
receive
(
:previous_id
=
).
with
(
55
).
ordered
expect
(
daemon
.
send
(
:gap_tracking
)
).
to
receive
(
:previous_id
=
).
with
(
55
).
ordered
batch
.
each
do
|
event_log
|
batch
.
each
do
|
event_log
|
expect
(
daemon
.
gap_tracking
).
to
receive
(
:previous_id
=
).
with
(
event_log
.
id
).
ordered
expect
(
daemon
.
send
(
:gap_tracking
)
).
to
receive
(
:previous_id
=
).
with
(
event_log
.
id
).
ordered
end
end
daemon
.
handle_events
(
batch
,
55
)
daemon
.
send
(
:handle_events
,
batch
,
55
)
end
end
it
'checks for gaps for each id in batch'
do
it
'checks for gaps for each id in batch'
do
batch
.
each
do
|
event_log
|
batch
.
each
do
|
event_log
|
expect
(
daemon
.
gap_tracking
).
to
receive
(
:check!
).
with
(
event_log
.
id
)
expect
(
daemon
.
send
(
:gap_tracking
)
).
to
receive
(
:check!
).
with
(
event_log
.
id
)
end
end
daemon
.
handle_events
(
batch
,
55
)
daemon
.
send
(
:handle_events
,
batch
,
55
)
end
end
it
'handles every single event'
do
it
'handles every single event'
do
...
@@ -214,7 +214,7 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql, :clean_gitlab_redis_shared
...
@@ -214,7 +214,7 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql, :clean_gitlab_redis_shared
expect
(
daemon
).
to
receive
(
:handle_single_event
).
with
(
event_log
)
expect
(
daemon
).
to
receive
(
:handle_single_event
).
with
(
event_log
)
end
end
daemon
.
handle_events
(
batch
,
55
)
daemon
.
send
(
:handle_events
,
batch
,
55
)
end
end
end
end
...
@@ -225,20 +225,20 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql, :clean_gitlab_redis_shared
...
@@ -225,20 +225,20 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql, :clean_gitlab_redis_shared
event_log
=
build
(
:geo_event_log
)
event_log
=
build
(
:geo_event_log
)
expect
(
daemon
).
not_to
receive
(
:can_replay?
)
expect
(
daemon
).
not_to
receive
(
:can_replay?
)
daemon
.
handle_single_event
(
event_log
)
daemon
.
send
(
:handle_single_event
,
event_log
)
end
end
it
'checks if it can replay the event'
do
it
'checks if it can replay the event'
do
expect
(
daemon
).
to
receive
(
:can_replay?
)
expect
(
daemon
).
to
receive
(
:can_replay?
)
daemon
.
handle_single_event
(
event_log
)
daemon
.
send
(
:handle_single_event
,
event_log
)
end
end
it
'processes event when it is replayable'
do
it
'processes event when it is replayable'
do
allow
(
daemon
).
to
receive
(
:can_replay?
).
and_return
(
true
)
allow
(
daemon
).
to
receive
(
:can_replay?
).
and_return
(
true
)
expect
(
daemon
).
to
receive
(
:process_event
).
with
(
event_log
.
event
,
event_log
)
expect
(
daemon
).
to
receive
(
:process_event
).
with
(
event_log
.
event
,
event_log
)
daemon
.
handle_single_event
(
event_log
)
daemon
.
send
(
:handle_single_event
,
event_log
)
end
end
end
end
...
@@ -246,7 +246,7 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql, :clean_gitlab_redis_shared
...
@@ -246,7 +246,7 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql, :clean_gitlab_redis_shared
gaps
=
[]
gaps
=
[]
Timecop
.
travel
(
12
.
minutes
)
do
Timecop
.
travel
(
12
.
minutes
)
do
daemon
.
gap_tracking
.
fill_gaps
{
|
id
|
gaps
<<
id
}
daemon
.
send
(
:gap_tracking
).
send
(
:fill_gaps
,
{
|
id
|
gaps
<<
id
})
end
end
gaps
gaps
...
...
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