Class: ElasticGraph::Admin::ClusterConfigurator::ClusterSettingsManager
- Inherits:
-
Object
- Object
- ElasticGraph::Admin::ClusterConfigurator::ClusterSettingsManager
- Defined in:
- lib/elastic_graph/admin/cluster_configurator/cluster_settings_manager.rb
Overview
Responsible for updating datastore cluster settings based on the mode EG is in, maintenance mode or indexing mode
Instance Method Summary collapse
-
#end_index_maintenance_mode!(cluster_spec) ⇒ Object
Ends index maintenance mode, if it has not already ended.
-
#in_index_maintenance_mode(cluster_spec) ⇒ Object
Runs a block in index maintenance mode.
-
#initialize(datastore_clients_by_name:, datastore_config:, logger:) ⇒ ClusterSettingsManager
constructor
A new instance of ClusterSettingsManager.
-
#start_index_maintenance_mode!(cluster_spec) ⇒ Object
Starts index maintenance mode, if it has not already been started.
Constructor Details
#initialize(datastore_clients_by_name:, datastore_config:, logger:) ⇒ ClusterSettingsManager
16 17 18 19 20 |
# File 'lib/elastic_graph/admin/cluster_configurator/cluster_settings_manager.rb', line 16 def initialize(datastore_clients_by_name:, datastore_config:, logger:) @datastore_clients_by_name = datastore_clients_by_name @datastore_config = datastore_config @logger = logger end |
Instance Method Details
#end_index_maintenance_mode!(cluster_spec) ⇒ Object
Ends index maintenance mode, if it has not already ended. This method is idempotent.
Outside of this mode, you cannot safely delete or update the index configuration. However, new rollover indices will correctly be auto-created as documents that fall in new months or years are indexed.
‘cluster_spec` can be the name of a specific cluster (as a string) or `:all_clusters`.
43 44 45 46 47 48 49 |
# File 'lib/elastic_graph/admin/cluster_configurator/cluster_settings_manager.rb', line 43 def end_index_maintenance_mode!(cluster_spec) cluster_names_for(cluster_spec).each do |cluster_name| datastore_client_named(cluster_name).put_persistent_cluster_settings( desired_cluster_settings(cluster_name, auto_create_index_patterns: ["*#{ROLLOVER_INDEX_INFIX_MARKER}*"]) ) end end |
#in_index_maintenance_mode(cluster_spec) ⇒ Object
Runs a block in index maintenance mode. Should be used to wrap any code that updates your index configuration.
‘cluster_spec` can be the name of a specific cluster (as a string) or `:all_clusters`.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/elastic_graph/admin/cluster_configurator/cluster_settings_manager.rb', line 54 def in_index_maintenance_mode(cluster_spec) start_index_maintenance_mode!(cluster_spec) begin yield rescue => e @logger.warn "WARNING: ClusterSettingsManager#in_index_maintenance_mode is not able to exit index maintenance mode due to exception #{e}.\n A bit of manual cleanup may be required (although a re-try should be idempotent)." raise # re-raise the same error else # Note: we intentionally do not end maintenance mode in an `ensure` block, because if an exception # happens while we `yield`, we do _not_ want to exit maintenance mode. Exiting maintenance mode # could put us in a state where indices are dynamically created when we do not want them to be. end_index_maintenance_mode!(cluster_spec) end end |
#start_index_maintenance_mode!(cluster_spec) ⇒ Object
Starts index maintenance mode, if it has not already been started. This method is idempotent.
In index maintenance mode, you can safely delete or update the index configuration without worrying about indices being auto-created with dynamic mappings (e.g. due to an indexing race condition). While in this mode, indexing operations on documents that fall into new rollover indices may fail since the auto-creation of those indices is disabled.
‘cluster_spec` can be the name of a specific cluster (as a string) or `:all_clusters`.
30 31 32 33 34 |
# File 'lib/elastic_graph/admin/cluster_configurator/cluster_settings_manager.rb', line 30 def start_index_maintenance_mode!(cluster_spec) cluster_names_for(cluster_spec).each do |cluster_name| datastore_client_named(cluster_name).put_persistent_cluster_settings(desired_cluster_settings(cluster_name)) end end |