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
1e8b7077
Commit
1e8b7077
authored
Nov 24, 2017
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Attachments migration event for Geo
parent
5b1b0b8a
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
182 additions
and
2 deletions
+182
-2
app/models/geo/event_log.rb
app/models/geo/event_log.rb
+6
-1
app/models/geo/hashed_storage_attachments_event.rb
app/models/geo/hashed_storage_attachments_event.rb
+9
-0
app/services/geo/hashed_storage_attachments_event_store.rb
app/services/geo/hashed_storage_attachments_event_store.rb
+23
-0
app/services/projects/hashed_storage/migrate_attachments_service.rb
...es/projects/hashed_storage/migrate_attachments_service.rb
+2
-0
db/migrate/20171124070437_add_attachments_migration_to_geo_migration_events.rb
...0437_add_attachments_migration_to_geo_migration_events.rb
+18
-0
db/schema.rb
db/schema.rb
+11
-1
ee/app/services/ee/projects/hashed_storage/migrate_attachments_service.rb
...ee/projects/hashed_storage/migrate_attachments_service.rb
+19
-0
spec/ee/spec/services/ee/projects/hashed_storage/migrate_attachments_service_spec.rb
...ojects/hashed_storage/migrate_attachments_service_spec.rb
+49
-0
spec/services/geo/hashed_storage_attachments_event_store_spec.rb
...rvices/geo/hashed_storage_attachments_event_store_spec.rb
+45
-0
No files found.
app/models/geo/event_log.rb
View file @
1e8b7077
...
...
@@ -30,6 +30,10 @@ module Geo
class_name:
'Geo::LfsObjectDeletedEvent'
,
foreign_key: :lfs_object_deleted_event_id
belongs_to
:hashed_storage_attachments_event
,
class_name:
'Geo::HashedStorageAttachmentsEvent'
,
foreign_key: :hashed_storage_attachments_event_id
def
self
.
latest_event
order
(
id: :desc
).
first
end
...
...
@@ -41,7 +45,8 @@ module Geo
repository_renamed_event
||
repositories_changed_event
||
hashed_storage_migrated_event
||
lfs_object_deleted_event
lfs_object_deleted_event
||
hashed_storage_attachments_event
end
def
project_id
...
...
app/models/geo/hashed_storage_attachments_event.rb
0 → 100644
View file @
1e8b7077
module
Geo
class
HashedStorageAttachmentsEvent
<
ActiveRecord
::
Base
include
Geo
::
Model
belongs_to
:project
validates
:project
,
:old_attachments_path
,
:new_attachments_path
,
presence:
true
end
end
app/services/geo/hashed_storage_attachments_event_store.rb
0 → 100644
View file @
1e8b7077
module
Geo
class
HashedStorageAttachmentsEventStore
<
EventStore
self
.
event_type
=
:hashed_storage_attachments_event
private
def
build_event
Geo
::
HashedStorageAttachmentsEvent
.
new
(
project:
project
,
old_attachments_path:
old_attachments_path
,
new_attachments_path:
new_attachments_path
)
end
def
old_attachments_path
params
.
fetch
(
:old_attachments_path
)
end
def
new_attachments_path
params
.
fetch
(
:new_attachments_path
)
end
end
end
app/services/projects/hashed_storage/migrate_attachments_service.rb
View file @
1e8b7077
...
...
@@ -5,6 +5,8 @@ module Projects
class
MigrateAttachmentsService
<
BaseService
attr_reader
:logger
,
:old_path
,
:new_path
prepend
::
EE
::
Projects
::
HashedStorage
::
MigrateAttachmentsService
def
initialize
(
project
,
logger
=
nil
)
@project
=
project
@logger
=
logger
||
Rails
.
logger
...
...
db/migrate/20171124070437_add_attachments_migration_to_geo_migration_events.rb
0 → 100644
View file @
1e8b7077
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class
AddAttachmentsMigrationToGeoMigrationEvents
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
change
create_table
:geo_hashed_storage_attachments_events
,
id: :bigserial
do
|
t
|
t
.
references
:project
,
index:
true
,
foreign_key:
{
on_delete: :cascade
},
null:
false
t
.
text
:old_attachments_path
,
null:
false
t
.
text
:new_attachments_path
,
null:
false
end
add_column
:geo_event_log
,
:hashed_storage_attachments_event_id
,
:integer
,
limit:
8
end
end
db/schema.rb
View file @
1e8b7077
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2017112
1144800
)
do
ActiveRecord
::
Schema
.
define
(
version:
2017112
4070437
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
@@ -882,6 +882,7 @@ ActiveRecord::Schema.define(version: 20171121144800) do
t
.
integer
"repository_created_event_id"
,
limit:
8
t
.
integer
"hashed_storage_migrated_event_id"
,
limit:
8
t
.
integer
"lfs_object_deleted_event_id"
,
limit:
8
t
.
integer
"hashed_storage_attachments_event_id"
,
limit:
8
end
add_index
"geo_event_log"
,
[
"repositories_changed_event_id"
],
name:
"index_geo_event_log_on_repositories_changed_event_id"
,
using: :btree
...
...
@@ -890,6 +891,14 @@ ActiveRecord::Schema.define(version: 20171121144800) do
add_index
"geo_event_log"
,
[
"repository_renamed_event_id"
],
name:
"index_geo_event_log_on_repository_renamed_event_id"
,
using: :btree
add_index
"geo_event_log"
,
[
"repository_updated_event_id"
],
name:
"index_geo_event_log_on_repository_updated_event_id"
,
using: :btree
create_table
"geo_hashed_storage_attachments_events"
,
id: :bigserial
,
force: :cascade
do
|
t
|
t
.
integer
"project_id"
,
null:
false
t
.
text
"old_attachments_path"
,
null:
false
t
.
text
"new_attachments_path"
,
null:
false
end
add_index
"geo_hashed_storage_attachments_events"
,
[
"project_id"
],
name:
"index_geo_hashed_storage_attachments_events_on_project_id"
,
using: :btree
create_table
"geo_hashed_storage_migrated_events"
,
id: :bigserial
,
force: :cascade
do
|
t
|
t
.
integer
"project_id"
,
null:
false
t
.
text
"repository_storage_name"
,
null:
false
...
...
@@ -2450,6 +2459,7 @@ ActiveRecord::Schema.define(version: 20171121144800) do
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_renamed_events"
,
column:
"repository_renamed_event_id"
,
name:
"fk_86c84214ec"
,
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_hashed_storage_attachments_events"
,
"projects"
,
on_delete: :cascade
add_foreign_key
"geo_hashed_storage_migrated_events"
,
"projects"
,
on_delete: :cascade
add_foreign_key
"geo_node_namespace_links"
,
"geo_nodes"
,
on_delete: :cascade
add_foreign_key
"geo_node_namespace_links"
,
"namespaces"
,
on_delete: :cascade
...
...
ee/app/services/ee/projects/hashed_storage/migrate_attachments_service.rb
0 → 100644
View file @
1e8b7077
module
EE
module
Projects
module
HashedStorage
module
MigrateAttachmentsService
def
execute
raise
NotImplementedError
.
new
unless
defined?
(
super
)
super
do
::
Geo
::
HashedStorageAttachmentsEventStore
.
new
(
project
,
old_attachments_path:
old_path
,
new_attachments_path:
new_path
).
create
end
end
end
end
end
end
spec/ee/spec/services/ee/projects/hashed_storage/migrate_attachments_service_spec.rb
0 → 100644
View file @
1e8b7077
require
'spec_helper'
describe
Projects
::
HashedStorage
::
MigrateAttachmentsService
do
let
(
:project
)
{
create
(
:project
,
storage_version:
1
)
}
let
(
:service
)
{
described_class
.
new
(
project
)
}
let
(
:legacy_storage
)
{
Storage
::
LegacyProject
.
new
(
project
)
}
let
(
:hashed_storage
)
{
Storage
::
HashedProject
.
new
(
project
)
}
let
(
:old_attachments_path
)
{
legacy_storage
.
disk_path
}
let
(
:new_attachments_path
)
{
hashed_storage
.
disk_path
}
describe
'#execute'
do
set
(
:primary
)
{
create
(
:geo_node
,
:primary
)
}
set
(
:secondary
)
{
create
(
:geo_node
)
}
context
'on success'
do
before
do
FileUtils
.
mkdir_p
(
FileUploader
.
dynamic_path_builder
(
old_attachments_path
))
end
it
'returns true'
do
expect
(
service
.
execute
).
to
be_truthy
end
it
'creates a Geo::HashedStorageAttachmentsEvent'
do
expect
{
service
.
execute
}.
to
change
(
Geo
::
EventLog
,
:count
).
by
(
1
)
event
=
Geo
::
EventLog
.
first
.
event
expect
(
event
).
to
be_a
(
Geo
::
HashedStorageAttachmentsEvent
)
expect
(
event
).
to
have_attributes
(
old_attachments_path:
old_attachments_path
,
new_attachments_path:
new_attachments_path
)
end
end
context
'on failure'
do
it
'does not create a Geo event when skipped'
do
expect
{
service
.
execute
}.
not_to
change
{
Geo
::
EventLog
.
count
}
end
it
'does not create a Geo event on failure'
do
expect
(
service
).
to
receive
(
:move_folder!
).
and_raise
(
::
Projects
::
HashedStorage
::
AttachmentMigrationError
)
expect
{
service
.
execute
}.
to
raise_error
(
::
Projects
::
HashedStorage
::
AttachmentMigrationError
)
expect
(
Geo
::
EventLog
.
count
).
to
eq
(
0
)
end
end
end
end
spec/services/geo/hashed_storage_attachments_event_store_spec.rb
0 → 100644
View file @
1e8b7077
require
'spec_helper'
describe
Geo
::
HashedStorageAttachmentsEventStore
do
let
(
:project
)
{
create
(
:project
,
:hashed
,
path:
'bar'
)
}
set
(
:secondary_node
)
{
create
(
:geo_node
)
}
let
(
:old_attachments_path
)
{
"/public/uploads/
#{
project
.
full_path
}
"
}
let
(
:new_attachments_path
)
{
"/public/uploads/
#{
project
.
disk_path
}
"
}
subject
(
:event_store
)
{
described_class
.
new
(
project
,
old_storage_version:
1
,
new_storage_version:
2
,
old_attachments_path:
old_attachments_path
,
new_attachments_path:
new_attachments_path
)
}
describe
'#create'
do
it
'does not create an event when not running on a primary node'
do
allow
(
Gitlab
::
Geo
).
to
receive
(
:primary?
)
{
false
}
expect
{
event_store
.
create
}.
not_to
change
(
Geo
::
HashedStorageAttachmentsEvent
,
:count
)
end
context
'when running on a primary node'
do
before
do
allow
(
Gitlab
::
Geo
).
to
receive
(
:primary?
)
{
true
}
end
it
'does not create an event when there are no secondary nodes'
do
allow
(
Gitlab
::
Geo
).
to
receive
(
:secondary_nodes
)
{
[]
}
expect
{
event_store
.
create
}.
not_to
change
(
Geo
::
HashedStorageAttachmentsEvent
,
:count
)
end
it
'creates a attachment migration event'
do
expect
{
event_store
.
create
}.
to
change
(
Geo
::
HashedStorageAttachmentsEvent
,
:count
).
by
(
1
)
end
it
'tracks project attributes'
do
event_store
.
create
event
=
Geo
::
HashedStorageAttachmentsEvent
.
last
expect
(
event
).
to
have_attributes
(
old_attachments_path:
old_attachments_path
,
new_attachments_path:
new_attachments_path
)
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