Class: Gitlab::Database::LoadBalancing::Configuration
- Inherits:
-
Object
- Object
- Gitlab::Database::LoadBalancing::Configuration
- Defined in:
- lib/gitlab/database/load_balancing/configuration.rb
Overview
Configuration settings for a single LoadBalancer instance.
Instance Attribute Summary collapse
-
#hosts ⇒ Object
Returns the value of attribute hosts.
-
#max_replication_difference ⇒ Object
Returns the value of attribute max_replication_difference.
-
#max_replication_lag_time ⇒ Object
Returns the value of attribute max_replication_lag_time.
-
#replica_check_interval ⇒ Object
Returns the value of attribute replica_check_interval.
-
#service_discovery ⇒ Object
Returns the value of attribute service_discovery.
Class Method Summary collapse
-
.for_model(model) ⇒ Object
Creates a configuration object for the given ActiveRecord model.
Instance Method Summary collapse
- #connection_specification_name ⇒ Object
- #db_config ⇒ Object
- #db_config_name ⇒ Object
-
#initialize(model, hosts = []) ⇒ Configuration
constructor
A new instance of Configuration.
-
#load_balancing_enabled? ⇒ Boolean
Returns ‘true` if the use of load balancing replicas should be enabled.
- #pool_size ⇒ Object
-
#service_discovery_enabled? ⇒ Boolean
This is disabled for Rake tasks to ensure e.g.
Constructor Details
#initialize(model, hosts = []) ⇒ Configuration
Returns a new instance of Configuration.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/gitlab/database/load_balancing/configuration.rb', line 47 def initialize(model, hosts = []) @max_replication_difference = 8.megabytes @max_replication_lag_time = 60.0 @replica_check_interval = 60.0 @model = model @hosts = hosts @service_discovery = { nameserver: 'localhost', port: 8600, record: nil, record_type: 'A', interval: 60, disconnect_timeout: 120, use_tcp: false, max_replica_pools: nil } end |
Instance Attribute Details
#hosts ⇒ Object
Returns the value of attribute hosts.
8 9 10 |
# File 'lib/gitlab/database/load_balancing/configuration.rb', line 8 def hosts @hosts end |
#max_replication_difference ⇒ Object
Returns the value of attribute max_replication_difference.
8 9 10 |
# File 'lib/gitlab/database/load_balancing/configuration.rb', line 8 def max_replication_difference @max_replication_difference end |
#max_replication_lag_time ⇒ Object
Returns the value of attribute max_replication_lag_time.
8 9 10 |
# File 'lib/gitlab/database/load_balancing/configuration.rb', line 8 def max_replication_lag_time @max_replication_lag_time end |
#replica_check_interval ⇒ Object
Returns the value of attribute replica_check_interval.
8 9 10 |
# File 'lib/gitlab/database/load_balancing/configuration.rb', line 8 def replica_check_interval @replica_check_interval end |
#service_discovery ⇒ Object
Returns the value of attribute service_discovery.
8 9 10 |
# File 'lib/gitlab/database/load_balancing/configuration.rb', line 8 def service_discovery @service_discovery end |
Class Method Details
.for_model(model) ⇒ Object
Creates a configuration object for the given ActiveRecord model.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gitlab/database/load_balancing/configuration.rb', line 13 def self.for_model(model) cfg = model.connection_db_config.configuration_hash.deep_symbolize_keys lb_cfg = cfg[:load_balancing] || {} config = new(model) if (diff = lb_cfg[:max_replication_difference]) config.max_replication_difference = diff end if (lag = lb_cfg[:max_replication_lag_time]) config.max_replication_lag_time = lag.to_f end if (interval = lb_cfg[:replica_check_interval]) config.replica_check_interval = interval.to_f end if (hosts = lb_cfg[:hosts]) config.hosts = hosts end discover = lb_cfg[:discover] || {} # We iterate over the known/default keys so we don't end up with # random keys in our configuration hash. config.service_discovery.each do |key, _| if (value = discover[key]) config.service_discovery[key] = value end end config end |
Instance Method Details
#connection_specification_name ⇒ Object
69 70 71 |
# File 'lib/gitlab/database/load_balancing/configuration.rb', line 69 def connection_specification_name @model.connection_specification_name end |
#db_config ⇒ Object
73 74 75 |
# File 'lib/gitlab/database/load_balancing/configuration.rb', line 73 def db_config @model.connection_db_config end |
#db_config_name ⇒ Object
65 66 67 |
# File 'lib/gitlab/database/load_balancing/configuration.rb', line 65 def db_config_name @model.connection_db_config.name.to_sym end |
#load_balancing_enabled? ⇒ Boolean
Returns ‘true` if the use of load balancing replicas should be enabled.
This is disabled for Rake tasks to ensure e.g. database migrations always produce consistent results.
93 94 95 96 97 |
# File 'lib/gitlab/database/load_balancing/configuration.rb', line 93 def load_balancing_enabled? return false if Gitlab::Runtime.rake? hosts.any? || service_discovery_enabled? end |
#pool_size ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/gitlab/database/load_balancing/configuration.rb', line 77 def pool_size # The pool size may change when booting up GitLab, as GitLab enforces # a certain number of threads. If a Configuration is memoized, this # can lead to incorrect pool sizes. # # To support this scenario, we always attempt to read the pool size # from the model's configuration. @model.connection_db_config.configuration_hash[:pool] || Database.default_pool_size end |
#service_discovery_enabled? ⇒ Boolean
This is disabled for Rake tasks to ensure e.g. database migrations always produce consistent results.
101 102 103 104 105 |
# File 'lib/gitlab/database/load_balancing/configuration.rb', line 101 def service_discovery_enabled? return false if Gitlab::Runtime.rake? service_discovery[:record].present? end |