Class: Shard
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Shard
- Defined in:
- app/models/shard.rb
Constant Summary
Constants inherited from ApplicationRecord
Constants included from ResetOnUnionError
ResetOnUnionError::MAX_RESET_PERIOD
Class Method Summary collapse
- .by_name(name) ⇒ Object
-
.populate! ⇒ Object
Store shard names from the configuration file in the database.
Methods inherited from ApplicationRecord
cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
Methods included from SensitiveSerializableHash
Class Method Details
.by_name(name) ⇒ Object
20 21 22 |
# File 'app/models/shard.rb', line 20 def self.by_name(name) safe_find_or_create_by(name: name) end |
.populate! ⇒ Object
Store shard names from the configuration file in the database. This is not a list of active shards - we just want to assign an immutable, unique ID to every shard name for easy indexing / referencing.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/models/shard.rb', line 7 def self.populate! return unless table_exists? # The GitLab config does not change for the lifecycle of the process in_config = Gitlab.config.repositories.storages.keys.map(&:to_s) in_db = all.pluck(:name) # This may race with other processes creating shards at the same time, but # `by_name` will handle that correctly missing = in_config - in_db missing.map { |name| by_name(name) } end |