Skip to content

changes required to enable replication #762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,24 @@
$users = {},
$grants = {},
$databases = {},
$replication_enable = false,
$rep_server_id = '1',
$master_slave = 'master',

# Deprecated parameters
$enabled = undef,
$manage_service = undef,
$old_root_password = undef
) inherits mysql::params {

$replication_options = {
'mysqld' => {
'server-id' => $rep_server_id,
"rpl_semi_sync_${master_slave}_enabled" => '1',
'log-bin' => 'mysql-bin',
},
}

# Deprecated parameters.
if $enabled {
crit('This parameter has been renamed to service_enabled.')
Expand All @@ -47,12 +58,18 @@
warning('old_root_password is no longer used and will be removed in a future release')
}

$custom_options = $replication_enable ? {
true => mysql_deepmerge($override_options, $replication_options),
default => $override_options,
}

# Create a merged together set of options. Rightmost hashes win over left.
$options = mysql_deepmerge($mysql::params::default_options, $override_options)
$options = mysql_deepmerge($mysql::params::default_options, $custom_options)

Class['mysql::server::root_password'] -> Mysql::Db <| |>

include '::mysql::server::install'
include '::mysql::server::replication'
include '::mysql::server::config'
include '::mysql::server::installdb'
include '::mysql::server::service'
Expand All @@ -78,6 +95,7 @@
Class['mysql::server::config'] ->
Class['mysql::server::installdb'] ->
Class['mysql::server::service'] ->
Class['mysql::server::replication'] ->
Class['mysql::server::root_password'] ->
Class['mysql::server::providers'] ->
Anchor['mysql::server::end']
Expand Down
11 changes: 10 additions & 1 deletion manifests/server/installdb.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@

}

exec { 'remove-replication-params':
command => "sed -i '/server-id/ d' /usr/my.cnf; sed -i '/rpl_semi_sync_/ d' /usr/my.cnf",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/puppetlabs/puppetlabs-mysql/blob/master/manifests/params.pp has a variable for where the my.cnf file is located. Please use that instead of hardcoding a single location.

creates => "${datadir}/mysql",
path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin',
}

exec { 'mysql_install_db':
command => "mysql_install_db ${install_db_args}",
creates => "${datadir}/mysql",
logoutput => on_failure,
path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin',
require => Package['mysql-server'],
require => [
Package['mysql-server'],
Exec['remove-replication-params'],
],
}

if $mysql::server::restart {
Expand Down
41 changes: 41 additions & 0 deletions manifests/server/replication.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
class mysql::server::replication {
$master_slave = $mysql::server::master_slave
$server_id = $mysql::server::rep_server_id

if $mysql::server::replication_enable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make the inclusion of the replication class optional in the mysql::server, instead of protecting the contents. This makes it easier to compose manually, in those ugly edge cases.


exec { 'install-replication-plugin':
command => "mysql -u root -e \"INSTALL PLUGIN rpl_semi_sync_${mysql::server::master_slave} SONAME 'semisync_${mysql::server::master_slave}.so';\"",
path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin',
onlyif => 'test `grep -c rpl_semi_sync /usr/my.cnf` != 1',
}

ini_setting { 'server-id':
ensure => present,
path => '/usr/my.cnf',
section => 'mysqld',
setting => 'server-id',
value => $server_id,
require => Exec['install-replication-plugin'],
notify => Exec['restart-service'],
}

ini_setting { 'rpl_semi_sync_master':
ensure => present,
path => '/usr/my.cnf',
section => 'mysqld',
setting => "rpl_semi_sync_${master_slave}_enabled",
value => '1',
require => Exec['install-replication-plugin'],
notify => Exec['restart-service'],
}

exec { 'restart-service':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please match this to the pattern of https://github.com/puppetlabs/puppetlabs-mysql/blob/master/manifests/server/installdb.pp#L26-L30 to make this work together with the rest of the module across all platforms.

command => '/etc/init.d/mysql restart',
path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin',
refreshonly => true,
}
}

}