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
a2aef6a8
Commit
a2aef6a8
authored
Aug 09, 2017
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement Geo support for repository rename events
parent
ea20437d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
89 additions
and
13 deletions
+89
-13
changelogs/unreleased-ee/sh-geo-cursor-rename-events.yml
changelogs/unreleased-ee/sh-geo-cursor-rename-events.yml
+4
-0
lib/gitlab/geo/log_cursor/daemon.rb
lib/gitlab/geo/log_cursor/daemon.rb
+42
-13
spec/factories/geo/event_log.rb
spec/factories/geo/event_log.rb
+17
-0
spec/lib/gitlab/geo/log_cursor/daemon_spec.rb
spec/lib/gitlab/geo/log_cursor/daemon_spec.rb
+26
-0
No files found.
changelogs/unreleased-ee/sh-geo-cursor-rename-events.yml
0 → 100644
View file @
a2aef6a8
---
title
:
Support handling of rename events in Geo Log Cursor
merge_request
:
author
:
lib/gitlab/geo/log_cursor/daemon.rb
View file @
a2aef6a8
...
...
@@ -65,11 +65,13 @@ module Gitlab
next
unless
can_replay?
(
event_log
)
if
event_log
.
repository_updated_event
handle_repository_update
(
event_log
.
repository_updated_event
)
handle_repository_update
(
event_log
)
elsif
event_log
.
repository_deleted_event
handle_repository_delete
(
event_log
.
repository_deleted_event
)
handle_repository_delete
(
event_log
)
elsif
event_log
.
repositories_changed_event
handle_repositories_changed
(
event_log
.
repositories_changed_event
)
elsif
event_log
.
repository_renamed_event
handle_repository_rename
(
event_log
)
end
end
end
...
...
@@ -102,7 +104,8 @@ module Gitlab
Gitlab
::
Geo
.
current_node
&
.
projects_include?
(
event_log
.
project_id
)
end
def
handle_repository_update
(
updated_event
)
def
handle_repository_update
(
event
)
updated_event
=
event
.
repository_updated_event
registry
=
::
Geo
::
ProjectRegistry
.
find_or_initialize_by
(
project_id:
updated_event
.
project_id
)
case
updated_event
.
source
...
...
@@ -112,10 +115,9 @@ module Gitlab
registry
.
resync_wiki
=
true
end
Gitlab
::
Geo
::
Logger
.
info
(
class:
self
.
class
.
name
,
log_event_
info
(
event
.
created_at
,
message:
"Repository update"
,
cursor_delay_s:
(
Time
.
now
-
updated_event
.
created_at
).
to_f
.
round
(
3
),
project_id:
updated_event
.
project_id
,
source:
updated_event
.
source
,
resync_repository:
registry
.
resync_repository
,
...
...
@@ -124,7 +126,8 @@ module Gitlab
registry
.
save!
end
def
handle_repository_delete
(
deleted_event
)
def
handle_repository_delete
(
event
)
deleted_event
=
event
.
repository_deleted_event
# Once we remove system hooks we can refactor
# GeoRepositoryDestroyWorker to avoid doing this
full_path
=
File
.
join
(
deleted_event
.
repository_storage_path
,
...
...
@@ -133,12 +136,11 @@ module Gitlab
deleted_event
.
project_id
,
deleted_event
.
deleted_project_name
,
full_path
)
Gitlab
::
Geo
::
Logger
.
info
(
class:
self
.
class
.
name
,
message:
"Deleted project"
,
project_id:
deleted_event
.
project_id
,
full_path:
full_path
,
job_id:
job_id
)
log_event_info
(
event
.
created_at
,
message:
"Deleted project"
,
project_id:
deleted_event
.
project_id
,
full_path:
full_path
,
job_id:
job_id
)
# No need to create a project entry if it doesn't exist
::
Geo
::
ProjectRegistry
.
where
(
project_id:
deleted_event
.
project_id
).
delete_all
end
...
...
@@ -155,6 +157,33 @@ module Gitlab
end
end
def
handle_repository_rename
(
event
)
renamed_event
=
event
.
repository_renamed_event
return
unless
renamed_event
.
project_id
old_path
=
renamed_event
.
old_path_with_namespace
new_path
=
renamed_event
.
new_path_with_namespace
job_id
=
::
GeoRepositoryMoveWorker
.
perform_async
(
renamed_event
.
project_id
,
""
,
old_path
,
new_path
)
log_event_info
(
event
.
created_at
,
message:
"Renaming project"
,
project_id:
renamed_event
.
project_id
,
old_path:
old_path
,
new_path:
new_path
,
job_id:
job_id
)
end
def
cursor_delay
(
created_at
)
(
Time
.
now
-
created_at
).
to_f
.
round
(
3
)
end
def
log_event_info
(
created_at
,
message
,
params
=
{})
params
[
:cursor_delay_s
]
=
cursor_delay
(
created_at
)
log_info
(
message
,
params
)
end
def
log_info
(
message
,
params
=
{})
Gitlab
::
Geo
::
Logger
.
info
({
class:
self
.
class
.
name
,
message:
message
}.
merge
(
params
))
end
...
...
spec/factories/geo/event_log.rb
View file @
a2aef6a8
...
...
@@ -7,6 +7,10 @@ FactoryGirl.define do
trait
:deleted_event
do
repository_deleted_event
factory: :geo_repository_deleted_event
end
trait
:renamed_event
do
repository_renamed_event
factory: :geo_repository_rename_event
end
end
factory
:geo_repository_updated_event
,
class:
Geo
::
RepositoryUpdatedEvent
do
...
...
@@ -41,4 +45,17 @@ FactoryGirl.define do
factory
:geo_repositories_changed_event
,
class:
Geo
::
RepositoriesChangedEvent
do
geo_node
end
factory
:geo_repository_rename_event
,
class:
Geo
::
RepositoryRenamedEvent
do
project
{
create
(
:project
,
:repository
)
}
repository_storage_name
{
project
.
repository_storage
}
repository_storage_path
{
project
.
repository_storage_path
}
old_path_with_namespace
{
project
.
path_with_namespace
}
new_path_with_namespace
{
project
.
path_with_namespace
+
'_new'
}
old_wiki_path_with_namespace
{
project
.
wiki
.
path_with_namespace
}
new_wiki_path_with_namespace
{
project
.
wiki
.
path_with_namespace
+
'_new'
}
old_path
{
project
.
path
}
new_path
{
project
.
path
+
'_new'
}
end
end
spec/lib/gitlab/geo/log_cursor/daemon_spec.rb
View file @
a2aef6a8
...
...
@@ -150,5 +150,31 @@ describe Gitlab::Geo::LogCursor::Daemon do
end
end
end
context
'when processing a repository renamed event'
do
let
(
:event_log
)
{
create
(
:geo_event_log
,
:renamed_event
)
}
let
(
:project
)
{
event_log
.
repository_rename_event
.
project
}
let!
(
:event_log_state
)
{
create
(
:geo_event_log_state
,
event_id:
event_log
.
id
-
1
)
}
let
(
:repository_rename_event
)
{
event_log
.
repository_renamed_event
}
before
do
allow
(
subject
).
to
receive
(
:exit?
).
and_return
(
false
,
true
)
end
it
'does not create a new project registry'
do
expect
{
subject
.
run!
}.
not_to
change
(
Geo
::
ProjectRegistry
,
:count
)
end
it
'schedules a GeoRepositoryDestroyWorker'
do
project_id
=
repository_rename_event
.
project_id
old_path_with_namespace
=
repository_rename_event
.
old_path_with_namespace
new_path_with_namespace
=
repository_rename_event
.
new_path_with_namespace
expect
(
::
GeoRepositoryMoveWorker
).
to
receive
(
:perform_async
)
.
with
(
project_id
,
''
,
old_path_with_namespace
,
new_path_with_namespace
)
subject
.
run!
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