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
acc6b3a1
Commit
acc6b3a1
authored
Feb 11, 2021
by
Dmitry Gruzd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify the execute_migration method
parent
cd4be563
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
28 additions
and
26 deletions
+28
-26
ee/app/models/elastic/migration_record.rb
ee/app/models/elastic/migration_record.rb
+2
-2
ee/app/workers/elastic/migration_worker.rb
ee/app/workers/elastic/migration_worker.rb
+12
-10
ee/spec/models/elastic/migration_record_spec.rb
ee/spec/models/elastic/migration_record_spec.rb
+7
-7
ee/spec/services/elastic/data_migration_service_spec.rb
ee/spec/services/elastic/data_migration_service_spec.rb
+2
-2
ee/spec/tasks/gitlab/elastic_rake_spec.rb
ee/spec/tasks/gitlab/elastic_rake_spec.rb
+2
-2
ee/spec/workers/elastic/migration_worker_spec.rb
ee/spec/workers/elastic/migration_worker_spec.rb
+3
-3
No files found.
ee/app/models/elastic/migration_record.rb
View file @
acc6b3a1
...
...
@@ -27,7 +27,7 @@ module Elastic
client
.
index
index:
index_name
,
type:
'_doc'
,
id:
version
,
body:
{
completed:
completed
,
state:
load_state
.
merge
(
state
)
}
end
def
persis
ted?
def
star
ted?
load_from_index
.
present?
end
...
...
@@ -49,7 +49,7 @@ module Elastic
name
.
underscore
end
def
self
.
persiste
d_versions
(
completed
:)
def
self
.
loa
d_versions
(
completed
:)
helper
=
Gitlab
::
Elastic
::
Helper
.
default
helper
.
client
.
search
(
index:
helper
.
migrations_index_name
,
body:
{
query:
{
term:
{
completed:
completed
}
}
})
...
...
ee/app/workers/elastic/migration_worker.rb
View file @
acc6b3a1
...
...
@@ -51,23 +51,25 @@ module Elastic
private
def
execute_migration
(
migration
)
if
migration
.
persis
ted?
&&
!
migration
.
batched?
if
migration
.
star
ted?
&&
!
migration
.
batched?
logger
.
info
"MigrationWorker: migration[
#{
migration
.
name
}
] did not execute migrate method since it was already executed. Waiting for migration to complete"
else
pause_indexing!
(
migration
)
logger
.
info
"MigrationWorker: migration[
#{
migration
.
name
}
] executing migrate method"
migration
.
migrate
return
end
if
migration
.
batched?
&&
!
migration
.
completed?
logger
.
info
"MigrationWorker: migration[
#{
migration
.
name
}
] kicking off next migration batch"
Elastic
::
MigrationWorker
.
perform_in
(
migration
.
throttle_delay
)
end
pause_indexing!
(
migration
)
logger
.
info
"MigrationWorker: migration[
#{
migration
.
name
}
] executing migrate method"
migration
.
migrate
if
migration
.
batched?
&&
!
migration
.
completed?
logger
.
info
"MigrationWorker: migration[
#{
migration
.
name
}
] kicking off next migration batch"
Elastic
::
MigrationWorker
.
perform_in
(
migration
.
throttle_delay
)
end
end
def
current_migration
completed_migrations
=
Elastic
::
MigrationRecord
.
persiste
d_versions
(
completed:
true
)
completed_migrations
=
Elastic
::
MigrationRecord
.
loa
d_versions
(
completed:
true
)
Elastic
::
DataMigrationService
.
migrations
.
find
{
|
migration
|
!
completed_migrations
.
include?
(
migration
.
version
)
}
end
...
...
ee/spec/models/elastic/migration_record_spec.rb
View file @
acc6b3a1
...
...
@@ -41,13 +41,13 @@ RSpec.describe Elastic::MigrationRecord, :elastic do
end
end
describe
'#
persis
ted?'
do
describe
'#
star
ted?'
do
it
'changes on object save'
do
expect
{
record
.
save!
(
completed:
true
)
}.
to
change
{
record
.
persis
ted?
}.
from
(
false
).
to
(
true
)
expect
{
record
.
save!
(
completed:
true
)
}.
to
change
{
record
.
star
ted?
}.
from
(
false
).
to
(
true
)
end
end
describe
'.
persiste
d_versions'
do
describe
'.
loa
d_versions'
do
let
(
:completed_versions
)
{
1
.
upto
(
5
).
map
{
|
i
|
described_class
.
new
(
version:
i
,
name:
i
,
filename:
nil
)
}
}
let
(
:in_progress_migration
)
{
described_class
.
new
(
version:
10
,
name:
10
,
filename:
nil
)
}
...
...
@@ -61,15 +61,15 @@ RSpec.describe Elastic::MigrationRecord, :elastic do
end
it
'loads all records'
do
expect
(
described_class
.
persiste
d_versions
(
completed:
true
)).
to
match_array
(
completed_versions
.
map
(
&
:version
))
expect
(
described_class
.
persiste
d_versions
(
completed:
false
)).
to
contain_exactly
(
in_progress_migration
.
version
)
expect
(
described_class
.
loa
d_versions
(
completed:
true
)).
to
match_array
(
completed_versions
.
map
(
&
:version
))
expect
(
described_class
.
loa
d_versions
(
completed:
false
)).
to
contain_exactly
(
in_progress_migration
.
version
)
end
it
'returns empty array if no index present'
do
es_helper
.
delete_migrations_index
expect
(
described_class
.
persiste
d_versions
(
completed:
true
)).
to
eq
([])
expect
(
described_class
.
persiste
d_versions
(
completed:
false
)).
to
eq
([])
expect
(
described_class
.
loa
d_versions
(
completed:
true
)).
to
eq
([])
expect
(
described_class
.
loa
d_versions
(
completed:
false
)).
to
eq
([])
end
end
end
ee/spec/services/elastic/data_migration_service_spec.rb
View file @
acc6b3a1
...
...
@@ -75,12 +75,12 @@ RSpec.describe Elastic::DataMigrationService, :elastic do
end
it
'creates all migration versions'
do
expect
(
Elastic
::
MigrationRecord
.
persiste
d_versions
(
completed:
true
).
count
).
to
eq
(
0
)
expect
(
Elastic
::
MigrationRecord
.
loa
d_versions
(
completed:
true
).
count
).
to
eq
(
0
)
subject
.
mark_all_as_completed!
refresh_index!
expect
(
Elastic
::
MigrationRecord
.
persiste
d_versions
(
completed:
true
).
count
).
to
eq
(
subject
.
migrations
.
count
)
expect
(
Elastic
::
MigrationRecord
.
loa
d_versions
(
completed:
true
).
count
).
to
eq
(
subject
.
migrations
.
count
)
end
it
'drops all cache keys'
do
...
...
ee/spec/tasks/gitlab/elastic_rake_spec.rb
View file @
acc6b3a1
...
...
@@ -69,13 +69,13 @@ RSpec.describe 'gitlab:elastic namespace rake tasks', :elastic do
it
'marks all migrations as completed'
do
expect
(
Elastic
::
DataMigrationService
).
to
receive
(
:mark_all_as_completed!
).
and_call_original
expect
(
Elastic
::
MigrationRecord
.
persiste
d_versions
(
completed:
true
)).
to
eq
([])
expect
(
Elastic
::
MigrationRecord
.
loa
d_versions
(
completed:
true
)).
to
eq
([])
subject
refresh_index!
migrations
=
Elastic
::
DataMigrationService
.
migrations
.
map
(
&
:version
)
expect
(
Elastic
::
MigrationRecord
.
persiste
d_versions
(
completed:
true
)).
to
eq
(
migrations
)
expect
(
Elastic
::
MigrationRecord
.
loa
d_versions
(
completed:
true
)).
to
eq
(
migrations
)
end
end
...
...
ee/spec/workers/elastic/migration_worker_spec.rb
View file @
acc6b3a1
...
...
@@ -77,7 +77,7 @@ RSpec.describe Elastic::MigrationWorker, :elastic do
context
'migration process'
do
before
do
allow
(
migration
).
to
receive
(
:
persisted?
).
and_return
(
persis
ted
)
allow
(
migration
).
to
receive
(
:
started?
).
and_return
(
star
ted
)
allow
(
migration
).
to
receive
(
:completed?
).
and_return
(
completed
)
allow
(
migration
).
to
receive
(
:batched?
).
and_return
(
batched
)
end
...
...
@@ -85,7 +85,7 @@ RSpec.describe Elastic::MigrationWorker, :elastic do
using
RSpec
::
Parameterized
::
TableSyntax
# completed is evaluated after migrate method is executed
where
(
:
persis
ted
,
:completed
,
:execute_migration
,
:batched
)
do
where
(
:
star
ted
,
:completed
,
:execute_migration
,
:batched
)
do
false
|
false
|
true
|
false
false
|
true
|
true
|
false
false
|
false
|
true
|
true
...
...
@@ -130,7 +130,7 @@ RSpec.describe Elastic::MigrationWorker, :elastic do
let
(
:batched
)
{
true
}
where
(
:
persis
ted
,
:completed
,
:expected
)
do
where
(
:
star
ted
,
:completed
,
:expected
)
do
false
|
false
|
false
true
|
false
|
false
true
|
true
|
true
...
...
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