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
04c3da24
Commit
04c3da24
authored
Jun 13, 2017
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Geo delete event log
parent
9fd5c408
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
135 additions
and
15 deletions
+135
-15
app/models/geo/event_log.rb
app/models/geo/event_log.rb
+4
-0
app/services/ee/projects/destroy_service.rb
app/services/ee/projects/destroy_service.rb
+42
-0
app/services/projects/destroy_service.rb
app/services/projects/destroy_service.rb
+2
-14
db/migrate/20170614053336_create_geo_repository_deleted_events.rb
...te/20170614053336_create_geo_repository_deleted_events.rb
+19
-0
db/migrate/20170614061551_add_geo_repository_deleted_events_foreign_key.rb
...14061551_add_geo_repository_deleted_events_foreign_key.rb
+16
-0
db/schema.rb
db/schema.rb
+14
-1
spec/services/projects/ee/destroy_service_spec.rb
spec/services/projects/ee/destroy_service_spec.rb
+38
-0
No files found.
app/models/geo/event_log.rb
View file @
04c3da24
...
...
@@ -5,5 +5,9 @@ module Geo
belongs_to
:repository_updated_event
,
class_name:
'Geo::RepositoryUpdatedEvent'
,
foreign_key: :repository_updated_event_id
belongs_to
:repository_deleted_event
,
class_name:
'Geo::RepositoryDeletedEvent'
,
foreign_key: :repository_deleted_event_id
end
end
app/services/ee/projects/destroy_service.rb
0 → 100644
View file @
04c3da24
module
EE
module
Projects
module
DestroyService
def
execute
raise
NotImplementedError
unless
defined?
(
super
)
super
log_geo_event
(
project
)
end
def
log_geo_event
(
project
)
return
unless
::
Gitlab
::
Geo
.
primary?
Geo
::
EventLog
.
transaction
do
event_log
=
Geo
::
EventLog
.
new
deleted_event
=
Geo
::
RepositoryDeletedEvent
.
new
(
project:
project
,
repository_storage_path:
project
.
repository_storage_path
,
deleted_path:
repo_path
,
deleted_wiki_path:
wiki_path
,
deleted_project_name:
project
.
name
)
event_log
.
repository_deleted_event
=
deleted_event
event_log
.
save
end
end
# Removes physical repository in a Geo replicated secondary node
# There is no need to do any database operation as it will be
# replicated by itself.
def
geo_replicate
# Flush the cache for both repositories. This has to be done _before_
# removing the physical repositories as some expiration code depends on
# Git data (e.g. a list of branch names).
flush_caches
(
project
,
wiki_path
)
trash_repositories!
remove_tracking_entries!
log_info
(
"Project
\"
#{
project
.
name
}
\"
was removed"
)
end
end
end
end
app/services/projects/destroy_service.rb
View file @
04c3da24
module
Projects
class
DestroyService
<
BaseService
include
Gitlab
::
ShellAdapter
prepend
::
EE
::
Projects
::
DestroyService
DestroyError
=
Class
.
new
(
StandardError
)
...
...
@@ -45,21 +46,8 @@ module Projects
log_info
(
"Project
\"
#{
project
.
path_with_namespace
}
\"
was removed"
)
system_hook_service
.
execute_hooks_for
(
project
,
:destroy
)
true
end
# Removes physical repository in a Geo replicated secondary node
# There is no need to do any database operation as it will be
# replicated by itself.
def
geo_replicate
# Flush the cache for both repositories. This has to be done _before_
# removing the physical repositories as some expiration code depends on
# Git data (e.g. a list of branch names).
flush_caches
(
project
,
wiki_path
)
trash_repositories!
remove_tracking_entries!
log_info
(
"Project
\"
#{
project
.
name
}
\"
was removed"
)
true
end
private
...
...
db/migrate/20170614053336_create_geo_repository_deleted_events.rb
0 → 100644
View file @
04c3da24
class
CreateGeoRepositoryDeletedEvents
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
change
create_table
:geo_repository_deleted_events
,
id: :bigserial
do
|
t
|
# If a project is deleted, we need to retain this entry
t
.
references
:project
,
index:
true
,
foreign_key:
false
,
null:
false
t
.
datetime
:created_at
,
null:
false
t
.
text
:repository_storage_path
,
null:
false
t
.
text
:deleted_path
,
null:
false
t
.
text
:deleted_wiki_path
t
.
text
:deleted_project_name
,
null:
false
end
add_column
:geo_event_log
,
:repository_deleted_event_id
,
:integer
,
limit:
8
end
end
db/migrate/20170614061551_add_geo_repository_deleted_events_foreign_key.rb
0 → 100644
View file @
04c3da24
class
AddGeoRepositoryDeletedEventsForeignKey
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
add_concurrent_foreign_key
:geo_event_log
,
:geo_repository_deleted_events
,
column: :repository_deleted_event_id
,
on_delete: :cascade
end
def
down
remove_foreign_key
:geo_event_log
,
column: :repository_deleted_event_id
end
end
db/schema.rb
View file @
04c3da24
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
201706
06202615
)
do
ActiveRecord
::
Schema
.
define
(
version:
201706
14061551
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
@@ -582,6 +582,7 @@ ActiveRecord::Schema.define(version: 20170606202615) do
create_table
"geo_event_log"
,
id: :bigserial
,
force: :cascade
do
|
t
|
t
.
datetime
"created_at"
,
null:
false
t
.
integer
"repository_updated_event_id"
,
limit:
8
t
.
integer
"repository_deleted_event_id"
,
limit:
8
end
add_index
"geo_event_log"
,
[
"repository_updated_event_id"
],
name:
"index_geo_event_log_on_repository_updated_event_id"
,
using: :btree
...
...
@@ -606,6 +607,17 @@ ActiveRecord::Schema.define(version: 20170606202615) do
add_index
"geo_nodes"
,
[
"host"
],
name:
"index_geo_nodes_on_host"
,
using: :btree
add_index
"geo_nodes"
,
[
"primary"
],
name:
"index_geo_nodes_on_primary"
,
using: :btree
create_table
"geo_repository_deleted_events"
,
id: :bigserial
,
force: :cascade
do
|
t
|
t
.
integer
"project_id"
,
null:
false
t
.
datetime
"created_at"
,
null:
false
t
.
text
"repository_storage_path"
,
null:
false
t
.
text
"deleted_path"
,
null:
false
t
.
text
"deleted_wiki_path"
t
.
text
"deleted_project_name"
,
null:
false
end
add_index
"geo_repository_deleted_events"
,
[
"project_id"
],
name:
"index_geo_repository_deleted_events_on_project_id"
,
using: :btree
create_table
"geo_repository_updated_events"
,
id: :bigserial
,
force: :cascade
do
|
t
|
t
.
datetime
"created_at"
,
null:
false
t
.
integer
"branches_affected"
,
null:
false
...
...
@@ -1789,6 +1801,7 @@ ActiveRecord::Schema.define(version: 20170606202615) do
add_foreign_key
"ci_triggers"
,
"users"
,
column:
"owner_id"
,
name:
"fk_e8e10d1964"
,
on_delete: :cascade
add_foreign_key
"ci_variables"
,
"projects"
,
name:
"fk_ada5eb64b3"
,
on_delete: :cascade
add_foreign_key
"container_repositories"
,
"projects"
add_foreign_key
"geo_event_log"
,
"geo_repository_deleted_events"
,
column:
"repository_deleted_event_id"
,
name:
"fk_c4b1c1f66e"
,
on_delete: :cascade
add_foreign_key
"geo_event_log"
,
"geo_repository_updated_events"
,
column:
"repository_updated_event_id"
,
on_delete: :cascade
add_foreign_key
"geo_repository_updated_events"
,
"projects"
,
on_delete: :cascade
add_foreign_key
"issue_assignees"
,
"issues"
,
name:
"fk_b7d881734a"
,
on_delete: :cascade
...
...
spec/services/projects/ee/destroy_service_spec.rb
0 → 100644
View file @
04c3da24
require
'spec_helper'
describe
Projects
::
DestroyService
,
services:
true
do
let!
(
:user
)
{
create
(
:user
)
}
let!
(
:project
)
{
create
(
:project
,
:repository
,
namespace:
user
.
namespace
)
}
let!
(
:project_id
)
{
project
.
id
}
let!
(
:project_name
)
{
project
.
name
}
let!
(
:project_path
)
{
project
.
path_with_namespace
}
let!
(
:wiki_path
)
{
project
.
path_with_namespace
+
'.wiki'
}
let!
(
:storage_path
)
{
project
.
repository_storage_path
}
let!
(
:geo_node
)
{
create
(
:geo_node
,
:primary
,
:current
)
}
before
do
stub_container_registry_config
(
enabled:
true
)
stub_container_registry_tags
(
repository: :any
,
tags:
[])
end
context
'Geo primary'
do
it
'logs the event'
do
# Run sidekiq immediatly to check that renamed repository will be removed
Sidekiq
::
Testing
.
inline!
{
destroy_project
(
project
,
user
,
{})
}
event
=
Geo
::
RepositoryDeletedEvent
.
first
expect
(
Geo
::
EventLog
.
count
).
to
eq
(
1
)
expect
(
Geo
::
RepositoryDeletedEvent
.
count
).
to
eq
(
1
)
expect
(
event
.
project_id
).
to
eq
(
project_id
)
expect
(
event
.
deleted_path
).
to
eq
(
project_path
)
expect
(
event
.
deleted_wiki_path
).
to
eq
(
wiki_path
)
expect
(
event
.
deleted_project_name
).
to
eq
(
project_name
)
expect
(
event
.
repository_storage_path
).
to
eq
(
storage_path
)
end
end
def
destroy_project
(
project
,
user
,
params
=
{})
described_class
.
new
(
project
,
user
,
params
).
execute
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