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
a88ad662
Commit
a88ad662
authored
Jul 26, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replays events for projects that belong to selected groups to replicate
parent
9c256781
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
97 additions
and
6 deletions
+97
-6
app/models/geo/event_log.rb
app/models/geo/event_log.rb
+10
-0
lib/gitlab/geo/log_cursor/daemon.rb
lib/gitlab/geo/log_cursor/daemon.rb
+8
-0
spec/factories/geo/event_log.rb
spec/factories/geo/event_log.rb
+8
-4
spec/lib/gitlab/geo/log_cursor/daemon_spec.rb
spec/lib/gitlab/geo/log_cursor/daemon_spec.rb
+30
-2
spec/models/geo/event_log_spec.rb
spec/models/geo/event_log_spec.rb
+41
-0
No files found.
app/models/geo/event_log.rb
View file @
a88ad662
...
...
@@ -13,5 +13,15 @@ module Geo
belongs_to
:repository_renamed_event
,
class_name:
'Geo::RepositoryRenamedEvent'
,
foreign_key: :repository_renamed_event_id
def
event
repository_updated_event
||
repository_deleted_event
||
repository_renamed_event
end
def
project_id
event
&
.
project_id
end
end
end
lib/gitlab/geo/log_cursor/daemon.rb
View file @
a88ad662
...
...
@@ -61,6 +61,8 @@ module Gitlab
def
handle_events
(
batch
)
batch
.
each
do
|
event
|
next
unless
can_replay?
(
event
)
# Update repository
if
event
.
repository_updated_event
handle_repository_update
(
event
.
repository_updated_event
)
...
...
@@ -88,6 +90,12 @@ module Gitlab
@exit
=
true
end
def
can_replay?
(
event
)
return
true
if
Gitlab
::
Geo
.
current_node
.
project_ids
.
nil?
Gitlab
::
Geo
.
current_node
.
project_ids
.
include?
(
event
.
project_id
)
end
def
handle_repository_update
(
updated_event
)
registry
=
::
Geo
::
ProjectRegistry
.
find_or_initialize_by
(
project_id:
updated_event
.
project_id
)
...
...
spec/factories/geo/event_log.rb
View file @
a88ad662
FactoryGirl
.
define
do
factory
:geo_event_log
,
class:
Geo
::
EventLog
do
trait
:updated_event
do
repository_updated_event
factory: :geo_repository_update_event
repository_updated_event
factory: :geo_repository_update
d
_event
end
trait
:deleted_event
do
repository_deleted_event
factory: :geo_repository_delete_event
repository_deleted_event
factory: :geo_repository_delete
d
_event
end
end
factory
:geo_repository_update_event
,
class:
Geo
::
RepositoryUpdatedEvent
do
factory
:geo_repository_update
d
_event
,
class:
Geo
::
RepositoryUpdatedEvent
do
source
0
branches_affected
0
tags_affected
0
project
end
factory
:geo_repository_delete_event
,
class:
Geo
::
RepositoryDeletedEvent
do
factory
:geo_repository_delete
d
_event
,
class:
Geo
::
RepositoryDeletedEvent
do
project
repository_storage_name
{
project
.
repository_storage
}
...
...
@@ -24,4 +24,8 @@ FactoryGirl.define do
deleted_path
{
project
.
path_with_namespace
}
deleted_project_name
{
project
.
name
}
end
factory
:geo_repository_renamed_event
,
class:
Geo
::
RepositoryRenamedEvent
do
project
end
end
spec/lib/gitlab/geo/log_cursor/daemon_spec.rb
View file @
a88ad662
...
...
@@ -21,12 +21,14 @@ describe Gitlab::Geo::LogCursor::Daemon do
end
end
context
'when processing a repository updated event'
do
context
'when replaying a repository updated event'
do
let!
(
:geo_node
)
{
create
(
:geo_node
)
}
let
(
:event_log
)
{
create
(
:geo_event_log
,
:updated_event
)
}
let!
(
:event_log_state
)
{
create
(
:geo_event_log_state
,
event_id:
event_log
.
id
-
1
)
}
let
(
:repository_updated_event
)
{
event_log
.
repository_updated_event
}
before
do
allow
(
Gitlab
::
Geo
).
to
receive
(
:current_node
).
and_return
(
geo_node
)
allow
(
subject
).
to
receive
(
:exit?
).
and_return
(
false
,
true
)
end
...
...
@@ -53,7 +55,7 @@ describe Gitlab::Geo::LogCursor::Daemon do
end
end
context
'when
process
ing a repository deleted event'
do
context
'when
replay
ing a repository deleted event'
do
let
(
:event_log
)
{
create
(
:geo_event_log
,
:deleted_event
)
}
let
(
:project
)
{
event_log
.
repository_deleted_event
.
project
}
let!
(
:event_log_state
)
{
create
(
:geo_event_log_state
,
event_id:
event_log
.
id
-
1
)
}
...
...
@@ -79,5 +81,31 @@ describe Gitlab::Geo::LogCursor::Daemon do
subject
.
run!
end
end
context
'when node have group restrictions'
do
let
(
:geo_node
)
{
create
(
:geo_node
)
}
let
(
:group
)
{
create
(
:group
)
}
let
(
:project
)
{
create
(
:empty_project
,
group:
group
)
}
let
(
:repository_updated_event
)
{
create
(
:geo_repository_updated_event
,
project:
project
)
}
let
(
:event_log
)
{
create
(
:geo_event_log
,
repository_updated_event:
repository_updated_event
)
}
let!
(
:event_log_state
)
{
create
(
:geo_event_log_state
,
event_id:
event_log
.
id
-
1
)
}
before
do
allow
(
Gitlab
::
Geo
).
to
receive
(
:current_node
).
and_return
(
geo_node
)
allow
(
subject
).
to
receive
(
:exit?
).
and_return
(
false
,
true
)
end
it
'replays events for projects that belong to selected groups to replicate'
do
geo_node
.
update_attribute
(
:groups
,
[
group
])
expect
{
subject
.
run!
}.
to
change
(
Geo
::
ProjectRegistry
,
:count
).
by
(
1
)
end
it
'does not replay events for projects that do not belong to selected groups to replicate'
do
geo_node
.
update_attribute
(
:groups
,
[
create
(
:group
)])
expect
{
subject
.
run!
}.
not_to
change
(
Geo
::
ProjectRegistry
,
:count
)
end
end
end
end
spec/models/geo/event_log_spec.rb
View file @
a88ad662
...
...
@@ -3,6 +3,47 @@ require 'spec_helper'
RSpec
.
describe
Geo
::
EventLog
,
type: :model
do
describe
'relationships'
do
it
{
is_expected
.
to
belong_to
(
:repository_updated_event
).
class_name
(
'Geo::RepositoryUpdatedEvent'
).
with_foreign_key
(
'repository_updated_event_id'
)
}
it
{
is_expected
.
to
belong_to
(
:repository_deleted_event
).
class_name
(
'Geo::RepositoryDeletedEvent'
).
with_foreign_key
(
'repository_deleted_event_id'
)
}
it
{
is_expected
.
to
belong_to
(
:repository_renamed_event
).
class_name
(
'Geo::RepositoryRenamedEvent'
).
with_foreign_key
(
'repository_renamed_event_id'
)
}
end
describe
'#event'
do
it
'returns nil when having no event associated'
do
expect
(
subject
.
event
).
to
be_nil
end
it
'returns repository_updated_event when set'
do
repository_updated_event
=
build
(
:geo_repository_updated_event
)
subject
.
repository_updated_event
=
repository_updated_event
expect
(
subject
.
event
).
to
eq
repository_updated_event
end
it
'returns repository_deleted_event when set'
do
repository_deleted_event
=
build
(
:geo_repository_deleted_event
)
subject
.
repository_deleted_event
=
repository_deleted_event
expect
(
subject
.
event
).
to
eq
repository_deleted_event
end
it
'returns repository_renamed_event when set'
do
repository_renamed_event
=
build
(
:geo_repository_renamed_event
)
subject
.
repository_renamed_event
=
repository_renamed_event
expect
(
subject
.
event
).
to
eq
repository_renamed_event
end
end
describe
'#project_id'
do
it
'returns nil when having no event associated'
do
expect
(
subject
.
project_id
).
to
be_nil
end
it
'returns event#project_id when an event is present'
do
repository_updated_event
=
build
(
:geo_repository_updated_event
)
subject
.
repository_updated_event
=
repository_updated_event
expect
(
subject
.
project_id
).
to
eq
repository_updated_event
.
project_id
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