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
e053a3e1
Commit
e053a3e1
authored
Jul 12, 2021
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move into proper scopes
This moves the idea of "candidate indexes" into a proper scope on the model
parent
f8de35f7
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
40 additions
and
21 deletions
+40
-21
lib/gitlab/database/postgres_index.rb
lib/gitlab/database/postgres_index.rb
+6
-1
lib/gitlab/database/reindexing.rb
lib/gitlab/database/reindexing.rb
+0
-6
lib/tasks/gitlab/db.rake
lib/tasks/gitlab/db.rake
+1
-1
spec/lib/gitlab/database/postgres_index_spec.rb
spec/lib/gitlab/database/postgres_index_spec.rb
+31
-0
spec/lib/gitlab/database/reindexing_spec.rb
spec/lib/gitlab/database/reindexing_spec.rb
+0
-11
spec/tasks/gitlab/db_rake_spec.rb
spec/tasks/gitlab/db_rake_spec.rb
+2
-2
No files found.
lib/gitlab/database/postgres_index.rb
View file @
e053a3e1
...
...
@@ -19,7 +19,12 @@ module Gitlab
end
# Indexes with reindexing support
scope
:reindexing_support
,
->
{
where
(
partitioned:
false
,
exclusion:
false
,
expression:
false
,
type:
Gitlab
::
Database
::
Reindexing
::
SUPPORTED_TYPES
)
}
scope
:reindexing_support
,
->
do
where
(
partitioned:
false
,
exclusion:
false
,
expression:
false
,
type:
Gitlab
::
Database
::
Reindexing
::
SUPPORTED_TYPES
)
.
not_match
(
"
#{
Gitlab
::
Database
::
Reindexing
::
ReindexConcurrently
::
TEMPORARY_INDEX_PATTERN
}
$"
)
end
scope
:reindexing_leftovers
,
->
{
match
(
"
#{
Gitlab
::
Database
::
Reindexing
::
ReindexConcurrently
::
TEMPORARY_INDEX_PATTERN
}
$"
)
}
scope
:not_match
,
->
(
regex
)
{
where
(
"name !~ ?"
,
regex
)
}
...
...
lib/gitlab/database/reindexing.rb
View file @
e053a3e1
...
...
@@ -14,12 +14,6 @@ module Gitlab
Coordinator
.
new
(
index
).
perform
end
end
def
self
.
candidate_indexes
Gitlab
::
Database
::
PostgresIndex
.
not_match
(
"
#{
ReindexConcurrently
::
TEMPORARY_INDEX_PATTERN
}
$"
)
.
reindexing_support
end
end
end
end
lib/tasks/gitlab/db.rake
View file @
e053a3e1
...
...
@@ -161,7 +161,7 @@ namespace :gitlab do
exit
end
indexes
=
Gitlab
::
Database
::
Reindexing
.
candidate_indexes
indexes
=
Gitlab
::
Database
::
PostgresIndex
.
reindexing_support
if
identifier
=
args
[
:index_name
]
raise
ArgumentError
,
"Index name is not fully qualified with a schema:
#{
identifier
}
"
unless
identifier
=~
/^\w+\.\w+$/
...
...
spec/lib/gitlab/database/postgres_index_spec.rb
View file @
e053a3e1
...
...
@@ -40,6 +40,37 @@ RSpec.describe Gitlab::Database::PostgresIndex do
expect
(
types
&
%w(btree gist)
).
to
eq
(
types
)
end
context
'with leftover indexes'
do
before
do
ActiveRecord
::
Base
.
connection
.
execute
(
<<~
SQL
)
CREATE INDEX foobar_ccnew ON users (id);
CREATE INDEX foobar_ccnew1 ON users (id);
SQL
end
subject
{
described_class
.
reindexing_support
.
map
(
&
:name
)
}
it
'excludes temporary indexes from reindexing'
do
expect
(
subject
).
not_to
include
(
'foobar_ccnew'
)
expect
(
subject
).
not_to
include
(
'foobar_ccnew1'
)
end
end
end
describe
'.reindexing_leftovers'
do
subject
{
described_class
.
reindexing_leftovers
}
before
do
ActiveRecord
::
Base
.
connection
.
execute
(
<<~
SQL
)
CREATE INDEX foobar_ccnew ON users (id);
CREATE INDEX foobar_ccnew1 ON users (id);
SQL
end
it
'retrieves leftover indexes matching the /_ccnew[0-9]*$/ pattern'
do
expect
(
subject
.
map
(
&
:name
)).
to
eq
(
%w(foobar_ccnew foobar_ccnew1)
)
end
end
describe
'.not_match'
do
...
...
spec/lib/gitlab/database/reindexing_spec.rb
View file @
e053a3e1
...
...
@@ -25,15 +25,4 @@ RSpec.describe Gitlab::Database::Reindexing do
subject
end
end
describe
'.candidate_indexes'
do
subject
{
described_class
.
candidate_indexes
}
it
'retrieves regular indexes that are no left-overs from previous runs'
do
result
=
double
expect
(
Gitlab
::
Database
::
PostgresIndex
).
to
receive_message_chain
(
'not_match.reindexing_support'
).
with
(
'\_ccnew[0-9]*$'
).
with
(
no_args
).
and_return
(
result
)
expect
(
subject
).
to
eq
(
result
)
end
end
end
spec/tasks/gitlab/db_rake_spec.rb
View file @
e053a3e1
...
...
@@ -203,7 +203,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do
context
'when no index_name is given'
do
it
'uses all candidate indexes'
do
expect
(
Gitlab
::
Database
::
Reindexing
).
to
receive
(
:candidate_indexes
).
and_return
(
indexes
)
expect
(
Gitlab
::
Database
::
PostgresIndex
).
to
receive
(
:reindexing_support
).
and_return
(
indexes
)
expect
(
Gitlab
::
Database
::
Reindexing
).
to
receive
(
:perform
).
with
(
indexes
)
run_rake_task
(
'gitlab:db:reindex'
)
...
...
@@ -214,7 +214,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do
let
(
:index
)
{
double
(
'index'
)
}
before
do
allow
(
Gitlab
::
Database
::
Reindexing
).
to
receive
(
:candidate_indexes
).
and_return
(
indexes
)
allow
(
Gitlab
::
Database
::
PostgresIndex
).
to
receive
(
:reindexing_support
).
and_return
(
indexes
)
end
it
'calls the index rebuilder with the proper arguments'
do
...
...
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