Commit fa7ed8b6 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Mark some module methods as private

parent 3a27579c
...@@ -18,54 +18,58 @@ module Gitlab ...@@ -18,54 +18,58 @@ module Gitlab
end end
end end
def self.register_models(models) class << self
registered_models.merge(models) def register_models(models)
end registered_models.merge(models)
end
def self.register_tables(tables) def register_tables(tables)
registered_tables.merge(tables) registered_tables.merge(tables)
end end
def self.registered_models def sync_partitions(models_to_sync = registered_for_sync)
@registered_models ||= Set.new Gitlab::AppLogger.info(message: 'Syncing dynamic postgres partitions')
end
def self.registered_tables Gitlab::Database::EachDatabase.each_model_connection(models_to_sync) do |model|
@registered_tables ||= Set.new PartitionManager.new(model).sync_partitions
end end
def self.registered_for_sync Gitlab::AppLogger.info(message: 'Finished sync of dynamic postgres partitions')
registered_models + registered_tables.map do |table|
TableWithoutModel.new(**table)
end end
end
def self.sync_partitions(models_to_sync = registered_for_sync) def report_metrics(models_to_monitor = registered_models)
Gitlab::AppLogger.info(message: 'Syncing dynamic postgres partitions') partition_monitoring = PartitionMonitoring.new
Gitlab::Database::EachDatabase.each_model_connection(models_to_sync) do |model| Gitlab::Database::EachDatabase.each_model_connection(models_to_monitor) do |model|
PartitionManager.new(model).sync_partitions partition_monitoring.report_metrics_for_model(model)
end
end end
Gitlab::AppLogger.info(message: 'Finished sync of dynamic postgres partitions') def drop_detached_partitions
end Gitlab::AppLogger.info(message: 'Dropping detached postgres partitions')
def self.report_metrics(models_to_monitor = registered_models) Gitlab::Database::EachDatabase.each_database_connection do
partition_monitoring = PartitionMonitoring.new DetachedPartitionDropper.new.perform
end
Gitlab::Database::EachDatabase.each_model_connection(models_to_monitor) do |model| Gitlab::AppLogger.info(message: 'Finished dropping detached postgres partitions')
partition_monitoring.report_metrics_for_model(model)
end end
end
def self.drop_detached_partitions private
Gitlab::AppLogger.info(message: 'Dropping detached postgres partitions')
Gitlab::Database::EachDatabase.each_database_connection do def registered_models
DetachedPartitionDropper.new.perform @registered_models ||= Set.new
end 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 end
end end
......
...@@ -45,7 +45,7 @@ RSpec.describe Gitlab::Database::Partitioning do ...@@ -45,7 +45,7 @@ RSpec.describe Gitlab::Database::Partitioning do
let(:model) { double('model') } let(:model) { double('model') }
it 'manages partitions for each registered model' do 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) allow(described_class).to receive(:registered_for_sync)
.and_return(registered_for_sync) .and_return(registered_for_sync)
...@@ -76,7 +76,7 @@ RSpec.describe Gitlab::Database::Partitioning do ...@@ -76,7 +76,7 @@ RSpec.describe Gitlab::Database::Partitioning do
end end
expect(Gitlab::Database::EachDatabase).to receive(:each_model_connection) 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(model1)
.and_yield(model2) .and_yield(model2)
...@@ -128,7 +128,7 @@ RSpec.describe Gitlab::Database::Partitioning do ...@@ -128,7 +128,7 @@ RSpec.describe Gitlab::Database::Partitioning do
context 'ensure that the registered models have partitioning strategy' do context 'ensure that the registered models have partitioning strategy' do
it 'fails when partitioning_strategy is not specified for the model' 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 end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment