Module: Gitlab::Database::Partitioning
- Defined in:
- lib/gitlab/database/partitioning.rb,
lib/gitlab/database/partitioning/replace_table.rb,
lib/gitlab/database/partitioning/time_partition.rb,
lib/gitlab/database/partitioning/monthly_strategy.rb,
lib/gitlab/database/partitioning/partition_manager.rb,
lib/gitlab/database/partitioning/list/convert_table.rb,
lib/gitlab/database/partitioning/partition_monitoring.rb,
lib/gitlab/database/partitioning/sliding_list_strategy.rb,
lib/gitlab/database/partitioning/ci_sliding_list_strategy.rb,
lib/gitlab/database/partitioning/detached_partition_dropper.rb,
lib/gitlab/database/partitioning/list/locking_configuration.rb,
lib/gitlab/database/partitioning/single_numeric_list_partition.rb
Defined Under Namespace
Modules: List Classes: CiSlidingListStrategy, DetachedPartitionDropper, MonthlyStrategy, PartitionManager, PartitionMonitoring, ReplaceTable, SingleNumericListPartition, SlidingListStrategy, TableWithoutModel, TimePartition
Class Method Summary collapse
- .drop_detached_partitions ⇒ Object
- .register_models(models) ⇒ Object
- .register_tables(tables) ⇒ Object
- .registered_models ⇒ Object
- .registered_tables ⇒ Object
- .report_metrics(models_to_monitor = registered_models) ⇒ Object
- .sync_partitions(models_to_sync = registered_for_sync, only_on: nil, analyze: true) ⇒ Object
- .sync_partitions_ignore_db_error(analyze: false) ⇒ Object
Class Method Details
.drop_detached_partitions ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/gitlab/database/partitioning.rb', line 64 def drop_detached_partitions return if Feature.enabled?(:disallow_database_ddl_feature_flags, type: :ops) return unless Feature.enabled?(:partition_manager_sync_partitions, type: :ops) Gitlab::AppLogger.info(message: 'Dropping detached postgres partitions') Gitlab::Database::EachDatabase.each_connection do DetachedPartitionDropper.new.perform end Gitlab::AppLogger.info(message: 'Finished dropping detached postgres partitions') end |
.register_models(models) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/gitlab/database/partitioning.rb', line 11 def register_models(models) models.each do |model| raise "#{model} should have partitioning strategy defined" unless model.respond_to?(:partitioning_strategy) registered_models << model end end |
.register_tables(tables) ⇒ Object
19 20 21 |
# File 'lib/gitlab/database/partitioning.rb', line 19 def register_tables(tables) registered_tables.merge(tables) end |
.registered_models ⇒ Object
78 79 80 |
# File 'lib/gitlab/database/partitioning.rb', line 78 def registered_models @registered_models ||= Set.new end |
.registered_tables ⇒ Object
82 83 84 |
# File 'lib/gitlab/database/partitioning.rb', line 82 def registered_tables @registered_tables ||= Set.new end |
.report_metrics(models_to_monitor = registered_models) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/gitlab/database/partitioning.rb', line 56 def report_metrics(models_to_monitor = registered_models) partition_monitoring = PartitionMonitoring.new Gitlab::Database::EachDatabase.each_model_connection(models_to_monitor) do |model| partition_monitoring.report_metrics_for_model(model) end end |
.sync_partitions(models_to_sync = registered_for_sync, only_on: nil, analyze: true) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/gitlab/database/partitioning.rb', line 29 def sync_partitions(models_to_sync = registered_for_sync, only_on: nil, analyze: true) return if Feature.enabled?(:disallow_database_ddl_feature_flags, type: :ops) return unless Feature.enabled?(:partition_manager_sync_partitions, type: :ops) Gitlab::AppLogger.info(message: 'Syncing dynamic postgres partitions') Gitlab::Database::EachDatabase.each_model_connection(models_to_sync, only_on: only_on) do |model| PartitionManager.new(model).sync_partitions(analyze: analyze) end unless only_on models_to_sync.each do |model| next if model < ::Gitlab::Database::SharedModel && !(model < TableWithoutModel) model_connection_name = model.connection_db_config.name Gitlab::Database::EachDatabase.each_connection(include_shared: false) do |connection, connection_name| if connection_name != model_connection_name PartitionManager.new(model, connection: connection).sync_partitions(analyze: analyze) end end end end Gitlab::AppLogger.info(message: 'Finished sync of dynamic postgres partitions') end |
.sync_partitions_ignore_db_error(analyze: false) ⇒ Object
23 24 25 26 27 |
# File 'lib/gitlab/database/partitioning.rb', line 23 def sync_partitions_ignore_db_error(analyze: false) sync_partitions(analyze: analyze) unless ENV['DISABLE_POSTGRES_PARTITION_CREATION_ON_STARTUP'] rescue ActiveRecord::ActiveRecordError, PG::Error # ignore - happens when Rake tasks yet have to create a database, e.g. for testing end |