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
f63b332f
Commit
f63b332f
authored
May 12, 2021
by
Terri Chu
Committed by
Dmitry Gruzd
May 12, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete Notes from original ES index
parent
4e34fe74
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
149 additions
and
0 deletions
+149
-0
ee/changelogs/unreleased/297646-es-migration-to-delete-notes-from-combined-index.yml
...7646-es-migration-to-delete-notes-from-combined-index.yml
+5
-0
ee/elastic/migrate/20210510143200_delete_notes_from_original_index.rb
...igrate/20210510143200_delete_notes_from_original_index.rb
+52
-0
ee/spec/elastic/migrate/20210510143200_delete_notes_from_original_index_spec.rb
...e/20210510143200_delete_notes_from_original_index_spec.rb
+92
-0
No files found.
ee/changelogs/unreleased/297646-es-migration-to-delete-notes-from-combined-index.yml
0 → 100644
View file @
f63b332f
---
title
:
Delete Notes from original ES index
merge_request
:
61399
author
:
type
:
changed
ee/elastic/migrate/20210510143200_delete_notes_from_original_index.rb
0 → 100644
View file @
f63b332f
# frozen_string_literal: true
class
DeleteNotesFromOriginalIndex
<
Elastic
::
Migration
batched!
throttle_delay
3
.
minutes
MAX_ATTEMPTS
=
30
QUERY_BODY
=
{
query:
{
term:
{
type:
'note'
}
}
}.
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 notes 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 notes:
#{
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
))
total_remaining
=
results
.
dig
(
'hits'
,
'total'
,
'value'
)
log
"Checking to see if migration is completed based on index counts remaining:
#{
total_remaining
}
"
total_remaining
==
0
end
end
ee/spec/elastic/migrate/20210510143200_delete_notes_from_original_index_spec.rb
0 → 100644
View file @
f63b332f
# frozen_string_literal: true
require
'spec_helper'
require
File
.
expand_path
(
'ee/elastic/migrate/20210510143200_delete_notes_from_original_index.rb'
)
RSpec
.
describe
DeleteNotesFromOriginalIndex
,
:elastic
,
:sidekiq_inline
do
let
(
:version
)
{
20210510143200
}
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
(
3
.
minutes
)
end
end
context
'notes 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
'notes are still present in the index'
do
# Create notes on different projects to ensure they are spread across all shards
let!
(
:notes
)
{
Array
.
new
(
10
).
map
{
create
(
:note
,
project:
create
(
:project
,
:public
))
}
}
before
do
set_elasticsearch_migration_to
:migrate_notes_to_separate_index
,
including:
false
ensure_elasticsearch_index!
end
it
'removes notes 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
stub_const
(
'DeleteNotesFromOriginalIndex::MAX_ATTEMPTS'
,
2
)
# run migration up to the set MAX_ATTEMPTS set in the migration
DeleteNotesFromOriginalIndex
::
MAX_ATTEMPTS
.
times
do
expect
{
migration
.
migrate
}.
to
raise_error
(
StandardError
)
end
migration
.
migrate
expect
(
migration
.
migration_state
).
to
match
(
retry_attempt:
2
,
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 notes/
)
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