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
c44339d4
Commit
c44339d4
authored
Jul 06, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix last processed event id when no event_log_state exist
parent
031aab53
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
14 deletions
+32
-14
lib/gitlab/geo/log_cursor/events.rb
lib/gitlab/geo/log_cursor/events.rb
+8
-2
spec/lib/gitlab/geo/log_cursor/events_spec.rb
spec/lib/gitlab/geo/log_cursor/events_spec.rb
+24
-12
No files found.
lib/gitlab/geo/log_cursor/events.rb
View file @
c44339d4
...
...
@@ -28,10 +28,16 @@ module Gitlab
# @return [Integer] id of last replicated event
def
self
.
last_processed
last
=
::
Geo
::
EventLogState
.
last_processed
.
try
(
:id
)
last
=
::
Geo
::
EventLogState
.
last_processed
&
.
id
return
last
if
last
::
Geo
::
EventLog
.
any?
?
::
Geo
::
EventLog
.
last
.
id
:
-
1
if
::
Geo
::
EventLog
.
any?
event_id
=
::
Geo
::
EventLog
.
last
.
id
save_processed
(
event_id
)
event_id
else
-
1
end
end
# private methods
...
...
spec/lib/gitlab/geo/log_cursor/events_spec.rb
View file @
c44339d4
...
...
@@ -2,20 +2,27 @@ require 'spec_helper'
describe
Gitlab
::
Geo
::
LogCursor
::
Events
,
lib:
true
do
describe
'.fetch_in_batches'
do
let!
(
:event_log
)
{
create
(
:geo_event_log
)
}
let!
(
:event_log_1
)
{
create
(
:geo_event_log
)
}
let!
(
:event_log_2
)
{
create
(
:geo_event_log
)
}
before
do
allow
(
described_class
).
to
receive
(
:last_processed
)
{
-
1
}
context
'when no event_log_state exist'
do
it
'does not yield a group of events'
do
expect
{
|
b
|
described_class
.
fetch_in_batches
(
&
b
)
}.
not_to
yield_with_args
([
event_log_1
,
event_log_2
])
end
end
it
'yields a group of events'
do
expect
{
|
b
|
described_class
.
fetch_in_batches
(
&
b
)
}.
to
yield_with_args
([
event_log
])
end
context
'when there is already an event_log_state'
do
let!
(
:event_log_state
)
{
create
(
:geo_event_log_state
,
event_id:
event_log_1
.
id
-
1
)
}
it
'yields a group of events'
do
expect
{
|
b
|
described_class
.
fetch_in_batches
(
&
b
)
}.
to
yield_with_args
([
event_log_1
,
event_log_2
])
end
it
'saves processed files
after yielding'
do
expect
(
described_class
).
to
receive
(
:save_processed
)
it
'saves last event as last processed
after yielding'
do
described_class
.
fetch_in_batches
{
|
batch
|
batch
}
described_class
.
fetch_in_batches
{
|
batch
|
batch
}
expect
(
Geo
::
EventLogState
.
last
.
event_id
).
to
eq
(
event_log_2
.
id
)
end
end
it
'skips execution if cannot achieve a lease'
do
...
...
@@ -26,15 +33,15 @@ describe Gitlab::Geo::LogCursor::Events, lib: true do
end
describe
'.save_processed'
do
it
'
saves a new entry in geo_event_log_state
'
do
it
'
creates a new event_log_state when no event_log_state exist
'
do
expect
{
described_class
.
save_processed
(
1
)
}.
to
change
(
Geo
::
EventLogState
,
:count
).
by
(
1
)
expect
(
Geo
::
EventLogState
.
last
.
event_id
).
to
eq
(
1
)
end
it
'
removes older entries from geo_
event_log_state'
do
it
'
updates the event_id when there is already an
event_log_state'
do
create
(
:geo_event_log_state
)
expect
{
described_class
.
save_processed
(
2
)
}.
to
change
(
Geo
::
EventLogState
,
:count
).
by
(
0
)
expect
{
described_class
.
save_processed
(
2
)
}.
not_to
change
(
Geo
::
EventLogState
,
:count
)
expect
(
Geo
::
EventLogState
.
last
.
event_id
).
to
eq
(
2
)
end
end
...
...
@@ -52,6 +59,11 @@ describe Gitlab::Geo::LogCursor::Events, lib: true do
it
'returns last event id'
do
expect
(
described_class
.
last_processed
).
to
eq
(
event_log
.
id
)
end
it
'saves last event as the last processed'
do
expect
{
described_class
.
last_processed
}.
to
change
(
Geo
::
EventLogState
,
:count
).
by
(
1
)
expect
(
Geo
::
EventLogState
.
last
.
event_id
).
to
eq
(
event_log
.
id
)
end
end
context
'when there is already an event_log_state'
do
...
...
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