From 5ea8e5f9205c71b5a3719bca5b65a2ad5bc53144 Mon Sep 17 00:00:00 2001 From: Lebedev Vadim Date: Mon, 8 Apr 2013 19:23:24 +0400 Subject: [PATCH] * Adding `server_idparameter to `mysql::config` * Adding `sql_log_bin` parameter to `mysql::config` * Adding `log_bin` parameter to `mysql::config` * Adding `max_binlog_size` parameter to `mysql::config` * Adding `binlog_do_db` parameter to `mysql::config` * Adding `expire_logs_days` parameter to `mysql::config` * Adding `log_bin_trust_function_creators` parameter to `mysql::config` * Adding `replicate_ignore_table` parameter to `mysql::config` * Adding `replicate_wild_do_table` parameter to `mysql::config` * Adding `replicate_wild_ignore_table` parameter to `mysql::config` * Adding `expire_logs_days` parameter to `mysql::params` * Adding `max_binlog_size` parameter to `mysql::params` --- manifests/config.pp | 82 +++++++++++++++++++--------- manifests/params.pp | 3 +- spec/classes/mysql_config_spec.rb | 91 +++++++++++++++++++++---------- templates/my.cnf.erb | 51 ++++++++++++----- 4 files changed, 157 insertions(+), 70 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index 04aa7f9..657361a 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -19,15 +19,14 @@ # [*default_engine] - configure a default table engine # [*root_group] - use specified group for root-owned files # [*restart] - whether to restart mysqld (true/false) -# [*character-set] - You can change the default server and -# client character set +# [*character_set] - You can change the default server and +# client character set # [*key_buffer] - Index blocks for MyISAM tables are buffered and -# are shared by all threads. key_buffer_size is the -# size of the buffer used for index blocks. +# are shared by all threads. key_buffer_size is the size of the buffer used +# for index blocks. # [*max_allowed_packet] - The maximum size of one packet or any -# generated/intermediate string, or any -# parameter sent by the mysql_stmt_send_long_data() -# C API function. +# generated/intermediate string, or any parameter sent by the +# mysql_stmt_send_long_data() C API function. # [*thread_stack] - The stack size for each thread. # [*thread_cache_size] - How many threads server should cache for reuse. # [*myisam-recover] - Set the MyISAM storage engine recovery mode. @@ -40,12 +39,35 @@ # [*tmp_table_size] - The maximum size of internal in-memory temporary # tables. # [*max_heap_table_size] - This variable sets the maximum size to which -# user-created MEMORY tables are permitted to grow. +# user-created MEMORY tables are permitted to grow. # [*table_open_cache] - The number of open tables for all threads. # [*long_query_time] - If a query takes longer than this many seconds, -# the server increments the Slow_queries status -# variable. -# +# the server increments the Slow_queries status variable. +# [*server_id] - The server ID, used in replication to give each +# master and slave a unique identity. +# [*sql_log_bin] - This variable controls whether logging to the +# binary log is done. The default value is 1. +# [*log_bin] - Enable binary logging. The server logs all +# statements that change data to the binary log, which is used for backup +# and replication. +# [*max_binlog_size] - If a write to the binary log causes the current +# log file size to exceed the value of this variable, the server rotates +# the binary logs (closes the current file and opens the next one). +# [*binlog_do_db] - This option affects binary logging in a manner +# similar to the way that --replicate-do-db affects replication. +# [*expire_logs_days] - The number of days for automatic binary log file +# removal. +# [*log_bin_trust_function_creators] - It controls whether stored function +# creators can be trusted not to create stored functions that will cause +# unsafe events to be written to the binary log. +# [*replicate_ignore_table] - Tells the slave SQL thread not to +# replicate any statement that updates the specified table, even if any +# other tables might be updated by the same statement. +# [*replicate_wild_do_table] - Tells the slave thread to restrict +# replication to statements where any of the updated tables match the +# specified database and table name patterns. +# [*replicate_wild_ignore_table] - Tells the slave thread not to +# replicate a statement where any table matches the given wildcard pattern. # # Actions: # @@ -81,21 +103,29 @@ class mysql::config( $restart = $mysql::params::restart, $purge_conf_dir = false, - $key_buffer = $mysql::params::key_buffer, - $max_allowed_packet = $mysql::params::max_allowed_packet, - $thread_stack = $mysql::params::thread_stack, - $thread_cache_size = $mysql::params::thread_cache_size, - $myisam_recover = $mysql::params::myisam_recover, - $query_cache_limit = $mysql::params::query_cache_limit, - $query_cache_size = $mysql::params::query_cache_size, - - $max_connections = 'UNSET', - $tmp_table_size = 'UNSET', - $max_heap_table_size = 'UNSET', - $table_open_cache = 'UNSET', - $long_query_time = 'UNSET', - $character_set = 'UNSET', - + $key_buffer = $mysql::params::key_buffer, + $max_allowed_packet = $mysql::params::max_allowed_packet, + $thread_stack = $mysql::params::thread_stack, + $thread_cache_size = $mysql::params::thread_cache_size, + $myisam_recover = $mysql::params::myisam_recover, + $query_cache_limit = $mysql::params::query_cache_limit, + $query_cache_size = $mysql::params::query_cache_size, + $max_binlog_size = $mysql::params::max_binlog_size, + $expire_logs_days = $mysql::params::expire_logs_days, + $max_connections = 'UNSET', + $tmp_table_size = 'UNSET', + $max_heap_table_size = 'UNSET', + $table_open_cache = 'UNSET', + $long_query_time = 'UNSET', + $character_set = 'UNSET', + $server_id = 'UNSET', + $sql_log_bin = 'UNSET', + $log_bin = 'UNSET', + $binlog_do_db = 'UNSET', + $log_bin_trust_function_creators = 'UNSET', + $replicate_ignore_table = 'UNSET', + $replicate_wild_do_table = 'UNSET', + $replicate_wild_ignore_table = 'UNSET', ) inherits mysql::params { File { diff --git a/manifests/params.pp b/manifests/params.pp index feaf4d5..f127fe1 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -24,7 +24,8 @@ class mysql::params { $myisam_recover = 'BACKUP' $query_cache_limit = '1M' $query_cache_size = '16M' - + $expire_logs_days = 10 + $max_binlog_size = 100M case $::operatingsystem { 'Ubuntu': { diff --git a/spec/classes/mysql_config_spec.rb b/spec/classes/mysql_config_spec.rb index 002fc98..55726c9 100644 --- a/spec/classes/mysql_config_spec.rb +++ b/spec/classes/mysql_config_spec.rb @@ -3,27 +3,37 @@ describe 'mysql::config' do let :constant_parameter_defaults do { - :root_password => 'UNSET', - :old_root_password => '', - :bind_address => '127.0.0.1', - :port => '3306', - :etc_root_password => false, - :datadir => '/var/lib/mysql', - :default_engine => 'UNSET', - :ssl => false, - :key_buffer => '16M', - :max_allowed_packet => '16M', - :thread_stack => '256K', - :thread_cache_size => 8, - :myisam_recover => 'BACKUP', - :query_cache_limit => '1M', - :query_cache_size => '16M', - :character_set => 'UNSET', - :max_connections => 'UNSET', - :tmp_table_size => 'UNSET', - :max_heap_table_size => 'UNSET', - :table_open_cache => 'UNSET', - :long_query_time => 'UNSET', + :root_password => 'UNSET', + :old_root_password => '', + :bind_address => '127.0.0.1', + :port => '3306', + :etc_root_password => false, + :datadir => '/var/lib/mysql', + :default_engine => 'UNSET', + :ssl => false, + :key_buffer => '16M', + :max_allowed_packet => '16M', + :thread_stack => '256K', + :thread_cache_size => 8, + :myisam_recover => 'BACKUP', + :query_cache_limit => '1M', + :query_cache_size => '16M', + :max_binlog_size => '100M', + :expire_logs_days => 10, + :character_set => 'UNSET', + :max_connections => 'UNSET', + :tmp_table_size => 'UNSET', + :max_heap_table_size => 'UNSET', + :table_open_cache => 'UNSET', + :long_query_time => 'UNSET', + :server_id => 'UNSET', + :sql_log_bin => 'UNSET', + :log_bin => 'UNSET', + :binlog_do_db => 'UNSET', + :log_bin_trust_function_creators => 'UNSET', + :replicate_ignore_table => 'UNSET', + :replicate_wild_do_table => 'UNSET', + :replicate_wild_ignore_table => 'UNSET', } end @@ -178,14 +188,16 @@ describe 'mysql::config' do "socket = #{param_values[:socket]}", "pid-file = #{param_values[:pidfile]}", "datadir = #{param_values[:datadir]}", - "bind-address = #{param_values[:bind_address]}", - "key_buffer = #{param_values[:key_buffer]}", - "max_allowed_packet = #{param_values[:max_allowed_packet]}", - "thread_stack = #{param_values[:thread_stack]}", - "thread_cache_size = #{param_values[:thread_cache_size]}", - "myisam-recover = #{param_values[:myisam_recover]}", - "query_cache_limit = #{param_values[:query_cache_limit]}", - "query_cache_size = #{param_values[:query_cache_size]}", + "bind-address = #{param_values[:bind_address]}", + "key_buffer = #{param_values[:key_buffer]}", + "max_allowed_packet = #{param_values[:max_allowed_packet]}", + "thread_stack = #{param_values[:thread_stack]}", + "thread_cache_size = #{param_values[:thread_cache_size]}", + "myisam-recover = #{param_values[:myisam_recover]}", + "query_cache_limit = #{param_values[:query_cache_limit]}", + "query_cache_size = #{param_values[:query_cache_size]}", + "expire_logs_days = #{param_values[:expire_logs_days]}", + "max_binlog_size = #{param_values[:max_binlog_size]}", ] if param_values[:max_connections] != 'UNSET' expected_lines = expected_lines | [ "max_connections = #{param_values[:max_connections]}" ] @@ -208,6 +220,27 @@ describe 'mysql::config' do if param_values[:character_set] != 'UNSET' expected_lines = expected_lines | [ "character-set-server = #{param_values[:character_set]}" ] end + if param_values[:sql_log_bin] != 'UNSET' + expected_lines = expected_lines | [ "sql_log_bin = #{param_values[:sql_log_bin]}" ] + end + if param_values[:log_bin] != 'UNSET' + expected_lines = expected_lines | [ "log-bin = #{param_values[:log_bin]}" ] + end + if param_values[:binlog_do_db] != 'UNSET' + expected_lines = expected_lines | [ "binlog-do-db = #{param_values[:binlog_do_db]}" ] + end + if param_values[:log_bin_trust_function_creators] != 'UNSET' + expected_lines = expected_lines | [ "log_bin_trust_function_creators = #{param_values[:log_bin_trust_function_creators]}" ] + end + if param_values[:replicate_ignore_table] != 'UNSET' + expected_lines = expected_lines | [ "replicate-ignore-table = #{param_values[:replicate_ignore_table]}" ] + end + if param_values[:replicate_wild_do_table] != 'UNSET' + expected_lines = expected_lines | [ "replicate-wild-do-table = #{param_values[:replicate_wild_do_table]}" ] + end + if param_values[:replicate_wild_ignore_table] != 'UNSET' + expected_lines = expected_lines | [ "replicate-wild-ignore-table = #{param_values[:replicate_wild_ignore_table]}" ] + end if param_values[:ssl] expected_lines = expected_lines | [ diff --git a/templates/my.cnf.erb b/templates/my.cnf.erb index 78b50ca..4569b89 100644 --- a/templates/my.cnf.erb +++ b/templates/my.cnf.erb @@ -20,17 +20,18 @@ datadir = <%= datadir %> tmpdir = /tmp skip-external-locking -<% if bind_address %> -bind-address = <%= bind_address %> -<% end %> - -key_buffer = <%= key_buffer %> -max_allowed_packet = <%= max_allowed_packet %> -thread_stack = <%= thread_stack %> -thread_cache_size = <%= thread_cache_size %> -myisam-recover = <%= myisam_recover %> -query_cache_limit = <%= query_cache_limit %> -query_cache_size = <%= query_cache_size %> +<% if bind_address -%> +bind-address = <%= bind_address %> +<% end -%> +key_buffer = <%= key_buffer %> +max_allowed_packet = <%= max_allowed_packet %> +thread_stack = <%= thread_stack %> +thread_cache_size = <%= thread_cache_size %> +myisam-recover = <%= myisam_recover %> +query_cache_limit = <%= query_cache_limit %> +query_cache_size = <%= query_cache_size %> +expire_logs_days = <%= expire_logs_days %> +max_binlog_size = <%= max_binlog_size %> <% if max_connections != 'UNSET' -%> max_connections = <%= max_connections %> @@ -47,12 +48,34 @@ table_open_cache = <%= table_open_cache %> <% if long_query_time != 'UNSET' -%> long_query_time = <%= long_query_time %> <% end -%> +<% if server_id != 'UNSET' -%> +server-id = <%= server_id %> +<% end -%> +<% if sql_log_bin != 'UNSET' -%> +sql_log_bin = <%= sql_log_bin %> +<% end -%> +<% if log_bin != 'UNSET' -%> +log-bin = <%= log_bin %> +<% end -%> +<% if binlog_do_db != 'UNSET' -%> +binlog-do-db = <%= binlog_do_db %> +<% end -%> +<% if log_bin_trust_function_creators != 'UNSET' -%> +log_bin_trust_function_creators = <%= log_bin_trust_function_creators %> +<% end -%> +<% if replicate_ignore_table != 'UNSET' -%> +replicate-ignore-table = <%= replicate_ignore_table %> +<% end -%> +<% if replicate_wild_do_table != 'UNSET' -%> +replicate-wild-do-table = <%= replicate_wild_do_table %> +<% end -%> +<% if replicate_wild_ignore_table != 'UNSET' -%> +replicate-wild-ignore-table = <%= replicate_wild_ignore_table %> +<% end -%> <% if log_error != 'syslog' -%> -log_error = <%= log_error %> +log_error = <%= log_error %> <% end -%> -expire_logs_days = 10 -max_binlog_size = 100M <% if default_engine != 'UNSET' %> default-storage-engine = <%= default_engine %> <% end -%>