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
c9d879cc
Commit
c9d879cc
authored
Jan 14, 2021
by
Dmitry Gruzd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove issues from old index
parent
640c5e42
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
141 additions
and
0 deletions
+141
-0
ee/elastic/migrate/20210112165500_delete_issues_from_original_index.rb
...grate/20210112165500_delete_issues_from_original_index.rb
+49
-0
ee/spec/elastic/migrate/20210112165500_delete_issues_from_original_index_spec.rb
.../20210112165500_delete_issues_from_original_index_spec.rb
+92
-0
No files found.
ee/elastic/migrate/20210112165500_delete_issues_from_original_index.rb
0 → 100644
View file @
c9d879cc
# frozen_string_literal: true
class
DeleteIssuesFromOriginalIndex
<
Elastic
::
Migration
batched!
throttle_delay
1
.
minute
MAX_ATTEMPTS
=
30
QUERY_BODY
=
{
query:
{
term:
{
type:
'issue'
}
}
}.
freeze
def
migrate
retry_attempt
=
migration_state
[
:retry_attempt
].
to_i
if
retry_attempt
>=
MAX_ATTEMPTS
fail_migration_halt_error!
(
retry_attempt:
retry_attempt
)
return
end
if
completed?
log
"Skipping removing issues from the original index since it is already applied"
return
end
response
=
client
.
delete_by_query
(
index:
helper
.
target_name
,
body:
QUERY_BODY
)
log_raise
"Failed to delete issues:
#{
response
[
'failures'
]
}
"
if
response
[
'failures'
].
present?
rescue
StandardError
=>
e
log
"migrate failed, increasing migration_state retry_attempt:
#{
retry_attempt
}
error:
#{
e
.
class
}
:
#{
e
.
message
}
"
set_migration_state
(
retry_attempt:
retry_attempt
+
1
)
raise
e
end
def
completed?
helper
.
refresh_index
results
=
client
.
search
(
index:
helper
.
target_name
,
body:
QUERY_BODY
.
merge
(
size:
0
))
results
.
dig
(
'hits'
,
'total'
,
'value'
)
==
0
end
end
ee/spec/elastic/migrate/20210112165500_delete_issues_from_original_index_spec.rb
0 → 100644
View file @
c9d879cc
# frozen_string_literal: true
require
'spec_helper'
require
File
.
expand_path
(
'ee/elastic/migrate/20210112165500_delete_issues_from_original_index.rb'
)
RSpec
.
describe
DeleteIssuesFromOriginalIndex
,
:elastic
,
:sidekiq_inline
do
let
(
:version
)
{
20210112165500
}
let
(
:migration
)
{
described_class
.
new
(
version
)
}
let
(
:helper
)
{
Gitlab
::
Elastic
::
Helper
.
new
}
before
do
stub_ee_application_setting
(
elasticsearch_search:
true
,
elasticsearch_indexing:
true
)
allow
(
migration
).
to
receive
(
:helper
).
and_return
(
helper
)
end
describe
'migration_options'
do
it
'has migration options set'
,
:aggregate_failures
do
expect
(
migration
.
batched?
).
to
be_truthy
expect
(
migration
.
throttle_delay
).
to
eq
(
1
.
minute
)
end
end
context
'issues are already deleted'
do
it
'does not execute delete_by_query'
do
expect
(
migration
.
completed?
).
to
be_truthy
expect
(
helper
.
client
).
not_to
receive
(
:delete_by_query
)
migration
.
migrate
end
end
context
'issues are still present in the index'
do
let
(
:issues
)
{
create_list
(
:issue
,
3
)
}
before
do
allow
(
Elastic
::
DataMigrationService
).
to
receive
(
:migration_has_finished?
)
.
with
(
:migrate_issues_to_separate_index
)
.
and_return
(
false
)
# ensure issues are indexed
issues
ensure_elasticsearch_index!
end
it
'removes issues from the index'
do
expect
{
migration
.
migrate
}.
to
change
{
migration
.
completed?
}.
from
(
false
).
to
(
true
)
end
end
context
'migration fails'
do
let
(
:client
)
{
double
(
'Elasticsearch::Transport::Client'
)
}
before
do
allow
(
migration
).
to
receive
(
:client
).
and_return
(
client
)
allow
(
migration
).
to
receive
(
:completed?
).
and_return
(
false
)
end
context
'exception is raised'
do
before
do
allow
(
client
).
to
receive
(
:delete_by_query
).
and_raise
(
StandardError
)
end
it
'increases retry_attempt'
do
migration
.
set_migration_state
(
retry_attempt:
1
)
expect
{
migration
.
migrate
}.
to
raise_error
(
StandardError
)
expect
(
migration
.
migration_state
).
to
match
(
retry_attempt:
2
)
end
it
'fails the migration after too many attempts'
do
migration
.
set_migration_state
(
retry_attempt:
30
)
migration
.
migrate
expect
(
migration
.
migration_state
).
to
match
(
retry_attempt:
30
,
halted:
true
,
halted_indexing_unpaused:
false
)
expect
(
client
).
not_to
receive
(
:delete_by_query
)
end
end
context
'es responds with errors'
do
before
do
allow
(
client
).
to
receive
(
:delete_by_query
).
and_return
(
'failures'
=>
[
'failed'
])
end
it
'raises an error and increases retry attempt'
do
expect
{
migration
.
migrate
}.
to
raise_error
(
/Failed to delete issues/
)
expect
(
migration
.
migration_state
).
to
match
(
retry_attempt:
1
)
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