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
fa7ed8b6
Commit
fa7ed8b6
authored
Oct 22, 2021
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mark some module methods as private
parent
3a27579c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
35 deletions
+39
-35
lib/gitlab/database/partitioning.rb
lib/gitlab/database/partitioning.rb
+36
-32
spec/lib/gitlab/database/partitioning_spec.rb
spec/lib/gitlab/database/partitioning_spec.rb
+3
-3
No files found.
lib/gitlab/database/partitioning.rb
View file @
fa7ed8b6
...
...
@@ -18,54 +18,58 @@ module Gitlab
end
end
def
self
.
register_models
(
models
)
registered_models
.
merge
(
models
)
end
class
<<
self
def
register_models
(
models
)
registered_models
.
merge
(
models
)
end
def
self
.
register_tables
(
tables
)
registered_tables
.
merge
(
tables
)
end
def
register_tables
(
tables
)
registered_tables
.
merge
(
tables
)
end
def
self
.
registered_models
@registered_models
||=
Set
.
new
end
def
sync_partitions
(
models_to_sync
=
registered_for_sync
)
Gitlab
::
AppLogger
.
info
(
message:
'Syncing dynamic postgres partitions'
)
def
self
.
registered_tables
@registered_tables
||=
Set
.
new
end
Gitlab
::
Database
::
EachDatabase
.
each_model_connection
(
models_to_sync
)
do
|
model
|
PartitionManager
.
new
(
model
).
sync_partitions
end
def
self
.
registered_for_sync
registered_models
+
registered_tables
.
map
do
|
table
|
TableWithoutModel
.
new
(
**
table
)
Gitlab
::
AppLogger
.
info
(
message:
'Finished sync of dynamic postgres partitions'
)
end
end
def
self
.
sync_partitions
(
models_to_sync
=
registered_for_sync
)
Gitlab
::
AppLogger
.
info
(
message:
'Syncing dynamic postgres partitions'
)
def
report_metrics
(
models_to_monitor
=
registered_models
)
partition_monitoring
=
PartitionMonitoring
.
new
Gitlab
::
Database
::
EachDatabase
.
each_model_connection
(
models_to_sync
)
do
|
model
|
PartitionManager
.
new
(
model
).
sync_partitions
Gitlab
::
Database
::
EachDatabase
.
each_model_connection
(
models_to_monitor
)
do
|
model
|
partition_monitoring
.
report_metrics_for_model
(
model
)
end
end
Gitlab
::
AppLogger
.
info
(
message:
'Finished sync of dynamic postgres partitions'
)
end
def
drop_detached_partitions
Gitlab
::
AppLogger
.
info
(
message:
'Dropping detached postgres partitions'
)
def
self
.
report_metrics
(
models_to_monitor
=
registered_models
)
partition_monitoring
=
PartitionMonitoring
.
new
Gitlab
::
Database
::
EachDatabase
.
each_database_connection
do
DetachedPartitionDropper
.
new
.
perform
end
Gitlab
::
Database
::
EachDatabase
.
each_model_connection
(
models_to_monitor
)
do
|
model
|
partition_monitoring
.
report_metrics_for_model
(
model
)
Gitlab
::
AppLogger
.
info
(
message:
'Finished dropping detached postgres partitions'
)
end
end
def
self
.
drop_detached_partitions
Gitlab
::
AppLogger
.
info
(
message:
'Dropping detached postgres partitions'
)
private
Gitlab
::
Database
::
EachDatabase
.
each_database_connection
do
DetachedPartitionDropper
.
new
.
perform
def
registered_models
@registered_models
||=
Set
.
new
end
Gitlab
::
AppLogger
.
info
(
message:
'Finished dropping detached postgres partitions'
)
def
registered_tables
@registered_tables
||=
Set
.
new
end
def
registered_for_sync
registered_models
+
registered_tables
.
map
do
|
table
|
TableWithoutModel
.
new
(
**
table
)
end
end
end
end
end
...
...
spec/lib/gitlab/database/partitioning_spec.rb
View file @
fa7ed8b6
...
...
@@ -45,7 +45,7 @@ RSpec.describe Gitlab::Database::Partitioning do
let
(
:model
)
{
double
(
'model'
)
}
it
'manages partitions for each registered model'
do
registered_for_sync
=
described_class
.
registered_for_sync
registered_for_sync
=
described_class
.
__send__
(
:registered_for_sync
)
allow
(
described_class
).
to
receive
(
:registered_for_sync
)
.
and_return
(
registered_for_sync
)
...
...
@@ -76,7 +76,7 @@ RSpec.describe Gitlab::Database::Partitioning do
end
expect
(
Gitlab
::
Database
::
EachDatabase
).
to
receive
(
:each_model_connection
)
.
with
(
described_class
.
registered_models
)
.
with
(
described_class
.
__send__
(
:registered_models
)
)
.
and_yield
(
model1
)
.
and_yield
(
model2
)
...
...
@@ -128,7 +128,7 @@ RSpec.describe Gitlab::Database::Partitioning do
context
'ensure that the registered models have partitioning strategy'
do
it
'fails when partitioning_strategy is not specified for the model'
do
expect
(
described_class
.
registered_models
).
to
all
(
respond_to
(
:partitioning_strategy
))
expect
(
described_class
.
__send__
(
:registered_models
)
).
to
all
(
respond_to
(
:partitioning_strategy
))
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