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
8315c66a
Commit
8315c66a
authored
Nov 07, 2017
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Kick off follow up background migration jobs
To process the unhashed_upload_files table.
parent
b6ea41d1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
105 additions
and
17 deletions
+105
-17
lib/gitlab/background_migration/populate_untracked_uploads.rb
...gitlab/background_migration/populate_untracked_uploads.rb
+51
-0
lib/gitlab/background_migration/prepare_unhashed_uploads.rb
lib/gitlab/background_migration/prepare_unhashed_uploads.rb
+7
-1
spec/lib/gitlab/background_migration/prepare_unhashed_uploads_spec.rb
...lab/background_migration/prepare_unhashed_uploads_spec.rb
+47
-16
No files found.
lib/gitlab/background_migration/populate_untracked_uploads.rb
0 → 100644
View file @
8315c66a
module
Gitlab
module
BackgroundMigration
class
PopulateUntrackedUploads
class
UnhashedUploadFile
<
ActiveRecord
::
Base
self
.
table_name
=
'unhashed_upload_files'
scope
:untracked
,
->
{
where
(
tracked:
false
)
}
def
ensure_tracked!
# TODO
# unless unhashed_upload_file.in_uploads?
# unhashed_upload_file.add_to_uploads
# end
#
# unhashed_upload_file.mark_as_tracked
end
def
model_id
# TODO
end
def
model_type
# TODO
end
def
uploader
# TODO
end
end
class
Upload
<
ActiveRecord
::
Base
self
.
table_name
=
'uploads'
end
def
perform
(
start_id
,
end_id
)
return
unless
migrate?
files
=
UnhashedUploadFile
.
untracked
.
where
(
id:
start_id
..
end_id
)
files
.
each
do
|
unhashed_upload_file
|
unhashed_upload_file
.
ensure_tracked!
end
end
private
def
migrate?
UnhashedUploadFile
.
table_exists?
&&
Upload
.
table_exists?
end
end
end
end
lib/gitlab/background_migration/prepare_unhashed_uploads.rb
View file @
8315c66a
module
Gitlab
module
BackgroundMigration
class
PrepareUnhashedUploads
# For bulk_queue_background_migration_jobs_by_range
include
Database
::
MigrationHelpers
FILE_PATH_BATCH_SIZE
=
500
UPLOAD_DIR
=
"
#{
CarrierWave
.
root
}
/uploads"
FOLLOW_UP_MIGRATION
=
'PopulateUntrackedUploads'
class
UnhashedUploadFile
<
ActiveRecord
::
Base
include
EachBatch
self
.
table_name
=
'unhashed_upload_files'
end
...
...
@@ -74,7 +80,7 @@ module Gitlab
end
def
schedule_populate_untracked_uploads_jobs
# TODO
bulk_queue_background_migration_jobs_by_range
(
UnhashedUploadFile
,
FOLLOW_UP_MIGRATION
)
end
end
end
...
...
spec/lib/gitlab/background_migration/prepare_unhashed_uploads_spec.rb
View file @
8315c66a
require
'spec_helper'
describe
Gitlab
::
BackgroundMigration
::
PrepareUnhashedUploads
,
:migration
,
schema:
20171103140253
do
describe
Gitlab
::
BackgroundMigration
::
PrepareUnhashedUploads
,
:migration
,
:sidekiq
,
schema:
20171103140253
do
let!
(
:unhashed_upload_files
)
{
table
(
:unhashed_upload_files
)
}
let
(
:user1
)
{
create
(
:user
)
}
...
...
@@ -9,6 +9,18 @@ describe Gitlab::BackgroundMigration::PrepareUnhashedUploads, :migration, schema
let
(
:project2
)
{
create
(
:project
)
}
let
(
:appearance
)
{
create
(
:appearance
)
}
matcher
:be_scheduled_migration
do
|*
expected
|
match
do
|
migration
|
BackgroundMigrationWorker
.
jobs
.
any?
do
|
job
|
job
[
'args'
]
==
[
migration
,
expected
]
end
end
failure_message
do
|
migration
|
"Migration `
#{
migration
}
` with args `
#{
expected
.
inspect
}
` not scheduled!"
end
end
context
'when files were uploaded before and after hashed storage was enabled'
do
before
do
fixture
=
Rails
.
root
.
join
(
'spec'
,
'fixtures'
,
'rails_sample.jpg'
)
...
...
@@ -28,17 +40,30 @@ describe Gitlab::BackgroundMigration::PrepareUnhashedUploads, :migration, schema
end
it
'adds unhashed files to the unhashed_upload_files table'
do
Sidekiq
::
Testing
.
fake!
do
expect
do
described_class
.
new
.
perform
end
.
to
change
{
unhashed_upload_files
.
count
}.
from
(
0
).
to
(
5
)
end
end
it
'does not add hashed files to the unhashed_upload_files table'
do
Sidekiq
::
Testing
.
fake!
do
described_class
.
new
.
perform
hashed_file_path
=
project2
.
uploads
.
where
(
uploader:
'FileUploader'
).
first
.
path
expect
(
unhashed_upload_files
.
where
(
"path like '%
#{
hashed_file_path
}
%'"
).
exists?
).
to
be_falsey
end
end
it
'correctly schedules the follow-up background migration jobs'
do
Sidekiq
::
Testing
.
fake!
do
described_class
.
new
.
perform
expect
(
described_class
::
FOLLOW_UP_MIGRATION
).
to
be_scheduled_migration
(
1
,
5
)
expect
(
BackgroundMigrationWorker
.
jobs
.
size
).
to
eq
(
1
)
end
end
# E.g. from a previous failed run of this background migration
context
'when there is existing data in unhashed_upload_files'
do
...
...
@@ -47,11 +72,13 @@ describe Gitlab::BackgroundMigration::PrepareUnhashedUploads, :migration, schema
end
it
'clears existing data before adding new data'
do
Sidekiq
::
Testing
.
fake!
do
expect
do
described_class
.
new
.
perform
end
.
to
change
{
unhashed_upload_files
.
count
}.
from
(
1
).
to
(
5
)
end
end
end
# E.g. The installation is in use at the time of migration, and someone has
# just uploaded a file
...
...
@@ -61,20 +88,24 @@ describe Gitlab::BackgroundMigration::PrepareUnhashedUploads, :migration, schema
end
it
'does not add files from /uploads/tmp'
do
Sidekiq
::
Testing
.
fake!
do
expect
do
described_class
.
new
.
perform
end
.
to
change
{
unhashed_upload_files
.
count
}.
from
(
0
).
to
(
5
)
end
end
end
end
# Very new or lightly-used installations that are running this migration
# may not have an upload directory because they have no uploads.
context
'when no files were ever uploaded'
do
it
'does not add to the unhashed_upload_files table (and does not raise error)'
do
Sidekiq
::
Testing
.
fake!
do
expect
do
described_class
.
new
.
perform
end
.
not_to
change
{
unhashed_upload_files
.
count
}.
from
(
0
)
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