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
50e3462a
Commit
50e3462a
authored
May 04, 2019
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor and improve Geo::LogCursor and tests
It also make it more efficient
parent
a9dbdac0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
14 deletions
+21
-14
ee/lib/gitlab/geo/log_cursor/event_logs.rb
ee/lib/gitlab/geo/log_cursor/event_logs.rb
+13
-12
ee/spec/lib/gitlab/geo/log_cursor/event_logs_spec.rb
ee/spec/lib/gitlab/geo/log_cursor/event_logs_spec.rb
+8
-2
No files found.
ee/lib/gitlab/geo/log_cursor/event_logs.rb
View file @
50e3462a
...
...
@@ -10,7 +10,7 @@ module Gitlab
# fetches up to BATCH_SIZE next events and keep track of batches
# rubocop: disable CodeReuse/ActiveRecord
def
fetch_in_batches
(
batch_size:
BATCH_SIZE
)
last_id
=
last_processed_id
last_id
=
last_processed_id
||
last_event_log_id
::
Geo
::
EventLog
.
where
(
'id > ?'
,
last_id
).
find_in_batches
(
batch_size:
batch_size
)
do
|
batch
|
yield
(
batch
,
last_id
)
...
...
@@ -31,18 +31,19 @@ module Gitlab
event_state
.
update!
(
event_id:
event_id
)
end
# @return [Integer] id of last replicated event
# @return [Integer] id of last replicated event
or nil if it does not exist
def
last_processed_id
last
=
::
Geo
::
EventLogState
.
last_processed
&
.
id
return
last
if
last
if
::
Geo
::
EventLog
.
any?
event_id
=
::
Geo
::
EventLog
.
last
.
id
save_processed
(
event_id
)
event_id
else
-
1
end
::
Geo
::
EventLogState
.
last_processed
&
.
id
end
# @return [Integer] id of the event we need to start processing from
def
last_event_log_id
last_id
=
::
Geo
::
EventLog
.
last
&
.
id
return
0
unless
last_id
save_processed
(
last_id
)
last_id
end
end
end
...
...
ee/spec/lib/gitlab/geo/log_cursor/event_logs_spec.rb
View file @
50e3462a
...
...
@@ -15,14 +15,16 @@ describe Gitlab::Geo::LogCursor::EventLogs, :postgresql, :clean_gitlab_redis_sha
let!
(
:event_log_2
)
{
create
(
:geo_event_log
)
}
context
'when there is no event_log_state'
do
it
'does not yield
s
a group of events'
do
it
'does not yield a group of events'
do
expect
{
|
b
|
subject
.
fetch_in_batches
(
&
b
)
}.
not_to
yield_with_args
([
event_log_1
,
event_log_2
])
end
end
context
'when there is already an event_log_state'
do
let
(
:last_event_id
)
{
event_log_1
.
id
-
1
}
before
do
create
(
:geo_event_log_state
,
event_id:
event_log_1
.
id
-
1
)
create
(
:geo_event_log_state
,
event_id:
last_event_id
)
end
it
'saves last event as last processed after yielding'
do
...
...
@@ -30,6 +32,10 @@ describe Gitlab::Geo::LogCursor::EventLogs, :postgresql, :clean_gitlab_redis_sha
expect
(
Geo
::
EventLogState
.
last
.
event_id
).
to
eq
(
event_log_2
.
id
)
end
it
'yields a group of events'
do
expect
{
|
b
|
subject
.
fetch_in_batches
(
&
b
)
}.
to
yield_with_args
([
event_log_1
,
event_log_2
],
last_event_id
)
end
end
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