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
37ddbe2f
Commit
37ddbe2f
authored
Jun 24, 2021
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Report reindexing metrics in log
parent
7415574f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
6 deletions
+39
-6
lib/gitlab/database/postgres_index.rb
lib/gitlab/database/postgres_index.rb
+2
-0
lib/gitlab/database/reindexing/reindex_concurrently.rb
lib/gitlab/database/reindexing/reindex_concurrently.rb
+35
-4
spec/lib/gitlab/database/reindexing/reindex_concurrently_spec.rb
...b/gitlab/database/reindexing/reindex_concurrently_spec.rb
+2
-2
No files found.
lib/gitlab/database/postgres_index.rb
View file @
37ddbe2f
...
...
@@ -32,6 +32,8 @@ module Gitlab
where
(
'NOT EXISTS (?)'
,
recent_actions
)
end
alias_method
:reset
,
:reload
def
bloat_size
strong_memoize
(
:bloat_size
)
{
bloat_estimate
&
.
bloat_size
||
0
}
end
...
...
lib/gitlab/database/reindexing/reindex_concurrently.rb
View file @
37ddbe2f
...
...
@@ -3,6 +3,7 @@
module
Gitlab
module
Database
module
Reindexing
# This is a >= PG12 reindexing strategy based on `REINDEX CONCURRENTLY`
class
ReindexConcurrently
include
Gitlab
::
Utils
::
StrongMemoize
...
...
@@ -39,17 +40,47 @@ module Gitlab
# While this has been backpatched, we continue to disable expression indexes until further review.
raise
ReindexError
,
'expression indexes are currently not supported'
if
index
.
expression?
logger
.
info
"Starting reindex of
#{
index
}
"
set_statement_timeout
do
e
xecute
(
"REINDEX INDEX CONCURRENTLY
#{
quote_table_name
(
index
.
schema
)
}
.
#{
quote_table_name
(
index
.
name
)
}
"
)
with_logging
do
set_statement_timeout
do
execute
(
"REINDEX INDEX CONCURRENTLY
#{
quote_table_name
(
index
.
schema
)
}
.
#{
quote_table_name
(
index
.
name
)
}
"
)
e
nd
end
ensure
cleanup_dangling_indexes
end
private
def
with_logging
bloat_size
=
index
.
bloat_size
ondisk_size_before
=
index
.
ondisk_size_bytes
logger
.
info
(
message:
"Starting reindex of
#{
index
}
"
,
index:
index
.
identifier
,
table:
index
.
tablename
,
estimated_bloat_bytes:
bloat_size
,
index_size_before_bytes:
ondisk_size_before
)
duration
=
Benchmark
.
realtime
do
yield
end
index
.
reset
logger
.
info
(
message:
"Finished reindex of
#{
index
}
"
,
index:
index
.
identifier
,
table:
index
.
tablename
,
estimated_bloat_bytes:
bloat_size
,
index_size_before_bytes:
ondisk_size_before
,
index_size_after_bytes:
index
.
ondisk_size_bytes
,
duration_s:
duration
.
round
(
2
)
)
end
def
cleanup_dangling_indexes
Gitlab
::
Database
::
PostgresIndex
.
match
(
"
#{
Regexp
.
escape
(
index
.
name
)
}#{
TEMPORARY_INDEX_PATTERN
}
"
).
each
do
|
lingering_index
|
remove_index
(
lingering_index
)
...
...
spec/lib/gitlab/database/reindexing/reindex_concurrently_spec.rb
View file @
37ddbe2f
...
...
@@ -8,7 +8,7 @@ RSpec.describe Gitlab::Database::Reindexing::ReindexConcurrently, '#perform' do
let
(
:table_name
)
{
'_test_reindex_table'
}
let
(
:column_name
)
{
'_test_column'
}
let
(
:index_name
)
{
'_test_reindex_index'
}
let
(
:index
)
{
instance_double
(
Gitlab
::
Database
::
PostgresIndex
,
indexrelid:
42
,
name:
index_name
,
schema:
'public'
,
tablename:
table_name
,
partitioned?:
false
,
unique?:
false
,
exclusion?:
false
,
expression?:
false
,
definition:
'CREATE INDEX _test_reindex_index ON public._test_reindex_table USING btree (_test_column)'
)
}
let
(
:index
)
{
Gitlab
::
Database
::
PostgresIndex
.
by_identifier
(
"public.
#{
index_name
}
"
)
}
let
(
:logger
)
{
double
(
'logger'
,
debug:
nil
,
info:
nil
,
error:
nil
)
}
let
(
:connection
)
{
ActiveRecord
::
Base
.
connection
}
...
...
@@ -18,7 +18,7 @@ RSpec.describe Gitlab::Database::Reindexing::ReindexConcurrently, '#perform' do
id serial NOT NULL PRIMARY KEY,
#{
column_name
}
integer NOT NULL);
CREATE INDEX
#{
index
.
name
}
ON
#{
table_name
}
(
#{
column_name
}
);
CREATE INDEX
#{
index
_
name
}
ON
#{
table_name
}
(
#{
column_name
}
);
SQL
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