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
8fd2496a
Commit
8fd2496a
authored
Jun 23, 2021
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Feature flag for PG12 reindexing
parent
31bf56d7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
39 deletions
+72
-39
config/feature_flags/development/database_reindexing_pg12.yml
...ig/feature_flags/development/database_reindexing_pg12.yml
+8
-0
lib/gitlab/database/reindexing/coordinator.rb
lib/gitlab/database/reindexing/coordinator.rb
+7
-1
spec/lib/gitlab/database/reindexing/coordinator_spec.rb
spec/lib/gitlab/database/reindexing/coordinator_spec.rb
+57
-38
No files found.
config/feature_flags/development/database_reindexing_pg12.yml
0 → 100644
View file @
8fd2496a
---
name
:
database_reindexing_pg12
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/64695
rollout_issue_url
:
https://gitlab.com/gitlab-org/gitlab/-/issues/334372
milestone
:
'
14.1'
type
:
development
group
:
group::database
default_enabled
:
false
lib/gitlab/database/reindexing/coordinator.rb
View file @
8fd2496a
...
...
@@ -41,7 +41,13 @@ module Gitlab
end
def
perform_for
(
index
,
action
)
ConcurrentReindex
.
new
(
index
).
perform
strategy
=
if
Feature
.
enabled?
(
:database_reindexing_pg12
,
type: :development
)
ReindexConcurrently
else
ConcurrentReindex
end
strategy
.
new
(
index
).
perform
rescue
StandardError
action
.
state
=
:failed
...
...
spec/lib/gitlab/database/reindexing/coordinator_spec.rb
View file @
8fd2496a
...
...
@@ -9,13 +9,6 @@ RSpec.describe Gitlab::Database::Reindexing::Coordinator do
describe
'.perform'
do
subject
{
described_class
.
new
(
index
,
notifier
).
perform
}
before
do
swapout_view_for_table
(
:postgres_indexes
)
allow
(
Gitlab
::
Database
::
Reindexing
::
ConcurrentReindex
).
to
receive
(
:new
).
with
(
index
).
and_return
(
reindexer
)
allow
(
Gitlab
::
Database
::
Reindexing
::
ReindexAction
).
to
receive
(
:create_for
).
with
(
index
).
and_return
(
action
)
end
let
(
:index
)
{
create
(
:postgres_index
)
}
let
(
:notifier
)
{
instance_double
(
Gitlab
::
Database
::
Reindexing
::
GrafanaNotifier
,
notify_start:
nil
,
notify_end:
nil
)
}
let
(
:reindexer
)
{
instance_double
(
Gitlab
::
Database
::
Reindexing
::
ConcurrentReindex
,
perform:
nil
)
}
...
...
@@ -26,57 +19,83 @@ RSpec.describe Gitlab::Database::Reindexing::Coordinator do
let
(
:lease_timeout
)
{
1
.
day
}
let
(
:uuid
)
{
'uuid'
}
context
'locking'
do
it
'acquires a lock while reindexing'
do
expect
(
lease
).
to
receive
(
:try_obtain
).
ordered
.
and_return
(
uuid
)
shared_examples_for
'reindexing coordination'
do
context
'locking'
do
it
'acquires a lock while reindexing'
do
expect
(
lease
).
to
receive
(
:try_obtain
).
ordered
.
and_return
(
uuid
)
expect
(
reindexer
).
to
receive
(
:perform
).
ordered
expect
(
reindexer
).
to
receive
(
:perform
).
ordered
expect
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:cancel
).
ordered
.
with
(
lease_key
,
uuid
)
expect
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:cancel
).
ordered
.
with
(
lease_key
,
uuid
)
subject
end
subject
end
it
'does not perform reindexing actions if lease is not granted'
do
expect
(
lease
).
to
receive
(
:try_obtain
).
ordered
.
and_return
(
false
)
expect
(
Gitlab
::
Database
::
Reindexing
::
ConcurrentReindex
).
not_to
receive
(
:new
)
it
'does not perform reindexing actions if lease is not granted'
do
expect
(
lease
).
to
receive
(
:try_obtain
).
ordered
.
and_return
(
false
)
expect
(
Gitlab
::
Database
::
Reindexing
::
ConcurrentReindex
).
not_to
receive
(
:new
)
subject
subject
end
end
end
context
'notifications'
do
it
'sends #notify_start before reindexing'
do
expect
(
notifier
).
to
receive
(
:notify_start
).
with
(
action
).
ordered
expect
(
reindexer
).
to
receive
(
:perform
).
ordered
context
'notifications'
do
it
'sends #notify_start before reindexing'
do
expect
(
notifier
).
to
receive
(
:notify_start
).
with
(
action
).
ordered
expect
(
reindexer
).
to
receive
(
:perform
).
ordered
subject
end
subject
it
'sends #notify_end after reindexing and updating the action is done'
do
expect
(
action
).
to
receive
(
:finish
).
ordered
expect
(
notifier
).
to
receive
(
:notify_end
).
with
(
action
).
ordered
subject
end
end
it
'sends #notify_end after reindexing and updating the action is done'
do
expect
(
action
).
to
receive
(
:finish
).
ordered
expect
(
notifier
).
to
receive
(
:notify_end
).
with
(
action
).
ordered
context
'action tracking'
do
it
'calls #finish on the action'
do
expect
(
reindexer
).
to
receive
(
:perform
).
ordered
expect
(
action
).
to
receive
(
:finish
).
ordered
subject
end
it
'upon error, it still calls finish and raises the error'
do
expect
(
reindexer
).
to
receive
(
:perform
).
ordered
.
and_raise
(
'something went wrong'
)
expect
(
action
).
to
receive
(
:finish
).
ordered
subject
expect
{
subject
}.
to
raise_error
(
/something went wrong/
)
expect
(
action
).
to
be_failed
end
end
end
context
'
action tracking
'
do
it
'calls #finish on the action'
do
expect
(
reindexer
).
to
receive
(
:perform
).
ordered
expect
(
action
).
to
receive
(
:finish
).
ordered
context
'
legacy reindexing method (< PG12) - to be removed
'
do
before
do
stub_feature_flags
(
database_reindexing_pg12:
false
)
swapout_view_for_table
(
:postgres_indexes
)
subject
allow
(
Gitlab
::
Database
::
Reindexing
::
ConcurrentReindex
).
to
receive
(
:new
).
with
(
index
).
and_return
(
reindexer
)
allow
(
Gitlab
::
Database
::
Reindexing
::
ReindexAction
).
to
receive
(
:create_for
).
with
(
index
).
and_return
(
action
)
end
it
'upon error, it still calls finish and raises the error'
do
expect
(
reindexer
).
to
receive
(
:perform
).
ordered
.
and_raise
(
'something went wrong'
)
expect
(
action
).
to
receive
(
:finish
).
ordered
it_behaves_like
'reindexing coordination'
end
expect
{
subject
}.
to
raise_error
(
/something went wrong/
)
context
'PG12 reindexing method'
do
before
do
stub_feature_flags
(
database_reindexing_pg12:
true
)
swapout_view_for_table
(
:postgres_indexes
)
expect
(
action
).
to
be_failed
allow
(
Gitlab
::
Database
::
Reindexing
::
ReindexConcurrently
).
to
receive
(
:new
).
with
(
index
).
and_return
(
reindexer
)
allow
(
Gitlab
::
Database
::
Reindexing
::
ReindexAction
).
to
receive
(
:create_for
).
with
(
index
).
and_return
(
action
)
end
it_behaves_like
'reindexing coordination'
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